------------------------------------------------------------------------------------------------------------------------------------------------------
name: STATA_Chapter3a
log: C:\Dropbox\PilesOfVariance\Chapter3a\STATA\STATA_Chapter3a_Output.smcl
log type: smcl
opened on: 3 Jan 2015, 16:27:14
.
. display as result "Chapter 3a Example: Means by group and time for learning outcome"
Chapter 3a Example: Means by group and time for learning outcome
. tabulate group time, summarize(outcome)
Means, Standard Deviations and Frequencies of outcome: Learning Outcome
group: |
Treatment |
Group |
(1=control | time: Occasion
, | (1=pre-test,
2=treatmen | 2=post-test)
t) | 1 2 | Total
-----------+----------------------+----------
1 | 49.076798 54.899163 | 51.98798
| 5.6852881 5.6282644 | 6.3241453
| 25 25 | 50
-----------+----------------------+----------
2 | 50.75874 58.623631 | 54.691186
| 4.5354041 4.932377 | 6.1457869
| 25 25 | 50
-----------+----------------------+----------
Total | 49.917769 56.761397 | 53.339583
| 5.1602464 5.5650746 | 6.3510064
| 50 50 | 100
.
. display as result "Eq 3a.1: Empty Between-Person Model"
Eq 3a.1: Empty Between-Person Model
. mixed outcome , ///
> || personid: , noconstant variance reml covariance(unstructured) ///
> residuals(independent,t(time)),
Note: t() not required for this residual structure; ignored
Note: all random-effects equations are empty; model is linear regression
Mixed-effects REML regression Number of obs = 100
Wald chi2(0) = .
Log restricted-likelihood = -325.79022 Prob > chi2 = .
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 53.33958 .6351006 83.99 0.000 52.09481 54.58436
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
var(Residual) | 40.33528 5.70427 30.57082 53.21857
------------------------------------------------------------------------------
. estat ic, n(50),
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | Obs ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 50 . -325.7902 2 655.5804 659.4045
-----------------------------------------------------------------------------
Note: N=50 used in calculating BIC
. estat wcorrelation, covariance,
model is linear regression; all observations are independent with standard deviation 6.3510064
. estat wcorrelation,
model is linear regression; all observations are independent with standard deviation 6.3510064
.
. display as result "Eq 3a.2: Empty Within-Person Model"
Eq 3a.2: Empty Within-Person Model
. mixed outcome , ///
> || personid: , noconstant variance reml covariance(unstructured) ///
> residuals(exchangeable,t(time)),
Note: t() not required for this residual structure; ignored
Obtaining starting values by EM:
Performing gradient-based optimization:
Iteration 0: log restricted-likelihood = -325.79022
Iteration 1: log restricted-likelihood = -323.41428
Iteration 2: log restricted-likelihood = -323.40474
Iteration 3: log restricted-likelihood = -323.40474
Computing standard errors:
Mixed-effects REML regression Number of obs = 100
Group variable: personid Number of groups = 50
Obs per group: min = 2
avg = 2.0
max = 2
Wald chi2(0) = .
Log restricted-likelihood = -323.40474 Prob > chi2 = .
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 53.33958 .7260282 73.47 0.000 51.91659 54.76257
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
personid: (empty) |
-----------------------------+------------------------------------------------
Residual: Exchangeable |
var(e) | 40.45905 6.025635 30.21654 54.17346
cov(e) | 12.25265 6.025634 .4426209 24.06267
------------------------------------------------------------------------------
LR test vs. linear regression: chi2(1) = 4.77 Prob > chi2 = 0.0289
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If this is not true, then the
reported test is conservative.
. estat ic, n(50),
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | Obs ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 50 . -323.4047 3 652.8095 658.5455
-----------------------------------------------------------------------------
Note: N=50 used in calculating BIC
. estat wcorrelation, covariance,
Covariances for personid = 1:
obs | 1 2
-------------+----------------
1 | 40.459
2 | 12.253 40.459
. estat wcorrelation,
Standard deviations and correlations for personid = 1:
Standard deviations:
obs | 1 2
-------------+----------------
sd | 6.361 6.361
Correlations:
obs | 1 2
-------------+----------------
1 | 1.000
2 | 0.303 1.000
.
. display as result "Eq 3a.7: Conditional Between-Person Model (top of Eq. 3.7)"
Eq 3a.7: Conditional Between-Person Model (top of Eq. 3.7)
. display as result "Manual Contrasts for Time and Group"
Manual Contrasts for Time and Group
. mixed outcome c.time1 c.treat c.time1#c.treat, ///
> || personid: , noconstant variance reml covariance(unstructured) ///
> residuals(independent,t(time)),
Note: t() not required for this residual structure; ignored
Note: all random-effects equations are empty; model is linear regression
Mixed-effects REML regression Number of obs = 100
Wald chi2(3) = 50.68
Log restricted-likelihood = -301.25352 Prob > chi2 = 0.0000
---------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
----------------+----------------------------------------------------------------
time1 | 5.822365 1.475792 3.95 0.000 2.929866 8.714864
treat | 1.681942 1.475792 1.14 0.254 -1.210557 4.574441
|
c.time1#c.treat | 2.042527 2.087085 0.98 0.328 -2.048085 6.133138
|
_cons | 49.0768 1.043542 47.03 0.000 47.03149 51.1221
---------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
var(Residual) | 27.22452 3.850129 20.63394 35.92017
------------------------------------------------------------------------------
. estat ic, n(50),
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | Obs ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 50 . -301.2535 5 612.507 622.0672
-----------------------------------------------------------------------------
Note: N=50 used in calculating BIC
. estat wcorrelation, covariance,
model is linear regression; all observations are independent with standard deviation 5.2177125
. estat wcorrelation,
model is linear regression; all observations are independent with standard deviation 5.2177125
. * Mean: Control Group at Pre-Test
. lincom _cons*1 + c.time1*0 + c.treat*0 + c.time1#c.treat*0
( 1) [outcome]_cons = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 49.0768 1.043542 47.03 0.000 47.03149 51.1221
------------------------------------------------------------------------------
. * Mean: Control Group at Post-Test
. lincom _cons*1 + c.time1*1 + c.treat*0 + c.time1#c.treat*0
( 1) [outcome]time1 + [outcome]_cons = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 54.89916 1.043542 52.61 0.000 52.85386 56.94447
------------------------------------------------------------------------------
. * Mean: Treatment Group at Pre-Test
. lincom _cons*1 + c.time1*0 + c.treat*1 + c.time1#c.treat*0
( 1) [outcome]treat + [outcome]_cons = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 50.75874 1.043542 48.64 0.000 48.71343 52.80405
------------------------------------------------------------------------------
. * Mean: Treatment Group at Post-Test
. lincom _cons*1 + c.time1*1 + c.treat*1 + c.time1#c.treat*1
( 1) [outcome]time1 + [outcome]treat + [outcome]c.time1#c.treat + [outcome]_cons = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 58.62363 1.043542 56.18 0.000 56.57833 60.66894
------------------------------------------------------------------------------
. * Time Effect for Control Group
. lincom c.time1*1 + c.time1#c.treat*0
( 1) [outcome]time1 = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 5.822365 1.475792 3.95 0.000 2.929866 8.714864
------------------------------------------------------------------------------
. * Time Effect for Treatment Group
. lincom c.time1*1 + c.time1#c.treat*1
( 1) [outcome]time1 + [outcome]c.time1#c.treat = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 7.864892 1.475792 5.33 0.000 4.972393 10.75739
------------------------------------------------------------------------------
. * Group Effect at Pre-Test
. lincom c.treat*1 + c.time1#c.treat*0
( 1) [outcome]treat = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 1.681942 1.475792 1.14 0.254 -1.210557 4.574441
------------------------------------------------------------------------------
. * Group Effect at Post-Test
. lincom c.treat*1 + c.time1#c.treat*1
( 1) [outcome]treat + [outcome]c.time1#c.treat = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 3.724468 1.475792 2.52 0.012 .8319694 6.616968
------------------------------------------------------------------------------
.
. display as result "Eq 3a.7: Conditional Within-Person Model (bottom of Eq. 3.7)"
Eq 3a.7: Conditional Within-Person Model (bottom of Eq. 3.7)
. display as result "Manual Contrasts for Time and Group"
Manual Contrasts for Time and Group
. mixed outcome c.time1 c.treat c.time1#c.treat, ///
> || personid: , noconstant variance reml covariance(unstructured) ///
> residuals(exchangeable,t(time)),
Note: t() not required for this residual structure; ignored
Obtaining starting values by EM:
Performing gradient-based optimization:
Iteration 0: log restricted-likelihood = -301.25352
Iteration 1: log restricted-likelihood = -274.38071
Iteration 2: log restricted-likelihood = -272.3562
Iteration 3: log restricted-likelihood = -272.3495
Iteration 4: log restricted-likelihood = -272.3495
Computing standard errors:
Mixed-effects REML regression Number of obs = 100
Group variable: personid Number of groups = 50
Obs per group: min = 2
avg = 2.0
max = 2
Wald chi2(3) = 272.93
Log restricted-likelihood = -272.3495 Prob > chi2 = 0.0000
---------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
----------------+----------------------------------------------------------------
time1 | 5.822365 .596328 9.76 0.000 4.653584 6.991147
treat | 1.681942 1.475792 1.14 0.254 -1.210557 4.574441
|
c.time1#c.treat | 2.042527 .8433351 2.42 0.015 .3896201 3.695433
|
_cons | 49.0768 1.043542 47.03 0.000 47.03149 51.1221
---------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
personid: (empty) |
-----------------------------+------------------------------------------------
Residual: Exchangeable |
var(e) | 27.22452 5.123633 18.8263 39.36912
cov(e) | 22.77944 5.123633 12.7373 32.82157
------------------------------------------------------------------------------
LR test vs. linear regression: chi2(1) = 57.81 Prob > chi2 = 0.0000
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If this is not true, then the
reported test is conservative.
. estat ic, n(50),
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | Obs ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 50 . -272.3495 6 556.699 568.1711
-----------------------------------------------------------------------------
Note: N=50 used in calculating BIC
. estat wcorrelation, covariance,
Covariances for personid = 1:
obs | 1 2
-------------+----------------
1 | 27.225
2 | 22.779 27.225
. estat wcorrelation,
Standard deviations and correlations for personid = 1:
Standard deviations:
obs | 1 2
-------------+----------------
sd | 5.218 5.218
Correlations:
obs | 1 2
-------------+----------------
1 | 1.000
2 | 0.837 1.000
. * Mean: Control Group at Pre-Test
. lincom _cons*1 + c.time1*0 + c.treat*0 + c.time1#c.treat*0
( 1) [outcome]_cons = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 49.0768 1.043542 47.03 0.000 47.03149 51.1221
------------------------------------------------------------------------------
. * Mean: Control Group at Post-Test
. lincom _cons*1 + c.time1*1 + c.treat*0 + c.time1#c.treat*0
( 1) [outcome]time1 + [outcome]_cons = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 54.89916 1.043542 52.61 0.000 52.85386 56.94447
------------------------------------------------------------------------------
. * Mean: Treatment Group at Pre-Test
. lincom _cons*1 + c.time1*0 + c.treat*1 + c.time1#c.treat*0
( 1) [outcome]treat + [outcome]_cons = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 50.75874 1.043542 48.64 0.000 48.71343 52.80405
------------------------------------------------------------------------------
. * Mean: Treatment Group at Post-Test
. lincom _cons*1 + c.time1*1 + c.treat*1 + c.time1#c.treat*1
( 1) [outcome]time1 + [outcome]treat + [outcome]c.time1#c.treat + [outcome]_cons = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 58.62363 1.043542 56.18 0.000 56.57833 60.66894
------------------------------------------------------------------------------
. * Time Effect for Control Group
. lincom c.time1*1 + c.time1#c.treat*0
( 1) [outcome]time1 = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 5.822365 .596328 9.76 0.000 4.653584 6.991147
------------------------------------------------------------------------------
. * Time Effect for Treatment Group
. lincom c.time1*1 + c.time1#c.treat*1
( 1) [outcome]time1 + [outcome]c.time1#c.treat = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 7.864892 .596328 13.19 0.000 6.69611 9.033673
------------------------------------------------------------------------------
. * Group Effect at Pre-Test
. lincom c.treat*1 + c.time1#c.treat*0
( 1) [outcome]treat = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 1.681942 1.475792 1.14 0.254 -1.210557 4.574441
------------------------------------------------------------------------------
. * Group Effect at Post-Test
. lincom c.treat*1 + c.time1#c.treat*1
( 1) [outcome]treat + [outcome]c.time1#c.treat = 0
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(1) | 3.724468 1.475792 2.52 0.012 .8319694 6.616968
------------------------------------------------------------------------------
.
. display as result "Eq 3a.7: Conditional Within-Person Model (bottom of Eq. 3.7)"
Eq 3a.7: Conditional Within-Person Model (bottom of Eq. 3.7)
. display as result "Categorical Predictors for Time and Group"
Categorical Predictors for Time and Group
. mixed outcome i.time1 i.treat i.time1#i.treat, ///
> || personid: , noconstant variance reml covariance(unstructured) ///
> residuals(exchangeable,t(time)),
Note: t() not required for this residual structure; ignored
Obtaining starting values by EM:
Performing gradient-based optimization:
Iteration 0: log restricted-likelihood = -301.25352
Iteration 1: log restricted-likelihood = -274.38071
Iteration 2: log restricted-likelihood = -272.3562
Iteration 3: log restricted-likelihood = -272.3495
Iteration 4: log restricted-likelihood = -272.3495
Computing standard errors:
Mixed-effects REML regression Number of obs = 100
Group variable: personid Number of groups = 50
Obs per group: min = 2
avg = 2.0
max = 2
Wald chi2(3) = 272.93
Log restricted-likelihood = -272.3495 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
1.time1 | 5.822365 .596328 9.76 0.000 4.653584 6.991147
1.treat | 1.681942 1.475792 1.14 0.254 -1.210557 4.574441
|
time1#treat |
1 1 | 2.042527 .8433351 2.42 0.015 .3896201 3.695433
|
_cons | 49.0768 1.043542 47.03 0.000 47.03149 51.1221
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
personid: (empty) |
-----------------------------+------------------------------------------------
Residual: Exchangeable |
var(e) | 27.22452 5.123633 18.8263 39.36912
cov(e) | 22.77944 5.123633 12.7373 32.82157
------------------------------------------------------------------------------
LR test vs. linear regression: chi2(1) = 57.81 Prob > chi2 = 0.0000
Note: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If this is not true, then the
reported test is conservative.
. estat ic, n(50),
Akaike's information criterion and Bayesian information criterion
-----------------------------------------------------------------------------
Model | Obs ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 50 . -272.3495 6 556.699 568.1711
-----------------------------------------------------------------------------
Note: N=50 used in calculating BIC
. estat wcorrelation, covariance,
Covariances for personid = 1:
obs | 1 2
-------------+----------------
1 | 27.225
2 | 22.779 27.225
. estat wcorrelation,
Standard deviations and correlations for personid = 1:
Standard deviations:
obs | 1 2
-------------+----------------
sd | 5.218 5.218
Correlations:
obs | 1 2
-------------+----------------
1 | 1.000
2 | 0.837 1.000
. contrast i.time1#i.treat,
Contrasts of marginal linear predictions
Margins : asbalanced
------------------------------------------------
| df chi2 P>chi2
-------------+----------------------------------
outcome |
time1#treat | 1 5.87 0.0154
------------------------------------------------
. margins i.time1#i.treat,
Adjusted predictions Number of obs = 100
Expression : Linear prediction, fixed portion, predict()
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
time1#treat |
0 0 | 49.0768 1.043542 47.03 0.000 47.03149 51.1221
0 1 | 50.75874 1.043542 48.64 0.000 48.71343 52.80405
1 0 | 54.89916 1.043542 52.61 0.000 52.85386 56.94447
1 1 | 58.62363 1.043542 56.18 0.000 56.57833 60.66894
------------------------------------------------------------------------------
. margins i.time1#i.treat, pwcompare(pveffects)
Pairwise comparisons of adjusted predictions
Expression : Linear prediction, fixed portion, predict()
--------------------------------------------------------
| Delta-method Unadjusted
| Contrast Std. Err. z P>|z|
----------------+---------------------------------------
time1#treat |
(0 1) vs (0 0) | 1.681942 1.475792 1.14 0.254
(1 0) vs (0 0) | 5.822365 .596328 9.76 0.000
(1 1) vs (0 0) | 9.546834 1.475792 6.47 0.000
(1 0) vs (0 1) | 4.140423 1.475792 2.81 0.005
(1 1) vs (0 1) | 7.864892 .596328 13.19 0.000
(1 1) vs (1 0) | 3.724468 1.475792 2.52 0.012
--------------------------------------------------------
. margins i.time1@i.treat,
Contrasts of adjusted predictions
Expression : Linear prediction, fixed portion, predict()
------------------------------------------------
| df chi2 P>chi2
-------------+----------------------------------
time1@treat |
0 | 1 95.33 0.0000
1 | 1 173.95 0.0000
Joint | 2 269.28 0.0000
------------------------------------------------
. margins i.treat@i.time1,
Contrasts of adjusted predictions
Expression : Linear prediction, fixed portion, predict()
------------------------------------------------
| df chi2 P>chi2
-------------+----------------------------------
treat@time1 |
0 | 1 1.30 0.2544
1 | 1 6.37 0.0116
Joint | 2 9.52 0.0086
------------------------------------------------
.
. ****** END CHAPTER 3a MODELS ******
.
. * Close log
. log close STATA_Chapter3a
name: STATA_Chapter3a
log: C:\Dropbox\PilesOfVariance\Chapter3a\STATA\STATA_Chapter3a_Output.smcl
log type: smcl
closed on: 3 Jan 2015, 16:27:17
------------------------------------------------------------------------------------------------------------------------------------------------------