------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  STATA_Chapter12
       log:  C:\Dropbox\PilesOfVariance\Chapter12\STATA\STATA_Chapter12_Output.smcl
  log type:  smcl
 opened on:  21 Oct 2014, 10:32:04


. . * Import chapter 12 stacked data . use "$filesave\STATA_Chapter12.dta", clear

. . * Collapse data into one row per person to summarize subject variables . display as result "Chapter 12: Descriptive Statistics for Subject-Level Variables" Chapter 12: Descriptive Statistics for Subject-Level Variables

. collapse older age, by(subjectid)

. tabulate older, summarize(age)

(mean) | Summary of (mean) age older | Mean Std. Dev. Freq. ------------+------------------------------------ 0 | 19.708333 2.2660732 96 1 | 75.701754 5.3684426 57 ------------+------------------------------------ Total | 40.568627 27.414164 153

. . * Re-import chapter 12 stacked data . use "$filesave\STATA_Chapter12.dta", clear

. . * Collapse data into one row per item to summarize item variables . display as result "Chapter 12: Descriptive Statistics for Item-Level Variables" Chapter 12: Descriptive Statistics for Item-Level Variables

. collapse relevance salience, by(itemid)

. summarize(relevance salience)

Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- relevance | 51 2.647059 1.906028 0 5 salience | 51 3.019608 1.104359 1 5

. . * Re-import chapter 12 stacked data and create variables for analysis . use "$filesave\STATA_Chapter12.dta", clear

. * Log of response time . gen logrt = log(rt) (157 missing values generated)

. * Make copy of 'older' and dummy codes to be used in heterogeneous variance models . gen agegroup = older

. gen isyounger=0

. replace isyounger=1 if (older==0) (4896 real changes made)

. gen isolder=1

. replace isolder=1 if (older==1) (0 real changes made)

. * Piecewise effect of age . gen yrs65=0

. replace yrs65=age-65 if (older==1) (2856 real changes made)

. * Item predictors . gen rel3 = relevance - 3

. gen sal3 = salience - 3

. * Item salience random slope for heterogeneous random effects by age . gen isysal = isyounger*sal3

. gen isosal = isolder*sal3

. label variable logrt "logrt: Natural Log RT in Seconds"

. label variable agegroup "agegroup: Younger=0, Older=1"

. label variable isyounger "isyounger: 0=Older, 1=Younger"

. label variable isolder "isolder: 0=Younger, 1=Older"

. label variable yrs65 "yrs65: Subject Years of Age Over 65 (0=65)"

. label variable rel3 "rel3: Item Relevance (0=3)"

. label variable sal3 "sal3: Item Salience (0=3)"

. label variable isysal "isysal: Younger Random Salience Slope"

. label variable isosal "isosal: Older Random Salience Slope"

. . * Subset sample to complete cases for all predictors . egen nummiss = rowmiss(older yrs65 relevance salience logrt)

. drop if nummiss>0 (157 observations deleted)

. . display as result "Chapter 12: Descriptive Statistics for Trial-Level Variables" Chapter 12: Descriptive Statistics for Trial-Level Variables

. summarize(rt logrt)

Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- rt | 7646 7.376688 8.08914 1.156 59.969 logrt | 7646 1.612058 .8284638 .1449658 4.093828

. . ******************************************************************************** . ******* BEGIN CHAPTER 12 CROSSED RANDOM EFFECTS MODELS ******* . ******* NOTE: MODELS WITH RANDOM SLOPES WILL NOT CONVERGE ******* . ******* BUT ARE PROVIDED BELOW FOR ILLUSTRATION ******* . ******************************************************************************** . . display as result "Eq 12.8: Empty Means, Single-Level Model for Log RT" Eq 12.8: Empty Means, Single-Level Model for Log RT

. mixed logrt , /// > || subjectid: , noconstant variance reml covariance(unstructured), Note: all random-effects equations are empty; model is linear regression

Mixed-effects REML regression Number of obs = 7646

Wald chi2(0) = . Log restricted-likelihood = -9413.6033 Prob > chi2 = .

------------------------------------------------------------------------------ logrt | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | 1.612058 .0094745 170.15 0.000 1.593488 1.630627 ------------------------------------------------------------------------------

------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ var(Residual) | .6863522 .0111006 .6649367 .7084574 ------------------------------------------------------------------------------

. estat ic, n(1),

Akaike's information criterion and Bayesian information criterion

----------------------------------------------------------------------------- Model | Obs ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- . | 1 . -9413.603 2 18831.21 18827.21 ----------------------------------------------------------------------------- Note: N=1 used in calculating BIC

