TITLE:
  Ch 5: Random Linear Time Model with TOEP2 R Matrix

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

DATA LONGTOWIDE:
  LONG = outcome;
  WIDE = outcome1-outcome4;
  IDVARIABLE = PersonID;
  REPETITION = wave (1-4);

DEFINE:
  time = wave - 1;

VARIABLE:
  NAMES = PersonID wave outcome;
  USEVARIABLES = outcome1-outcome4;
  MISSING = ALL (-9999);

ANALYSIS:
  ESTIMATOR = ML;
  PROCESSORS = 4;

OUTPUT:
  STDYX;

MODEL:
  RandInt BY outcome1-outcome4@1;
  RandLin BY outcome1@0 outcome2@1 outcome3@2 outcome4@3;
  RandInt RandLin (intvar linvar);
  RandInt WITH RandLin;
  [outcome1-outcome4@0 RandInt RandLin];
  outcome1-outcome4 (resvar);
  outcome1-outcome3 PWITH outcome2-outcome4 (rescov1-rescov3);

MODEL CONSTRAINT:
  NEW(TOEPcor1);
! Residual Covariance for Outcome 1 and 2
  rescov1 = TOEPcor1*SQRT(resvar)*SQRT(resvar);
! Residual Covariance for Outcome 2 and 3
  rescov2 = TOEPcor1*SQRT(resvar)*SQRT(resvar);
! Residual Covariance for Outcome 3 and 4
  rescov3 = TOEPcor1*SQRT(resvar)*SQRT(resvar);