Borexino
Borexino

Reputation: 842

How to use sample weights in GAM (mgcv) on survey data for Logit regression?

I'm interesting in performing a GAM regression on data from a national wide survey which presents sample weights. I read with interest this post. I selected my vars of interest generating a DF:

nhanesAnalysis <- nhanesDemo %>%
                    select(fpl,
                           age,
                           gender,
                           persWeight,
                           psu,
                           strata)

Than, for what I understood, I generated a weighted DF with the following code:

library(survey)    
nhanesDesign <- svydesign(    id      = ~psu,
                              strata  = ~strata,
                              weights = ~persWeight,
                              nest    = TRUE,
                              data    = nhanesAnalysis)

Let's say that I would select only subjects with age≥30:

ageDesign <- subset(nhanesDesign, age >= 30)

Now, I would fit a GAM model (fpl ~ s(age) + gender) with mgcv package. Is it possible to do so with the weights argument or using svydesign object ageDesign ?

EDIT

I was wondering if is it correct to extrapolate computed weights from the an svyglm object and use it for weights argument in GAM.

Upvotes: 10

Views: 2107

Answers (1)

Thomas Lumley
Thomas Lumley

Reputation: 106

This is more difficult than it looks. There are two issues

  1. You want to get the right amount of smoothing
  2. You want valid standard errors.

Just giving the sampling weights to mgcv::gam() won't do either of these: gam() treats the weights as frequency weights and so will think it has a lot more data than it actually has. You will get undersmoothing and underestimated standard errors because of the weights, and you will also likely get underestimated standard errors because of the cluster sampling.

The simple work-around is to use regression splines (splines package) instead. These aren't quite as good as the penalised splines used by mgcv, but the difference usually isn't a big deal, and they work straightforwardly with svyglm. You do need to choose how many degrees of freedom to assign.

library(splines)
svglm(fpl ~ ns(age,4) + gender, design = nhanesDesign)

Upvotes: 8

Related Questions