############################missing data############################ library(survey) ## generate data set.seed(100) x<-rnorm(20) ex.data<-as.data.frame(x) ex.data[5,]<-NA ## calculate mean and total #5% sample is missing, so presumably about 5% of the population #has missing data. Expect the total over the non-missing part of the population #to be 5% smaller than the total over the whole population des <- svydesign(ids=~1, data=ex.data,fpc=rep(100,20)) smean<-svymean(~x, design=des, na.rm=TRUE) stotal<-svytotal(~x, design=des, na.rm=TRUE) smean stotal ##want to do reweighting, so that the totals estimate the whole ##population,missing and non-missing rwt<-calibrate(subset(des,!is.na(x)),formula=~1,population=100) svymean(~x,rwt) svytotal(~x,rwt)