Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: How do I graph prediction of mean growth trajectory?
From
Michael Norman Mitchell <[email protected]>
To
[email protected]
Subject
Re: st: How do I graph prediction of mean growth trajectory?
Date
Fri, 21 May 2010 19:29:30 -0700
Dear David
I think that this is a case where the -margins- command could be your
friend. It won't directly draw the graph that you seek, but I think it
will be useful for obtaining the adjusted means that you could then use
for drawing a graph. I have created an example modeled after your
description using the Stata example dataset -nlswork-. I renamed the
variables to match your description and fit a model based on what I saw
in your email. The creating of the dataset and the xtmixed command to
fit the model is shown below...
. webuse nlswork, clear
. * age
. rename ttl_exp assess
. rename collgrad homeenv
. rename c_city trt
. rename race matiq
. xtmixed ln_w c.age##c.age assess homeenv i.matiq##i.trt || id: ,
cov(unstruct)
Then, after fitting this model, I used the -margins- command to get
the adjusted means (averaging across the other variables in the model)
for ages ranging from 40 to 45 crossed with the three levels of maternal
IQ. This yields 6 (age) times 3 (matiq) = 18 predicted means.
. margins , at(age=(40(1)45) matiq=(1 2 3))
The margins command, by default, is giving the "Average Marginal
Effect", which is averaging the across all of the other predictors in
the model. You might be asking yourself, shouldn't these be held
constant at their mean? (I ask myself this.) On my website, I have a
page that describes the difference between "Marginal Effect at the Mean"
and "Average Marginal Effects", and it shows that although these are
different in a logit model, they are identical in a linear model. The
URL (which may wrap) is....
http://www.michaelnormanmitchell.com/stow/marginal-effect-at-mean-vs-average-marginal-effect.html
Below I show the commands again with the output...
. webuse nlswork, clear
(National Longitudinal Survey. Young Women 14-26 years of age in 1968)
.
. * age
. rename ttl_exp assess
. rename collgrad homeenv
. rename c_city trt
. rename race matiq
.
. xtmixed ln_w c.age##c.age assess homeenv i.matiq##i.trt || id: ,
cov(unstruct)
Note: single-variable random-effects specification; covariance structure
set to
identity
Performing EM optimization:
Performing gradient-based optimization:
Iteration 0: log restricted-likelihood = -9818.6258
Iteration 1: log restricted-likelihood = -9818.6258
Computing standard errors:
Mixed-effects REML regression Number of obs =
28502
Group variable: idcode Number of groups
= 4710
Obs per group: min
= 1
avg
= 6.1
max
= 15
Wald chi2(9) =
7180.74
Log restricted-likelihood = -9818.6258 Prob > chi2 =
0.0000
------------------------------------------------------------------------------
ln_wage | Coef. Std. Err. z P>|z| [95% Conf.
Interval]
-------------+----------------------------------------------------------------
age | .0456086 .0026478 17.22 0.000 .040419
.0507983
|
c.age#c.age | -.0009042 .000044 -20.53 0.000 -.0009905
-.0008179
|
assess | .0450014 .0009785 45.99 0.000 .0430836
.0469192
homeenv | .3603894 .0117634 30.64 0.000 .3373336
.3834452
|
matiq |
2 | -.121281 .0127061 -9.55 0.000 -.1461844
-.0963776
3 | .1005461 .0497622 2.02 0.043 .0030141
.1980782
|
1.trt | .0390282 .0071551 5.45 0.000 .0250044
.053052
|
matiq#trt |
2 1 | .0363523 .0137009 2.65 0.008 .0094991
.0632055
3 1 | -.0515755 .0558514 -0.92 0.356 -.1610422
.0578911
|
_cons | .8204718 .0391195 20.97 0.000 .7437989
.8971446
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf.
Interval]
-----------------------------+------------------------------------------------
idcode: Identity |
sd(_cons) | .281425 .003769 .274134
.28891
-----------------------------+------------------------------------------------
sd(Residual) | .2962138 .0013607 .2935589
.2988928
------------------------------------------------------------------------------
LR test vs. linear regression: chibar2(01) = 9454.47 Prob >= chibar2 =
0.0000
. margins , at(age=(40(1)45) matiq=(1 2 3))
Predictive margins Number of obs =
28502
Expression : Linear prediction, fixed portion, predict()
1._at : age = 40
matiq = 1
2._at : age = 40
matiq = 2
3._at : age = 40
matiq = 3
4._at : age = 41
matiq = 1
5._at : age = 41
matiq = 2
6._at : age = 41
matiq = 3
7._at : age = 42
matiq = 1
8._at : age = 42
matiq = 2
9._at : age = 42
matiq = 3
10._at : age = 43
matiq = 1
11._at : age = 43
matiq = 2
12._at : age = 43
matiq = 3
13._at : age = 44
matiq = 1
14._at : age = 44
matiq = 2
15._at : age = 44
matiq = 3
16._at : age = 45
matiq = 1
17._at : age = 45
matiq = 2
18._at : age = 45
matiq = 3
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf.
Interval]
-------------+----------------------------------------------------------------
_at |
1 | 1.552311 .0093973 165.19 0.000 1.533893
1.570729
2 | 1.444016 .0119263 121.08 0.000 1.420641
1.467392
3 | 1.634432 .043937 37.20 0.000 1.548318
1.720547
4 | 1.524682 .0102364 148.95 0.000 1.504619
1.544745
5 | 1.416388 .0126123 112.30 0.000 1.391668
1.441107
6 | 1.606804 .0441239 36.42 0.000 1.520322
1.693285
7 | 1.495245 .0111808 133.73 0.000 1.473331
1.517159
8 | 1.38695 .0134051 103.46 0.000 1.360677
1.413224
9 | 1.577366 .0443525 35.56 0.000 1.490437
1.664296
10 | 1.463999 .0122296 119.71 0.000 1.44003
1.487969
11 | 1.355705 .0143071 94.76 0.000 1.327663
1.383746
12 | 1.546121 .0446286 34.64 0.000 1.45865
1.633591
13 | 1.430945 .0133814 106.93 0.000 1.404718
1.457172
14 | 1.322651 .0153192 86.34 0.000 1.292626
1.352676
15 | 1.513067 .0449583 33.65 0.000 1.42495
1.601183
16 | 1.396083 .014635 95.39 0.000 1.367399
1.424767
17 | 1.287788 .0164415 78.33 0.000 1.255564
1.320013
18 | 1.478204 .0453477 32.60 0.000 1.389324
1.567084
------------------------------------------------------------------------------
.
end of do-file
I hope this helps,
Best luck,
Michael N. Mitchell
See the Stata tidbit of the week at...
http://www.MichaelNormanMitchell.com
On 2010-05-21 2.27 PM, David Torres wrote:
Hello all,
I am trying to graph expected growth in IQ scores by maternal IQ class
and treatment/control group assignment. Since there are three
maternal IQ classes and two group assignments, I should have six lines
or growth curves.
Now, my models were calculated using Stata's -xtmixed- command, so
I've been following Rabe-Hesketh and Skrondal's text on multilevel
modeling, 2nd edition, page 210-220. They give an example of how to
graph growth, but the example does not include interactions nor does
it allow for the slopes to change between some other time-varying
covariate, which I have in my model. The outcome is test score, of
course. The list of the predictor variables in the full model from
which I would like to create my graphs follow:
1. age
2. age^2
3. assessment given (two different assessments over several years, so
this is entered as a time-varying covariate. It would be great if I
could get the slope to vary by assessment) - Stanford-Binet or
Wechsler
4. home environment - 0/1, less stimulating/more stimulating
5. treatment - 0/1, control/treatment
6 & 7. maternal IQ class - 1/2/3, IQ<=75/IQ between 76&90/IQ between
91&110
1 is the reference category
8 & 9. interaction between treatment and maternal IQ class
All of the variables in this model are significant, so I want to make
sure that my graph accurately reflects that. Also, I understand that
since interactions can be difficult to interpret sometimes a visual
represention of the data are always good as an accompaniment.
A related question is this: If I have to produce these lines
separately, creating six graphs, is there a way I can overlay them?
--------------------------------------------
David Diego Torres, MA(Sociology)
PhD Candidate in Sociology
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/