* Stop syntax and large titles from printing to output.
SET PRINTBACK=NONE HEADER=NO.

***********************************************************************************.
*******             BEGIN DATA MANIPULATION OF CHAPTER 8 EXAMPLE            *******.
*******               CHANGE "filesave" to your directory                   *******.
***********************************************************************************.

* Define location of files used in code below.
FILE HANDLE filesave /NAME = "C:\Dropbox\PilesOfVariance\Chapter8\SPSS".

* Import chapter 8 stacked data. 
GET FILE = "filesave/SPSS_Chapter8.sav".
DATASET NAME Chapter8 WINDOW=FRONT.

* Create person means across time.
SORT CASES BY PersonID.
DATASET DECLARE PersonMeans8.
AGGREGATE
   /OUTFILE="PersonMeans8"
   /PRESORTED
   /BREAK = PersonID
   /PMwomen = MEAN(women)
   /PMbaseage = MEAN(baseage)
   /PMmood = MEAN(mood)
   /PMstressor = MEAN(stressor).

* Merge person means back into original data.
DATASET ACTIVATE Chapter8.
MATCH FILES
   /FILE = *
   /TABLE = "PersonMeans8"
   /BY PersonID.
EXECUTE.
VARIABLE LABELS
PMmood "PMmood: Person Mean Negative Mood"
PMstressor "PMstressor: Person Mean Stressors".

* Create centered predictors for analysis.
COMPUTE age80 = baseage - 80.
COMPUTE mood2 = mood - 2.
COMPUTE WPmood = mood - PMmood.
COMPUTE PMmood2 = PMmood - 2.
COMPUTE WPstressor = stressor - PMstressor.
COMPUTE PMstressor40 = PMstressor - .40.
VARIABLE LABELS
age80 "age80: Baseline Age (0=80)"
mood2 "mood2: Daily Negative Mood (0=2)"
WPmood "WPmood: Within-Person Negative Mood (0=PM)"
PMmood2 "PMmood2: Person Mean Negative Mood (0=2)"
WPstressor "WPstressor: Within-Person Stressors (0=PM)"
PMstressor40 "PMstressor40: Mean #Days with Stressor (0=0.40)".

* Subset sample to complete cases for all predictors.
SELECT IF NVALID(women, baseage, symptoms, mood, stressor, mood)=6.
* Subset sample to study days within a two-week period.
SELECT IF (studyday<15).
EXECUTE.

***********************************************************************************.
*******                        BEGIN CHAPTER 8 MODELS                       *******.
*******    NOTE: HETEROGENEOUS VARIANCE MODELS ARE NOT POSSIBLE IN SPSS     *******.
***********************************************************************************.

* Open output directory.
OUTPUT NAME SPSS_Chapter8_Output.

DATASET ACTIVATE PersonMeans8.
ECHO "Chapter 8: Descriptive Statistics for Time-Invariant Variables".
SUMMARIZE
   /TABLES = PMwomen PMbaseage PMmood PMstressor
   /FORMAT = NOLIST TOTAL 
   /CELLS  = COUNT MEAN STDDEV MIN MAX.

DATASET ACTIVATE Chapter8.
ECHO "Chapter 8: Descriptive Statistics for Time-Varying Variables".
SUMMARIZE
   /TABLES = symptoms mood stressor WPmood WPstressor
   /FORMAT = NOLIST TOTAL 
   /CELLS  = COUNT MEAN STDDEV MIN MAX.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.1: Conditional Baseline Model;'.
