TITLE:
  Ch 4: Empty Means, First-Order Auto-Regressive Heterogeneous R-Only Model

DATA:
  FILE = MPLUS_Chapter4.csv;
  FORMAT = FREE;

DATA LONGTOWIDE:
  LONG = posmood;
  WIDE = posmood1-posmood7;
  IDVARIABLE = PersonID;
  REPETITION = studyday (1-7);

VARIABLE:
  NAMES = PersonID studyday posmood;
  USEVARIABLES = posmood1-posmood7;
  MISSING = ALL (-9999);

ANALYSIS:
  ESTIMATOR = ML;
  PROCESSORS = 4;

OUTPUT:
  STDYX;

MODEL:
  posmood1-posmood7 (totvar1-totvar7);
  posmood1-posmood6 PWITH posmood2-posmood7 (totcov1-totcov6);
  posmood1-posmood5 PWITH posmood3-posmood7 (totcov7-totcov11);
  posmood1-posmood4 PWITH posmood4-posmood7 (totcov12-totcov15);
  posmood1-posmood3 PWITH posmood5-posmood7 (totcov16-totcov18);
  posmood1-posmood2 PWITH posmood6-posmood7 (totcov19-totcov20);
  posmood1          PWITH posmood7          (totcov21);
  [posmood1-posmood7] (mean);

MODEL CONSTRAINT:
  NEW(AR1cor);
! Total Covariance for Studyday 1 and 2
  totcov1  = AR1cor**1*SQRT(totvar1)*SQRT(totvar2);
! Total Covariance for Studyday 2 and 3
  totcov2  = AR1cor**1*SQRT(totvar2)*SQRT(totvar3);
! Total Covariance for Studyday 3 and 4
  totcov3  = AR1cor**1*SQRT(totvar3)*SQRT(totvar4);
! Total Covariance for Studyday 4 and 5
  totcov4  = AR1cor**1*SQRT(totvar4)*SQRT(totvar5);
! Total Covariance for Studyday 5 and 6
  totcov5  = AR1cor**1*SQRT(totvar5)*SQRT(totvar6);
! Total Covariance for Studyday 6 and 7
  totcov6  = AR1cor**1*SQRT(totvar6)*SQRT(totvar7);
! Total Covariance for Studyday 1 and 3
  totcov7  = AR1cor**2*SQRT(totvar1)*SQRT(totvar3);
! Total Covariance for Studyday 2 and 4
  totcov8  = AR1cor**2*SQRT(totvar2)*SQRT(totvar4);
! Total Covariance for Studyday 3 and 5
  totcov9  = AR1cor**2*SQRT(totvar3)*SQRT(totvar5);
! Total Covariance for Studyday 4 and 6
  totcov10 = AR1cor**2*SQRT(totvar4)*SQRT(totvar6);
! Total Covariance for Studyday 5 and 7
  totcov11 = AR1cor**2*SQRT(totvar5)*SQRT(totvar7);
! Total Covariance for Studyday 1 and 4
  totcov12 = AR1cor**3*SQRT(totvar1)*SQRT(totvar4);
! Total Covariance for Studyday 2 and 5
  totcov13 = AR1cor**3*SQRT(totvar2)*SQRT(totvar5);
! Total Covariance for Studyday 3 and 6
  totcov14 = AR1cor**3*SQRT(totvar3)*SQRT(totvar6);
! Total Covariance for Studyday 4 and 7
  totcov15 = AR1cor**3*SQRT(totvar4)*SQRT(totvar7);
! Total Covariance for Studyday 1 and 5
  totcov16 = AR1cor**4*SQRT(totvar1)*SQRT(totvar5);
! Total Covariance for Studyday 2 and 6
  totcov17 = AR1cor**4*SQRT(totvar2)*SQRT(totvar6);
! Total Covariance for Studyday 3 and 7
  totcov18 = AR1cor**4*SQRT(totvar3)*SQRT(totvar7);
! Total Covariance for Studyday 1 and 6
  totcov19 = AR1cor**5*SQRT(totvar1)*SQRT(totvar6);
! Total Covariance for Studyday 2 and 7
  totcov20 = AR1cor**5*SQRT(totvar2)*SQRT(totvar7);
! Total Covariance for Studyday 1 and 7
  totcov21 = AR1cor**6*SQRT(totvar1)*SQRT(totvar7);