Announcement

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

  • Multilevel mixed effects model: random slopes

    Hello,

    I am using -mixed- and was hoping for advice on (1) how to add in random slopes to the model; and (2) if my postestimation method is appropriate.

    BACKGROUND: In a cross-over design, participants completed two exercise conditions, each with 4 sample timepoints (baseline, post, post30min, post60min). I would like to use LMEM to determine changes in the dependent variable (Cell viability) from baseline to the post-exercise timepoints.

    (1) My current code is below with Participants classified as a random intercept. But I am unsure how to also add random slopes?

    Code:
    mixed Viability i.Condition##Time || Participant:

    (2) I am also new to LMEMs (if this wasn’t already obvious😊) and only previously used Two-way RM ANOVA where following the test I would run a post hoc analysis. Following LMEM, I have tried the postestimation commands below but unsure which, if any, is appropriate? Would it also be possible to calculate effect sizes e.g. Cohen’s d or η² following LMEM?

    Code:
    contrast r.Time@Condition, pveffects
    Code:
    pwcompare Condition##Time, mcompare(bonferroni) effects
    Any suggestions greatly appreciated - thank you!


  • #2
    Originally posted by Rachael Kemp View Post

    (1) My current code is below with Participants classified as a random intercept. But I am unsure how to also add random slopes?
    The documentation shows you how to do this. See

    Code:
    help mixed
    Setup
    . webuse nlswork

    Random-intercept model, analogous to xtreg
    . mixed ln_w grade age c.age#c.age ttl_exp tenure c.tenure#c.tenure || id:

    Random-intercept and random-slope (coefficient) model
    . mixed ln_w grade age c.age#c.age ttl_exp tenure c.tenure#c.tenure || id: tenure
    For post-estimation tools for mixed, refer to

    Code:
    help mixed_postestimation

    Comment


    • #3
      Hi Rachael,

      I second Andrew's suggestion to read Stata's mixed documentation, including the postestimation material. I thought I would add a couple of other pieces of information specific to your case.

      As you probably know, there is much overlap between mixed models and ANOVAs. Mixed models are preferred because they are highly flexible with options for random slopes (slope heterogeneity), heteroskedastic residuals, corrections for small samples, etc.

      In your case, I am guessing that you are interested in investigating whether the association between Condition and Viability varies across participants as a function of Time. If so, the following syntax will run such a model for you:
      Code:
      * Treat time as continuous and having a linear relation with Viability
      mixed Viability i.Condition##c.Time || Participant: Time, cov(un)  reml 
      
      * Treat time as categorical (similarly as in ANOVA)
      mixed Viability i.Condition##i.Time || Participant: i.Time, cov(un)  reml
      If you have a small sample (say < 30 participants), you should use a small sample standard error correction. The option dfmethod(kroger) is a good one.

      For your second question about follow-up comparisons, you have a lot of options. The types of comparisons you would make in the ANOVA setting are just as relevant with mixed models. Both of the ones presented seem appropriate to me. If you end up using the small sample size correction, you can add the small option to your contrast and pwcompare commands. You can also visualize the interaction effect using margins with marginsplot:
      Code:
      * If treating time continuously
      margins Condition, at(Time = (1(1)4)) // change depending on how time is coded
      marginsplot, xdimension(Time)
      
      * If treating time categorically
      margins Condition#Time
      marginsplot, xdimension(Time)
      You can also get contrasts (and plots of them) with the contrast option of margins. Consult help margins contrast.

      Comment


      • #4
        This is an incredibly helpful and clear explanation and the code works great - thank you for your time!

        Comment

        Working...
        X