ECHO 'Just Sex and Age in the Model for the Means'.
MIXED symptoms BY PersonID WITH women age80
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Ch 8: Empty Means, Random Intercept Model for Negative Mood Predictor'.
MIXED mood BY PersonID
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    =
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.3: Adding BP and WP Effects of Negative Mood to the Model for the Means;'.
ECHO 'Using Person-Mean-Centering for Negative Mood'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'Multivariate Test of BP and WP Negative Mood Fixed Effects' PMmood2 1; WPmood 1
     /TEST     = 'Age Slope for Men'                            age80 1 women*age80 0
     /TEST     = 'Age Slope for Women'                          age80 1 women*age80 1
     /TEST     = 'Contextual Negative Mood Effect'              WPmood -1 PMmood2 1
     /TEST     = 'Predicted Symptoms for PMmood=2 WPmood=-1'    intercept 1 PMmood2 0 WPmood -1
     /TEST     = 'Predicted Symptoms for PMmood=2 WPmood=0'     intercept 1 PMmood2 0 WPmood 0
     /TEST     = 'Predicted Symptoms for PMmood=2 WPmood=1'     intercept 1 PMmood2 0 WPmood 1
     /TEST     = 'Predicted Symptoms for PMmood=3 WPmood=-1'    intercept 1 PMmood2 1 WPmood -1
     /TEST     = 'Predicted Symptoms for PMmood=3 WPmood=0'     intercept 1 PMmood2 1 WPmood 0
     /TEST     = 'Predicted Symptoms for PMmood=3 WPmood=1'     intercept 1 PMmood2 1 WPmood 1
     /TEST     = 'Predicted Symptoms for PMmood=1 WPmood=0'     intercept 1 PMmood2 -1 WPmood 0
     /TEST     = 'Predicted Symptoms for PMmood=2 WPmood=0'     intercept 1 PMmood2 0 WPmood 0
     /TEST     = 'Predicted Symptoms for PMmood=3 WPmood=0'     intercept 1 PMmood2 1 WPmood 0
     /TEST     = 'Predicted Symptoms for PMmood=4 WPmood=0'     intercept 1 PMmood2 2 WPmood 0
     /SAVE     = FIXPRED(PredBPWPMood)
.
CORRELATIONS symptoms PredBPWPMood.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.5: Adding Smushed Effect of Negative Mood to the Model for the Means;'.
ECHO 'Using Grand-Mean-Centering for Negative Mood'.
MIXED symptoms BY PersonID WITH women age80 mood2
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 mood2
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'Age Slope for Men'             age80 1 women*age80 0
     /TEST     = 'Age Slope for Women'           age80 1 women*age80 1
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.7: Adding a Contextual Effect of Negative Mood to the Model for the Means;'.
ECHO 'Using Person-Mean-Centering for Negative Mood'.
MIXED symptoms BY PersonID WITH women age80 mood2 PMmood2
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 mood2 PMmood2
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'Age Slope for Men'                  age80 1 women*age80 0
     /TEST     = 'Age Slope for Women'                age80 1 women*age80 1
     /TEST     = 'Between-Person Negative Mood Effect'mood2 1 PMmood2 1
     /SAVE     = FIXPRED(PredBPWPMood2)
.
CORRELATIONS symptoms PredBPWPMood2.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.9: Adding a Random Effect of Negative Mood to the Model for the Variance;'.
ECHO 'Using Person-Mean-Centering for Negative Mood'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV G
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood
     /RANDOM   = INTERCEPT WPmood | COVTYPE(UN) SUBJECT(PersonID)
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.9: Adding a Random Effect of Negative Mood to the Model for the Variance;'.
ECHO 'Using Grand-Mean-Centering for Negative Mood'.
MIXED symptoms BY PersonID WITH women age80 mood2 PMmood2
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV G
     /FIXED    = women age80 women*age80
                 mood2 PMmood2
     /RANDOM   = INTERCEPT mood2 | COVTYPE(UN) SUBJECT(PersonID)
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.10: Adding Contextual and WP Effects of Stressors to the Model for the Means;'.
ECHO 'Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood PMstressor40 stressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood PMstressor40 stressor
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'Multivariate Test of Stressor Fixed Effects' PMstressor40 1; stressor 1
     /TEST     = 'Intercept for Women'                          intercept 1 women 1
     /TEST     = 'Age Slope for Women'                          age80 1 women*age80 1
     /TEST     = 'Contextual Negative Mood Effect'              WPmood -1 PMmood2 1
     /TEST     = 'Between-Person Stressor Effect'               stressor 1 PMstressor40 1
     /TEST     = 'Contextual Negative Mood Effect Per Day'      PMmood2 .2
     /SAVE     = FIXPRED(PredBPWPStressor)
