############################################## # # EXEMPLAR 2 - uncorrected data # HOW TO USE THIS FILE # A text version of this file (ex2.R) is also available which can just be sourced # into the R program # This file is intended for you to use interactively by pasting # the red bits into R # Comments are in black - red bits are commands that can be pasted # # ######### ANY TEXT AFTER THE # CHARACTER ARE TREATED AS COMMENTS # # data stored in c:/GR/aprojects/peas/web/exemp2/data/.Rdata # this file is c:/GR/aprojects/peas/web/exemp2/program_code/ex2_R.rtf # ############################################## # # library(survey) # # shs.des_nc <- svydesign(id=~PSU, weights=~IND_WT,strata=~STRATUM,data=shs_nc) # # if you are smart at R you can use this code to work out which # PSUs are causing the problem # First get unique combinations of PSU and stratum # and then work out for which there are >1 startum check1<-shs_nc[!duplicated(paste(shs_nc$PSU,shs_nc$STRATUM)),c(1,12)] check2<-table(check1[,1]) check2[check2>1] # # but you can force nesting # shs.des_nc <- svydesign(id=~PSU, weights=~IND_WT,strata=~STRATUM,data=shs_nc,nest=T) svymean(~INTUSE,shs.des_nc,deff=T) # # this fails from a lonely PSU, need to try other options options(survey.lonely.psu='removee') svymean(~INTUSE,shs.des_nc,deff=T) options(survey.lonely.psu='adjust') svymean(~INTUSE,shs.des_nc,deff=T) warnings() #