TITLE:
  Ch 10b: Multivariate Model of Symptoms and Positive Affect

DATA:
  ! Prior necessary data manipulation conducted using other programs
  FILE = MPLUS_Chapter10b.csv;
  FORMAT = FREE;

DEFINE:
  b1sq = burst1*burst1;

VARIABLE:
  NAMES = PersonID burst session symptoms posaff slope12 slope26 burst1 b1or2;
  USEVARIABLES = symptoms posaff slope12 slope26 burst1 b1or2 b1sq;
  MISSING = ALL (-9999);
  CLUSTER = PersonID burst;
  WITHIN = slope12 slope26;
  BETWEEN = (burst) burst1 b1or2 b1sq;

ANALYSIS:
  ESTIMATOR = ML;
  PROCESSORS = 4;
  TYPE = THREELEVEL RANDOM;

MODEL:

%WITHIN%
  symptoms posaff (SRvar1 PRvar1);
  symptoms WITH posaff (SRPRcov1);
  slope1s | symptoms ON slope12;
  slope2s | symptoms ON slope26;
  slope1p | posaff   ON slope12;
  slope2p | posaff   ON slope26;

%BETWEEN burst%
  symptoms slope1s slope2s (SIvar2 S1var2 S2var2);
  posaff   slope1p slope2p (PIvar2 P2var2 P2var2);
  symptoms WITH slope1s slope2s posaff (SIS1cov2 SIS2cov2 SIPIcov2);
  symptoms WITH slope1p slope2p (SIP1cov2 SIP2cov2);
  slope1s  WITH slope2s posaff  (S1S2cov2 S1PIcov2);
  slope1s  WITH slope1p slope2p (S1P1cov2 S1P2cov2);
  slope2s  WITH posaff slope1p slope2p (S2PIcov2 S2P1cov2 S2P2cov2);
  posaff   WITH slope1p slope2p (PIP1cov2 PIP2cov2);
  slope1p  WITH slope2p (P1P2cov2);
  lins  | symptoms ON burst1;
  quads | symptoms ON b1sq;
  slope2s ON burst1 b1sq (bLsd26s bQsd26s);
  linp  | posaff ON burst1;
  mb12p | posaff ON b1or2;
  slope1 ON b1or2 (b12sd12);

%BETWEEN PersonID%
  [symptoms slope1s slope2s lins quads]   (Sint bs12s bs26s blins bquads);
  [posaff   slope1p slope2p linp mb12p@0] (Pint bs12p bs26p blinp bmb12p);
  symptoms lins quads@0 slope1s@0 slope2s@0 (SIvar3 SLvar3 SQvar3  S1var3 S2var3);
  posaff   linp mb12p@0 slope1p   slope2p   (PIvar3 PLvar3 Pmb12v3 P1var3 P2var3);
  symptoms WITH lins posaff linp(SISLcov3 SIPIcov3 SIPLcov3);
  symptoms WITH slope1p slope2p (SIP1cov3 SIP2cov3);
  lins     WITH posaff linp slope1p slope2p (SLPIcov3 SLPLcov3 SLP1cov3 SLP2cov3);
  posaff   WITH linp slope1p slope2p (PIPLcov3 PIP1cov3 PIP2cov3);
  linp     WITH slope1p slope2p (PLP1cov3 PLP2cov3);
  slope1p  WITH slope2p (P1P2cov3);

MODEL CONSTRAINT:
  NEW(SISLcor3 SIPIcor3 SIPLcor3 SIP1cor3 SIP2cor3 SLPIcor3 SLPLcor3 SLP1cor3 SLP2cor3);
  NEW(PIPLcor3 PIP1cor3 PIP2cor3 PLP1cor3 PLP2cor3 P1P2cor3);
  NEW(SIS1cor2 SIS2cor2 SIPIcor2 SIP1cor2 SIP2cor2 S1S2cor2 S1PIcor2 S1P1cor2 S1P2cor2);
  NEW(S2PIcor2 S2P1cor2 S2P2cor2 PIP1cor2 PIP2cor2 P1P2cor2 SRPRcor1);
! Level-3 Correlation: Symptoms Intercept with Symptoms Linear Burst Slope
  SISLcor3 = SISLcov3 / (SQRT(SIvar3)*SQRT(SLvar3));
! Level-3 Correlation: Symptoms Intercept with Positive Affect Intercept
  SIPIcor3 = SIPIcov3 / (SQRT(SIvar3)*SQRT(PIvar3));
! Level-3 Correlation: Symptoms Intercept with Positive Affect Linear Burst Slope
  SIPLcor3 = SIPLcov3 / (SQRT(SIvar3)*SQRT(PLvar3));
! Level-3 Correlation: Symptoms Intercept with Positive Affect Session Slope12
  SIP1cor3 = SIP1cov3 / (SQRT(SIvar3)*SQRT(P1var3));
! Level-3 Correlation: Symptoms Intercept with Positive Affect Session Slope26
  SIP2cor3 = SIP2cov3 / (SQRT(SIvar3)*SQRT(P2var3));
