Draw from a given list according to empirical distribution

I have two lists, where each time I have age-income vectors. Given the distribution of age in the first list, I would like to draw a sample with the similar distribution of age from the second list (and then compare ultimately distributions of incomes in list 1 and in the drawn sample).

While I can easily get empirical distribution of age from the list 1, how can I draw a similar distribution from the 2nd given list of age values?

Thanks a lot!

• A couple of data samples and maybe initial attempts would improve the question. – gwr Jun 21 '15 at 20:25

Let's generate two dummy samples of data of size 100 that match the form you have given:

sample1 = {
RandomInteger[ {20, 60}, 100], (* age *)
RandomReal[ {1000, 5000}, 100] (* income *)
} // Transpose; (* make tuples *)

sample2 = {
RandomInteger[ {30, 50}, 100], (* age *)
RandomReal[ {3000, 7000}, 100] (* income *)
} // Transpose; (* make tuples *)

Now we extract the ages from group1 and generate a smooth Kernel distribution for it:

ageDistribution1 = KernelMixtureDistribution @ sample1[[All, 1]]

This can be used to caculate sampling weights. The weights simple are the probability density for any age of the second group using the Smooth Kernel Distribution according to the first groups data:

weights = 10.^3 PDF[ ageDistribution1, #] & /@ sample2[[All, 1]];
(* the weights are scaled which helps numerics I believe *)

Now one can simply sample from the 2nd group using the age distribution of the first group:

sample = With[
{ sampleSize = 10 }, (* or another value less than group size *)
RandomSample[ weights -> sample2, sampleSize ]
];
• FANTASTIC!! Thanks a lot!! I did not know how to make steps "weights" and "sample" (I am quite new to Mathematica)... If you only saw pages of codes through which I tried to implement this. Thank you very much!! – Kass Jun 21 '15 at 19:53
• Great if that helped. Btw you may also upvote...hint,hint. ;-) – gwr Jun 21 '15 at 19:54
• Rhh I would really love to do this, upvote, but it tells me that I need 15 reputations and apparently I don't have them. Guys around -- please upvote this answer!! – Kass Jun 21 '15 at 19:56
• @gwr I like you answer! – Bob Brooks Dec 2 '16 at 14:50