.
CORRELATIONS symptoms PredBPWPStressor.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Ch 8: Adding Random WP Effect of Stressors to the Model for the Variance;'.
ECHO 'Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood PMstressor40 stressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV G
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood PMstressor40 stressor
     /RANDOM   = INTERCEPT stressor | COVTYPE(UN) SUBJECT(PersonID)
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.11: Adding 4 Sex*Negative Mood and Sex*Stressors Interactions to the Model for the Means;'.
ECHO 'Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood PMstressor40 stressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood PMstressor40 stressor
                 women*PMmood2 women*WPmood women*PMstressor40 women*stressor
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'Multivariate Test of 4 Sex Interactions' women*PMmood2 1; women*WPmood 1; women*PMstressor40 1; women*stressor 1
     /TEST     = 'Intercept: Men'                          intercept 1 women 0
     /TEST     = 'Intercept: Women'                        intercept 1 women 1
     /TEST     = 'Intercept: Sex Diff'                     women 1
     /TEST     = 'Age Slope: Men'                          age80 1 women*age80 0
     /TEST     = 'Age Slope: Women'                        age80 1 women*age80 1
     /TEST     = 'Age Slope: Sex Diff'                     women*age80 1
     /TEST     = 'BP Negative Mood: Men'                   PMmood2 1 women*PMmood2 0
     /TEST     = 'BP Negative Mood: Women'                 PMmood2 1 women*PMmood2 1
     /TEST     = 'BP Negative Mood: Sex Diff'              women*PMmood2 1
     /TEST     = 'Contextual Negative Mood: Men'           WPmood -1 women*WPmood  0 PMmood2 1 women*PMmood2 0
     /TEST     = 'Contextual Negative Mood: Women'         WPmood -1 women*WPmood -1 PMmood2 1 women*PMmood2 1
     /TEST     = 'Contextual Negative Mood: Sex Diff'      women*WPmood -1 women*PMmood2 1
     /TEST     = 'WP Negative Mood: Men'                   WPmood 1 women*WPmood 0
     /TEST     = 'WP Negative Mood: Women'                 WPmood 1 women*WPmood 1
     /TEST     = 'WP Negative Mood: Sex Diff'              women*WPmood 1
     /TEST     = 'BP Stressors: Men'                       stressor 1 women*stressor 0 PMstressor40 1 women*PMstressor40 0
     /TEST     = 'BP Stressors: Women'                     stressor 1 women*stressor 1 PMstressor40 1 women*PMstressor40 1
     /TEST     = 'BP Stressors: Sex Diff'                  women*stressor 1 women*PMstressor40 1
     /TEST     = 'Contextual Stressors: Men'               PMstressor40 1 women*PMstressor40 0
     /TEST     = 'Contextual Stressors: Women'             PMstressor40 1 women*PMstressor40 1
     /TEST     = 'Contextual Stressors: Sex Diff'          women*PMstressor40 1
     /TEST     = 'WP Stressors: Men'                       stressor 1 women*stressor 0
     /TEST     = 'WP Stressors: Women'                     stressor 1 women*stressor 1
     /TEST     = 'WP Stressors: Sex Diff'                  women*stressor 1
     /TEST     = 'Contextual Stressors per Day'            PMstressor40 .2
     /SAVE     = FIXPRED(PredSex4)
.
CORRELATIONS symptoms PredSex4.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.11reduced: Adding Only 2 Sex*Stressors Interactions to the Model for the Means;'.
ECHO 'Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood PMstressor40 stressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood PMstressor40 stressor
                 women*PMstressor40 women*stressor
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'Multivariate Test of 2 Sex Interactions' women*PMstressor40 1; women*stressor 1
     /SAVE     = FIXPRED(PredSex2)
