The goal of surveysd is to combine all necessary steps to use calibrated bootstrapping with custom estimation functions. This vignette will cover the usage of the most important functions. For insights in the theory used in this package, refer to vignette("methodology").

Load dummy data

A test data set based on data(eusilc, package = "laeken") can be created with demo.eusilc()

library(surveysd)
## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang
##    year povertyRisk gender  pWeight
## 1: 2010       FALSE female 504.5696
## 2: 2010       FALSE   male 504.5696
## 3: 2010       FALSE   male 504.5696
## 4: 2010       FALSE female 493.3824
## 5: 2010       FALSE   male 493.3824

Draw bootstrap replicates

Use stratified resampling without replacement to generate 10 samples. Those samples are consistent with respect to the reference periods.

dat_boot <- draw.bootstrap(eusilc, REP = 10, hid = "hid", weights = "pWeight", 
                           strata = "region", period = "year")

Calibrate bootstrap replicates

Calibrate each sample according to the distribution of gender (on a personal level) and region (on a household level).

dat_boot_calib <- recalib(dat_boot, conP.var = "gender", conH.var = "region")
## Convergence reached in 2 steps
## Convergence reached in 3 steps 
## 
## Convergence reached in 3 steps
## Convergence reached in 1 steps
## Convergence reached in 2 steps
## Convergence reached in 3 steps
## Convergence reached in 1 steps
## Convergence reached in 3 steps
## Convergence reached in 2 steps 
## 
## Convergence reached in 2 steps
##    year povertyRisk gender  pWeight       w1       w2       w3       w4
## 1: 2010       FALSE female 504.5696 1.456272 1.458504 1006.351 1007.677
## 2: 2010       FALSE   male 504.5696 1.456272 1.458504 1006.351 1007.677
## 3: 2010       FALSE   male 504.5696 1.456272 1.458504 1006.351 1007.677
## 4: 2011       FALSE female 504.5696 1.464918 1.563892 1012.509 1007.677
## 5: 2011       FALSE   male 504.5696 1.464918 1.563892 1012.509 1007.677

Estimate with respect to a grouping variable

Estimate relative amount of persons at risk of poverty per period and gender.

err.est <- calc.stError(dat_boot_calib, var = "povertyRisk", fun = weightedRatio, group = "gender")
err.est$Estimates
##    year     n       N gender val_povertyRisk stE_povertyRisk
## 1: 2010  7267 3979572   male        12.02660       0.4889923
## 2: 2010  7560 4202650 female        16.73351       0.5343574
## 3: 2010 14827 8182222   <NA>        14.44422       0.4300383
## 4: 2011  7267 3979572   male        12.81921       0.4693456
## 5: 2011  7560 4202650 female        16.62488       0.4896667
## 6: 2011 14827 8182222   <NA>        14.77393       0.4166631

The output contains estimates (val_povertyRisk) as well as standard errors (stE_povertyRisk) measured in percent.

Estimate with respect to several variables

Estimate relative amount of persons at risk of poverty per period for each region, gender, and combination of both.

group <- list("gender", "region", c("gender", "region"))
err.est <- calc.stError(dat_boot_calib, var = "povertyRisk", fun = weightedRatio, group = group)
head(err.est$Estimates)
##    year   n        N gender     region val_povertyRisk stE_povertyRisk
## 1: 2010 261 122741.8   male Burgenland       17.414524        3.175991
## 2: 2010 288 137822.2 female Burgenland       21.432598        4.118974
## 3: 2010 359 182732.9   male Vorarlberg       12.973259        2.147179
## 4: 2010 374 194622.1 female Vorarlberg       19.883637        2.682142
## 5: 2010 440 253143.7   male   Salzburg        9.156964        2.080256
## 6: 2010 484 282307.3 female   Salzburg       17.939382        3.167576