. estimates store FitEmpty1,

. . display as result "Eq 12.9: Add Subject Random Intercept Variance" Eq 12.9: Add Subject Random Intercept Variance

. mixed logrt , /// > || subjectid: , variance reml covariance(unstructured), Note: single-variable random-effects specification in subjectid equation; covariance structure set to identity

Performing EM optimization:

Performing gradient-based optimization:

Iteration 0: log restricted-likelihood = -8540.3628 Iteration 1: log restricted-likelihood = -8540.3628

Computing standard errors:

Mixed-effects REML regression Number of obs = 7646 Group variable: subjectid Number of groups = 153

Obs per group: min = 43 avg = 50.0 max = 51



Wald chi2(0) = . Log restricted-likelihood = -8540.3628 Prob > chi2 = .

------------------------------------------------------------------------------ logrt | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | 1.619391 .0347712 46.57 0.000 1.55124 1.687541 ------------------------------------------------------------------------------

------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ subjectid: Identity | var(_cons) | .1746526 .0212411 .1376108 .2216652 -----------------------------+------------------------------------------------ var(Residual) | .5157229 .0084258 .4994702 .5325045 ------------------------------------------------------------------------------ LR test vs. linear regression: chibar2(01) = 1746.48 Prob >= chibar2 = 0.0000

. estat ic, n(1),

Akaike's information criterion and Bayesian information criterion

----------------------------------------------------------------------------- Model | Obs ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- . | 1 . -8540.363 3 17086.73 17080.73 ----------------------------------------------------------------------------- Note: N=1 used in calculating BIC

. estat icc,

Intraclass correlation

------------------------------------------------------------------------------ Level | ICC Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ subjectid | .252982 .0232155 .2102295 .3011139 ------------------------------------------------------------------------------

. estimates store FitEmpty2,

. . display as result "Eq 12.10: Add Item Random Intercept Variance" Eq 12.10: Add Item Random Intercept Variance

. mixed logrt , /// > || _all: R.subjectid , variance reml /// > || _all: R.itemid ,

Performing EM optimization:

Performing gradient-based optimization:

Iteration 0: log restricted-likelihood = -7591.0186 Iteration 1: log restricted-likelihood = -7591.0186

Computing standard errors:

Mixed-effects REML regression Number of obs = 7646 Group variable: _all Number of groups = 1

Obs per group: min = 7646 avg = 7646.0 max = 7646



Wald chi2(0) = . Log restricted-likelihood = -7591.0186 Prob > chi2 = .

------------------------------------------------------------------------------ logrt | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | 1.622606 .0608129 26.68 0.000 1.503414 1.741797 ------------------------------------------------------------------------------

------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ _all: Identity | var(R.subjec~d) | .1802584 .0215904 .1425421 .2279543 -----------------------------+------------------------------------------------ _all: Identity | var(R.itemid) | .1259187 .0257051 .0843968 .1878688 -----------------------------+------------------------------------------------ var(Residual) | .3898709 .006391 .3775438 .4026006 ------------------------------------------------------------------------------ LR test vs. linear regression: chi2(2) = 3645.17 Prob > chi2 = 0.0000

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

. estat ic, n(1),

Akaike's information criterion and Bayesian information criterion

----------------------------------------------------------------------------- Model | Obs ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- . | 1 . -7591.019 4 15190.04 15182.04 ----------------------------------------------------------------------------- Note: N=1 used in calculating BIC

. estimates store FitEmpty3,

. lrtest FitEmpty3 FitEmpty2,

Likelihood-ratio test LR chi2(1) = 1898.69 (Assumption: FitEmpty2 nested in FitEmpty3) 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. Note: LR tests based on REML are valid only when the fixed-effects specification is identical for both models.

. . display as result "Eq 12.11: Add Fixed Effects of Item Predictors" Eq 12.11: Add Fixed Effects of Item Predictors

. mixed logrt c.rel3 c.sal3 c.rel3#c.sal3, /// > || _all: R.subjectid , variance reml /// > || _all: R.itemid ,

Performing EM optimization:

Performing gradient-based optimization:

Iteration 0: log restricted-likelihood = -7590.5374 Iteration 1: log restricted-likelihood = -7590.5374

Computing standard errors:

Mixed-effects REML regression Number of obs = 7646 Group variable: _all Number of groups = 1

Obs per group: min = 7646 avg = 7646.0 max = 7646



Wald chi2(3) = 19.44 Log restricted-likelihood = -7590.5374 Prob > chi2 = 0.0002

