Houssein Assaad
Senior Statistician and Software Developer
StataCorp LLC
Webinar, College Station
01 Nov 2017
*Slides are available at http://bit.ly/2yD1TeP
...First, an existential question:
Let \(h_t\) be the expected height of a tree at time \(t\) which is modelled using a logistic growth model
is approximated very well
in the interval \([0.4, 1.6]\) by the \(5^{th}\) degree polynomial
+---------------------+
| id X Y |
|---------------------|
| 1 14 5.6 |
| 1 21 9.6 |
| 1 42 15.5 |
|---------------------|
| 2 15 12.6 |
| 2 21 16.4 |
| 2 42 16.9 |
| 2 51 18.9 |
+---------------------+
fixed effect
random effect
mixed effect
where
where
2 observations on \(j^{th}\) subject
. webuse unicorn
(Brain shrinkage of unicorns in the land of Zootopia)
. twoway connected weight time if id < 10, connect(L) ///
title(Brain Shrinkage of unicorn)
+--------------------------+
| id time weight |
|--------------------------|
1. | 1 0 8.266746 |
2. | 1 .1666667 7.163768 |
3. | 1 .3333333 6.725025 |
4. | 1 .5 6.38325 |
5. | 1 .6666667 6.00481 |
|--------------------------|
776. | 60 1.333333 3.75486 |
777. | 60 1.5 3.581552 |
778. | 60 1.666667 3.701847 |
779. | 60 1.833333 3.836078 |
780. | 60 2 3.729806 |
+--------------------------+
. list id time weight if (_n <=5 | _n >775), sep(5)
where \(\epsilon_{ij}\sim N\left(0,\sigma^2\right)\)
. menl weight = {b1}+{U[id]} + ({beta2} - ({b1}+{U[id]}) )*exp(-{beta3}*time)
(Output is on next slide)
menl
gsem-like syntax
. menl weight = {b1}+{U[id]} + ({beta2} - ({b1}+{U[id]}) )*exp(-{beta3}*time)
Obtaining starting values by EM:
Alternating PNLS/LME algorithm:
Iteration 1: linearization log likelihood = -56.9757597
Computing standard errors:
Mixed-effects ML nonlinear regression Number of obs = 780
Group variable: id Number of groups = 60
Obs per group:
min = 13
avg = 13.0
max = 13
Linearization log likelihood = -56.97576
------------------------------------------------------------------------------
weight | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
/b1 | 4.707954 .1414511 33.28 0.000 4.430715 4.985193
/beta2 | 8.089432 .0260845 310.12 0.000 8.038307 8.140556
/beta3 | 4.13201 .0697547 59.24 0.000 3.995293 4.268726
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
id: Identity |
var(U) | 1.189809 .2180058 .8308328 1.703887
-----------------------------+------------------------------------------------
var(Residual) | .0439199 .0023148 .0396095 .0486995
------------------------------------------------------------------------------
. menl weight = {b1}+{U[id]} + ({beta2} - ({b1}+{U[id]}) )*exp(-{beta3}*time)
. menl weight = {beta1:} + ({beta2} - {beta1:})*exp({beta3}*time),
> define(beta1: {b1}+{U[id]})
define()
+---------------------------------------------+
| id cupcake time female weight |
|---------------------------------------------|
1. | 1 2 0 female 8.266746 |
2. | 1 2 .1666667 female 7.163768 |
3. | 1 2 .3333333 female 6.725025 |
4. | 1 2 .5 female 6.38325 |
5. | 1 2 .6666667 female 6.00481 |
|---------------------------------------------|
776. | 60 4 1.333333 male 3.75486 |
777. | 60 4 1.5 male 3.581552 |
778. | 60 4 1.666667 male 3.701847 |
779. | 60 4 1.833333 male 3.836078 |
780. | 60 4 2 male 3.729806 |
+---------------------------------------------+
. list if (_n <=5 | _n >775), sep(5)
define(beta3: {b30} + {b31}*cupcake)
define(beta1: {b10} + {b11}*1.female + {U[id]})
decay rate
. menl weight = {beta1:} + ({beta2:} - {beta1:})*exp(-{beta3:}*time),
> define(beta1: {b10}+{b11}*1.female+{U0[id]})
> define(beta2: {b2})
> define(beta3: {b30}+{b31}*cupcake)
Mixed-effects ML nonlinear regression Number of obs = 780
Group variable: id Number of groups = 60
Obs per group:
min = 13
avg = 13.0
max = 13
Linearization log likelihood = -29.014988
beta1: {b10}+{b11}*1.female+{U0[id]}
beta2: {b2}
beta3: {b30}+{b31}*cupcake
------------------------------------------------------------------------------
weight | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
/b10 | 4.072752 .1627414 25.03 0.000 3.753785 4.39172
/b11 | 1.264407 .2299723 5.50 0.000 .8136694 1.715144
/b2 | 8.088102 .0255465 316.60 0.000 8.038032 8.138172
/b30 | 4.706926 .1325714 35.50 0.000 4.44709 4.966761
/b31 | -.2007309 .0356814 -5.63 0.000 -.2706651 -.1307966
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
id: Identity |
var(U0) | .7840578 .1438924 .5471839 1.123473
-----------------------------+------------------------------------------------
var(Residual) | .0420763 .0022176 .0379468 .0466551
------------------------------------------------------------------------------
Based on our results, consuming rainbow cupcakes after birth indeed slows down brain shrinkage: \(\mathtt{/b31}\) is roughly \(-0.2\) with a 95% \(\mathtt{CI}\) of \([-.27, -.13]\)
define(beta3: {b30} + {b31}*cupcake + {b32}*juice + {U2[id]})
define(beta3: cupcake juice U2[id])
define(beta3: {b30} + {b31}*cupcake)
define(beta3: cupcake, xb)
e.g.,
and
\(\texttt{\{U0[id]\}}\)
. webuse theoph
. twoway connected conc time, connect(L)
Because each of the model parameters must be positive to be meaningful, we write
(Output is on next slide)
. menl conc =(dose*{ke:}*{ka:}/({cl:}*({ka:}-{ke:})))*
> (exp(-{ke:}*time)-exp(-{ka:}*time)),
> define(cl: exp({b0}+{U0[subject]}))
> define(ka: exp({b1}+{U1[subject]}))
> define(ke: exp({b2}))
Mixed-effects ML nonlinear regression Number of obs = 132
Group variable: subject Number of groups = 12
Obs per group:
min = 11
avg = 11.0
max = 11
Linearization log likelihood = -177.02233
cl: exp({b0}+{U0[subject]})
ka: exp({b1}+{U1[subject]})
ke: exp({b2})
------------------------------------------------------------------------------
conc | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
/b0 | -3.227212 .0600089 -53.78 0.000 -3.344827 -3.109597
/b1 | .4656357 .1985941 2.34 0.019 .0763984 .854873
/b2 | -2.454679 .0524896 -46.77 0.000 -2.557556 -2.351801
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
subject: Independent |
var(U0) | .027864 .0121371 .0118652 .0654355
var(U1) | .4143467 .1945672 .165067 1.040082
-----------------------------+------------------------------------------------
var(Residual) | .5030242 .0688883 .3846079 .6578995
------------------------------------------------------------------------------
covariance(U1 U2 U3, unstructured)
covariance(U*, exchangeable)
covariance(U*, identity)
covariance(U2 U3, unstructured)
. menl conc =(dose*{ke:}*{ka:}/({cl:}*({ka:}-{ke:})))*
> (exp(-{ke:}*time)-exp(-{ka:}*time)),
> define(cl: exp({b0}+{U0[subject]}))
> define(ka: exp({b1}+{U1[subject]}))
> define(ke: exp({b2})) covariance(U*, unstructured)
. menl conc =(dose*{ke:}*{ka:}/({cl:}*({ka:}-{ke:})))*
> (exp(-{ke:}*time)-exp(-{ka:}*time)),
> define(cl: exp({b0}+{U0[subject]}))
> define(ka: exp({b1}+{U1[subject]}))
> define(ke: exp({b2})) covariance(U*, unstructured)
Linearization log likelihood = -177.02222
cl: exp({b0}+{U0[subject]})
ka: exp({b1}+{U1[subject]})
ke: exp({b2})
--------------------------------------------------------------------------------
conc | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------------+----------------------------------------------------------------
/b0 | -3.227224 .0600072 -53.78 0.000 -3.344836 -3.109612
/b1 | .4656428 .1985911 2.34 0.019 .0764113 .8548742
/b2 | -2.454696 .0524895 -46.77 0.000 -2.557574 -2.351819
--------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
subject: Unstructured |
var(U0) | .0278616 .0121451 .0118566 .0654714
var(U1) | .4143347 .194565 .1650595 1.040069
cov(U0,U1) | -.0002056 .0332183 -.0653122 .0649011
-----------------------------+------------------------------------------------
var(Residual) | .5030238 .0688885 .3846073 .6578995
------------------------------------------------------------------------------
So far, we have assumed that \(\text{Var}\left(\epsilon_{ij}\right) = \sigma^2\) and \(\text{cov}\left(\epsilon_{sj}, \epsilon_{tj}\right)=0\)
menl
resvariance()
rescorrelation()
resvariance()
rescorrelation()
rescovariance()
resvariance(power _yhat)
Adding a constant avoids the variance of zero at \(\texttt{time}_{ij}\) = 0, because the concentration is zero at that time.
reml
. menl conc =(dose*{ke:}*{ka:}/({cl:}*({ka:}-{ke:})))*
> (exp(-{ke:}*time)-exp(-{ka:}*time)),
> define(cl: exp({b0}+{U0[subject]}))
> define(ka: exp({b1}+{U1[subject]}))
> define(ke: exp({b2}))
> resvariance(power _yhat) reml
Mixed-effects REML nonlinear regression
Linear. log restricted-likelihood = -172.44384
cl: exp({b0}+{U0[subject]})
ka: exp({b1}+{U1[subject]})
ke: exp({b2})
------------------------------------------------------------------------------
conc | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
/b0 | -3.227295 .0619113 -52.13 0.000 -3.348639 -3.105951
/b1 | .4354519 .2072387 2.10 0.036 .0292716 .8416322
/b2 | -2.453743 .0517991 -47.37 0.000 -2.555267 -2.352218
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
subject: Independent |
var(U0) | .0316416 .014531 .0128634 .0778326
var(U1) | .4500585 .2228206 .1705476 1.187661
-----------------------------+------------------------------------------------
Residual variance: |
Power _yhat |
sigma2 | .1015759 .086535 .0191263 .5394491
delta | .3106636 .2466547 -.1727707 .7940979
_cons | .7150935 .3745256 .2561837 1.996063
------------------------------------------------------------------------------
. predict (Cl = {cl:})
. list subject Cl if subject[_n]!=subject[_n-1], sep(0) noobs
+--------------------+
| subject Cl |
|--------------------|
| 1 .0274995 |
| 2 .0402322 |
| 3 .0406919 |
| 4 .0371865 |
| 5 .0425807 |
| 6 .0461769 |
| 7 .0466375 |
| 8 .0442402 |
| 9 .0324682 |
| 10 .0356245 |
| 11 .0510018 |
| 12 .03785 |
+--------------------+
Stage I:
Stage II:
menl y = <menlexpr>, define() [define() ...]
covariance(U0 U1 [U2 ...], <covtype>)
resvariance() rescorrelation()
with
and
2-stage specification
Single-stage specification
menl y = <menlexpr>
rescovariance()
Zone 1
Zone 5
Tree 27
Tree 6
Tree 30
Tree 1
Tree 2
\(1990\)
\(1991\)
\(2003\)
Zone 2
Level 3
Level 2
Level 1
. menl circum = {b1}/(1 + exp(-(age - {beta2:})/{b3})),
> define(beta2: {b2} + {U1[zone]} + {U2[zone > tree]}) stddeviations
Mixed-effects ML nonlinear regression Number of obs = 420
-------------------------------------------------------------
| No. of Observations per Group
Path | Groups Minimum Average Maximum
----------------+--------------------------------------------
zone | 5 56 84.0 112
zone>tree | 30 14 14.0 14
-------------------------------------------------------------
Linearization log likelihood = 313.18701
beta2: {b2}+{U1[zone]}+{U2[zone>tree]}
------------------------------------------------------------------------------
circumf | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
/b1 | 30.01228 .0228861 1311.38 0.000 29.96742 30.05713
/b2 | 6.459742 .0757833 85.24 0.000 6.311209 6.608274
/b3 | 2.902458 .0046722 621.21 0.000 2.893301 2.911615
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
zone: Identity |
sd(U1) | .1599475 .057271 .0792858 .3226707
-----------------------------+------------------------------------------------
zone>tree: Identity |
sd(U2) | .1244983 .0178957 .0939312 .1650126
-----------------------------+------------------------------------------------
sd(Residual) | .0966751 .0034615 .0901233 .1037034
------------------------------------------------------------------------------
. predict (beta2_i = {beta2:}), relevel(zone)
. list zone beta2_i if zone[_n]!=zone[_n-1], sep(0) noobs
+----------------------------+
| zone beta2_i |
|----------------------------|
| New England 6.357335 |
| Mid Atlantic 6.273229 |
| E North Central 6.723731 |
| W North Central 6.481954 |
| South Atlantic 6.46246 |
+----------------------------+
supports single-stage and two-stage specifications.
menl
menl
menl
menl
initial()