Announcement

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

  • Calling predict & margins after bayesmh / Bayesian multi-level random effects analysis

    Following the examples of e.g. https://www.stata.com/features/overv...evel-modeling/ I am estimating a hierarchical model with random effects of a categorical variable (here: foreign) and its interaction with a dummy I am interested in (here: dummy). Simplified, my analysis looks like this:

    Code:
    webuse auto, clear
    gen dummy = runiformint(0,1)
    
    bayesmh price dummy U0[foreign] c.dummy#U1[foreign], ///
         likelihood(normal({var_0})) ///
         prior({price: _cons dummy}, normal(0,10)) ///
         prior({var_U0 var_U1 var_0}, igamma(2.001, 1.001) split) ///
         block({var_0} {var_U0} {var_U1}) ///
         showreffects ///
         rseed(38593150)
    I want to generate fitted values and calculate marginal effects for the categorical variable (foreign) and its interaction with the dummy (dummy). In frequentist analysis such as "regress", I would simply use the commands "predict" and "margins". However, it seems like these options are not supported for bayesmh. Is there an alternative in Stata (18)? The code & errors for predict and margins (after running the model above):

    Code:
    predit p_price
    Error: requested action not valid after most recent estimation command r(321);

    Code:
    margins foreign
    Error: last estimates not found r(301);

    Furthermore, I'd also be thankful for someone showing me how to calculate the marginal effects of the interaction in this setting, i.e. whether it's possible to refer to the object simply as "c.dummy#U1[foreign]".
    Last edited by Alexander Busch; 10 Jun 2024, 02:19.

  • #2
    Code:
    help bayesian_postestimation
    for what post estimation tools are available for bayesmh.

    Comment


    • #3
      Thank you for the reference, my question regarding predicting values is solved. The helpme also lead me to this old thread on using bayesmh in the style of margins and interactions: https://www.statalist.org/forums/for...ian-estimation

      I also realise that I was not as precise with my language as I could have been - I was more interested in linear combinations ("lincom" for frequentist usage in Stata) of my interaction and baseline, which makes more sense in this context than just a general reference to marginal effects.

      For completeness, I include the working code below. Note that I also now use the saving() option to run bayespredict:


      Code:
      webuse auto, clear
      gen dummy = runiformint(0,1)
      
      bayesmh price dummy U0[foreign] c.dummy#U1[foreign], ///
           likelihood(normal({var_0})) ///
           prior({price: _cons dummy}, normal(0,10)) ///
           prior({var_U0 var_U1 var_0}, igamma(2.001, 1.001) split) ///
           block({var_0} {var_U0} {var_U1}) ///
           showreffects ///
           saving(results, replace) ///
           rseed(38593150)
      
      bayespredict price_p , mean rseed(38593150)
      
      bayesstats summary ({price:dummy})
      bayesstats summary ({U1[1.foreign]})
      
      bayesstats summary ({price:dummy}+{U1[1.foreign]})
      bayesstats summary ({price:dummy}+{U1[0.foreign]})

      Comment


      • #4
        Hi everyone, I am using linear mixed models to analyse foetal growth data (e.g., head circumference, HC). From the LMM, I am predicting the mean HC at different gestational ages using the margins command.

        However, I want to predict the median, 10th and 3rd centile head circumference. How can I do this?

        Please see my code for mean prediction. Note, hivpositive (HIV status) is my main exposure which is inserted in the model as a covariate, and I am predicting the means by HIV status.

        Linear mixed model:
        mixed HC_mm i.hivpositive ///
        age_mat ib1.bmicat_bas_mat i.smoke_mat i.alcohol_mat i.nullipara_cat i.maristat ///
        i.sex_foet i.ironpreg i.folpreg i.wealth_index3 i.occup i.apo_bas ///
        GA_div10_sq GA_div10_sqln || ///
        id: ga_at_usd_visits_wks_, ///
        cov(unstructured) nolog

        Predicting mean HC at 16 weeks:
        margins hivpositive, at(GA_div10_sq = 2.56 GA_div10_sqln = 1.2032093) //16 weeks

        Your kind help is highly appreciated.

        Comment

        Working...
        X