------------------------------------------------------------------------------- logrt | Coef. Std. Err. z P>|z| [95% Conf. Interval] --------------+---------------------------------------------------------------- rel3 | -.0502735 .0237461 -2.12 0.034 -.096815 -.003732 sal3 | -.1377454 .0421438 -3.27 0.001 -.2203457 -.0551451 | c.rel3#c.sal3 | -.0114669 .0199695 -0.57 0.566 -.0506065 .0276727 | _cons | 1.612585 .0569471 28.32 0.000 1.500971 1.7242 -------------------------------------------------------------------------------

------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ _all: Identity | var(R.subjec~d) | .1802798 .0215928 .1425592 .2279811 -----------------------------+------------------------------------------------ _all: Identity | var(R.itemid) | .0941133 .0199527 .0621141 .1425973 -----------------------------+------------------------------------------------ var(Residual) | .3898702 .006391 .3775431 .4025998 ------------------------------------------------------------------------------ LR test vs. linear regression: chi2(2) = 3265.05 Prob > chi2 = 0.0000

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

. estat ic, n(1),

Akaike's information criterion and Bayesian information criterion

----------------------------------------------------------------------------- Model | Obs ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- . | 1 . -7590.537 7 15195.07 15181.07 ----------------------------------------------------------------------------- Note: N=1 used in calculating BIC

