statdivlab / rigr

Regression, Inference, and General Data Analysis Tools for R
Other
10 stars 3 forks source link

rigr + survey weights (advice for future users) #150

Open adw96 opened 1 year ago

adw96 commented 1 year ago

The issue here is that the documentation for weights should be updated to give guidance on using survey weights.

Someone wrote recently about using survey weights from survey::svydesign() as the input to the weights argument for rigr::regress(). Their reasoning for doing so was that rigr gives robust errors, which they wanted.

It turns out that survey:: svyglm does give robust standard errors, even though they aren't labeled as such. From the docs: "svyglm always returns 'model-robust' standard errors; the Horvitz-Thompson-type standard errors used everywhere in the survey package are a generalisation of the model-robust 'sandwich' estimators. In particular, a quasi-Poisson svyglm will return correct standard errors for relative risk regression models."

Therefore, when working with survey weights, we recommend that you just use svyglm(), not regress(), and keep in mind that you do get robust errors from svyglm().

FYI, the only reason why standard errors differ between svyglm() and regress() with svydesign(id=~1, ...) is because From Thomas Lumley "regress() [covariances] is scaled by n/(n-p), where p is the number of predictors in the model. This is not used by svyglm() because it doesn't generalise well to cluster sampling."

Similarly, svycontrast can be used instead of lincom with svyglm objects.

I hope this helps folx working with survey weights in future!