R Under development (unstable) (2024-03-08 r86070 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## check poisson sampling > library(survey) Loading required package: grid Loading required package: Matrix Loading required package: survival Attaching package: 'survey' The following object is masked from 'package:graphics': dotchart > 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)))) + ))) > > > proc.time() user system elapsed 1.04 0.17 1.20