. * Multivariate Test of 3 Item Predictor Effects . test (c.rel3=0) (c.sal3=0) (c.rel3#c.sal3=0)

( 1) [logrt]rel3 = 0 ( 2) [logrt]sal3 = 0 ( 3) [logrt]c.rel3#c.sal3 = 0

chi2( 3) = 19.44 Prob > chi2 = 0.0002

. estimates store FitItem,

. . display as result "Ch 12: Remove Item Random Intercept Variance" Ch 12: Remove Item Random Intercept Variance

. mixed logrt c.rel3 c.sal3 c.rel3#c.sal3, /// > || _all: R.subjectid , variance reml,

Performing EM optimization:

Performing gradient-based optimization:

Iteration 0: log restricted-likelihood = -8269.5097 Iteration 1: log restricted-likelihood = -8269.5097

Computing standard errors:

Mixed-effects REML regression Number of obs = 7646 Group variable: _all Number of groups = 1

Obs per group: min = 7646 avg = 7646.0 max = 7646



Wald chi2(3) = 590.13 Log restricted-likelihood = -8269.5097 Prob > chi2 = 0.0000

------------------------------------------------------------------------------- logrt | Coef. Std. Err. z P>|z| [95% Conf. Interval] --------------+---------------------------------------------------------------- rel3 | -.0502263 .0043269 -11.61 0.000 -.0587068 -.0417458 sal3 | -.1377934 .0076733 -17.96 0.000 -.1528327 -.122754 | c.rel3#c.sal3 | -.010456 .0036467 -2.87 0.004 -.0176033 -.0033087 | _cons | 1.610471 .0349977 46.02 0.000 1.541877 1.679065 -------------------------------------------------------------------------------

------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ _all: Identity | var(R.subjec~d) | .1769577 .021418 .1395869 .2243335 -----------------------------+------------------------------------------------ var(Residual) | .4781735 .0078139 .4631011 .4937363 ------------------------------------------------------------------------------ LR test vs. linear regression: chibar2(01) = 1907.10 Prob >= chibar2 = 0.0000

. estat ic, n(1),

Akaike's information criterion and Bayesian information criterion

----------------------------------------------------------------------------- Model | Obs ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- . | 1 . -8269.51 6 16551.02 16539.02 ----------------------------------------------------------------------------- Note: N=1 used in calculating BIC

. estimates store FitNoRandItem,

. lrtest FitItem FitNoRandItem,

Likelihood-ratio test LR chi2(1) = 1357.94 (Assumption: FitNoRandItem nested in FitItem) 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. Note: LR tests based on REML are valid only when the fixed-effects specification is identical for both models.

. . display as result "Eq 12.12: Add Fixed Main Effects of Subject Predictors" Eq 12.12: Add Fixed Main Effects of Subject Predictors

. mixed logrt c.rel3 c.sal3 c.rel3#c.sal3 c.older c.yrs65, /// > || _all: R.subjectid , variance reml /// > || _all: R.itemid ,

Performing EM optimization:

Performing gradient-based optimization:

Iteration 0: log restricted-likelihood = -7459.9523 Iteration 1: log restricted-likelihood = -7459.9523

Computing standard errors:

Mixed-effects REML regression Number of obs = 7646 Group variable: _all Number of groups = 1

Obs per group: min = 7646 avg = 7646.0 max = 7646



Wald chi2(5) = 784.45 Log restricted-likelihood = -7459.9523 Prob > chi2 = 0.0000

------------------------------------------------------------------------------- logrt | Coef. Std. Err. z P>|z| [95% Conf. Interval] --------------+---------------------------------------------------------------- rel3 | -.0503054 .0237415 -2.12 0.034 -.096838 -.0037728 sal3 | -.1377449 .0421357 -3.27 0.001 -.2203294 -.0551604 | c.rel3#c.sal3 | -.0114916 .0199657 -0.58 0.565 -.0506237 .0276404 | older | .5899115 .0555622 10.62 0.000 .4810116 .6988114 yrs65 | .0202122 .0044056 4.59 0.000 .0115774 .028847 _cons | 1.312313 .048333 27.15 0.000 1.217582 1.407044 -------------------------------------------------------------------------------

------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ _all: Identity | var(R.subjec~d) | .0233284 .0035999 .0172398 .0315673 -----------------------------+------------------------------------------------ _all: Identity | var(R.itemid) | .0940765 .019945 .0620896 .1425421 -----------------------------+------------------------------------------------ var(Residual) | .3898702 .006391 .3775431 .4025998 ------------------------------------------------------------------------------ LR test vs. linear regression: chi2(2) = 1507.28 Prob > chi2 = 0.0000

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

. estat ic, n(1),

Akaike's information criterion and Bayesian information criterion

----------------------------------------------------------------------------- Model | Obs ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- . | 1 . -7459.952 9 14937.9 14919.9 ----------------------------------------------------------------------------- Note: N=1 used in calculating BIC

. * Multivariate Test of 2 Subject Predictor Effects . test (c.older=0) (c.yrs65=0)

( 1) [logrt]older = 0 ( 2) [logrt]yrs65 = 0

chi2( 2) = 765.18 Prob > chi2 = 0.0000

. estimates store FitSubject,

. . display as result "Ch 12: Remove Subject Random Intercept Variance" Ch 12: Remove Subject Random Intercept Variance

. mixed logrt c.rel3 c.sal3 c.rel3#c.sal3 c.older c.yrs65, /// > || _all: R.itemid , variance reml,

Performing EM optimization:

Performing gradient-based optimization:

Iteration 0: log restricted-likelihood = -7573.6119 Iteration 1: log restricted-likelihood = -7573.6119

Computing standard errors:

Mixed-effects REML regression Number of obs = 7646 Group variable: _all Number of groups = 1

Obs per group: min = 7646 avg = 7646.0 max = 7646



Wald chi2(5) = 2855.58 Log restricted-likelihood = -7573.6119 Prob > chi2 = 0.0000

------------------------------------------------------------------------------- logrt | Coef. Std. Err. z P>|z| [95% Conf. Interval] --------------+---------------------------------------------------------------- rel3 | -.0503109 .0237036 -2.12 0.034 -.0967692 -.0038527 sal3 | -.1373275 .0420683 -3.26 0.001 -.2197799 -.0548751 | c.rel3#c.sal3 | -.0114482 .0199339 -0.57 0.566 -.0505178 .0276215 | older | .5881574 .0287204 20.48 0.000 .5318664 .6444483 yrs65 | .0201377 .0022896 8.80 0.000 .0156502 .0246253 _cons | 1.312469 .0456966 28.72 0.000 1.222905 1.402032 -------------------------------------------------------------------------------

------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ _all: Identity | var(R.itemid) | .0936142 .0198811 .0617404 .1419429 -----------------------------+------------------------------------------------ var(Residual) | .4128586 .0067005 .3999325 .4262026 ------------------------------------------------------------------------------ LR test vs. linear regression: chibar2(01) = 1279.96 Prob >= chibar2 = 0.0000

. estat ic, n(1),

Akaike's information criterion and Bayesian information criterion

----------------------------------------------------------------------------- Model | Obs ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- . | 1 . -7573.612 8 15163.22 15147.22 ----------------------------------------------------------------------------- Note: N=1 used in calculating BIC

. estimates store FitNoRandSubject,

. lrtest FitSubject FitNoRandSubject,

Likelihood-ratio test LR chi2(1) = 227.32 (Assumption: FitNoRandSub~t nested in FitSubject) 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. Note: LR tests based on REML are valid only when the fixed-effects specification is identical for both models.

. . ****** END CHAPTER 12 MODELS ****** . . * Close log . log close STATA_Chapter12 name: STATA_Chapter12 log: C:\Dropbox\PilesOfVariance\Chapter12\STATA\STATA_Chapter12_Output.smcl log type: smcl closed on: 21 Oct 2014, 10:33:39 ------------------------------------------------------------------------------------------------------------------------------------------------------