Let's say that I have a categorical variable which can take the values A, B, C and D. How can I generate 10000 random data points and control for the frequency of each? For example:
A = 10% B = 20% C = 65% D = 5%
Any ideas how I can do this?
|
Let's say that I have a categorical variable which can take the values A, B, C and D. How can I generate 10000 random data points and control for the frequency of each? For example: A = 10% B = 20% C = 65% D = 5% Any ideas how I can do this? |
||||
|
|
|
Do you want the proportions in the sample to be exactly the proportions stated? or to represent the idea of sampling from a very large population with those proportions (so the sample proportions will be close but not exact)? If you want the exact proportions then you can follow Brandon's suggestion and use the R If you want to sample from the population, but not restrict the proportions to be exact then you can still use the
|
|||
|
|
|
Using R (http://cran.r-project.org/). All I'm doing here is creating a random list with the proportions you specified.
/me Waits patiently for argument over how truly random this is |
|||||
|
I have no doubt this is truly random. I mean, to the extent that |
|||||||||
|
|
If you're a SAS user, recent versions provide a similar ability to pull from what it calls a "table" distribution - which is what you are looking for, as part of the Rand() function. See http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001466748.htm |
|||
|
|