library(survey) source("c:/courses/st446/rcode/confintt.r") domain <- read.table("c://courses/st446/Rcode/agsrs.txt",header=T) N=3078 # population size n=300 # sample size fpc <- c(rep(N,n)) domaindt <- cbind(domain,fpc) domaindat <- data.frame(domaindt) #domaindat # Create the sampling design domain_dsgn <- svydesign(data=domaindat, id=~1, fpc=~fpc ) domain_dsgn # Estimation of the mean for each region (domain) # Estimation of domain totals # Domain = NC esttotal <- svytotal(~ACRES92,subset(domain_dsgn,REGION=="NC")) esttotal confint(esttotal,df=n-1) # Domain = NE esttotal <- svytotal(~ACRES92,subset(domain_dsgn,REGION=="NE")) esttotal confint(esttotal,df=n-1) # Domain = S esttotal <- svytotal(~ACRES92,subset(domain_dsgn,REGION=="S")) esttotal confint(esttotal,df=n-1) # Domain = W esttotal <- svytotal(~ACRES92,subset(domain_dsgn,REGION=="W")) esttotal confint(esttotal,df=n-1) # Estimation of domain means # Domain = NC estmean <- svymean(~ACRES92,subset(domain_dsgn,REGION=="NC")) estmean confint(estmean,df=n-1) # Domain = NE estmean <- svymean(~ACRES92,subset(domain_dsgn,REGION=="NE")) estmean confint(estmean,df=n-1) # Domain = S estmean <- svymean(~ACRES92,subset(domain_dsgn,REGION=="S")) estmean confint(estmean,df=n-1) # Domain = W estmean <- svymean(~ACRES92,subset(domain_dsgn,REGION=="W")) estmean confint(estmean,df=n-1)