bschneidr / fastsurvey

A fork of the `survey` R package, using {Rcpp}
7 stars 0 forks source link

Handle stage-specific calibration #1

Closed bschneidr closed 2 years ago

bschneidr commented 2 years ago

Here's the functionality that needs to be added from multistage() to arma_multistage(): https://github.com/bschneidr/fastsurvey/blob/face51166adc4530b2da61052c7edd4f64286c05/R/multistage.R#L358-L367

Almost nobody uses this functionality, but it is probably useful to a few users and it does seem like it can be supported with Rcpp.

Some documentation to help with this:

The test example from when this functionality was firsted added:

https://github.com/cran/survey/commit/c05f7a5ba7465a3a79a5b4f0206b1c741dbca27a#diff-7382879dc500f074347b2f7f70931c40c19f72a4b773e4d7739bbb6f65882ebdR1-R29

The commit for version 3.0 where this stage-specific calibration functionality was added: https://github.com/cran/survey/commit/c05f7a5ba7465a3a79a5b4f0206b1c741dbca27a Reading through this commit could be helpful for finding examples to use for testing and for updating arma_multistage().

Some additional documentation on stage-specific calibration was added in 3.11-2: https://github.com/cran/survey/commit/fce58055229ad1d6db17c4a4e41011517dea50a3

bschneidr commented 2 years ago

Ultimately, stage-specific calibration is just too tricky to handle with multistage_rcpp() in its current implementation in the survey package, which makes heavy use of lists and special QR objects from the qr() function. Given that very few users ultimately use the stage-specific calibration functionality, I'm not going down that rabbit hole for now. So if there's stage-specific g-calibration, then multistage() will be used instead of multistage_rcpp().

https://github.com/bschneidr/fastsurvey/blob/225e0ae70a3c603996e5744c8b054a8ddd29669d/R/multistage.R#L342-L350

The flag of whether to use Rcpp use_rcpp will be set to TRUE unless svyrecvar() identifies the use of g-calibration at any stage beyond 0.

https://github.com/bschneidr/fastsurvey/blob/225e0ae70a3c603996e5744c8b054a8ddd29669d/R/multistage.R#L305-L318