.
CORRELATIONS symptoms PredSex2.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.12: Adding 4 Negative Mood*Stressors Interactions to the Model for the Means;'.
ECHO 'Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood PMstressor40 stressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood PMstressor40 stressor
                 women*PMstressor40 women*stressor
                 PMmood2*stressor PMmood2*PMstressor40 WPmood*stressor WPmood*PMstressor40
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'Multivariate Test of 4 Negative Mood*Stressors Interactions' PMmood2*stressor 1; PMmood2*PMstressor40 1; WPmood*stressor 1; WPmood*PMstressor40 1
     /TEST     = 'Intercept: Men'                                    intercept 1 women 0
     /TEST     = 'Intercept: Women'                                  intercept 1 women 1
     /TEST     = 'Intercept: Sex Diff'                               women 1
     /TEST     = 'Age Slope: Men'                                    age80 1 women*age80 0
     /TEST     = 'Age Slope: Women'                                  age80 1 women*age80 1
     /TEST     = 'Age Slope: Sex Diff'                               women*age80 1
     /TEST     = 'BP Negative Mood'                                  PMmood2 1
     /TEST     = 'Contextual Negative Mood'                          WPmood -1 PMmood2 1
     /TEST     = 'WP Negative Mood'                                  WPmood 1
     /TEST     = 'BP Stressors: Men'                                 stressor 1 women*stressor 0 PMstressor40 1 women*PMstressor40 0
     /TEST     = 'BP Stressors: Women'                               stressor 1 women*stressor 1 PMstressor40 1 women*PMstressor40 1
     /TEST     = 'BP Stressors: Sex Diff'                            women*stressor 1 women*PMstressor40 1
     /TEST     = 'Contextual Stressors: Men'                         PMstressor40 1 women*PMstressor40 0
     /TEST     = 'Contextual Stressors: Women'                       PMstressor40 1 women*PMstressor40 1
     /TEST     = 'Contextual Stressors: Sex Diff'                    women*PMstressor40 1
     /TEST     = 'WP Stressors: Men'                                 stressor 1 women*stressor 0
     /TEST     = 'WP Stressors: Women'                               stressor 1 women*stressor 1
     /TEST     = 'WP Stressors: Sex Diff'                            women*stressor 1
     /TEST     = 'Contextual Stressors per Day'                      PMstressor40 .2
     /TEST     = 'BP Negative Mood by BP Stressors'                  PMmood2*stressor 1 PMmood2*PMstressor40 1
     /TEST     = 'BP Negative Mood by Contextual Stressors'          PMmood2*PMstressor40 1
     /TEST     = 'BP Negative Mood by WP Stressors'                  PMmood2*stressor 1
     /TEST     = 'Contextual Negative Mood by BP Stressors'          WPmood*stressor -1 PMmood2*stressor 1 WPmood*PMstressor40 -1 PMmood2*PMstressor40 1
     /TEST     = 'Contextual Negative Mood by Contextual Stressors'  WPmood*PMstressor40 -1 PMmood2*PMstressor40 1
     /TEST     = 'Contextual Negative Mood by WP Stressors'          WPmood*stressor -1 PMmood2*stressor 1
     /TEST     = 'WP Negative Mood by BP Stressors'                  WPmood*stressor 1 WPmood*PMstressor40 1
     /TEST     = 'WP Negative Mood by Contextual Stressors'          WPmood*PMstressor40 1
     /TEST     = 'WP Negative Mood by WP Stressors'                  WPmood*stressor 1
     /SAVE     = FIXPRED(PredMoodStressor4)
