library(survey) source("c:/courses/st446/rcode/confintt.r") # One-stage cluster sample from Figure 8b N =100 n =10 M =4 wgt = N/n y <- c(20,15,25,21,31,31,37,37,19,24,17,24,33,25,31,34,32,32,37,38, 29,38,40,38,41,44,49,41,34,39,33,34,50,45,48,50,49,44,52,52) clusterid <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6, 7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10) fpc <- c(rep(N,n*M)) Fig8b <- data.frame(cbind(clusterid,y,fpc)) dsgn8b <- svydesign(ids=~clusterid,weights=c(rep(wgt,n*M)),fpc=~fpc,data=Fig8b) esttotal <- svytotal(~y,design=dsgn8b) print(esttotal,digits=15) confint.t(esttotal,level=.95,tdf=n-1) estmean <- svymean(~y,design=dsgn8b) print(estmean,digits=15) confint.t(estmean,level=.95,tdf=n-1)