I need to find a way to sample groups so that the observed proportions match the expected ones. I would like to keep as many of the observations in each group as possible.
Simple example: Group A = 302 (60.3%) Group B = 199 (39.7%)
The proportions I expect are 46.6% and 53.4%, so in this instance I would keep all the observations in Group B and sample Group A by 0.576 to get 174 observations. Is this correct?
Is there anyway to write a rule in SAS or R that would give you the appropriate sampling rate for n groups? My actual problem involves 14 groups with counts ranging from 2 to 77:
Group A = 77 , observed = 21.51%, expected = 15.10%
Group B = 5 , observed = 1.4%, expected = 0.54%
Group C = 2, observed = 0.56%, expected = 1.62%
etc.
Many thanks for your help.
I believe you can use PROC SURVEYSELECT to achieve this. You need to store the expected sampling rate per group in a separate dataset, then apply the the option "SAMPRATE=SAS data set" in the PROC SURVEYSELECT statement. See the online documentation on this procedure for more information.
Here is a dodgy little function to play with:
minsamp <- function(obs,expect) {
## get the groups where the number of people available
## isn't enough to simply multiply it out
underrep <- obs[which(obs - expect * sum(obs) < 0)]
# name of the smallest underrepresented group
urname <- names(which.min(underrep))
# get the final result
round(expect * (obs[urname]/expect[urname]))
}
And an example (based on your simple example:
obs <- c(a=302,b=199)
expect <- c(a=0.466,b=0.534)
> minsamp(obs,expect)
a b
174 199
And you can see it worked:
> prop.table(minsamp(obs,expect))
a b
0.4664879 0.5335121
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With