[R] Comparison of means in survey package
Simon Kiss
sjkiss at gmail.com
Thu Aug 18 21:25:33 CEST 2011
Dear list colleagues,
I'm trying to come up with a test question for undergraduates to illustrate comparison of means from a complex survey design. The data for the example looks roughly like this:
mytest<-data.frame(harper=rnorm(500, mean=60, sd=1), party=sample(c("BQ", "NDP", "Conservative", "Liberal", "None", NA), size=500, replace=TRUE), natwgt=sample(c(0.88, 0.99, 1.43, 1.22, 1.1), size=500, replace=TRUE), gender=sample(c("Male", "Female"), size=500, replace=TRUE))
Using svyby I can get the means for each group of interest (primarily the party variable), but I can't get further to actually do the comparison of means. I saw a reference on the help listserv to the effect that the survey package does not do ttests and that one should use svyglm. However, that was in 2009 and I see that there's a command, svytteset in the package which seems to be on point. However, when I've tried that command I can't get it to work: it returns the following error message:
t = NaN, df = 3255, p-value = NA
alternative hypothesis: true difference in mean is not equal to 0
sample estimates:
difference in mean
38.80387
This is from my data, not the code above. Would there also be a way just to do the comparison of means test between two subgroups of a factor, and not just on all factor levels?
Using 2.13 on mac os 10.6 and the latest version of survey package.
Yours, Simon Kiss
*********************************
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606
More information about the R-help
mailing list