Announcement

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

  • Plotting trajectories from a growth curve analysis model (mixed effects model with linear splines) using marginsplot

    Hi All

    I'm running a mixed-effects model (or multilevel model or growth curve analysis) to estimate trajectories in my outcome variable using multiple imputed data. I know that the margingsplot package does not work with multiple imputed data but I'm trying the following where I plot the model based trajectories using just one of the imputed datasets:

    Code:
    * my time variable is age, that I centre below so that the model constant is set at age 36. I then create the spline variables for 4 time periods (4 of them):
    
    gen agec=age-36 mkspline age36_43 7 age43_53 17 age53_63 27 age63_69 = agec
    
    br ID agec age36_43 age43_53 age53_63 age63_69 
    
    * The model includes interactions between categorical social class (adultsc) and all 4 spline variables:
    
    mixed score age36_43##i.adultsc age43_53##i.adultsc age53_63##i.adultsc age63_69##i.adultsc i.childsc ib2.education2 sex || NSHD_ID: agec, cov(unstr) mle, if _mi_m==20
    
    * Margins command:
    
    margins adultsc, at(agec=(0 7 17 27 33)) atmeans
    marginsplot, noci

    The mixed-effects model runs well (no issues).

    However, I'm unable to generate the margins for adultsc as I get an error msg saying that 'agec' not found in list of covariates, which is of course true. The splines were based on the variable agec.

    So, how would I overcome this problem? I can't include agec in the fixed effects part of the model.

    In more general: How would one plots trajectories from a growth curve analysis (mixed effects model) based on multiple imputed data?

    Thanks!

    Amal

  • #2
    You might try using the -over()- option:

    Code:
    webuse mksp1, clear
    mkspline age1 20 age2 30 age3 40 age4 50 age5 60 age6 = age
    gen edcat = (educ <=12)
    regress lninc i.edcat#(c.age?)
    qui margins i.edcat, over(age)
    marginsplot, xdim(age) noci
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	69.9 KB
ID:	1558222

    Comment


    • #3
      you could also try a little program I wrote for cases like this.
      (although for the CI, Im not sure if margins relies only the post estimation VCV to calculate margins, but if it does, then there shouldnt be any problem)

      Code:
      ssc install f_able
      webuse mksp1, clear
      
      fgen age2=max(age-20,0)
      fgen age3=max(age-30,0)
      fgen age4=max(age-40,0)
      fgen age5=max(age-50,0)
      fgen age6=max(age-60,0)
      gen edcat = (educ <=12)
      regress lninc i.edcat#(c.age*) 
      f_able, nlvar(age2 age3 age4 age5 age6)
      qui margins i.edcat, at(age=(15(1)69))
      marginsplot,  noci

      Comment


      • #4
        Thanks Scott - That worked really well!

        /Amal

        Comment

        Working...
        X