Re: discrete frequency distribution
- To: mathgroup at smc.vnet.net
- Subject: [mg43130] Re: discrete frequency distribution
- From: Bill Rowe <listuser at earthlink.net>
- Date: Wed, 13 Aug 2003 07:50:00 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 8/12/03 at 4:43 AM, schmedes at rz.uni-potsdam.de (Jan Schmedes) wrote: > i have a set of points which describe a varaible and his frequency, e.g. > counting the age of N people in "age-bins" 0-10 a,10-20 a,20-30 a,... . > Given this discrete frequency distribution i want to produce random > numbers. > How could i do this? The basic trick is to note the cumulative distribution function for any distribution is uniform over 0 to 1. So, what you need to do order the data in a convient order and sum the frequencies. For example, Suppose you had three values a, b, and c with frequencies of 1/6,1/2 and 1/3. Then you could order the values as say a 1/6 b 2/3 c 1 Where the numbers are the cumulative frequencies. To get the desired discrete distribution simply generate a random uniform deviate using Random[] and use something equivalent to the following function f[x_]:= a/; x<=1/6 f[x_]:=b/; 1/6<x && x<=2/3 f[x_]:=c/;2/3<x && x<=1 Then f[Random[]] will generate the desired distribution. Note, although this will work and is likely be fine if you only have a few discrete values, the way I've written f is not the most efficient for a large number of number of discrete values