use weights in mediation package

Hi. I have been trying to use themediation package to do a mediation analysis, with models from the survey package.

wt <- svydesign(id = ~id, weights = ~weights, strata = ~strata, data = wt_pre, nest = T)

model.M  <- svyglm(a ~ b+c, wt, family = quasibinomial())
model.Y <- svyglm(y ~ a+b+c, wt, family = quasibinomial())

results <- mediate(model.M, model.Y, treat="b", mediator="a", boot=TRUE, sims=500)

Returns error message:
ERROR in R: Error in statistic(data, original, ...) : unsupported glm family

Any advice to fix it? Thx.

Partial function signature for svyglm

survexp(formula, data, weights, subset, na.action, rmap, times,
method=c("ederer", "hakulinen", "conditional", "individual.h",
"individual.s"), \dots

Doesn't include the argument given. That explains the error from a syntax perspective. Details provides the reason

Quasilikelihood-based inferences are not allowed for the mediator model because the functional form must be exactly specified for the estimation algorithm to work. The ’binomial’ family can only be used for binary response mediators and cannot be used for multiple-trial responses. This is due to conflicts between how the latter type of models are implemented in glm and how ’mediate’ is currently written.

Thanks for the explanation. Is there any method to combine the mediation package with survey weights?

Appears so (not my area of interest, though)

The prior weights in the mediator and outcome models are taken as sampling weights and the estimated effects will be weighted averages when non-NULL weights are used in fitting ’model.m’ and ’model.y’. This will be useful when data does not come from a simple random sample, for example.

There is a weights argument in mediate().

Thanks for the explanation. I used weights()function to get the weights from survey design, then use this weights argument in mediate(). I am wondering if this process is right.

I don't want to give you false comfort by offering an opinion because this isn't something that I've done. I'd suggest reading the vignette and working some of the examples to understand how the weights argument is to be used.

Thanks for your advice. I will try to understand how it works.

1 Like