tests/poisson.R

## check poisson sampling
library(survey)
data(api)
set.seed(2021-7-15)
apipop$prob<-apipop$api00/1000
insample<-rbinom(nrow(apipop),1,apipop$prob)
apipois<-apipop[insample,]
des<-svydesign(id=~1, prob=~prob, pps=poisson_sampling(apipois$prob), data=apipois)

stopifnot(isTRUE(all.equal(
 as.vector(SE(svytotal(~api00,design=des))),
 as.vector(sqrt(sum( (apipois$api00*weights(des))^2*(1-apipois$prob))))
 )))
 

Try the survey package in your browser

Any scripts or data that you put into this service are public.

survey documentation built on July 19, 2021, 9:06 a.m.