! Level-3 Correlation: Symptoms Linear Burst Slope with Positive Affect Intercept
  SLPIcor3 = SLPIcov3 / (SQRT(SLvar3)*SQRT(PIvar3));
! Level-3 Correlation: Symptoms Linear Burst Slope with Positive Affect Linear Burst Slope
  SLPLcor3 = SLPLcov3 / (SQRT(SLvar3)*SQRT(PLvar3));
! Level-3 Correlation: Symptoms Linear Burst Slope with Positive Affect Session Slope12
  SLP1cor3 = SLP1cov3 / (SQRT(SLvar3)*SQRT(P1var3));
! Level-3 Correlation: Symptoms Linear Burst Slope with Positive Affect Session Slope26
  SLP2cor3 = SLP2cov3 / (SQRT(SLvar3)*SQRT(P2var3));
! Level-3 Correlation: Positive Affect Intercept with Positive Affect Linear Burst Slope
  PIPLcor3 = PIPLcov3 / (SQRT(PIvar3)*SQRT(PLvar3));
! Level-3 Correlation: Positive Affect Intercept with Positive Affect Session Slope12
  PIP1cor3 = PIP1cov3 / (SQRT(PIvar3)*SQRT(P1var3));
! Level-3 Correlation: Positive Affect Intercept with Positive Affect Session Slope26
  PIP2cor3 = PIP2cov3 / (SQRT(PIvar3)*SQRT(P2var3));
! Level-3 Correlation: Positive Affect Linear Burst Slope with Positive Affect Session Slope12
  PLP1cor3 = PLP1cov3 / (SQRT(PLvar3)*SQRT(P1var3));
! Level-3 Correlation: Positive Affect Linear Burst Slope with Positive Affect Session Slope26
  PLP2cor3 = PLP2cov3 / (SQRT(PLvar3)*SQRT(P2var3));
! Level-3 Correlation: Positive Affect Session Slope12 with Positive Affect Session Slope26
  P1P2cor3 = P1P2cov3 / (SQRT(P1var3)*SQRT(P2var3));
! Level-2 Correlation: Symptoms Intercept with Symptoms Session Slope12
  SIS1cor2 = SIS1cov2 / (SQRT(SIvar2)*SQRT(S1var2));
! Level-2 Correlation: Symptoms Intercept with Symptoms Session Slope26
  SIS2cor2 = SIS2cov2 / (SQRT(SIvar2)*SQRT(S2var2));
! Level-2 Correlation: Symptoms Intercept with Positive Affect Intercept
  SIPIcor2 = SIPIcov2 / (SQRT(SIvar2)*SQRT(PIvar2));
! Level-2 Correlation: Symptoms Intercept with Positive Affect Session Slope12
  SIP1cor2 = SIP1cov2 / (SQRT(SIvar2)*SQRT(P1var2));
! Level-2 Correlation: Symptoms Intercept with Positive Affect Session Slope26
  SIP2cor2 = SIP2cov2 / (SQRT(SIvar2)*SQRT(P2var2));
! Level-2 Correlation: Symptoms Session Slope12 with Symptoms Session Slope26
  S1S2cor2 = S1S2cov2 / (SQRT(S1var2)*SQRT(S2var2));
! Level-2 Correlation: Symptoms Session Slope12 with Positive Affect Intercept
  S1PIcor2 = S1PIcov2 / (SQRT(S1var2)*SQRT(PIvar2));
! Level-2 Correlation: Symptoms Session Slope12 with Positive Affect Session Slope12
  S1P1cor2 = S1P1cov2 / (SQRT(S1var2)*SQRT(P1var2));
! Level-2 Correlation: Symptoms Session Slope12 with Positive Affect Session Slope26
  S1P2cor2 = S1P2cov2 / (SQRT(S1var2)*SQRT(P2var2));
! Level-2 Correlation: Symptoms Session Slope26 with Positive Affect Intercept
  S2PIcor2 = S2PIcov2 / (SQRT(S2var2)*SQRT(PIvar2));
! Level-2 Correlation: Symptoms Session Slope26 with Positive Affect Session Slope12
  S2P1cor2 = S2P1cov2 / (SQRT(S2var2)*SQRT(P1var2));
! Level-2 Correlation: Symptoms Session Slope26 with Positive Affect Session Slope26
  S2P2cor2 = S2P2cov2 / (SQRT(S2var2)*SQRT(P2var2));
! Level-2 Correlation: Positive Affect Intercept with Positive Affect Session Slope12
  PIP1cor2 = PIP1cov2 / (SQRT(PIvar2)*SQRT(P1var2));
! Level-2 Correlation: Positive Affect Intercept with Positive Affect Session Slope26
  PIP2cor2 = PIP2cov2 / (SQRT(PIvar2)*SQRT(P2var2));
! Level-2 Correlation: Positive Affect Session Slope12 with Positive Affect Session Slope26
  P1P2cor2 = P1P2cov2 / (SQRT(P1var2)*SQRT(P2var2));
! Level-1 Correlation: Symptoms Residual with Positive Affect Residual
  SRPRcor1 = SRPRcov1 / (SQRT(SRvar1)*SQRT(PRvar1));