.
CORRELATIONS symptoms PredMoodStressor4.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Ch 8: Checking Inter-Variable Interactions via PMC Negative Mood by PMC Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood PMstressor40 WPstressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood PMstressor40 WPstressor
                 women*PMstressor40 women*WPstressor
                 PMmood2*WPstressor PMmood2*PMstressor40 WPmood*WPstressor WPmood*PMstressor40
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'BP Negative Mood by BP Stressors'                  PMmood2*PMstressor40 1
     /TEST     = 'BP Negative Mood by Contextual Stressors'          PMmood2*WPstressor -1 PMmood2*PMstressor40 1
     /TEST     = 'BP Negative Mood by WP Stressors'                  PMmood2*WPstressor 1
     /TEST     = 'Contextual Negative Mood by BP Stressors'          WPmood*PMstressor40 -1 PMmood2*PMstressor40 1
     /TEST     = 'Contextual Negative Mood by Contextual Stressors'  WPmood*PMstressor40 -1 PMmood2*PMstressor40 1 PMmood2*WPstressor -1 WPmood*WPstressor 1
     /TEST     = 'Contextual Negative Mood by WP Stressors'          WPmood*WPstressor -1 PMmood2*WPstressor 1
     /TEST     = 'WP Negative Mood by BP Stressors'                  WPmood*PMstressor40 1
     /TEST     = 'WP Negative Mood by Contextual Stressors'          WPmood*WPstressor -1 WPmood*PMstressor40 1
     /TEST     = 'WP Negative Mood by WP Stressors'                  WPmood*WPstressor 1
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Ch 8: Checking Inter-Variable Interactions via GMC Negative Mood by GMC Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 mood2 PMstressor40 stressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 mood2 PMstressor40 stressor
                 women*PMstressor40 women*stressor
                 PMmood2*stressor PMmood2*PMstressor40 mood2*stressor mood2*PMstressor40
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'BP Negative Mood by BP Stressors'                  mood2*PMstressor40 1 PMmood2*PMstressor40 1 stressor*PMmood2 1 mood2*stressor 1
     /TEST     = 'BP Negative Mood by Contextual Stressors'          mood2*PMstressor40 1 PMmood2*PMstressor40 1
     /TEST     = 'BP Negative Mood by WP Stressors'                  PMmood2*stressor 1 mood2*stressor 1
     /TEST     = 'Contextual Negative Mood by BP Stressors'          PMmood2*stressor 1 PMmood2*PMstressor40 1
     /TEST     = 'Contextual Negative Mood by Contextual Stressors'  PMmood2*PMstressor40 1
     /TEST     = 'Contextual Negative Mood by WP Stressors'          PMmood2*stressor 1
     /TEST     = 'WP Negative Mood by BP Stressors'                  mood2*PMstressor40 1 mood2*stressor 1
     /TEST     = 'WP Negative Mood by Contextual Stressors'          mood2*PMstressor40 1
     /TEST     = 'WP Negative Mood by WP Stressors'                  mood2*stressor 1
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Ch 8: Checking Inter-Variable Interactions via GMC Negative Mood by PMC Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 mood2 PMstressor40 WPstressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 mood2 PMstressor40 WPstressor
                 women*PMstressor40 women*WPstressor
                 PMmood2*WPstressor PMmood2*PMstressor40 mood2*WPstressor mood2*PMstressor40
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'BP Negative Mood by BP Stressors'                  mood2*PMstressor40 1 PMmood2*PMstressor40 1
     /TEST     = 'BP Negative Mood by Contextual Stressors'          PMmood2*WPstressor -1 mood2*WPstressor -1 mood2*PMstressor40 1 PMmood2*PMstressor40 1
     /TEST     = 'BP Negative Mood by WP Stressors'                  PMmood2*WPstressor 1 mood2*WPstressor 1
     /TEST     = 'Contextual Negative Mood by BP Stressors'          PMmood2*PMstressor40 1
     /TEST     = 'Contextual Negative Mood by Contextual Stressors'  PMmood2*WPstressor -1 PMmood2*PMstressor40 1
     /TEST     = 'Contextual Negative Mood by WP Stressors'          PMmood2*WPstressor 1
     /TEST     = 'WP Negative Mood by BP Stressors'                  mood2*PMstressor40 1
     /TEST     = 'WP Negative Mood by Contextual Stressors'          mood2*WPstressor -1 mood2*PMstressor40 1
     /TEST     = 'WP Negative Mood by WP Stressors'                  mood2*WPstressor 1
