TITLE:
  Ch 6: 6c: Random Asymptote Random Amount Fixed Rate Model
  Would not converge in Mplus

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

DATA LONGTOWIDE:
  LONG = rt;
  WIDE = rt1-rt6;
  IDVARIABLE = PersonID;
  REPETITION = session (1-6);

DEFINE:
  ! Rescale original rt so Mplus will show all results
  rt = rt/10;

VARIABLE:
  NAMES = PersonID session rt;
  USEVARIABLES = rt1-rt6;
  MISSING = ALL (-9999);

ANALYSIS:
  ESTIMATOR = ML;
  PROCESSORS = 4;

MODEL:
  rt1-rt6 (totvar1-totvar6);
  rt1 WITH rt2-rt6 (totcov1-totcov5)  ;
  rt2 WITH rt3-rt6 (totcov6-totcov9)  ;
  rt3 WITH rt4-rt6 (totcov10-totcov12);
  rt4 WITH rt5-rt6 (totcov13-totcov14);
  rt5 WITH rt6     (totcov15)         ;
  [rt1-rt6] (mean1-mean6);

MODEL CONSTRAINT:
  NEW(fasymp famount frate resvar asympvar amountvar aacovar);
! Session=1 Time=0 Predicted Mean
  mean1 = fasymp + famount*EXP(frate*0);
! Session=2 Time=1 Predicted Mean
  mean2 = fasymp + famount*EXP(frate*1);
! Session=3 Time=2 Predicted Mean
  mean3 = fasymp + famount*EXP(frate*2);
! Session=4 Time=3 Predicted Mean
  mean4 = fasymp + famount*EXP(frate*3);
! Session=5 Time=4 Predicted Mean
  mean5 = fasymp + famount*EXP(frate*4);
! Session=6 Time=5 Predicted Mean
  mean6 = fasymp + famount*EXP(frate*5);
! Session=1 Time=0 Predicted Variance
  totvar1 = resvar + asympvar + aacovar*2*EXP(frate*0) + amountvar*EXP(frate*0)**2;
! Session=2 Time=1 Predicted Variance
  totvar2 = resvar + asympvar + aacovar*2*EXP(frate*1) + amountvar*EXP(frate*1)**2;
! Session=3 Time=2 Predicted Variance
  totvar3 = resvar + asympvar + aacovar*2*EXP(frate*2) + amountvar*EXP(frate*2)**2;
! Session=4 Time=3 Predicted Variance
  totvar4 = resvar + asympvar + aacovar*2*EXP(frate*3) + amountvar*EXP(frate*3)**2;
! Session=5 Time=4 Predicted Variance
  totvar5 = resvar + asympvar + aacovar*2*EXP(frate*4) + amountvar*EXP(frate*4)**2;
! Session=6 Time=5 Predicted Variance
  totvar6 = resvar + asympvar + aacovar*2*EXP(frate*5) + amountvar*EXP(frate*5)**2;
! Predicted Covariance for Sessions 1 and 2
  totcov1  = asympvar + aacovar*(EXP(frate*0)+EXP(frate*1)) + amountvar*(EXP(frate*0)*EXP(frate*1));
! Predicted Covariance for Sessions 1 and 3
  totcov2  = asympvar + aacovar*(EXP(frate*0)+EXP(frate*2)) + amountvar*(EXP(frate*0)*EXP(frate*2));
! Predicted Covariance for Sessions 1 and 4
  totcov3  = asympvar + aacovar*(EXP(frate*0)+EXP(frate*3)) + amountvar*(EXP(frate*0)*EXP(frate*3));
! Predicted Covariance for Sessions 1 and 5
  totcov4  = asympvar + aacovar*(EXP(frate*0)+EXP(frate*4)) + amountvar*(EXP(frate*0)*EXP(frate*4));
! Predicted Covariance for Sessions 1 and 6
  totcov5  = asympvar + aacovar*(EXP(frate*0)+EXP(frate*5)) + amountvar*(EXP(frate*0)*EXP(frate*5));
! Predicted Covariance for Sessions 2 and 3
  totcov6  = asympvar + aacovar*(EXP(frate*1)+EXP(frate*2)) + amountvar*(EXP(frate*1)*EXP(frate*2));
! Predicted Covariance for Sessions 2 and 4
  totcov7  = asympvar + aacovar*(EXP(frate*1)+EXP(frate*3)) + amountvar*(EXP(frate*1)*EXP(frate*3));
! Predicted Covariance for Sessions 2 and 5
  totcov8  = asympvar + aacovar*(EXP(frate*1)+EXP(frate*4)) + amountvar*(EXP(frate*1)*EXP(frate*4));
! Predicted Covariance for Sessions 2 and 6
  totcov9  = asympvar + aacovar*(EXP(frate*1)+EXP(frate*5)) + amountvar*(EXP(frate*1)*EXP(frate*5));
! Predicted Covariance for Sessions 3 and 4
  totcov10 = asympvar + aacovar*(EXP(frate*2)+EXP(frate*3)) + amountvar*(EXP(frate*2)*EXP(frate*3));
! Predicted Covariance for Sessions 3 and 5
  totcov11 = asympvar + aacovar*(EXP(frate*2)+EXP(frate*4)) + amountvar*(EXP(frate*2)*EXP(frate*4));
! Predicted Covariance for Sessions 3 and 6
  totcov12 = asympvar + aacovar*(EXP(frate*2)+EXP(frate*5)) + amountvar*(EXP(frate*2)*EXP(frate*5));
! Predicted Covariance for Sessions 4 and 5
  totcov13 = asympvar + aacovar*(EXP(frate*3)+EXP(frate*4)) + amountvar*(EXP(frate*3)*EXP(frate*4));
! Predicted Covariance for Sessions 4 and 6
  totcov14 = asympvar + aacovar*(EXP(frate*3)+EXP(frate*5)) + amountvar*(EXP(frate*3)*EXP(frate*5));
! Predicted Covariance for Sessions 5 and 6
  totcov15 = asympvar + aacovar*(EXP(frate*4)+EXP(frate*5)) + amountvar*(EXP(frate*4)*EXP(frate*5));