Announcement

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

  • multilevel models and confidence interval (xtmixed)

    I am running multi-level models using the xtmixed command in stata. I'm trying to make a graph that has mean predicted trajectory along with two confidence interval trajectories (upper and lower bounds of the mean). I consulted the "Multilevel and Longitudinal Modeling Using Stata" written by Rabe-Hesketh and Skrondal but still couldn't quite figure out how to do it. My main confusion is how to calculate the confidence interval in the growth curve models? Anybody can help out? Thanks in advance!

  • #2
    I'm not sure what you found in the book or what it is that causes you trouble, but you can take a look at the graphs produced by the do-file below and see whether one of those would get you nearer to what you're looking for. What's plotted is the linear prediction (i.e., without random effects) and asymptotic 95% confidence bounds.

    Code:
    version 14.1
    
    clear *
    set more off
    webuse pig
    
    *
    * Time-as-continuous
    *
    mixed weight week || id: week, nolrtest nostderr nolog
    predict double xb, xb
    predict double stdp, stdp
    generate double ll = xb - invnormal(0.975) * stdp
    generate double ul = xb + invnormal(0.975) * stdp
    graph twoway line xb week if id == 1, lcolor(black) || ///
        line ll week if id == 1, lcolor(black) lpattern(dash) || ///
        line ul week if id == 1, lcolor(black) lpattern(dash) ///
        ytitle(Weight) ylabel( , angle(horizontal) nogrid) ///
        xtitle(Week) ///
        legend(off) name(TAC)
    
    *
    * Time at Discrete Intervals
    *
    drop xb-ul
    mixed weight i.week || id: , nolrtest nostderr nolog
    predict double xb, xb
    predict double stdp, stdp
    generate double ll = xb - invnormal(0.975) * stdp
    generate double ul = xb + invnormal(0.975) * stdp
    graph twoway line xb week if id == 1, lcolor(black) || ///
        line ll week if id == 1, lcolor(black) lpattern(dash) || ///
        line ul week if id == 1, lcolor(black) lpattern(dash) ///
        ytitle(Weight) ylabel( , angle(horizontal) nogrid) ///
        xtitle(Week) ///
        legend(off) name(TADI)
    
    exit

    Comment


    • #3
      Thank you. I have a follow up question. The codes above produce the 95% of the fitted line. But I also want to take random-effect part into the calculation of the 95% confidence interval. Can you advise me how to do it?
      Last edited by Jessi Huang; 04 Nov 2015, 09:28.

      Comment


      • #4
        It already does, by virtue of including the random effects in the model. You can see that by omitting the random effects equation from the model and computing the confidence bounds, comparing them to what you get with the random effects included (see below for do-file). What I meant by "no random effects" is that the predictions are from estimates of the population parameters and not individual animal predictions. So you can use "if id == 1" for a cleaner graph without worrying that you're getting only the first pig's predicted values.

        Code:
        version 14.1
        
        clear *
        set more off
        
        webuse pig
        
        mixed weight c.week || id: week, covariance(unstructured) nolrtest nolog
        predict double avec_hat, xb
        predict double avec_stdp, stdp
        
        mixed weight c.week , nolog
        predict double sans_hat, xb
        predict double sans_stdp, stdp
        
        foreach fit in avec sans {
            generate double `fit'_ll = `fit'_hat - invnormal(0.975) * `fit'_stdp
            generate double `fit'_ul = `fit'_hat + invnormal(0.975) * `fit'_stdp
        }
        
        preserve
        quietly keep if id == 1 & inlist(week, 6, 9) // focus on the upper end for better visibility
        graph twoway line avec_hat week, lcolor(red) || ///
            line avec_ll week, lcolor(red) lpattern(dash) || ///
            line avec_ul week, lcolor(red) lpattern(dash) || ///
            line sans_hat week, lcolor(blue) || ///
            line sans_ll week, lcolor(blue) lpattern(dash) || ///
            line sans_ul week, lcolor(blue) lpattern(dash) ///
                ytitle(Weight) ylabel( , angle(horizontal) nogrid) ///
                xtitle(Week) legend(off)
        
        exit

        Comment


        • #5
          Thank you loads!

          Comment

          Working...
          X