.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.13: Adding 5 Intra-Variable Interactions to the Model for the Means;'.
ECHO 'Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood PMstressor40 stressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood PMstressor40 stressor
                 women*PMstressor40 women*stressor
                 PMmood2*PMmood2 WPmood*WPmood PMmood2*WPmood PMstressor40*PMstressor40 PMstressor40*stressor
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
     /TEST     = 'Multivariate Test of 5 Intra-Variable Interactions' PMmood2*PMmood2 1; WPmood*WPmood 1; PMmood2*WPmood 1; PMstressor40*PMstressor40 1; PMstressor40*stressor 1
     /TEST     = 'BP Negative Mood: Linear'                PMmood2 1
     /TEST     = 'BP Negative Mood: Quadratic'             PMmood2*PMmood2 1
     /TEST     = 'Contextual Negative Mood: Linear'        WPmood -1 PMmood2 1
     /TEST     = 'Contextual Negative Mood: Quadratic'     PMmood2*WPmood -1 PMmood2*PMmood2 1 WPmood*WPmood 1
     /TEST     = 'WP Negative Mood: Linear'                WPmood 1
     /TEST     = 'WP Negative Mood: Quadratic'             WPmood*WPmood 1
     /TEST     = 'BP by WP Negative Mood'                  PMmood2*WPmood 1
     /TEST     = 'Contextual by WP Negative Mood'          PMmood2*WPmood 1 WPmood*WPmood -2
     /TEST     = 'BP Stressor: Linear'                     PMstressor40 1 stressor 1
     /TEST     = 'BP Stressor: Quadratic'                  PMstressor40*PMstressor40 1 PMstressor40*stressor 1
     /TEST     = 'Contextual Stressors: Linear'            PMstressor40 1
     /TEST     = 'Contextual Stressors: Quadratic'         PMstressor40*PMstressor40 1
     /TEST     = 'WP Stressors: Linear'                    stressor 1
     /TEST     = 'BP/Contextual by WP Stressors'           PMstressor40*stressor 1
     /TEST     = 'BP Negative Mood: Linear at 1'           PMmood2 1 PMmood2*PMmood2 -2
     /TEST     = 'BP Negative Mood: Linear at 3'           PMmood2 1 PMmood2*PMmood2 2
     /SAVE     = FIXPRED(PredIntra5)
.
CORRELATIONS symptoms PredIntra5.

DATASET ACTIVATE Chapter8 WINDOW=FRONT.
ECHO 'Eq 8.13reduced: Baseline Homogeneous Variance Model with Significant Fixed Effects Only;'.
ECHO 'Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors'.
MIXED symptoms BY PersonID WITH women age80 PMmood2 WPmood PMstressor40 stressor
     /METHOD   = ML
     /PRINT    = SOLUTION TESTCOV
     /FIXED    = women age80 women*age80
                 PMmood2 WPmood PMstressor40 stressor
                 women*PMstressor40 women*stressor
                 PMmood2*PMmood2 PMmood2*WPmood
     /RANDOM   = INTERCEPT | COVTYPE(UN) SUBJECT(PersonID)
.

****** END CHAPTER 8 MODELS ******.

* Close output directory.
OUTPUT EXPORT NAME=SPSS_Chapter8_Output
     /CONTENTS EXPORT=VISIBLE LAYERS=VISIBLE MODELVIEWS=VISIBLE
     /HTML DOCUMENTFILE='C:\Dropbox\PilesOfVariance\Chapter8\SPSS\SPSS_Chapter8_Output.html'
           IMAGEFORMAT=PNG STYLING=YES.