After defining your survey dataset (please refer back to ‘survey’ package blog (1) & (2) ), you could use the functions below to describe your survey data and estimate population.
Let’s still use apiclus1 data. After svydesign() function, you have a designed survey dataset, dclus1, which we designed in the last week. In this dataset, there are several variables we are going to mention in the following syntax.
api00: continuous variable, integer
api99: continuous variable, integer
enroll: continuous variable, integer
sch.wide: categorical variable, which is also recognized as factor in R
stype: categorical variable, which is also recognized as factor in R
- svymean()
svymean(~api00, dclus1) #calculate survey mean of variable api00 in defined survey dataset dclus1
- svyby()
svyby(~api99, ~stype, dclus1, svymean)# calculate survey mean of variable api99 by variable stype
- svychisq()
svychisq(~sch.wide+stype, dclus1) #contingency tables and chisquared tests between sch.wide and stype. The default (statistic=”F”) is the Rao-Scott second-order correction. And there are other options for “statistics”, such as “Wald”, “Lincom”.
- svyhist()
svyhist(~enroll, dclus1, main=”Survey weighted”,col=”purple”,ylim=c(0,1.3e-3)) #create a weighted histogram graph for variable enroll, named as “Survey weighted”, colored as purple, range of y axis is from zero to 0.0013
- svyboxplot()
svyboxplot(enroll~stype,dclus1,all.outliers=TRUE) #create a boxplot for variable enroll, grouped by variable stype, and keep all the outliers
- svyplot()
svyplot(api00~api99, design=dclus1, style=”bubble”) # create a scatter plot graph for api00 and api99 using bubble as the scatter shape