Announcement

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

  • Pre and post Mixed effects graph

    Hello,

    I am trying to replicate figure 3 in thee publication below which is a linear mixed model with confidence intervals. I have used the codes below but I get a scatter plot or flat line that does not look anything like the graph above. I would also like to add a trajectory line to the pre-time to predict thee line if no treatment was added. Can anyone point me to a package in Stata that can create similar graphs? Thank you in advance


    meologit FVC time || Assign:
    margins, at(time = (-5 -4 -3 -2 -1 1 2 3 4 5))
    margins-plot
    A. Mixed-effects model estimates for percentage of predicted forced vital capacity (FVC%) over time for the entire cohort. B. Mixed-effects model estimates for percentage of predicted diffusing capacity (DLCO%) over time for the entire cohort. Solid line is the mean; broken lines show 95% confidence bands. MMF: mycophenolate mofetil.
    Last edited by May Blake; 12 May 2020, 20:03.

  • #2
    I'm not sure why you're using meologit. According to the article, the authors used SAS's PROC MIXED with an unstructured covariance matrix. So I think that what you're looking for would be something more along the following lines. Run the code below to see how it plays out—the graph it produces is shown below the code. (Start at the "Begin here" comment; the first part of the code just creates a phony dataset for illustration.)
    Code:
    version 16.1
    
    clear *
    
    set seed `=strreverse("1552810")'
    
    quietly drawnorm intercept slope, double corr(1 -0.25 \ -0.25 1) n(250)
    generate int pid = _n
    
    quietly expand 10
    generate double tim = runiform(-100, 100) // weeks from mycophenolate mofetil initiation
    generate double FVC = ///
        70 + 0 * tim + ///
            intercept * sqrt(0.15 * 70) + slope * tim + ///
                rnormal(0, sqrt(0.15 * 70))
    
    *
    * Begin here
    *
    mixed FVC c.tim || pid: tim, covariance(unstructured) nolrtest nolog
    
    quietly margins , at(tim = (-100(25)100))
    
    marginsplot , title("") ///
        plotopts(msymbol(none) lcolor(black)) ///
        ytitle(FVC (%)) ylabel( , angle(horizontal) nogrid) ///
        xtitle(Weeks) ///
        level(50) recastci(rline) ciopts(lcolor(black) lpattern(dash))
    
    quietly graph export Illustration.png
    
    exit
    You can change the y-axis to start from zero, if you need to please your audience in that way. Change the ylabel() option to something like, say,
    Code:
    ylabel(0(25)100, angle(horizontal) nogrid)
    Click image for larger version

Name:	Illustration.png
Views:	1
Size:	28.5 KB
ID:	1552819

    Comment


    • #3
      Click image for larger version

Name:	Screen Shot 2020-05-13 at 11.08.50 AM.png
Views:	1
Size:	130.0 KB
ID:	1552938 Thank you Jospeh, This worked wonderfully. Can I ask how I can also add the line at 0? Can I use xline(0)? I am wondering how they got the graph to kink in the middle of the graph. Can you help me out with this? I would also like to add a trajectory line like the one in my second picture here. Thank you so much.

      Comment


      • #4
        Originally posted by May Blake View Post
        Can I ask how I can also add the line at 0? Can I use xline(0)?
        Yes, for a vertical line.

        I am wondering how they got the graph to kink in the middle of the graph. Can you help me out with this?
        It looks like they created an indicator ("dummy") variable for time values greater than zero, and then formed an interaction term. Something like the following.
        Code:
        generate byte aft = time > 0
        mixed FVC c.tim##i.aft . . .
        I can only guess how the authors managed the random slopes. You'd need to ask the authors.

        I would also like to add a trajectory line like the one in my second picture here.
        Either generate the predictions and graph those as an overlay (|| line prediction time if time > 0), or use graph function (again as an overlay) with the regression coefficients to define the function to graph.

        Comment

        Working...
        X