Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to calculate marginal proportions after a random-effects logistic regression?

    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

  • #2
    have you tried
    Code:
    margins, dydx(*) predict(fixedonly mu)
    Probably dydx(*) is not needed after meglm, but I always put it because some commands sometimes have other predetermined margin.
    Alfonso Sanchez-Penalver

    Comment


    • #3
      Thanks to Alfonso for the suggestion. I have tried

      margins, at(urban=1) predict(fixedonly mu)

      and it works, but it does not answer the question I wanted to answer.

      I wanted to know the prevalence of contraceptive use in a fantasy scenario, where all the women are urbanized, but where everything else (including the distribution of random district effects) stays the same as in the real world. The -fixedonly- suboption, by contrast, gives the prevalence of contraceptive use in a scenario where all the women are urbanized, and the random district effects are all set to zero (so every district is an average district), but everything else stays the same. With a non-linear link function (such as the logit), the prevalence in all districts combined will not be the same thing as the prevalence in an average district, where the random district effect (a hidden varriable constant within district) is set to zero.

      Fortunately, the conditional prevalence, for each combination of X-values, can be estimated using numerical quadrature over the range of the random district effect. Unfortunately, -predict- seems to know this, and -margins- seems not to. (If I am not mistaken.)

      Best wishes

      Roger

      Comment


      • #4
        predicted mean outcomes after meglm and gsem are computed using empirical Bayes' (EB) estimates for the random effects/latent variables. The EB estimates are computed using the fitted model and require the original data. Using the at() options with margins

        Code:
        margins, at(urban=1) predict(fixedonly mu)
        causes margins to change the data temporarily before calling predict, but predict will complain because it needs the original data.

        Roger's last statement is partially correct.

        Fortunately, the conditional prevalence, for each combination of X-values, can be estimated using numerical quadrature over the range of the random district effect. Unfortunately, -predict- seems to know this, and -margins- seems not to. (If I am not mistaken.)
        predict is using EB estimates instead of computing the mean marginally with respect to the random effects, otherwise margins would have no trouble computing what Roger wants.

        predicted mean outcomes that are marginal with respect to random effects/latent variables is on my wish list for a future Stata.

        Comment


        • #5
          Thanks to Jeff for clarifying this issue. I too would like to see predicted mean outcomes that are marginal with respect to random effects/latent variables in a future Stata. After all, not many people understand odds and their ratios, but most people can understand counterfactual scenario proportions and their differences. (Or even their ratios, which are known as population unattributable fractions and are estimated using the SSC packages -punaf- and -punafcc-..)

          Best wishes

          Roger

          Comment

          Working...
          X