DESIGN.OBJECT <-svydesign(id =~1, weights =~WEIGHTVAR, fpc =~N, data=DF)# WEIGHTVAR = variable containing sampling weights# N = variable that contains finite population size
(Some) R Commands for Survey Estimation
Must first use svydesign() to make survey design object. Variables are y, x1, x2.
Estimate a mean:
svymean(~y, design=DESIGN.OBJECT) # DESIGN.OBJECT = design object from svydesign()
Estimate a proportion:
# proportions at each level of the factorsvymean(~factor(x1), design=DESIGN.OBJECT)# if variable is 1/0 or TRUE/FALSE can use svymean() to get proportionsvymean(~x1, design=DESIGN.OBJECT)
Estimate a total:
svytotal(~x1, design=DESIGN.OBJECT)
Linear and logistic regression:
# linear regression (y on x1 and x2)svyglm(y ~ x1 + x2, design=DESIGN.OBJECT)# logistic regression (x1 on x2)svyglm(x1 ~ x2, family=binomial(link="logit"), design=DESIGN.OBJECT)