data(api)
## population
mean(apipop$api00)
quantile(apipop$api00,c(.25,.5,.75))
var(apipop$api00)
sum(apipop$enroll)
sum(apipop$api.stu)/sum(apipop$enroll)
## one-stage cluster sample
dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
summary(dclus1)
svymean(~api00, dclus1)
svyquantile(~api00, dclus1, c(.25,.5,.75))
svyvar(~api00, dclus1)
svytotal(~enroll, dclus1)
svyratio(~api.stu, ~enroll, dclus1)
#stratified sample
dstrat<-svydesign(id=~1, strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
summary(dstrat)
svymean(~api00, dstrat)
svyquantile(~api00, dstrat, c(.25,.5,.75))
svyvar(~api00, dstrat)
svytotal(~enroll, dstrat)
svyratio(~api.stu, ~enroll, dstrat)
# replicate weights - jackknife (this is slow)
jkstrat<-as.svrepdesign(dstrat)
summary(jkstrat)
svrepmean(~api00, jkstrat)
svrepquantile(~api00, jkstrat, c(.25,.5,.75))
svreptotal(~enroll, jkstrat)
svrepratio(~api.stu, ~enroll, jkstrat)
# BRR method
data(scd)
repweights<-2*cbind(c(1,0,1,0,1,0), c(1,0,0,1,0,1), c(0,1,1,0,0,1),
c(0,1,0,1,1,0))
scdrep<-svrepdesign(data=scd, type="BRR", repweights=repweights)
svrepmean(~arrests+alive, design=scdrep)
Run the code above in your browser using DataLab