1## check poisson sampling 2library(survey) 3data(api) 4set.seed(2021-7-15) 5apipop$prob<-apipop$api00/1000 6insample<-rbinom(nrow(apipop),1,apipop$prob) 7apipois<-apipop[insample,] 8des<-svydesign(id=~1, prob=~prob, pps=poisson_sampling(apipois$prob), data=apipois) 9 10stopifnot(isTRUE(all.equal( 11 as.vector(SE(svytotal(~api00,design=des))), 12 as.vector(sqrt(sum( (apipois$api00*weights(des))^2*(1-apipois$prob)))) 13 ))) 14