R – Reporting Average Marginal Effects of Survey-Weighted Logit Models

logisticmarginal-effectrregressionsurvey-weights

I'm working with survey data of a complex sample to estimate binary outcome models. I am trying to report average marginal effects of a logit model, which I estimated through svyglm of the survey package in R. However, I get the following error when I use margins from the package of the same name:

margins(fit, design = lapop) %>% summary()

Error in h(simpleError(msg, call)) : error in evaluating the argument 'object' in selecting a method for function 'summary': arguments imply differing number of rows: 6068, 6054

Seems it is not the summary function, since the error pops up when executing the margins command with its arguments. I have tried to simply ignore the survey weights at all and shows me equal coefficients and AMEs but not standard errors. Obviously, I cannot present this work by ignoring the survey weights. So I guess what I really need is the standard errors.

I have been reading on the topic and have found no clear solution, I suspect it might have something to do with missing values of the X in the model, but as with any other linear model, R should be just working with complete cases.

I'm not sure if anybody knows anything about this, or if I should simply just report AMEs without standard errors (and thus without p-values). I have uploaded a MWE if anyone is interested, which can be found here.

Best Answer

What version of the margins package are you using? In 0.3.26 (which dates from January) there's a margins.svyglm method, and it seems to work

> fit<-svyglm(api00~ell+meals+mobility, design=dclus2)
> margins(fit)
Note: Estimating marginal effects without survey weights. Specify 'design' to adjust for weighting.
Average marginal effects
svyglm(formula = api00 ~ ell + meals + mobility, design = dclus2)

    ell  meals mobility
 -2.059 -1.777   0.3253
> margins(fit, design=dclus2)
Average marginal effects (survey-weighted)
svyglm(formula = api00 ~ ell + meals + mobility, design = dclus2)

    ell  meals mobility
 -2.059 -1.777   0.3253
> summary(margins(fit, design=dclus2))
   factor     AME     SE       z      p   lower  upper
      ell -2.0592 1.4076 -1.4629 0.1435 -4.8180 0.6997
    meals -1.7772 1.1053 -1.6078 0.1079 -3.9436 0.3892
 mobility  0.3253 0.5305  0.6131 0.5398 -0.7145 1.3650

If your problem is missing data you can subset those data out

fit2<-svyglm(ctol ~ y16 + age,
             design = lapop[-fit$na.action,],
             family = quasibinomial(link = 'logit'))
margins(fit2,design=lapop[-fit$na.action,])
Related Question