I have been studying random-effects logstic regression, and I have a problem. I find that, whether I use -xtglm-, -meglm- or -sem- to fit these, I do not seem to be able to use -margins- after the model fit to estimate counterfactual marginal proportions for the random-effects model under scenarios specified using the -at()- option. And this is deterring me from using random-effects models more, because not many non-statisticians understand odds ratios, but a lot understand counterfactual marginal proportions under different scenarios and their differences (also known as population attributable risks).
For instance, if I use the Bangladeshi fertility data used in [R] -meglm- and [R] -meglm postestimation-, I type
use http://www.stata-press.com/data/r13/bangladesh, clear
meglm c_use urban age child* || district: urban, family(bernoulli) link(logit) eform
and the model runs as advertised, regressing contraceptive use with respect to the predictors and displaying the odds ratios.. However, if I then try to estimate the marginal rate
of contraceptive use that would exist if all these women were urbanized and other things stayed the same, by typing
margins, at(urban=1) predict(mu)
then Stata protests with the error message
prediction is a function of possibly stochastic quantities other than e(b)
r(498);
I realise that the calculation of conditional means under a random-effects model with a non-linear link function involves numerical quadrature over the range of the random effects. However, if I type
predict yhat, mu
then Stata replies
(predictions based on fixed effects and posterior means of random effects)
(using 7 quadrature points)
and creates a sensible-looking conditional-mean variable under the model, which it claims has been calculated using quadrature. So the problem does not seem to be the fact that "prediction is a function of possibly stochastic quantities other than e(b)", at least to me. It seems to be -margins- that is finding a problem, not -predict- (which is used by -margins-).
Is there something here that I am missing? It bothers me that Stata's random-effects logistic models apparently cannot be used to calculate population uattributable and attributable risks and fractions. Can they?
Best wishes (and thanks in advance)
Roger
For instance, if I use the Bangladeshi fertility data used in [R] -meglm- and [R] -meglm postestimation-, I type
use http://www.stata-press.com/data/r13/bangladesh, clear
meglm c_use urban age child* || district: urban, family(bernoulli) link(logit) eform
and the model runs as advertised, regressing contraceptive use with respect to the predictors and displaying the odds ratios.. However, if I then try to estimate the marginal rate
of contraceptive use that would exist if all these women were urbanized and other things stayed the same, by typing
margins, at(urban=1) predict(mu)
then Stata protests with the error message
prediction is a function of possibly stochastic quantities other than e(b)
r(498);
I realise that the calculation of conditional means under a random-effects model with a non-linear link function involves numerical quadrature over the range of the random effects. However, if I type
predict yhat, mu
then Stata replies
(predictions based on fixed effects and posterior means of random effects)
(using 7 quadrature points)
and creates a sensible-looking conditional-mean variable under the model, which it claims has been calculated using quadrature. So the problem does not seem to be the fact that "prediction is a function of possibly stochastic quantities other than e(b)", at least to me. It seems to be -margins- that is finding a problem, not -predict- (which is used by -margins-).
Is there something here that I am missing? It bothers me that Stata's random-effects logistic models apparently cannot be used to calculate population uattributable and attributable risks and fractions. Can they?
Best wishes (and thanks in advance)
Roger
Comment