title: Longitudinal Latent Change Score Modeling with Lavaan in R
body: <p>I have the following data set:</p>
  <pre><code>structure(list(ID = c(38623L, 38806L, 39593L, 39820L, 39951L, 
  40286L, 43762L, 52577L, 54153L, 57445L, 58503L, 59344L, 59361L, 
  60575L, 61656L, 62210L, 62285L, 62937L, 64081L, 64328L, 65302L, 
  65478L, 65480L, 65487L, 65572L, 65935L, 65974L, 65991L, 65995L, 
  66013L, 66154L, 66237L, 66245L, 66389L, 66460L, 67174L, 73230L, 
  73525L, 73539L, 73677L, 73942L, 73953L, 74113L, 74114L, 74439L, 
  74641L, 74657L, 74794L, 74800L, 74836L, 74942L, 74962L, 74969L, 
  74977L, 74985L, 74989L, 75220L, 75229L, 75407L, 75653L, 75735L, 
  75757L, 75895L, 75898L, 76381L, 76559L, 76594L, 76746L, 76751L, 
  76775L, 77088L, 77091L, 77099L, 77134L, 77188L, 77252L, 77304L, 
  77413L, 77528L, 77556L, 77585L, 78262L, 79724L, 79730L, 79850L, 
  79977L, 80052L, 80819L, 80901L, 80932L, 81071L, 81098L, 81142L, 
  81175L), Sex = structure(c(2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 
  2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
  2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
  2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
  1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 
  1L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 
  1L, 1L, 1L, 1L, 2L), .Label = c(&quot;Male&quot;, &quot;Female&quot;), class = &quot;factor&quot;), 
      T1 = c(0.00103209, 0.001136335, 0.001130695, 0.00113139, 
      0.000986063, 0.0010712, 0.00110197, 0.001090875, 0.001030151, 
      0.001035065, 0.001056565, 0.001064622, 0.001114025, 0.001087175, 
      0.001087645, 0.0010694, 0.001089425, 0.001129075, 0.00110335, 
      0.00111867, 0.00108407, 0.001076165, 0.00112799, 0.00106542, 
      0.00105824, 0.001051684, 0.001073525, 0.00102377, 0.0011, 
      0.001039055, 0.00105945, 0.001083505, 0.0010723, 0.001123395, 
      0.00110417, 0.00114891, 0.001115405, 0.00110057, 0.001054205, 
      0.00105165, 0.001095601, 0.001112195, 0.001061645, 0.001081505, 
      0.00112992, 0.001069345, 0.00108842, 0.001066665, 0.00106081, 
      0.001065165, 0.00108621, 0.00103779, 0.00103329, 0.00107046, 
      0.001094945, 0.001063225, 0.001077665, 0.0011242, 0.001161425, 
      0.001092915, 0.001120835, 0.001060845, 0.001072238, 0.00109486, 
      0.00111587, 0.001166475, 0.00107877, 0.00103524, 0.001112615, 
      0.000992363, 0.001057025, 0.001055855, 0.001165165, 0.001046216, 
      0.001015101, 0.001094015, 0.00104152, 0.00104361, 0.001056924, 
      0.0011807, 0.001090905, 0.00106178, 0.00113283, 0.001154635, 
      0.00110195, 0.001115265, 0.001102255, 0.00106396, 0.001073585, 
      0.001047345, 0.001022798, 0.001187635, 0.001033095, 0.00112301
      ), T2 = c(0.00102627, 0.00110609, 0.001158665, 0.00112353, 
      0.00097819, 0.001078495, 0.00109504, 0.001056945, 0.001034427, 
      0.00105191, 0.001014149, 0.001018892, 0.00112666, 0.001024891, 
      0.001071736, 0.001075945, 0.001031211, 0.001122935, 0.00107988, 
      0.001161715, 0.00112603, 0.00107674, 0.001147125, 0.00104971, 
      0.00108423, 0.00103364, 0.001071835, 0.00101976, 0.00107818, 
      0.001067145, 0.001062425, 0.00110346, 0.00108456, 0.00113592, 
      0.001110565, 0.00110386, 0.00112389, 0.001091155, 0.00105652, 
      0.001030636, 0.001106515, 0.00109062, 0.001030305, 0.00108161, 
      0.00112294, 0.001052327, 0.00107416, 0.001091, 0.001057725, 
      0.00107489, 0.0010597, 0.001047792, 0.000995212, 0.001092055, 
      0.00106338, 0.001078475, 0.00110247, 0.00111765, 0.00113914, 
      0.001073185, 0.001091145, 0.001040767, 0.00106448, 0.00105502, 
      0.00108874, 0.00117407, 0.001044455, 0.00104921, 0.001136435, 
      0.001009874, 0.00106717, 0.001055338, 0.001157375, 0.001061175, 
      0.000983892, 0.001094945, 0.001018795, 0.00107304, 0.0010772, 
      0.00114321, 0.00111869, 0.0010709, 0.00116752, 0.001175765, 
      0.001113535, 0.001123455, 0.001081295, 0.001084425, 0.00107189, 
      0.001030513, 0.001043751, 0.001157355, 0.001039899, 0.00116496
      ), T3 = c(0.001076605, 0.001113025, 0.00115085, 0.00115274, 
      0.001005614, 0.00111759, 0.00107761, 0.00111791, 0.001033532, 
      0.001038104, 0.001059563, 0.001027819, 0.001120055, 0.00108158, 
      0.001099325, 0.001086375, 0.001109065, 0.001077765, 0.00109264, 
      0.00116222, 0.00112626, 0.001091765, 0.00113837, 0.00104618, 
      0.00109727, 0.001055565, 0.001115175, 0.000986792, 0.00107968, 
      0.00106097, 0.001067105, 0.001083625, 0.00109082, 0.00114355, 
      0.001099115, 0.001125253, 0.001131355, 0.001104175, 0.001104315, 
      0.00103858, 0.001072123, 0.00109497, 0.00107783, 0.00107379, 
      0.00114186, 0.00110761, 0.001102845, 0.001090495, 0.00105551, 
      0.00108908, 0.001082845, 0.0010599, 0.001042808, 0.00108644, 
      0.00106482, 0.00111119, 0.001077005, 0.001183845, 0.001134605, 
      0.00107317, 0.00112268, 0.00108716, 0.00108437, 0.0010827, 
      0.00111043, 0.001177305, 0.00110218, 0.00103996, 0.00111301, 
      0.00100762, 0.00106678, 0.001030939, 0.001161045, 0.001080915, 
      0.001053775, 0.001072078, 0.00103878, 0.00112049, 0.001085025, 
      0.001165745, 0.00114263, 0.00109784, 0.001187105, 0.001194925, 
      0.001139195, 0.0011009, 0.00110112, 0.00107563, 0.001055985, 
      0.00100656, 0.001022506, 0.00114974, 0.00105716, 0.00113243
      )), row.names = c(NA, -94L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
  ))
  </code></pre>
  <p>Which looks like:</p>
  <pre><code>DF
  # A tibble: 94 x 5
        ID Sex          T1       T2      T3
     &lt;int&gt; &lt;fct&gt;     &lt;dbl&gt;    &lt;dbl&gt;   &lt;dbl&gt;
   1 38623 Female 0.00103  0.00103  0.00108
   2 38806 Female 0.00114  0.00111  0.00111
   3 39593 Female 0.00113  0.00116  0.00115
   4 39820 Female 0.00113  0.00112  0.00115
   5 39951 Male   0.000986 0.000978 0.00101
   6 40286 Female 0.00107  0.00108  0.00112
   7 43762 Female 0.00110  0.00110  0.00108
   8 52577 Female 0.00109  0.00106  0.00112
   9 54153 Male   0.00103  0.00103  0.00103
  10 57445 Female 0.00104  0.00105  0.00104
  # ... with 84 more rows
  </code></pre>
  <p>Each time point (<code>T1</code>, <code>T2</code>, <code>T3</code>) represents a physiological measure collected at that visit for each subject (<code>ID</code>).</p>
  <p><strong>I am trying to model the change in intercepts and slopes, specifically to measure inter-individual differences across time points.</strong></p>
  <p>My model:</p>
  <pre><code>linear.lcm &lt;- &quot;
                # Define the Latent Variables
                int =~ 1*T1 + 1*T2 + 1*T3
                slp =~ 0*T1 + 1*T2 + 2*T3
                
                # Define Factor Means
                int ~ 1
                slp ~ 1
                
                # Define Factor (Co)Variances
                int ~~ int
                int ~~ slp
                slp ~~ slp
                
                # Define Indicator Residual Variances
                T1 ~~ T1
                T2 ~~ T2
                T3 ~~ T3
  &quot;
  </code></pre>
  <p>A normalize function to scale the small values (credit to an answer from this site):</p>
  <pre><code>#normalize
  normalize = function(a,x){
      ((a-min(a))/(max(a)-min(a)))+x
  }
  </code></pre>
  <p>Fitting the model:</p>
  <pre><code>#lcm model
  lcm &lt;- lavaan::growth(linear.lcm, 
                        data = normalize(DF[,3:5],1),
                        estimator = &quot;MLR&quot;,
                        missing = &quot;FIML&quot;)
  </code></pre>
  <p>However, I get a warning:</p>
  <pre><code>Warning message:
  In lav_object_post_check(object) :
    lavaan WARNING: some estimated ov variances are negative
  </code></pre>
  <p>I can see that <code>T1</code> variance is negative. This doesn't seem correct, and I would appreciate help in correcting my model.</p>
  <pre><code>summary(lcm, fit.measures = FALSE, estimates=  TRUE, 
          standardize = TRUE, rsquare = TRUE)
  </code></pre>