Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 72787

Constructing -twoway function- mean growth curve trajectory plot with 95% limit curves from -GLAMM, log(link) family(gamma)- estimates

$
0
0
Hello Statalisters,

I am having difficulty creating this plot from my GLAMM model results in Stata 13.1.

The data has 295 observations from 94 individuals from two data sources. The model is a quadratic function (age and age^2) on a continuous outcome with a gender covariate and random intercept and heteroskedastic level-1 residuals over the two data sources.

In a linear -mixed- model the code is pretty straightforward (developed from Rabe-Hesketh and Skrondal 2012 Multilevel and Longitudinal Modeling using Stata, Third Ed.)

My original -mixed- model showing output in two ways:

standard output:


Mixed-effects ML regression Number of obs = 295
Group variable: id Number of groups = 94

Obs per group: min = 2
avg = 3.1
max = 7


Wald chi2(3) = 11.79
Log likelihood = -1352.081 Prob > chi2 = 0.0081

------------------------------------------------------------------------------
dv | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
age_m16 | -1.523835 .5706592 -2.67 0.008 -2.642307 -.4053638
age_m16sq | .0403451 .0146584 2.75 0.006 .0116151 .0690751
female | -12.15963 5.642459 -2.16 0.031 -23.21864 -1.100612
_cons | 154.8028 5.124446 30.21 0.000 144.759 164.8465
------------------------------------------------------------------------------

------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
id: Identity |
var(_cons) | 631.9921 108.3007 451.6961 884.2539
-----------------------------+------------------------------------------------
Residual: Independent, |
by source |
0: var(e) | 176.468 29.7399 126.8277 245.5374
1: var(e) | 399.1276 48.86902 313.9721 507.3791
------------------------------------------------------------------------------
LR test vs. linear regression: chi2(2) = 151.98 Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.


. mixed dv age_m16 age_m16sq female if eligible || id:, residuals(independent, by(source)) estmetr
> ic

-, estmetric- output:

Mixed-effects ML regression Number of obs = 295
Group variable: id Number of groups = 94

Obs per group: min = 2
avg = 3.1
max = 7


Wald chi2(3) = 11.79
Log likelihood = -1352.081 Prob > chi2 = 0.0081

------------------------------------------------------------------------------
dv | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
dv |
age_m16 | -1.523835 .5706592 -2.67 0.008 -2.642307 -.4053638
age_m16sq | .0403451 .0146584 2.75 0.006 .0116151 .0690751
female | -12.15963 5.642459 -2.16 0.031 -23.21864 -1.100612
_cons | 154.8028 5.124446 30.21 0.000 144.759 164.8465
-------------+----------------------------------------------------------------
lns1_1_1 |
_cons | 3.224438 .085682 37.63 0.000 3.056505 3.392372
-------------+----------------------------------------------------------------
lnsig_e |
_cons | 2.58657 .0842643 30.70 0.000 2.421415 2.751725
-------------+----------------------------------------------------------------
r_lns2ose |
_cons | .4080709 .103755 3.93 0.000 .2047148 .6114271
------------------------------------------------------------------------------


From those estimates I constructed twoway function plots,

first, the mean trajectory plot pulling parameters from the standard output:
twoway (function Weight=_b[_cons]+_b[age_m16]*x + _b[age_m16sq]*x^2, range(0 50)), title(Mean Growth Curve Trajectory)xtitle(Age above 16 in years) ytitle(dv) yscale (range(140 170)) ylab (140(5)170)


then, to get the plot with 95% limit curves, I computed a scalar of the standard deviation of the intercept from the -,estmetric- ins1_1_1 parameter (same as square root of the intercept variance in standard model):
scalar sdofi = sqrt(exp(2*[lns1_1_1]_cons))
twoway (function Weight=_b[_cons]+_b[age_m16]*x + _b[age_m16sq]*x^2, range(0 50)) (function upper=_b[_cons]+1.96*sdofi+_b[age_m16]*x+_b[age_m16sq]*x^2, lcolor(red) range(0 50) lpatt(dash)) ///
(function lower=_b[_cons]-1.96*sdofi+_b[age_m16]*x+_b[age_m16sq]*x^2, lcolor(red) range(0 50) lpatt(dash)), title(Mean Growth Curve Trajectory) ///
xtitle(Age above 16 in years) ytitle(dv) yscale (range(90 230)) ylab (90(20)230) ymtick(100(20)220) xmtick (5(10)45) legend(order(1 "Mean" 2 "95% range"))

Array

The plots do not account for the differing residual variance for the two data sources. If you believe I should be accounting for this in some way, please let me know.

After fitting the linear plots, I realized that using a -GLAMM, log(link) family(gamma)- model substantially improved model fit by accounting for the modest positive skew in the outcome, so I am trying to construct the same plots with my glamm estimates.

gllamm dv age_m16 age_m16sq female if eligible, i(id_n) family(gamma) link(log) s(source) allc

gllamm model

log likelihood = -1347.8402

------------------------------------------------------------------------------
dv | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
age_m16 | -.0154749 .0029956 -5.17 0.000 -.0213462 -.0096036
age_m16sq | .000447 .000066 6.77 0.000 .0003176 .0005763
female | -.0393388 .021871 -1.80 0.072 -.0822052 .0035276
_cons | 5.044003 .0272085 185.38 0.000 4.990675 5.097331
------------------------------------------------------------------------------

Squared Coefficient of Variation
------------------------------------------------------------------------------


equation for log coefficient of variation

0: -2.3582722 (.07548027)
1: -1.9510304 (.06067891)

Variances and covariances of random effects
------------------------------------------------------------------------------


***level 2 (id_n)

var(1): .03347912 (.00346842)
------------------------------------------------------------------------------


------------------------------------------------------------------------------
dv | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
dv |
age_m16 | -.0154749 .0029956 -5.17 0.000 -.0213462 -.0096036
age_m16sq | .000447 .000066 6.77 0.000 .0003176 .0005763
female | -.0393388 .021871 -1.80 0.072 -.0822052 .0035276
_cons | 5.044003 .0272085 185.38 0.000 4.990675 5.097331
-------------+----------------------------------------------------------------
lns1 |
0 | -2.358272 .0754803 -31.24 0.000 -2.506211 -2.210334
1 | -1.95103 .0606789 -32.15 0.000 -2.069959 -1.832102
-------------+----------------------------------------------------------------
id_n1 |
_cons | .182973 .009478 19.31 0.000 .1643965 .2015495
------------------------------------------------------------------------------


I believe I have figured out the mean trajectory plot (have to exponentiate the whole RHS):

twoway (function mean=exp(_b[_cons] + _b[age_m16]*x + _b[age_m16sq]*x^2), range(0 50)), title(Mean Growth Curve Trajectory)xtitle(Age above 16 in years) ytitle(dv) yscale (range(140 220)) ylab (140(10)220)

Array

but, I am having difficulty with the 95% limits. The intercept variance estimate seems to be additive to the intercept beta coefficient, but the intercept shift at the 95% limits should be constant at all time points, and I perceive at least a couple problems because of the exponentiation:

1) the implied SD of the intercept is different depending on if being added for the high limit or subtracted for the low limit (within the exponent)
2) the overall curve shape changes if the SD is simply added into the exponent

Any thoughts would be greatly appreciated!

Viewing all articles
Browse latest Browse all 72787

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>