jmv::descriptives(mydata, vars = vars( LBStotal, CASI_ADHD_CSum), missing = TRUE)
## 
##  DESCRIPTIVES
## 
##  Descriptives                                         
##  ──────────────────────────────────────────────────── 
##                          LBStotal    CASI_ADHD_CSum   
##  ──────────────────────────────────────────────────── 
##    N                          395               432   
##    Missing                    145               108   
##    Mean                  25.82278          11.10648   
##    Median                      25          11.00000   
##    Standard deviation    6.537202          4.051038   
##    Minimum                     10                 0   
##    Maximum                     46                24   
##  ────────────────────────────────────────────────────
jmv::descriptives(mydata, vars = vars(COVIDrestrictionstotal, COVID_childimpact_T1, COVIDstressscale), missing = TRUE)
## 
##  DESCRIPTIVES
## 
##  Descriptives                                                                                 
##  ──────────────────────────────────────────────────────────────────────────────────────────── 
##                          COVIDrestrictionstotal    COVID_childimpact_T1    COVIDstressscale   
##  ──────────────────────────────────────────────────────────────────────────────────────────── 
##    N                                        392                     398                 398   
##    Missing                                  148                     142                 142   
##    Mean                                59.63776                19.13819            31.19598   
##    Median                              62.00000                19.00000            32.00000   
##    Standard deviation                  27.34195                5.035241            8.921815   
##    Minimum                                    0                       8                   2   
##    Maximum                                  106                      36                  55   
##  ────────────────────────────────────────────────────────────────────────────────────────────
jmv::descriptives(mydata, vars = vars(anxiety_T1, anxiety_T2, anxiety_T3, anxiety_T4))
## 
##  DESCRIPTIVES
## 
##  Descriptives                                                                   
##  ────────────────────────────────────────────────────────────────────────────── 
##                          anxiety_T1    anxiety_T2    anxiety_T3    anxiety_T4   
##  ────────────────────────────────────────────────────────────────────────────── 
##    N                            394           147           163           110   
##    Missing                      146           393           377           430   
##    Mean                    1.256839      1.422902      1.297546      1.405051   
##    Median                  1.333333      1.444444      1.333333      1.444444   
##    Standard deviation     0.5985536     0.4171743     0.4953677     0.5071884   
##    Minimum                 0.000000      0.000000      0.000000      0.000000   
##    Maximum                 3.000000      2.555556      2.666667      2.333333   
##  ──────────────────────────────────────────────────────────────────────────────
jmv::descriptives(mydata, vars = vars(depression_T1, depression_T2, depression_T3, depression_T4))
## 
##  DESCRIPTIVES
## 
##  Descriptives                                                                               
##  ────────────────────────────────────────────────────────────────────────────────────────── 
##                          depression_T1    depression_T2    depression_T3    depression_T4   
##  ────────────────────────────────────────────────────────────────────────────────────────── 
##    N                               394              147              163              110   
##    Missing                         146              393              377              430   
##    Mean                       1.192470         1.325964         1.239264         1.363636   
##    Median                     1.250000         1.250000         1.250000         1.500000   
##    Standard deviation        0.6964080        0.5275807        0.6011497        0.6016380   
##    Minimum                    0.000000         0.000000         0.000000         0.000000   
##    Maximum                    3.000000         2.500000         3.000000         2.750000   
##  ──────────────────────────────────────────────────────────────────────────────────────────
tabyl(mydata$income.f)
##  mydata$income.f   n   percent valid_percent
##    less than 40k  55 0.1018519     0.1185345
##           40-65k  80 0.1481481     0.1724138
##           66-80k  68 0.1259259     0.1465517
##          80-106k 119 0.2203704     0.2564655
##        over 106k 142 0.2629630     0.3060345
##             <NA>  76 0.1407407            NA
tabyl(mydata$education.f)
##     mydata$education.f   n     percent valid_percent
##  less than high school   2 0.003703704    0.00422833
##     high school or GED  25 0.046296296    0.05285412
##           some college  45 0.083333333    0.09513742
##                college  90 0.166666667    0.19027484
##        bachelor degree 201 0.372222222    0.42494715
##     some graduate work  36 0.066666667    0.07610994
##         masters degree  57 0.105555556    0.12050740
##        doctoral degree  17 0.031481481    0.03594080
##   prefer not to answer   0 0.000000000    0.00000000
##                   <NA>  67 0.124074074            NA
tabyl(mydata$child.age.f)
##  mydata$child.age.f   n    percent valid_percent
##                 0-5  13 0.02407407    0.02748414
##                5-10 253 0.46851852    0.53488372
##               10-15 187 0.34629630    0.39534884
##               15-20  20 0.03703704    0.04228330
##                <NA>  67 0.12407407            NA
tabyl(mydata$school.modality.f)
##  mydata$school.modality.f   n    percent valid_percent
##                 in person 303 0.56111111     0.6460554
##               alternating 113 0.20925926     0.2409382
##                   virtual  53 0.09814815     0.1130064
##                      <NA>  71 0.13148148            NA
tabyl(mydata$child.race.f)
##                      mydata$child.race.f   n     percent valid_percent
##  Aboriginal/ First Nations/ Métis/ Inuit  80 0.148148148   0.177777778
##                         White/ Caucasian 303 0.561111111   0.673333333
##                              South Asian   1 0.001851852   0.002222222
##                                    Black  20 0.037037037   0.044444444
##                                 Filipino   1 0.001851852   0.002222222
##                           Latin American  16 0.029629630   0.035555556
##                                     Arab   0 0.000000000   0.000000000
##                          Southeast Asian   0 0.000000000   0.000000000
##                               West Asian   0 0.000000000   0.000000000
##                                   Korean   0 0.000000000   0.000000000
##                                 Japanese   1 0.001851852   0.002222222
##                               Multi-race   4 0.007407407   0.008888889
##                     Prefer not to answer  22 0.040740741   0.048888889
##                                    Other   2 0.003703704   0.004444444
##                                     <NA>  90 0.166666667            NA
tabyl(mydata$child.gender.f)
##   mydata$child.gender.f   n   percent valid_percent
##                     boy 270 0.5000000     0.5708245
##                    girl 203 0.3759259     0.4291755
##  neither option applies   0 0.0000000     0.0000000
##                    <NA>  67 0.1240741            NA
tabyl(mydata$DxTotal)
##  mydata$DxTotal   n     percent valid_percent
##               0 164 0.303703704    0.34672304
##               1 107 0.198148148    0.22621564
##               2 123 0.227777778    0.26004228
##               3  46 0.085185185    0.09725159
##               4  27 0.050000000    0.05708245
##               5   4 0.007407407    0.00845666
##               6   2 0.003703704    0.00422833
##              NA  67 0.124074074            NA
mydata %>% 
   dplyr::select(CASI_17,CASI_18,CASI_19,CASI_20,CASI_21,CASI_22,CASI_23,CASI_24,CASI_25) %>% 
   psych::alpha()
## 
## Reliability analysis   
## Call: psych::alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean  sd median_r
##       0.86      0.86    0.86      0.41 6.4 0.0088  1.3 0.6     0.41
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.85  0.86  0.88
## Duhachek  0.85  0.86  0.88
## 
##  Reliability if an item is dropped:
##         raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## CASI_17      0.85      0.85    0.84      0.42 5.7   0.0097 0.0027  0.41
## CASI_18      0.85      0.85    0.84      0.41 5.6   0.0099 0.0027  0.41
## CASI_19      0.85      0.85    0.83      0.41 5.5   0.0101 0.0023  0.41
## CASI_20      0.85      0.85    0.84      0.41 5.5   0.0100 0.0027  0.41
## CASI_21      0.85      0.85    0.84      0.42 5.8   0.0096 0.0031  0.42
## CASI_22      0.85      0.85    0.84      0.42 5.8   0.0096 0.0024  0.41
## CASI_23      0.85      0.85    0.84      0.42 5.8   0.0096 0.0030  0.42
## CASI_24      0.85      0.85    0.84      0.42 5.7   0.0097 0.0028  0.42
## CASI_25      0.85      0.85    0.84      0.41 5.7   0.0098 0.0025  0.41
## 
##  Item statistics 
##           n raw.r std.r r.cor r.drop mean   sd
## CASI_17 392  0.69  0.69  0.64   0.59  1.3 0.87
## CASI_18 394  0.71  0.71  0.66   0.62  1.2 0.89
## CASI_19 393  0.73  0.73  0.69   0.64  1.3 0.88
## CASI_20 393  0.72  0.72  0.68   0.63  1.2 0.87
## CASI_21 393  0.67  0.67  0.61   0.56  1.3 0.88
## CASI_22 392  0.67  0.67  0.62   0.57  1.3 0.85
## CASI_23 389  0.66  0.67  0.61   0.56  1.3 0.82
## CASI_24 393  0.68  0.68  0.63   0.58  1.2 0.86
## CASI_25 393  0.69  0.69  0.64   0.60  1.3 0.86
## 
## Non missing response frequency for each item
##            0    1    2    3 miss
## CASI_17 0.20 0.42 0.30 0.08 0.27
## CASI_18 0.24 0.43 0.25 0.08 0.27
## CASI_19 0.20 0.44 0.26 0.09 0.27
## CASI_20 0.20 0.44 0.27 0.08 0.27
## CASI_21 0.18 0.42 0.30 0.10 0.27
## CASI_22 0.18 0.45 0.29 0.09 0.27
## CASI_23 0.14 0.47 0.31 0.08 0.28
## CASI_24 0.22 0.44 0.27 0.07 0.27
## CASI_25 0.19 0.45 0.27 0.08 0.27
#time 1 anxiety: .86

mydata %>% 
   dplyr::select(CASI_18,CASI_26,CASI_27,CASI_28) %>% 
   psych::alpha()
## 
## Reliability analysis   
## Call: psych::alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean  sd median_r
##       0.79      0.79    0.74      0.49 3.8 0.015  1.2 0.7     0.49
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.76  0.79  0.82
## Duhachek  0.76  0.79  0.82
## 
##  Reliability if an item is dropped:
##         raw_alpha std.alpha G6(smc) average_r S/N alpha se   var.r med.r
## CASI_18      0.71      0.72    0.63      0.46 2.5    0.021 0.00117  0.45
## CASI_26      0.73      0.73    0.64      0.47 2.7    0.020 0.00065  0.48
## CASI_27      0.76      0.76    0.68      0.52 3.2    0.018 0.00276  0.49
## CASI_28      0.75      0.75    0.67      0.50 3.0    0.019 0.00551  0.50
## 
##  Item statistics 
##           n raw.r std.r r.cor r.drop mean   sd
## CASI_18 394  0.81  0.81  0.73   0.65  1.2 0.89
## CASI_26 392  0.79  0.80  0.70   0.62  1.2 0.87
## CASI_27 393  0.76  0.76  0.62   0.56  1.2 0.91
## CASI_28 393  0.77  0.77  0.65   0.58  1.2 0.89
## 
## Non missing response frequency for each item
##            0    1    2    3 miss
## CASI_18 0.24 0.43 0.25 0.08 0.27
## CASI_26 0.24 0.41 0.28 0.06 0.27
## CASI_27 0.24 0.42 0.24 0.09 0.27
## CASI_28 0.21 0.42 0.27 0.09 0.27
#time 1 depression: .79

mydata %>% 
   dplyr::select(CASI_17_T3,CASI_18_T3,CASI_19_T3,CASI_20_T3,CASI_21_T3,CASI_22_T3,CASI_23_T3,CASI_24_T3,CASI_25_T3) %>% 
   psych::alpha()
## 
## Reliability analysis   
## Call: psych::alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean  sd median_r
##       0.79      0.79    0.78      0.29 3.8 0.014  1.3 0.5     0.29
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.76  0.79  0.82
## Duhachek  0.76  0.79  0.82
## 
##  Reliability if an item is dropped:
##            raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## CASI_17_T3      0.78      0.78    0.77      0.30 3.4    0.015 0.0043  0.30
## CASI_18_T3      0.77      0.77    0.76      0.29 3.3    0.015 0.0052  0.30
## CASI_19_T3      0.76      0.76    0.75      0.29 3.2    0.016 0.0046  0.27
## CASI_20_T3      0.77      0.77    0.76      0.29 3.3    0.015 0.0049  0.29
## CASI_21_T3      0.78      0.78    0.77      0.30 3.4    0.015 0.0046  0.31
## CASI_22_T3      0.77      0.77    0.75      0.29 3.3    0.015 0.0032  0.28
## CASI_23_T3      0.77      0.77    0.76      0.30 3.4    0.015 0.0032  0.28
## CASI_24_T3      0.78      0.78    0.77      0.30 3.5    0.015 0.0050  0.32
## CASI_25_T3      0.76      0.76    0.75      0.29 3.2    0.015 0.0048  0.28
## 
##  Item statistics 
##              n raw.r std.r r.cor r.drop mean   sd
## CASI_17_T3 163  0.57  0.58  0.49   0.44  1.3 0.77
## CASI_18_T3 163  0.62  0.61  0.54   0.48  1.3 0.86
## CASI_19_T3 163  0.67  0.66  0.60   0.54  1.2 0.88
## CASI_20_T3 163  0.63  0.63  0.56   0.50  1.3 0.83
## CASI_21_T3 162  0.59  0.58  0.50   0.44  1.4 0.85
## CASI_22_T3 162  0.63  0.63  0.58   0.50  1.2 0.81
## CASI_23_T3 163  0.59  0.60  0.53   0.46  1.3 0.76
## CASI_24_T3 163  0.56  0.57  0.47   0.42  1.3 0.78
## CASI_25_T3 163  0.64  0.65  0.59   0.52  1.3 0.75
## 
## Non missing response frequency for each item
##               0    1    2    3 miss
## CASI_17_T3 0.15 0.40 0.41 0.03  0.7
## CASI_18_T3 0.20 0.42 0.31 0.07  0.7
## CASI_19_T3 0.23 0.38 0.33 0.07  0.7
## CASI_20_T3 0.15 0.44 0.33 0.08  0.7
## CASI_21_T3 0.15 0.42 0.34 0.09  0.7
## CASI_22_T3 0.19 0.44 0.33 0.05  0.7
## CASI_23_T3 0.13 0.47 0.35 0.05  0.7
## CASI_24_T3 0.15 0.44 0.36 0.05  0.7
## CASI_25_T3 0.13 0.51 0.31 0.05  0.7
#time 3 anxiety: .79

mydata %>% 
   dplyr::select(CASI_18_T3,CASI_26_T3,CASI_27_T3,CASI_28_T3) %>% 
   psych::alpha()
## 
## Reliability analysis   
## Call: psych::alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean  sd median_r
##       0.69      0.69    0.65      0.36 2.2 0.022  1.2 0.6     0.33
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.64  0.69  0.73
## Duhachek  0.65  0.69  0.73
## 
##  Reliability if an item is dropped:
##            raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## CASI_18_T3      0.63      0.64    0.56      0.37 1.7    0.027 0.0225  0.32
## CASI_26_T3      0.53      0.53    0.43      0.27 1.1    0.035 0.0034  0.25
## CASI_27_T3      0.71      0.71    0.63      0.45 2.4    0.022 0.0101  0.47
## CASI_28_T3      0.61      0.61    0.53      0.34 1.6    0.029 0.0150  0.32
## 
##  Item statistics 
##              n raw.r std.r r.cor r.drop mean   sd
## CASI_18_T3 163  0.71  0.71  0.55   0.46  1.3 0.86
## CASI_26_T3 163  0.81  0.81  0.75   0.62  1.3 0.84
## CASI_27_T3 163  0.63  0.62  0.40   0.33  1.1 0.84
## CASI_28_T3 163  0.73  0.74  0.61   0.50  1.3 0.81
## 
## Non missing response frequency for each item
##               0    1    2    3 miss
## CASI_18_T3 0.20 0.42 0.31 0.07  0.7
## CASI_26_T3 0.18 0.44 0.31 0.07  0.7
## CASI_27_T3 0.25 0.40 0.31 0.04  0.7
## CASI_28_T3 0.17 0.44 0.34 0.06  0.7
#time 3 depression: .69

mydata %>% 
   dplyr::select(LBS_1, LBS_2, LBS_3, LBS_4, LBS_5, LBS_6, LBS_7, LBS_8, LBS_9, LBS_11, LBS_13, LBS_14, LBS_15, LBS_16, LBS_17, LBS_18, LBS_20, LBS_21, LBS_23, LBS_24, LBS_25, LBS_26, LBS_27, LBS_28, LBS_29) %>% 
   psych::alpha(check.keys = TRUE)
## 
## Reliability analysis   
## Call: psych::alpha(x = ., check.keys = TRUE)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean   sd median_r
##       0.82      0.82    0.84      0.15 4.5 0.011 0.98 0.28     0.17
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt      0.8  0.82  0.84
## Duhachek   0.8  0.82  0.84
## 
##  Reliability if an item is dropped:
##         raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## LBS_1-       0.82      0.82    0.84      0.16 4.6    0.011 0.012  0.17
## LBS_2        0.82      0.81    0.84      0.15 4.3    0.011 0.013  0.17
## LBS_3        0.82      0.81    0.84      0.15 4.4    0.011 0.013  0.17
## LBS_4-       0.82      0.82    0.84      0.16 4.5    0.011 0.013  0.17
## LBS_5        0.81      0.81    0.83      0.15 4.2    0.011 0.013  0.17
## LBS_6        0.82      0.81    0.84      0.15 4.4    0.011 0.013  0.17
## LBS_7        0.82      0.81    0.84      0.15 4.3    0.011 0.013  0.17
## LBS_8        0.81      0.81    0.83      0.15 4.2    0.012 0.012  0.16
## LBS_9        0.81      0.81    0.83      0.15 4.2    0.011 0.012  0.17
## LBS_11-      0.83      0.82    0.84      0.16 4.6    0.011 0.012  0.17
## LBS_13       0.82      0.81    0.84      0.15 4.4    0.011 0.013  0.17
## LBS_14       0.81      0.81    0.83      0.15 4.3    0.011 0.013  0.17
## LBS_15       0.81      0.81    0.83      0.15 4.2    0.011 0.012  0.17
## LBS_16       0.81      0.81    0.83      0.15 4.2    0.011 0.012  0.16
## LBS_17       0.81      0.81    0.83      0.15 4.2    0.011 0.013  0.17
## LBS_18       0.82      0.81    0.83      0.15 4.3    0.011 0.013  0.17
## LBS_20-      0.82      0.82    0.84      0.16 4.5    0.011 0.013  0.17
## LBS_21       0.81      0.81    0.83      0.15 4.2    0.012 0.012  0.16
## LBS_23       0.82      0.81    0.84      0.15 4.3    0.011 0.013  0.17
## LBS_24       0.82      0.81    0.84      0.15 4.3    0.011 0.013  0.17
## LBS_25-      0.83      0.82    0.84      0.16 4.7    0.010 0.011  0.17
## LBS_26       0.82      0.81    0.83      0.15 4.3    0.011 0.012  0.17
## LBS_27       0.82      0.82    0.84      0.16 4.5    0.011 0.013  0.17
## LBS_28-      0.83      0.82    0.84      0.16 4.6    0.011 0.012  0.17
## LBS_29       0.81      0.81    0.83      0.15 4.3    0.011 0.012  0.17
## 
##  Item statistics 
##           n raw.r std.r r.cor r.drop mean   sd
## LBS_1-  395  0.24  0.26  0.20  0.162 0.88 0.53
## LBS_2   395  0.46  0.45  0.42  0.377 0.96 0.68
## LBS_3   395  0.44  0.43  0.39  0.358 1.00 0.66
## LBS_4-  390  0.31  0.32  0.27  0.227 0.91 0.60
## LBS_5   395  0.54  0.53  0.51  0.466 1.03 0.70
## LBS_6   394  0.44  0.44  0.40  0.362 1.13 0.69
## LBS_7   392  0.45  0.45  0.42  0.378 0.99 0.63
## LBS_8   391  0.59  0.58  0.57  0.519 1.18 0.71
## LBS_9   393  0.53  0.52  0.50  0.459 1.06 0.66
## LBS_11- 394  0.23  0.24  0.18  0.143 0.86 0.61
## LBS_13  392  0.42  0.42  0.38  0.343 1.02 0.62
## LBS_14  393  0.52  0.51  0.49  0.446 0.95 0.64
## LBS_15  395  0.55  0.54  0.52  0.474 0.95 0.72
## LBS_16  394  0.54  0.53  0.51  0.466 1.09 0.70
## LBS_17  393  0.55  0.55  0.53  0.481 1.02 0.64
## LBS_18  395  0.49  0.48  0.45  0.410 0.97 0.65
## LBS_20- 394  0.35  0.36  0.32  0.270 0.85 0.63
## LBS_21  395  0.56  0.55  0.53  0.485 1.13 0.69
## LBS_23  395  0.45  0.45  0.41  0.376 1.08 0.65
## LBS_24  392  0.46  0.46  0.42  0.385 0.87 0.64
## LBS_25- 392  0.17  0.18  0.13  0.084 0.93 0.61
## LBS_26  393  0.47  0.46  0.43  0.390 0.93 0.66
## LBS_27  395  0.36  0.36  0.31  0.280 0.94 0.60
## LBS_28- 394  0.22  0.23  0.17  0.129 0.92 0.65
## LBS_29  389  0.50  0.50  0.47  0.430 0.98 0.64
## 
## Non missing response frequency for each item
##           0    1    2 miss
## LBS_1  0.09 0.70 0.21 0.27
## LBS_2  0.25 0.53 0.21 0.27
## LBS_3  0.22 0.56 0.22 0.27
## LBS_4  0.14 0.63 0.23 0.28
## LBS_5  0.23 0.51 0.26 0.27
## LBS_6  0.18 0.51 0.31 0.27
## LBS_7  0.20 0.61 0.19 0.27
## LBS_8  0.18 0.46 0.36 0.28
## LBS_9  0.19 0.56 0.25 0.27
## LBS_11 0.12 0.61 0.27 0.27
## LBS_13 0.18 0.62 0.20 0.27
## LBS_14 0.23 0.60 0.18 0.27
## LBS_15 0.29 0.48 0.24 0.27
## LBS_16 0.20 0.51 0.29 0.27
## LBS_17 0.20 0.59 0.21 0.27
## LBS_18 0.23 0.57 0.20 0.27
## LBS_20 0.13 0.58 0.28 0.27
## LBS_21 0.18 0.51 0.31 0.27
## LBS_23 0.18 0.57 0.26 0.27
## LBS_24 0.28 0.58 0.15 0.27
## LBS_25 0.15 0.62 0.23 0.27
## LBS_26 0.25 0.57 0.18 0.27
## LBS_27 0.21 0.64 0.15 0.27
## LBS_28 0.18 0.57 0.26 0.27
## LBS_29 0.21 0.60 0.19 0.28
# LBS .82

mydata %>% 
   dplyr::select(COVID_worriedcatchvirus,COVID_worriedfamilysafe,
    COVID_worriedhealthcaresystem,COVID_worriedgrocerystoresfood,COVID_worriedgrocerystoresshutdown,
    COVID_worriedgrocerystoresclearningsupplies,COVID_worriedtouchpublicplace,
    COVID_worriedsomeonecoughs,COVID_troubleconcentrating,COVID_disturbingmentalimages,
    COVID_troublesleeping) %>% 
   psych::alpha()
## 
## Reliability analysis   
## Call: psych::alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean  sd median_r
##        0.9       0.9    0.91      0.44 8.8 0.0066  2.9 0.8     0.42
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.88   0.9  0.91
## Duhachek  0.89   0.9  0.91
## 
##  Reliability if an item is dropped:
##                                             raw_alpha std.alpha G6(smc)
## COVID_worriedcatchvirus                          0.89      0.89    0.90
## COVID_worriedfamilysafe                          0.89      0.89    0.89
## COVID_worriedhealthcaresystem                    0.89      0.89    0.90
## COVID_worriedgrocerystoresfood                   0.89      0.89    0.89
## COVID_worriedgrocerystoresshutdown               0.89      0.89    0.89
## COVID_worriedgrocerystoresclearningsupplies      0.89      0.89    0.89
## COVID_worriedtouchpublicplace                    0.89      0.89    0.90
## COVID_worriedsomeonecoughs                       0.89      0.89    0.89
## COVID_troubleconcentrating                       0.89      0.89    0.89
## COVID_disturbingmentalimages                     0.89      0.89    0.89
## COVID_troublesleeping                            0.89      0.89    0.90
##                                             average_r S/N alpha se  var.r med.r
## COVID_worriedcatchvirus                          0.45 8.2   0.0071 0.0071  0.43
## COVID_worriedfamilysafe                          0.44 7.9   0.0072 0.0073  0.42
## COVID_worriedhealthcaresystem                    0.45 8.1   0.0071 0.0074  0.42
## COVID_worriedgrocerystoresfood                   0.44 7.9   0.0073 0.0060  0.42
## COVID_worriedgrocerystoresshutdown               0.44 7.8   0.0073 0.0059  0.42
## COVID_worriedgrocerystoresclearningsupplies      0.44 7.9   0.0073 0.0069  0.42
## COVID_worriedtouchpublicplace                    0.45 8.2   0.0070 0.0068  0.43
## COVID_worriedsomeonecoughs                       0.44 8.0   0.0072 0.0071  0.42
## COVID_troubleconcentrating                       0.44 7.9   0.0073 0.0069  0.41
## COVID_disturbingmentalimages                     0.44 8.0   0.0072 0.0067  0.43
## COVID_troublesleeping                            0.45 8.2   0.0071 0.0062  0.43
## 
##  Item statistics 
##                                               n raw.r std.r r.cor r.drop mean
## COVID_worriedcatchvirus                     398  0.67  0.68  0.63   0.59  3.0
## COVID_worriedfamilysafe                     396  0.71  0.72  0.68   0.64  3.0
## COVID_worriedhealthcaresystem               394  0.69  0.69  0.65   0.61  2.9
## COVID_worriedgrocerystoresfood              395  0.72  0.72  0.69   0.65  2.8
## COVID_worriedgrocerystoresshutdown          395  0.74  0.74  0.72   0.67  2.7
## COVID_worriedgrocerystoresclearningsupplies 394  0.72  0.72  0.68   0.65  2.8
## COVID_worriedtouchpublicplace               395  0.66  0.66  0.62   0.58  3.1
## COVID_worriedsomeonecoughs                  394  0.70  0.71  0.67   0.63  3.2
## COVID_troubleconcentrating                  396  0.73  0.73  0.70   0.66  2.6
## COVID_disturbingmentalimages                395  0.71  0.71  0.67   0.63  2.7
## COVID_troublesleeping                       395  0.68  0.68  0.64   0.60  2.6
##                                              sd
## COVID_worriedcatchvirus                     1.1
## COVID_worriedfamilysafe                     1.2
## COVID_worriedhealthcaresystem               1.2
## COVID_worriedgrocerystoresfood              1.2
## COVID_worriedgrocerystoresshutdown          1.2
## COVID_worriedgrocerystoresclearningsupplies 1.1
## COVID_worriedtouchpublicplace               1.1
## COVID_worriedsomeonecoughs                  1.1
## COVID_troubleconcentrating                  1.1
## COVID_disturbingmentalimages                1.2
## COVID_troublesleeping                       1.2
## 
## Non missing response frequency for each item
##                                                1    2    3    4    5 miss
## COVID_worriedcatchvirus                     0.09 0.27 0.29 0.25 0.10 0.26
## COVID_worriedfamilysafe                     0.10 0.24 0.30 0.25 0.11 0.27
## COVID_worriedhealthcaresystem               0.15 0.21 0.32 0.24 0.08 0.27
## COVID_worriedgrocerystoresfood              0.16 0.28 0.28 0.21 0.07 0.27
## COVID_worriedgrocerystoresshutdown          0.16 0.30 0.28 0.18 0.08 0.27
## COVID_worriedgrocerystoresclearningsupplies 0.14 0.26 0.32 0.20 0.08 0.27
## COVID_worriedtouchpublicplace               0.07 0.24 0.34 0.24 0.11 0.27
## COVID_worriedsomeonecoughs                  0.05 0.22 0.31 0.30 0.13 0.27
## COVID_troubleconcentrating                  0.16 0.32 0.28 0.20 0.05 0.27
## COVID_disturbingmentalimages                0.20 0.27 0.27 0.20 0.07 0.27
## COVID_troublesleeping                       0.23 0.28 0.24 0.20 0.05 0.27
#covid parent stress .90
#correlation Matrix
corrplot(cor1b, method = "color",type = "upper", 
                   p.mat = cor1$p,  addCoef.col = 'black', sig.level = 0.05,  
                                    insig = "label_sig", number.cex=0.8, tl.col="black",
                 col=colorRampPalette(c("#94AEBC",  "white", "thistle"))(50))

# level of covid restriction is weakly, positively correlated with the impact on the child
# and on the stress reported
# covid impacts on child is strongly positively correlated with covid stress
# and depression and anxiety at baseline, and negatively strongly linked
# to learning behavior scale. covid impact is weakly, positively correlated
# with anxiety at T3s
# total diagnoses is moderately, positively correlated with all variables, except
# negative with learning behavior scale score
# covid stress is moderately negatively correlated to learning behaavior scale
# and strongly positive linked to depression and anxiety at T1, and moderately
# positively linked to anxiety at T3
# baseline adhd symptoms are strongly, positively correlated to baseline anxiety,
# depresion, covid impact on child and covid parent stress, and negatively strongly
# linked to learning behavior scale scores
# so baseline covid measures (impact, stress) tend to be linked to higher anxiety
# over time but not to depression
# learning behavior scale is moderately to strongly linked to lower levels of anxiety and 
# depression at T1 and T3
model1 <- lm(data = mydata, anxiety_T3 ~ anxiety_T1 + Educationhousehold + Familyincome_T1r + Child_gender + Childagecategory + school.modality.f + Child_raceethnicity_T1 + COVIDrestrictionstotal + COVID_childimpact_T1 + COVIDstressscale + LBStotal + CASI_ADHD_CSum + DxTotal) 

summary(model1)
## 
## Call:
## lm(formula = anxiety_T3 ~ anxiety_T1 + Educationhousehold + Familyincome_T1r + 
##     Child_gender + Childagecategory + school.modality.f + Child_raceethnicity_T1 + 
##     COVIDrestrictionstotal + COVID_childimpact_T1 + COVIDstressscale + 
##     LBStotal + CASI_ADHD_CSum + DxTotal, data = mydata)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.84473 -0.20192 -0.02942  0.22881  1.10566 
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)   
## (Intercept)                   1.825629   0.542885   3.363  0.00104 **
## anxiety_T1                    0.257247   0.108539   2.370  0.01938 * 
## Educationhousehold           -0.025878   0.031577  -0.820  0.41411   
## Familyincome_T1r             -0.023401   0.033431  -0.700  0.48530   
## Child_gender                  0.009407   0.069542   0.135  0.89262   
## Childagecategory              0.007434   0.060774   0.122  0.90285   
## school.modality.falternating  0.077728   0.090745   0.857  0.39340   
## school.modality.fvirtual      0.228810   0.094925   2.410  0.01745 * 
## Child_raceethnicity_T1       -0.021573   0.017822  -1.210  0.22847   
## COVIDrestrictionstotal       -0.002491   0.001688  -1.475  0.14270   
## COVID_childimpact_T1         -0.010983   0.011485  -0.956  0.34085   
## COVIDstressscale              0.015284   0.006239   2.450  0.01574 * 
## LBStotal                     -0.025989   0.009070  -2.865  0.00492 **
## CASI_ADHD_CSum               -0.014928   0.012829  -1.164  0.24690   
## DxTotal                      -0.027795   0.036791  -0.755  0.45143   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3806 on 120 degrees of freedom
##   (405 observations deleted due to missingness)
## Multiple R-squared:  0.3805, Adjusted R-squared:  0.3083 
## F-statistic: 5.265 on 14 and 120 DF,  p-value: 1.084e-07
tab_model(model1, show.std=TRUE)
  anxiety T 3
Predictors Estimates std. Beta CI standardized CI p
(Intercept) 1.83 -0.13 0.75 – 2.90 -0.32 – 0.06 0.001
anxiety T1 0.26 0.25 0.04 – 0.47 0.04 – 0.47 0.019
Educationhousehold -0.03 -0.07 -0.09 – 0.04 -0.24 – 0.10 0.414
Familyincome T1r -0.02 -0.06 -0.09 – 0.04 -0.25 – 0.12 0.485
Child gender 0.01 0.01 -0.13 – 0.15 -0.14 – 0.16 0.893
Childagecategory 0.01 0.01 -0.11 – 0.13 -0.16 – 0.18 0.903
school modality f
[alternating]
0.08 0.17 -0.10 – 0.26 -0.22 – 0.56 0.393
school modality f
[virtual]
0.23 0.50 0.04 – 0.42 0.09 – 0.91 0.017
Child raceethnicity T1 -0.02 -0.11 -0.06 – 0.01 -0.28 – 0.07 0.228
COVIDrestrictionstotal -0.00 -0.11 -0.01 – 0.00 -0.27 – 0.04 0.143
COVID childimpact T1 -0.01 -0.09 -0.03 – 0.01 -0.29 – 0.10 0.341
COVIDstressscale 0.02 0.20 0.00 – 0.03 0.04 – 0.37 0.016
LBStotal -0.03 -0.33 -0.04 – -0.01 -0.56 – -0.10 0.005
CASI ADHD CSum -0.01 -0.12 -0.04 – 0.01 -0.31 – 0.08 0.247
DxTotal -0.03 -0.07 -0.10 – 0.05 -0.24 – 0.11 0.451
Observations 135
R2 / R2 adjusted 0.381 / 0.308
calc.relimp(model1)
## Response variable: anxiety_T3 
## Total response variance: 0.2094583 
## Analysis based on 135 observations 
## 
## 14 Regressors: 
## Some regressors combined in groups: 
##         Group  school.modality.f : school.modality.falternating school.modality.fvirtual 
## 
##  Relative importance of 13 (groups of) regressors assessed: 
##  school.modality.f anxiety_T1 Educationhousehold Familyincome_T1r Child_gender Childagecategory Child_raceethnicity_T1 COVIDrestrictionstotal COVID_childimpact_T1 COVIDstressscale LBStotal CASI_ADHD_CSum DxTotal 
##  
## Proportion of variance explained by model: 38.05%
## Metrics are not normalized (rela=FALSE). 
## 
## Relative importance metrics: 
## 
##                                lmg
## school.modality.f      0.047150931
## anxiety_T1             0.089915089
## Educationhousehold     0.010145835
## Familyincome_T1r       0.029908876
## Child_gender           0.006605688
## Childagecategory       0.006923134
## Child_raceethnicity_T1 0.012010386
## COVIDrestrictionstotal 0.017187177
## COVID_childimpact_T1   0.008358904
## COVIDstressscale       0.051466177
## LBStotal               0.086186936
## CASI_ADHD_CSum         0.010173048
## DxTotal                0.004501692
## 
## Average coefficients for different model sizes: 
## 
##                                   1group     2groups      3groups       4groups
## anxiety_T1                    0.44521875  0.42964651  0.414449328  0.3993833069
## Educationhousehold           -0.06555076 -0.05349584 -0.044643303 -0.0381430212
## Familyincome_T1r             -0.11024324 -0.09712450 -0.085919133 -0.0762196207
## Child_gender                  0.12984922  0.11524703  0.101560248  0.0886913877
## Childagecategory              0.10261550  0.08549614  0.073024170  0.0635751638
## school.modality.falternating  0.22773906  0.20253890  0.182925694  0.1667562797
## school.modality.fvirtual      0.26504065  0.26850559  0.268829458  0.2669433725
## Child_raceethnicity_T1       -0.02887463 -0.02608655 -0.024241126 -0.0229791652
## COVIDrestrictionstotal       -0.00239581 -0.00279712 -0.003030606 -0.0031514013
## COVID_childimpact_T1          0.01953452  0.01345075  0.008472895  0.0043663399
## COVIDstressscale              0.02277336  0.02110372  0.019863058  0.0189204773
## LBStotal                     -0.03228009 -0.03103808 -0.030025724 -0.0291963016
## CASI_ADHD_CSum                0.01783673  0.01051471  0.004739235  0.0001669794
## DxTotal                       0.03350987  0.01490473  0.001443286 -0.0082630156
##                                    5groups      6groups      7groups
## anxiety_T1                    0.3842755874  0.369008439  0.353510203
## Educationhousehold           -0.0333957914 -0.029975699 -0.027579211
## Familyincome_T1r             -0.0677223777 -0.060197219 -0.053465713
## Child_gender                  0.0766267403  0.065373884  0.054940737
## Childagecategory              0.0560158216  0.049557434  0.043657107
## school.modality.falternating  0.1528110620  0.140399231  0.129130374
## school.modality.fvirtual      0.2635904378  0.259337965  0.254607240
## Child_raceethnicity_T1       -0.0220989532 -0.021488369 -0.021085491
## COVIDrestrictionstotal       -0.0031950968 -0.003185239 -0.003137676
## COVID_childimpact_T1          0.0009632031 -0.001858644 -0.004190067
## COVIDstressscale              0.0181883439  0.017606720  0.017133545
## LBStotal                     -0.0285160141 -0.027959326 -0.027505778
## CASI_ADHD_CSum               -0.0034602657 -0.006339438 -0.008622767
## DxTotal                      -0.0151990091 -0.020079839 -0.023433589
##                                   8groups      9groups     10groups
## anxiety_T1                    0.337751502  0.321745469  0.305551047
## Educationhousehold           -0.025990089 -0.025053772 -0.024657399
## Familyincome_T1r             -0.047386214 -0.041843820 -0.036743993
## Child_gender                  0.045330665  0.036542637  0.028571529
## Childagecategory              0.037950733  0.032207337  0.026298097
## school.modality.falternating  0.118783560  0.109231999  0.100399140
## school.modality.fvirtual      0.249707012  0.244863755  0.240245351
## Child_raceethnicity_T1       -0.020855182 -0.020775053 -0.020827140
## COVIDrestrictionstotal       -0.003063232 -0.002969438 -0.002861685
## COVID_childimpact_T1         -0.006100682 -0.007645662 -0.008870268
## COVIDstressscale              0.016738417  0.016398614  0.016096502
## LBStotal                     -0.027137723 -0.026838715 -0.026592341
## CASI_ADHD_CSum               -0.010429061 -0.011851410 -0.012962591
## DxTotal                      -0.025653817 -0.027034580 -0.027795193
##                                  11groups     12groups     13groups
## anxiety_T1                    0.289278714  0.273098161  0.257247293
## Educationhousehold           -0.024713355 -0.025145497 -0.025878309
## Familyincome_T1r             -0.032009046 -0.027576807 -0.023400715
## Child_gender                  0.021406786  0.015029294  0.009407427
## Childagecategory              0.020175701  0.013860902  0.007433643
## school.modality.falternating  0.092232903  0.084690478  0.077728355
## school.modality.fvirtual      0.235976721  0.232147108  0.228810061
## Child_raceethnicity_T1       -0.020992991 -0.021250733 -0.021573337
## COVIDrestrictionstotal       -0.002743999 -0.002619557 -0.002491016
## COVID_childimpact_T1         -0.009812871 -0.010507014 -0.010982903
## COVIDstressscale              0.015817835  0.015550631  0.015284463
## LBStotal                     -0.026381364 -0.026187052 -0.025988618
## CASI_ADHD_CSum               -0.013818993 -0.014463572 -0.014928106
## DxTotal                      -0.028098858 -0.028067607 -0.027795000
model2 <- lm(data = mydata, depression_T3 ~ depression_T1 + Educationhousehold + Familyincome_T1r + Child_gender + Childagecategory + school.modality.f + Child_raceethnicity_T1 + COVIDrestrictionstotal + COVID_childimpact_T1 + COVIDstressscale + LBStotal + CASI_ADHD_CSum + DxTotal) 

summary(model2)
## 
## Call:
## lm(formula = depression_T3 ~ depression_T1 + Educationhousehold + 
##     Familyincome_T1r + Child_gender + Childagecategory + school.modality.f + 
##     Child_raceethnicity_T1 + COVIDrestrictionstotal + COVID_childimpact_T1 + 
##     COVIDstressscale + LBStotal + CASI_ADHD_CSum + DxTotal, data = mydata)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.10166 -0.38413  0.02493  0.37059  1.20198 
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)   
## (Intercept)                   1.541031   0.712530   2.163  0.03254 * 
## depression_T1                 0.256603   0.107260   2.392  0.01829 * 
## Educationhousehold           -0.014205   0.042185  -0.337  0.73691   
## Familyincome_T1r             -0.132481   0.044500  -2.977  0.00352 **
## Child_gender                  0.019003   0.093362   0.204  0.83906   
## Childagecategory              0.076286   0.082084   0.929  0.35456   
## school.modality.falternating  0.062158   0.121155   0.513  0.60886   
## school.modality.fvirtual      0.073032   0.127825   0.571  0.56883   
## Child_raceethnicity_T1       -0.013043   0.024042  -0.543  0.58847   
## COVIDrestrictionstotal       -0.002101   0.002264  -0.928  0.35527   
## COVID_childimpact_T1         -0.011860   0.015333  -0.774  0.44074   
## COVIDstressscale              0.013575   0.008294   1.637  0.10431   
## LBStotal                     -0.010566   0.012225  -0.864  0.38915   
## CASI_ADHD_CSum               -0.012755   0.017282  -0.738  0.46194   
## DxTotal                      -0.036171   0.049317  -0.733  0.46472   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5117 on 120 degrees of freedom
##   (405 observations deleted due to missingness)
## Multiple R-squared:  0.2848, Adjusted R-squared:  0.2013 
## F-statistic: 3.412 on 14 and 120 DF,  p-value: 0.0001171
tab_model(model2, show.std=TRUE)
  depression T 3
Predictors Estimates std. Beta CI standardized CI p
(Intercept) 1.54 -0.05 0.13 – 2.95 -0.25 – 0.16 0.033
depression T1 0.26 0.25 0.04 – 0.47 0.04 – 0.46 0.018
Educationhousehold -0.01 -0.03 -0.10 – 0.07 -0.21 – 0.15 0.737
Familyincome T1r -0.13 -0.29 -0.22 – -0.04 -0.49 – -0.10 0.004
Child gender 0.02 0.02 -0.17 – 0.20 -0.15 – 0.18 0.839
Childagecategory 0.08 0.09 -0.09 – 0.24 -0.10 – 0.27 0.355
school modality f
[alternating]
0.06 0.11 -0.18 – 0.30 -0.31 – 0.53 0.609
school modality f
[virtual]
0.07 0.13 -0.18 – 0.33 -0.31 – 0.57 0.569
Child raceethnicity T1 -0.01 -0.05 -0.06 – 0.03 -0.24 – 0.14 0.588
COVIDrestrictionstotal -0.00 -0.08 -0.01 – 0.00 -0.24 – 0.09 0.355
COVID childimpact T1 -0.01 -0.08 -0.04 – 0.02 -0.29 – 0.13 0.441
COVIDstressscale 0.01 0.14 -0.00 – 0.03 -0.03 – 0.32 0.104
LBStotal -0.01 -0.11 -0.03 – 0.01 -0.35 – 0.14 0.389
CASI ADHD CSum -0.01 -0.08 -0.05 – 0.02 -0.29 – 0.13 0.462
DxTotal -0.04 -0.07 -0.13 – 0.06 -0.25 – 0.12 0.465
Observations 135
R2 / R2 adjusted 0.285 / 0.201
calc.relimp(model2)
## Response variable: depression_T3 
## Total response variance: 0.3278607 
## Analysis based on 135 observations 
## 
## 14 Regressors: 
## Some regressors combined in groups: 
##         Group  school.modality.f : school.modality.falternating school.modality.fvirtual 
## 
##  Relative importance of 13 (groups of) regressors assessed: 
##  school.modality.f depression_T1 Educationhousehold Familyincome_T1r Child_gender Childagecategory Child_raceethnicity_T1 COVIDrestrictionstotal COVID_childimpact_T1 COVIDstressscale LBStotal CASI_ADHD_CSum DxTotal 
##  
## Proportion of variance explained by model: 28.48%
## Metrics are not normalized (rela=FALSE). 
## 
## Relative importance metrics: 
## 
##                                lmg
## school.modality.f      0.014766154
## depression_T1          0.063644695
## Educationhousehold     0.008845919
## Familyincome_T1r       0.089033358
## Child_gender           0.004957479
## Childagecategory       0.009748902
## Child_raceethnicity_T1 0.016213084
## COVIDrestrictionstotal 0.005453117
## COVID_childimpact_T1   0.005235176
## COVIDstressscale       0.022112901
## LBStotal               0.035401830
## CASI_ADHD_CSum         0.006021568
## DxTotal                0.003321919
## 
## Average coefficients for different model sizes: 
## 
##                                    1group      2groups      3groups
## depression_T1                 0.362080367  0.343382706  0.328228603
## Educationhousehold           -0.080338414 -0.067042499 -0.056865357
## Familyincome_T1r             -0.181456644 -0.172502364 -0.164960951
## Child_gender                  0.137351779  0.122424606  0.108695680
## Childagecategory              0.132125355  0.113792448  0.100664789
## school.modality.falternating  0.228005226  0.201490825  0.180666609
## school.modality.fvirtual      0.186219512  0.185990751  0.181792353
## Child_raceethnicity_T1       -0.046905228 -0.043036531 -0.039909215
## COVIDrestrictionstotal       -0.001141883 -0.001603693 -0.001891763
## COVID_childimpact_T1          0.020450762  0.014281267  0.009351145
## COVIDstressscale              0.018572113  0.016892697  0.015744842
## LBStotal                     -0.030202206 -0.027814913 -0.025757392
## CASI_ADHD_CSum                0.020263902  0.012334512  0.006001607
## DxTotal                       0.038363797  0.017891610  0.002746074
##                                    4groups      5groups       6groups
## depression_T1                 0.3156007411  0.304808366  0.2953935702
## Educationhousehold           -0.0489171954 -0.042564832 -0.0373548012
## Familyincome_T1r             -0.1585479017 -0.153062407 -0.1483625556
## Child_gender                  0.0959574582  0.084129358  0.0731731735
## Childagecategory              0.0911150339  0.084068318  0.0788355601
## school.modality.falternating  0.1633097525  0.148178841  0.1345783428
## school.modality.fvirtual      0.1747378781  0.165703725  0.1553476630
## Child_raceethnicity_T1       -0.0371819563 -0.034665739 -0.0322516981
## COVIDrestrictionstotal       -0.0020643154 -0.002159128 -0.0022014825
## COVID_childimpact_T1          0.0053679464  0.002115583 -0.0005689237
## COVIDstressscale              0.0149572627  0.014417253  0.0140494376
## LBStotal                     -0.0239522496 -0.022338295 -0.0208641769
## CASI_ADHD_CSum                0.0009298009 -0.003129718 -0.0063608430
## DxTotal                      -0.0084994954 -0.016854905 -0.0230501838
##                                   7groups      8groups      9groups
## depression_T1                 0.287066263  0.279660087  0.273103956
## Educationhousehold           -0.032962290 -0.029155092 -0.025766467
## Familyincome_T1r             -0.144348294 -0.140950562 -0.138125220
## Child_gender                  0.063062772  0.053775511  0.045291094
## Childagecategory              0.074997321  0.072323479  0.070719183
## school.modality.falternating  0.122112333  0.110547274  0.099735731
## school.modality.fvirtual      0.144149436  0.132454221  0.120510008
## Child_raceethnicity_T1       -0.029870169 -0.027467280 -0.024991500
## COVIDrestrictionstotal       -0.002208879 -0.002194008 -0.002166740
## COVID_childimpact_T1         -0.002811813 -0.004714364 -0.006361535
## COVIDstressscale              0.013802627  0.013641756  0.013543069
## LBStotal                     -0.019483882 -0.018153427 -0.016828320
## CASI_ADHD_CSum               -0.008897596 -0.010834390 -0.012232971
## DxTotal                      -0.027619397 -0.030953166 -0.033332655
##                                  10groups     11groups     12groups
## depression_T1                 0.267405407  0.262643134  0.258966829
## Educationhousehold           -0.022673235 -0.019776944 -0.016986934
## Familyincome_T1r             -0.135850658 -0.134128338 -0.132985661
## Child_gender                  0.037591452  0.030659036  0.024472883
## Childagecategory              0.070190396  0.070824143  0.072779523
## school.modality.falternating  0.089573554  0.079975778  0.070863544
## school.modality.fvirtual      0.108495176  0.096534909  0.084706230
## Child_raceethnicity_T1       -0.022385801 -0.019582794 -0.016501277
## COVIDrestrictionstotal       -0.002135525 -0.002108416 -0.002093859
## COVID_childimpact_T1         -0.007828521 -0.009186017 -0.010504786
## COVIDstressscale              0.013491398  0.013478836  0.013504414
## LBStotal                     -0.015461530 -0.014001712 -0.012391522
## CASI_ADHD_CSum               -0.013127060 -0.013525387 -0.013413507
## DxTotal                      -0.034952144 -0.035934124 -0.036339054
##                                  13groups
## depression_T1                 0.256602815
## Educationhousehold           -0.014204931
## Familyincome_T1r             -0.132480512
## Child_gender                  0.019002968
## Childagecategory              0.076286244
## school.modality.falternating  0.062157907
## school.modality.fvirtual      0.073032359
## Child_raceethnicity_T1       -0.013043343
## COVIDrestrictionstotal       -0.002101334
## COVID_childimpact_T1         -0.011859920
## COVIDstressscale              0.013574512
## LBStotal                     -0.010565907
## CASI_ADHD_CSum               -0.012754640
## DxTotal                      -0.036171181
# time-variant: attention symptoms at each time point (CASI_ADHD_CSum)
# time-invariant: final academic scores (Academicperformance_total_T4)
# without sociodemographic variables (only continuous covariate of ADHD)

predict.model2 <- '
# latent growth factors
 Intercept =~ 1*depression_T1 + 1*depression_T2 + 1*depression_T3 + 1*depression_T4
 Linear =~ 0*depression_T1 + 1*depression_T2 + 2*depression_T3 + 3*depression_T4
# covariates
 Intercept ~ CASI_ADHD_CSum + CASI_ADHD_CSum_T2 + CASI_ADHD_CSum_T3 + CASI_ADHDCSum_T4 
 Linear ~ CASI_ADHD_CSum + CASI_ADHD_CSum_T2 + CASI_ADHD_CSum_T3 + CASI_ADHDCSum_T4 
# observed variables regressed on the time-varying covariate
                    depression_T1 ~ CASI_ADHD_CSum
                    depression_T2 ~ CASI_ADHD_CSum_T2
                    depression_T3 ~ CASI_ADHD_CSum_T3
                    depression_T4 ~ CASI_ADHDCSum_T4'

# fit prediction model to data
predict2 <- lavaan::growth(predict.model2, data=mydata, missing = "fiml", estimator = "MLR")
lavaan::summary(predict2, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6.17 ended normally after 84 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        21
## 
##                                                   Used       Total
##   Number of observations                            57         540
##   Number of missing patterns                         1            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                24.329      40.271
##   Degrees of freedom                                 9           9
##   P-value (Chi-square)                           0.004       0.000
##   Scaling correction factor                                  0.604
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                                96.733      85.070
##   Degrees of freedom                                22          22
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.137
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.795       0.504
##   Tucker-Lewis Index (TLI)                       0.499      -0.212
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.769
##   Robust Tucker-Lewis Index (TLI)                            0.436
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -105.042    -105.042
##   Scaling correction factor                                  1.453
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)        -92.878     -92.878
##   Scaling correction factor                                  1.198
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                 252.085     252.085
##   Bayesian (BIC)                               294.989     294.989
##   Sample-size adjusted Bayesian (SABIC)        228.974     228.974
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.173       0.247
##   90 Percent confidence interval - lower         0.092       0.152
##   90 Percent confidence interval - upper         0.257       0.351
##   P-value H_0: RMSEA <= 0.050                    0.011       0.001
##   P-value H_0: RMSEA >= 0.080                    0.968       0.997
##                                                                   
##   Robust RMSEA                                               0.176
##   90 Percent confidence interval - lower                     0.099
##   90 Percent confidence interval - upper                     0.257
##   P-value H_0: Robust RMSEA <= 0.050                         0.007
##   P-value H_0: Robust RMSEA >= 0.080                         0.976
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.088       0.088
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     depression_T1     1.000                           
##     depression_T2     1.000                           
##     depression_T3     1.000                           
##     depression_T4     1.000                           
##   Linear =~                                           
##     depression_T1     0.000                           
##     depression_T2     1.000                           
##     depression_T3     2.000                           
##     depression_T4     3.000                           
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~                                         
##     CASI_ADHD_CSum    0.042    0.027    1.532    0.125
##     CASI_ADHD_CS_T   -0.028    0.031   -0.909    0.363
##     CASI_ADHD_CS_T   -0.012    0.019   -0.601    0.548
##     CASI_ADHDCS_T4    0.021    0.020    1.074    0.283
##   Linear ~                                            
##     CASI_ADHD_CSum   -0.011    0.013   -0.864    0.388
##     CASI_ADHD_CS_T    0.014    0.010    1.419    0.156
##     CASI_ADHD_CS_T    0.015    0.007    2.178    0.029
##     CASI_ADHDCS_T4   -0.014    0.011   -1.253    0.210
##   depression_T1 ~                                     
##     CASI_ADHD_CSum    0.044    0.030    1.489    0.136
##   depression_T2 ~                                     
##     CASI_ADHD_CS_T    0.065    0.017    3.749    0.000
##   depression_T3 ~                                     
##     CASI_ADHD_CS_T    0.057    0.015    3.738    0.000
##   depression_T4 ~                                     
##     CASI_ADHDCS_T4    0.071    0.026    2.745    0.006
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .Intercept ~~                                        
##    .Linear            0.005    0.017    0.281    0.778
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .Intercept         0.533    0.744    0.716    0.474
##    .Linear           -0.363    0.198   -1.835    0.067
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .depression_T1     0.168    0.064    2.605    0.009
##    .depression_T2     0.125    0.022    5.655    0.000
##    .depression_T3     0.099    0.029    3.471    0.001
##    .depression_T4     0.171    0.045    3.780    0.000
##    .Intercept         0.006    0.046    0.131    0.896
##    .Linear           -0.003    0.008   -0.327    0.743
## 
## R-Square:
##                    Estimate
##     depression_T1     0.276
##     depression_T2     0.313
##     depression_T3     0.433
##     depression_T4     0.285
##     Intercept         0.733
##     Linear               NA
#standardized estimates
standardizedSolution(predict2, type = "std.all", se = TRUE, pvalue = TRUE, ci = TRUE)
##                  lhs op               rhs est.std     se      z pvalue ci.lower
## 1          Intercept =~     depression_T1   0.312  0.389  0.800  0.424   -0.452
## 2          Intercept =~     depression_T2   0.351  0.438  0.801  0.423   -0.508
## 3          Intercept =~     depression_T3   0.358  0.446  0.804  0.421   -0.515
## 4          Intercept =~     depression_T4   0.306  0.378  0.810  0.418   -0.434
## 5             Linear =~     depression_T1   0.000  0.000     NA     NA    0.000
## 6             Linear =~     depression_T2   0.110  0.201  0.546  0.585   -0.284
## 7             Linear =~     depression_T3   0.224  0.409  0.546  0.585   -0.579
## 8             Linear =~     depression_T4   0.287  0.519  0.553  0.580   -0.730
## 9          Intercept  ~    CASI_ADHD_CSum   0.827  0.863  0.959  0.338   -0.864
## 10         Intercept  ~ CASI_ADHD_CSum_T2  -0.535  0.680 -0.787  0.432   -1.867
## 11         Intercept  ~ CASI_ADHD_CSum_T3  -0.243  0.407 -0.597  0.550   -1.040
## 12         Intercept  ~  CASI_ADHDCSum_T4   0.435  0.522  0.832  0.405   -0.589
## 13            Linear  ~    CASI_ADHD_CSum  -0.692  1.564 -0.443  0.658   -3.757
## 14            Linear  ~ CASI_ADHD_CSum_T2   0.821  1.618  0.508  0.612   -2.349
## 15            Linear  ~ CASI_ADHD_CSum_T3   1.032  1.895  0.545  0.586   -2.682
## 16            Linear  ~  CASI_ADHDCSum_T4  -0.893  1.625 -0.550  0.582   -4.077
## 17     depression_T1  ~    CASI_ADHD_CSum   0.275  0.182  1.510  0.131   -0.082
## 18     depression_T2  ~ CASI_ADHD_CSum_T2   0.430  0.110  3.912  0.000    0.214
## 19     depression_T3  ~ CASI_ADHD_CSum_T3   0.431  0.115  3.752  0.000    0.206
## 20     depression_T4  ~  CASI_ADHDCSum_T4   0.448  0.166  2.698  0.007    0.123
## 21     depression_T1 ~~     depression_T1   0.724  0.215  3.368  0.001    0.303
## 22     depression_T2 ~~     depression_T2   0.687  0.141  4.871  0.000    0.410
## 23     depression_T3 ~~     depression_T3   0.567  0.154  3.686  0.000    0.266
## 24     depression_T4 ~~     depression_T4   0.715  0.160  4.479  0.000    0.402
## 25         Intercept ~~         Intercept   0.267  1.440  0.185  0.853   -2.556
## 26            Linear ~~            Linear  -1.247  8.201 -0.152  0.879  -17.321
## 27         Intercept ~~            Linear   1.201  7.492  0.160  0.873  -13.483
## 28    CASI_ADHD_CSum ~~    CASI_ADHD_CSum   1.000  0.000     NA     NA    1.000
## 29    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2   0.386  0.000     NA     NA    0.386
## 30    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3   0.092  0.000     NA     NA    0.092
## 31    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4   0.014  0.000     NA     NA    0.014
## 32 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2   1.000  0.000     NA     NA    1.000
## 33 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3   0.513  0.000     NA     NA    0.513
## 34 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4   0.424  0.000     NA     NA    0.424
## 35 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3   1.000  0.000     NA     NA    1.000
## 36 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4   0.252  0.000     NA     NA    0.252
## 37  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4   1.000  0.000     NA     NA    1.000
## 38     depression_T1 ~1                     0.000  0.000     NA     NA    0.000
## 39     depression_T2 ~1                     0.000  0.000     NA     NA    0.000
## 40     depression_T3 ~1                     0.000  0.000     NA     NA    0.000
## 41     depression_T4 ~1                     0.000  0.000     NA     NA    0.000
## 42    CASI_ADHD_CSum ~1                     4.415  0.000     NA     NA    4.415
## 43 CASI_ADHD_CSum_T2 ~1                     4.396  0.000     NA     NA    4.396
## 44 CASI_ADHD_CSum_T3 ~1                     6.227  0.000     NA     NA    6.227
## 45  CASI_ADHDCSum_T4 ~1                     6.477  0.000     NA     NA    6.477
## 46         Intercept ~1                     3.553  6.128  0.580  0.562   -8.457
## 47            Linear ~1                    -7.745 14.503 -0.534  0.593  -36.171
##    ci.upper
## 1     1.075
## 2     1.210
## 3     1.231
## 4     1.047
## 5     0.000
## 6     0.503
## 7     1.026
## 8     1.303
## 9     2.518
## 10    0.798
## 11    0.554
## 12    1.458
## 13    2.373
## 14    3.992
## 15    4.746
## 16    2.291
## 17    0.631
## 18    0.645
## 19    0.657
## 20    0.773
## 21    1.145
## 22    0.963
## 23    0.869
## 24    1.027
## 25    3.090
## 26   14.828
## 27   15.886
## 28    1.000
## 29    0.386
## 30    0.092
## 31    0.014
## 32    1.000
## 33    0.513
## 34    0.424
## 35    1.000
## 36    0.252
## 37    1.000
## 38    0.000
## 39    0.000
## 40    0.000
## 41    0.000
## 42    4.415
## 43    4.396
## 44    6.227
## 45    6.477
## 46   15.563
## 47   20.681
#unstandardized estimates
parameterEstimates(predict2)
##                  lhs op               rhs    est    se      z pvalue ci.lower
## 1          Intercept =~     depression_T1  1.000 0.000     NA     NA    1.000
## 2          Intercept =~     depression_T2  1.000 0.000     NA     NA    1.000
## 3          Intercept =~     depression_T3  1.000 0.000     NA     NA    1.000
## 4          Intercept =~     depression_T4  1.000 0.000     NA     NA    1.000
## 5             Linear =~     depression_T1  0.000 0.000     NA     NA    0.000
## 6             Linear =~     depression_T2  1.000 0.000     NA     NA    1.000
## 7             Linear =~     depression_T3  2.000 0.000     NA     NA    2.000
## 8             Linear =~     depression_T4  3.000 0.000     NA     NA    3.000
## 9          Intercept  ~    CASI_ADHD_CSum  0.042 0.027  1.532  0.125   -0.012
## 10         Intercept  ~ CASI_ADHD_CSum_T2 -0.028 0.031 -0.909  0.363   -0.090
## 11         Intercept  ~ CASI_ADHD_CSum_T3 -0.012 0.019 -0.601  0.548   -0.049
## 12         Intercept  ~  CASI_ADHDCSum_T4  0.021 0.020  1.074  0.283   -0.017
## 13            Linear  ~    CASI_ADHD_CSum -0.011 0.013 -0.864  0.388   -0.036
## 14            Linear  ~ CASI_ADHD_CSum_T2  0.014 0.010  1.419  0.156   -0.005
## 15            Linear  ~ CASI_ADHD_CSum_T3  0.015 0.007  2.178  0.029    0.002
## 16            Linear  ~  CASI_ADHDCSum_T4 -0.014 0.011 -1.253  0.210   -0.035
## 17     depression_T1  ~    CASI_ADHD_CSum  0.044 0.030  1.489  0.136   -0.014
## 18     depression_T2  ~ CASI_ADHD_CSum_T2  0.065 0.017  3.749  0.000    0.031
## 19     depression_T3  ~ CASI_ADHD_CSum_T3  0.057 0.015  3.738  0.000    0.027
## 20     depression_T4  ~  CASI_ADHDCSum_T4  0.071 0.026  2.745  0.006    0.020
## 21     depression_T1 ~~     depression_T1  0.168 0.064  2.605  0.009    0.041
## 22     depression_T2 ~~     depression_T2  0.125 0.022  5.655  0.000    0.082
## 23     depression_T3 ~~     depression_T3  0.099 0.029  3.471  0.001    0.043
## 24     depression_T4 ~~     depression_T4  0.171 0.045  3.780  0.000    0.083
## 25         Intercept ~~         Intercept  0.006 0.046  0.131  0.896   -0.084
## 26            Linear ~~            Linear -0.003 0.008 -0.327  0.743   -0.019
## 27         Intercept ~~            Linear  0.005 0.017  0.281  0.778   -0.029
## 28    CASI_ADHD_CSum ~~    CASI_ADHD_CSum  8.857 0.000     NA     NA    8.857
## 29    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2  3.229 0.000     NA     NA    3.229
## 30    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3  0.861 0.000     NA     NA    0.861
## 31    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4  0.133 0.000     NA     NA    0.133
## 32 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2  7.917 0.000     NA     NA    7.917
## 33 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3  4.546 0.000     NA     NA    4.546
## 34 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4  3.675 0.000     NA     NA    3.675
## 35 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3  9.921 0.000     NA     NA    9.921
## 36 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4  2.447 0.000     NA     NA    2.447
## 37  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4  9.469 0.000     NA     NA    9.469
## 38     depression_T1 ~1                    0.000 0.000     NA     NA    0.000
## 39     depression_T2 ~1                    0.000 0.000     NA     NA    0.000
## 40     depression_T3 ~1                    0.000 0.000     NA     NA    0.000
## 41     depression_T4 ~1                    0.000 0.000     NA     NA    0.000
## 42    CASI_ADHD_CSum ~1                   13.140 0.000     NA     NA   13.140
## 43 CASI_ADHD_CSum_T2 ~1                   12.368 0.000     NA     NA   12.368
## 44 CASI_ADHD_CSum_T3 ~1                   19.614 0.000     NA     NA   19.614
## 45  CASI_ADHDCSum_T4 ~1                   19.930 0.000     NA     NA   19.930
## 46         Intercept ~1                    0.533 0.744  0.716  0.474   -0.926
## 47            Linear ~1                   -0.363 0.198 -1.835  0.067   -0.750
##    ci.upper
## 1     1.000
## 2     1.000
## 3     1.000
## 4     1.000
## 5     0.000
## 6     1.000
## 7     2.000
## 8     3.000
## 9     0.095
## 10    0.033
## 11    0.026
## 12    0.060
## 13    0.014
## 14    0.033
## 15    0.029
## 16    0.008
## 17    0.103
## 18    0.099
## 19    0.087
## 20    0.122
## 21    0.294
## 22    0.169
## 23    0.156
## 24    0.260
## 25    0.096
## 26    0.014
## 27    0.039
## 28    8.857
## 29    3.229
## 30    0.861
## 31    0.133
## 32    7.917
## 33    4.546
## 34    3.675
## 35    9.921
## 36    2.447
## 37    9.469
## 38    0.000
## 39    0.000
## 40    0.000
## 41    0.000
## 42   13.140
## 43   12.368
## 44   19.614
## 45   19.930
## 46    1.991
## 47    0.025
semPaths(predict2,what = "path", whatLabels = "est",  edge.label.cex=.7,
                 intercepts = TRUE, edge.color = "black", nCharNodes = 0, nCharEdges=0,
                 sizeLat = 6, sizeMan=9, exoVar = FALSE, exoCov = FALSE,
                 shapeInt = "circle", covAtResiduals = FALSE)

# predicted means and covariances for observed variables
lavaan::fitted(predict2)
## $cov
##                   dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## depression_T1      0.232                                                   
## depression_T2      0.035  0.182                                            
## depression_T3      0.019  0.045  0.175                                     
## depression_T4      0.028  0.053  0.054  0.240                              
## CASI_ADHD_CSum     0.663  0.440  0.237  0.157         8.857                
## CASI_ADHD_CSum_T2  0.078  0.543  0.380  0.475         3.229           7.917
## CASI_ADHD_CSum_T3 -0.118  0.312  0.755  0.533         0.861           4.546
## CASI_ADHDCSum_T4   0.079  0.270  0.129  0.621         0.133           3.675
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## depression_T1                               
## depression_T2                               
## depression_T3                               
## depression_T4                               
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           9.921           
## CASI_ADHDCSum_T4            2.447      9.469
## 
## $mean
##     depression_T1     depression_T2     depression_T3     depression_T4 
##             1.507             1.423             1.434             1.424 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##            13.140            12.368            19.614            19.930
# predicted means and correlation for factors
lavaan::lavInspect(predict2, add.labels = TRUE, "mean.lv")
## Intercept    Linear 
##     0.923    -0.307
lavaan::lavInspect(predict2, add.labels = TRUE, "cor.lv")
##           Intrcp Linear
## Intercept  1.000       
## Linear    -0.337  1.000
# residuals
lavaan::residuals(predict2, type = "raw")
## $type
## [1] "raw"
## 
## $cov
##                   dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## depression_T1      0.000                                                   
## depression_T2      0.035 -0.019                                            
## depression_T3     -0.018 -0.036  0.029                                     
## depression_T4      0.036 -0.004  0.014 -0.024                              
## CASI_ADHD_CSum     0.033 -0.036 -0.003  0.019         0.000                
## CASI_ADHD_CSum_T2  0.039 -0.137  0.149 -0.108         0.000           0.000
## CASI_ADHD_CSum_T3  0.089 -0.262  0.258 -0.177         0.000           0.000
## CASI_ADHDCSum_T4  -0.166  0.102  0.133 -0.200         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## depression_T1                               
## depression_T2                               
## depression_T3                               
## depression_T4                               
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##     depression_T1     depression_T2     depression_T3     depression_T4 
##            -0.003             0.011            -0.013             0.010 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
lavaan::residuals(predict2, type = "standardized.mplus")
## $type
## [1] "standardized.mplus"
## 
## $cov
##                   dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## depression_T1     -0.016                                                   
## depression_T2      5.211     NA                                            
## depression_T3     -0.698     NA  1.530                                     
## depression_T4      2.157 -0.411     NA     NA                              
## CASI_ADHD_CSum     0.494 -0.348 -0.101  0.162         0.000                
## CASI_ADHD_CSum_T2  0.261 -4.854     NA -0.567         0.000           0.000
## CASI_ADHD_CSum_T3  0.580     NA     NA -1.086         0.000           0.000
## CASI_ADHDCSum_T4  -1.283  2.077     NA -1.582         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## depression_T1                               
## depression_T2                               
## depression_T3                               
## depression_T4                               
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##     depression_T1     depression_T2     depression_T3     depression_T4 
##            -0.835                NA                NA                NA 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
lavaan::residuals(predict2, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##                   dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## depression_T1      0.000                                                   
## depression_T2      0.190  0.000                                            
## depression_T3     -0.089 -0.205  0.000                                     
## depression_T4      0.169  0.005  0.059  0.000                              
## CASI_ADHD_CSum     0.023 -0.010 -0.016  0.020         0.000                
## CASI_ADHD_CSum_T2  0.029 -0.095  0.093 -0.064         0.000           0.000
## CASI_ADHD_CSum_T3  0.059 -0.193  0.139 -0.102         0.000           0.000
## CASI_ADHDCSum_T4  -0.112  0.094  0.089 -0.118         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## depression_T1                               
## depression_T2                               
## depression_T3                               
## depression_T4                               
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##     depression_T1     depression_T2     depression_T3     depression_T4 
##            -0.005             0.027            -0.029             0.022 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
# the mean for the intercept factor is the average outcome score at T1, and its variance
# is the random variation around this mean initial level. The linear factor mean is the average amount
# of increase in the outcome per time point, which is assumed to be the same between all pairs of adjacent
# measurement occasion
# time-variant: attention symptoms at each time point (CASI_ADHD_CSum)
# time-invariant: final academic scores (Academicperformance_total_T4)
# without sociodemographic variables

predict.model4 <- '
# latent growth factors
 Intercept =~ 1*anxiety_T1 + 1*anxiety_T2 + 1*anxiety_T3 + 1*anxiety_T4
 Linear =~ 0*anxiety_T1 + 1*anxiety_T2 + 2*anxiety_T3 + 3*anxiety_T4
# covariates
 Intercept ~ CASI_ADHD_CSum + CASI_ADHD_CSum_T2 + CASI_ADHD_CSum_T3 + CASI_ADHDCSum_T4 
 Linear ~ CASI_ADHD_CSum + CASI_ADHD_CSum_T2 + CASI_ADHD_CSum_T3 + CASI_ADHDCSum_T4 
# observed variables regressed on the time-varying covariate
                    anxiety_T1 ~ CASI_ADHD_CSum
                    anxiety_T2 ~ CASI_ADHD_CSum_T2
                    anxiety_T3 ~ CASI_ADHD_CSum_T3
                    anxiety_T4 ~ CASI_ADHDCSum_T4'

# fit prediction model to data
predict4 <- lavaan::growth(predict.model4, data=mydata, missing = "fiml", estimator = "mlr")
lavaan::summary(predict4, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6.17 ended normally after 99 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        21
## 
##                                                   Used       Total
##   Number of observations                            57         540
##   Number of missing patterns                         1            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                24.097      28.571
##   Degrees of freedom                                 9           9
##   P-value (Chi-square)                           0.004       0.001
##   Scaling correction factor                                  0.843
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                               139.834     137.466
##   Degrees of freedom                                22          22
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.017
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.872       0.831
##   Tucker-Lewis Index (TLI)                       0.687       0.586
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.857
##   Robust Tucker-Lewis Index (TLI)                            0.651
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)                -23.486     -23.486
##   Scaling correction factor                                  1.275
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)        -11.437     -11.437
##   Scaling correction factor                                  1.146
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                  88.971      88.971
##   Bayesian (BIC)                               131.875     131.875
##   Sample-size adjusted Bayesian (SABIC)         65.860      65.860
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.172       0.195
##   90 Percent confidence interval - lower         0.090       0.111
##   90 Percent confidence interval - upper         0.256       0.286
##   P-value H_0: RMSEA <= 0.050                    0.012       0.005
##   P-value H_0: RMSEA >= 0.080                    0.966       0.984
##                                                                   
##   Robust RMSEA                                               0.177
##   90 Percent confidence interval - lower                     0.104
##   90 Percent confidence interval - upper                     0.256
##   P-value H_0: Robust RMSEA <= 0.050                         0.005
##   P-value H_0: Robust RMSEA >= 0.080                         0.982
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.079       0.079
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     anxiety_T1        1.000                           
##     anxiety_T2        1.000                           
##     anxiety_T3        1.000                           
##     anxiety_T4        1.000                           
##   Linear =~                                           
##     anxiety_T1        0.000                           
##     anxiety_T2        1.000                           
##     anxiety_T3        2.000                           
##     anxiety_T4        3.000                           
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~                                         
##     CASI_ADHD_CSum   -0.012    0.017   -0.687    0.492
##     CASI_ADHD_CS_T   -0.010    0.014   -0.703    0.482
##     CASI_ADHD_CS_T   -0.005    0.009   -0.563    0.573
##     CASI_ADHDCS_T4    0.028    0.011    2.608    0.009
##   Linear ~                                            
##     CASI_ADHD_CSum    0.007    0.007    1.001    0.317
##     CASI_ADHD_CS_T    0.014    0.008    1.694    0.090
##     CASI_ADHD_CS_T    0.006    0.005    1.120    0.263
##     CASI_ADHDCS_T4   -0.018    0.007   -2.517    0.012
##   anxiety_T1 ~                                        
##     CASI_ADHD_CSum    0.077    0.023    3.364    0.001
##   anxiety_T2 ~                                        
##     CASI_ADHD_CS_T    0.079    0.015    5.092    0.000
##   anxiety_T3 ~                                        
##     CASI_ADHD_CS_T    0.051    0.013    3.936    0.000
##   anxiety_T4 ~                                        
##     CASI_ADHDCS_T4    0.060    0.020    2.971    0.003
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .Intercept ~~                                        
##    .Linear            0.015    0.007    2.098    0.036
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .Intercept         0.375    0.300    1.249    0.212
##    .Linear           -0.110    0.096   -1.143    0.253
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .anxiety_T1        0.124    0.034    3.656    0.000
##    .anxiety_T2        0.046    0.011    4.315    0.000
##    .anxiety_T3        0.051    0.011    4.570    0.000
##    .anxiety_T4        0.123    0.023    5.370    0.000
##    .Intercept        -0.019    0.014   -1.400    0.161
##    .Linear           -0.009    0.004   -2.075    0.038
## 
## R-Square:
##                    Estimate
##     anxiety_T1        0.143
##     anxiety_T2        0.578
##     anxiety_T3        0.484
##     anxiety_T4        0.189
##     Intercept            NA
##     Linear               NA
#standardized estimates
standardizedSolution(predict4, type = "std.all", pvalue = TRUE)
##                  lhs op               rhs est.std    se     z pvalue ci.lower
## 1          Intercept =~        anxiety_T1      NA    NA    NA     NA       NA
## 2          Intercept =~        anxiety_T2      NA    NA    NA     NA       NA
## 3          Intercept =~        anxiety_T3      NA    NA    NA     NA       NA
## 4          Intercept =~        anxiety_T4      NA    NA    NA     NA       NA
## 5             Linear =~        anxiety_T1      NA    NA    NA     NA       NA
## 6             Linear =~        anxiety_T2      NA    NA    NA     NA       NA
## 7             Linear =~        anxiety_T3      NA    NA    NA     NA       NA
## 8             Linear =~        anxiety_T4      NA    NA    NA     NA       NA
## 9          Intercept  ~    CASI_ADHD_CSum      NA    NA    NA     NA       NA
## 10         Intercept  ~ CASI_ADHD_CSum_T2      NA    NA    NA     NA       NA
## 11         Intercept  ~ CASI_ADHD_CSum_T3      NA    NA    NA     NA       NA
## 12         Intercept  ~  CASI_ADHDCSum_T4      NA    NA    NA     NA       NA
## 13            Linear  ~    CASI_ADHD_CSum      NA    NA    NA     NA       NA
## 14            Linear  ~ CASI_ADHD_CSum_T2      NA    NA    NA     NA       NA
## 15            Linear  ~ CASI_ADHD_CSum_T3      NA    NA    NA     NA       NA
## 16            Linear  ~  CASI_ADHDCSum_T4      NA    NA    NA     NA       NA
## 17        anxiety_T1  ~    CASI_ADHD_CSum   0.603 0.178 3.397  0.001    0.255
## 18        anxiety_T2  ~ CASI_ADHD_CSum_T2   0.674 0.112 6.037  0.000    0.455
## 19        anxiety_T3  ~ CASI_ADHD_CSum_T3   0.510 0.120 4.236  0.000    0.274
## 20        anxiety_T4  ~  CASI_ADHDCSum_T4   0.476 0.168 2.844  0.004    0.148
## 21        anxiety_T1 ~~        anxiety_T1   0.857 0.147 5.817  0.000    0.568
## 22        anxiety_T2 ~~        anxiety_T2   0.422 0.114 3.702  0.000    0.199
## 23        anxiety_T3 ~~        anxiety_T3   0.516 0.106 4.869  0.000    0.308
## 24        anxiety_T4 ~~        anxiety_T4   0.811 0.134 6.036  0.000    0.548
## 25         Intercept ~~         Intercept      NA    NA    NA     NA       NA
## 26            Linear ~~            Linear      NA    NA    NA     NA       NA
## 27         Intercept ~~            Linear   1.144 0.195 5.878  0.000    0.763
## 28    CASI_ADHD_CSum ~~    CASI_ADHD_CSum   1.000 0.000    NA     NA    1.000
## 29    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2   0.386 0.000    NA     NA    0.386
## 30    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3   0.092 0.000    NA     NA    0.092
## 31    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4   0.014 0.000    NA     NA    0.014
## 32 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2   1.000 0.000    NA     NA    1.000
## 33 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3   0.513 0.000    NA     NA    0.513
## 34 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4   0.424 0.000    NA     NA    0.424
## 35 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3   1.000 0.000    NA     NA    1.000
## 36 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4   0.252 0.000    NA     NA    0.252
## 37  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4   1.000 0.000    NA     NA    1.000
## 38        anxiety_T1 ~1                     0.000 0.000    NA     NA    0.000
## 39        anxiety_T2 ~1                     0.000 0.000    NA     NA    0.000
## 40        anxiety_T3 ~1                     0.000 0.000    NA     NA    0.000
## 41        anxiety_T4 ~1                     0.000 0.000    NA     NA    0.000
## 42    CASI_ADHD_CSum ~1                     4.415 0.000    NA     NA    4.415
## 43 CASI_ADHD_CSum_T2 ~1                     4.396 0.000    NA     NA    4.396
## 44 CASI_ADHD_CSum_T3 ~1                     6.227 0.000    NA     NA    6.227
## 45  CASI_ADHDCSum_T4 ~1                     6.477 0.000    NA     NA    6.477
## 46         Intercept ~1                        NA    NA    NA     NA       NA
## 47            Linear ~1                        NA    NA    NA     NA       NA
##    ci.upper
## 1        NA
## 2        NA
## 3        NA
## 4        NA
## 5        NA
## 6        NA
## 7        NA
## 8        NA
## 9        NA
## 10       NA
## 11       NA
## 12       NA
## 13       NA
## 14       NA
## 15       NA
## 16       NA
## 17    0.952
## 18    0.892
## 19    0.746
## 20    0.805
## 21    1.146
## 22    0.646
## 23    0.724
## 24    1.074
## 25       NA
## 26       NA
## 27    1.526
## 28    1.000
## 29    0.386
## 30    0.092
## 31    0.014
## 32    1.000
## 33    0.513
## 34    0.424
## 35    1.000
## 36    0.252
## 37    1.000
## 38    0.000
## 39    0.000
## 40    0.000
## 41    0.000
## 42    4.415
## 43    4.396
## 44    6.227
## 45    6.477
## 46       NA
## 47       NA
#unstandardized estimates
parameterEstimates(predict4)
##                  lhs op               rhs    est    se      z pvalue ci.lower
## 1          Intercept =~        anxiety_T1  1.000 0.000     NA     NA    1.000
## 2          Intercept =~        anxiety_T2  1.000 0.000     NA     NA    1.000
## 3          Intercept =~        anxiety_T3  1.000 0.000     NA     NA    1.000
## 4          Intercept =~        anxiety_T4  1.000 0.000     NA     NA    1.000
## 5             Linear =~        anxiety_T1  0.000 0.000     NA     NA    0.000
## 6             Linear =~        anxiety_T2  1.000 0.000     NA     NA    1.000
## 7             Linear =~        anxiety_T3  2.000 0.000     NA     NA    2.000
## 8             Linear =~        anxiety_T4  3.000 0.000     NA     NA    3.000
## 9          Intercept  ~    CASI_ADHD_CSum -0.012 0.017 -0.687  0.492   -0.045
## 10         Intercept  ~ CASI_ADHD_CSum_T2 -0.010 0.014 -0.703  0.482   -0.036
## 11         Intercept  ~ CASI_ADHD_CSum_T3 -0.005 0.009 -0.563  0.573   -0.022
## 12         Intercept  ~  CASI_ADHDCSum_T4  0.028 0.011  2.608  0.009    0.007
## 13            Linear  ~    CASI_ADHD_CSum  0.007 0.007  1.001  0.317   -0.007
## 14            Linear  ~ CASI_ADHD_CSum_T2  0.014 0.008  1.694  0.090   -0.002
## 15            Linear  ~ CASI_ADHD_CSum_T3  0.006 0.005  1.120  0.263   -0.004
## 16            Linear  ~  CASI_ADHDCSum_T4 -0.018 0.007 -2.517  0.012   -0.031
## 17        anxiety_T1  ~    CASI_ADHD_CSum  0.077 0.023  3.364  0.001    0.032
## 18        anxiety_T2  ~ CASI_ADHD_CSum_T2  0.079 0.015  5.092  0.000    0.048
## 19        anxiety_T3  ~ CASI_ADHD_CSum_T3  0.051 0.013  3.936  0.000    0.026
## 20        anxiety_T4  ~  CASI_ADHDCSum_T4  0.060 0.020  2.971  0.003    0.021
## 21        anxiety_T1 ~~        anxiety_T1  0.124 0.034  3.656  0.000    0.057
## 22        anxiety_T2 ~~        anxiety_T2  0.046 0.011  4.315  0.000    0.025
## 23        anxiety_T3 ~~        anxiety_T3  0.051 0.011  4.570  0.000    0.029
## 24        anxiety_T4 ~~        anxiety_T4  0.123 0.023  5.370  0.000    0.078
## 25         Intercept ~~         Intercept -0.019 0.014 -1.400  0.161   -0.046
## 26            Linear ~~            Linear -0.009 0.004 -2.075  0.038   -0.018
## 27         Intercept ~~            Linear  0.015 0.007  2.098  0.036    0.001
## 28    CASI_ADHD_CSum ~~    CASI_ADHD_CSum  8.857 0.000     NA     NA    8.857
## 29    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2  3.229 0.000     NA     NA    3.229
## 30    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3  0.861 0.000     NA     NA    0.861
## 31    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4  0.133 0.000     NA     NA    0.133
## 32 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2  7.917 0.000     NA     NA    7.917
## 33 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3  4.546 0.000     NA     NA    4.546
## 34 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4  3.675 0.000     NA     NA    3.675
## 35 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3  9.921 0.000     NA     NA    9.921
## 36 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4  2.447 0.000     NA     NA    2.447
## 37  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4  9.469 0.000     NA     NA    9.469
## 38        anxiety_T1 ~1                    0.000 0.000     NA     NA    0.000
## 39        anxiety_T2 ~1                    0.000 0.000     NA     NA    0.000
## 40        anxiety_T3 ~1                    0.000 0.000     NA     NA    0.000
## 41        anxiety_T4 ~1                    0.000 0.000     NA     NA    0.000
## 42    CASI_ADHD_CSum ~1                   13.140 0.000     NA     NA   13.140
## 43 CASI_ADHD_CSum_T2 ~1                   12.368 0.000     NA     NA   12.368
## 44 CASI_ADHD_CSum_T3 ~1                   19.614 0.000     NA     NA   19.614
## 45  CASI_ADHDCSum_T4 ~1                   19.930 0.000     NA     NA   19.930
## 46         Intercept ~1                    0.375 0.300  1.249  0.212   -0.213
## 47            Linear ~1                   -0.110 0.096 -1.143  0.253   -0.298
##    ci.upper
## 1     1.000
## 2     1.000
## 3     1.000
## 4     1.000
## 5     0.000
## 6     1.000
## 7     2.000
## 8     3.000
## 9     0.022
## 10    0.017
## 11    0.012
## 12    0.049
## 13    0.022
## 14    0.030
## 15    0.015
## 16   -0.004
## 17    0.122
## 18    0.109
## 19    0.076
## 20    0.100
## 21    0.190
## 22    0.066
## 23    0.073
## 24    0.168
## 25    0.008
## 26   -0.001
## 27    0.029
## 28    8.857
## 29    3.229
## 30    0.861
## 31    0.133
## 32    7.917
## 33    4.546
## 34    3.675
## 35    9.921
## 36    2.447
## 37    9.469
## 38    0.000
## 39    0.000
## 40    0.000
## 41    0.000
## 42   13.140
## 43   12.368
## 44   19.614
## 45   19.930
## 46    0.962
## 47    0.079
semPaths(predict4,what = "path", whatLabels = "est",  edge.label.cex=.7,
                 intercepts = TRUE, edge.color = "black", nCharNodes = 0, nCharEdges=0,
                 sizeLat = 6, sizeMan=9, exoVar = FALSE, exoCov = FALSE,
                 shapeInt = "circle", covAtResiduals = FALSE)

# predicted means and covariances for observed variables
lavaan::fitted(predict4)
## $cov
##                   anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## anxiety_T1         0.144                                                   
## anxiety_T2         0.014  0.108                                            
## anxiety_T3         0.017  0.042  0.099                                     
## anxiety_T4         0.048  0.058  0.028  0.152                              
## CASI_ADHD_CSum     0.547  0.233  0.136  0.214         8.857                
## CASI_ADHD_CSum_T2  0.216  0.686  0.389  0.474         3.229           7.917
## CASI_ADHD_CSum_T3  0.033  0.407  0.637  0.361         0.861           4.546
## CASI_ADHDCSum_T4   0.227  0.405  0.139  0.485         0.133           3.675
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## anxiety_T1                                  
## anxiety_T2                                  
## anxiety_T3                                  
## anxiety_T4                                  
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           9.921           
## CASI_ADHDCSum_T4            2.447      9.469
## 
## $mean
##        anxiety_T1        anxiety_T2        anxiety_T3        anxiety_T4 
##             1.578             1.459             1.403             1.526 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##            13.140            12.368            19.614            19.930
# predicted means for factors
lavaan::lavInspect(predict4, add.labels = TRUE, "mean.lv")
## Intercept    Linear 
##     0.567    -0.081
lavaan::lavInspect(predict4, add.labels = TRUE, "cor.lv")
##           Intrcp Linear
## Intercept      1       
## Linear       NaN      1
# residuals
lavaan::residuals(predict4, type = "raw")
## $type
## [1] "raw"
## 
## $cov
##                   anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## anxiety_T1        -0.018                                                   
## anxiety_T2         0.008 -0.005                                            
## anxiety_T3         0.000 -0.002  0.020                                     
## anxiety_T4        -0.010 -0.002 -0.006 -0.019                              
## CASI_ADHD_CSum    -0.013  0.033 -0.058  0.063         0.000                
## CASI_ADHD_CSum_T2  0.062 -0.045  0.024  0.002         0.000           0.000
## CASI_ADHD_CSum_T3  0.167 -0.175  0.185 -0.140         0.000           0.000
## CASI_ADHDCSum_T4  -0.126  0.005  0.144 -0.237         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## anxiety_T1                                  
## anxiety_T2                                  
## anxiety_T3                                  
## anxiety_T4                                  
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##        anxiety_T1        anxiety_T2        anxiety_T3        anxiety_T4 
##             0.001             0.004            -0.009             0.012 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
lavaan::residuals(predict4, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##                   anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## anxiety_T1         0.000                                                   
## anxiety_T2         0.077  0.000                                            
## anxiety_T3         0.001 -0.041  0.000                                     
## anxiety_T4        -0.033  0.031 -0.052  0.000                              
## CASI_ADHD_CSum     0.022  0.040 -0.069  0.071         0.000                
## CASI_ADHD_CSum_T2  0.077 -0.032 -0.013  0.032         0.000           0.000
## CASI_ADHD_CSum_T3  0.151 -0.163  0.116 -0.101         0.000           0.000
## CASI_ADHDCSum_T4  -0.101  0.016  0.124 -0.183         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## anxiety_T1                                  
## anxiety_T2                                  
## anxiety_T3                                  
## anxiety_T4                                  
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##        anxiety_T1        anxiety_T2        anxiety_T3        anxiety_T4 
##             0.003             0.011            -0.027             0.033 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
#########################################################################################################
#########################################################################################################
#########################################################################################################

# THE FOLLOWING IS ALL SUPPLEMENTAL MATERIAL AND TESTING VARIOUS MODEL APPROACHES
# ONLY KEEPING IN HERE FOR A RECORD/PAPER TRAIL, BUT IGNORE IT UNLESS REVIEWERS ASK FOR SOMETHING

#########################################################################################################
#########################################################################################################
#########################################################################################################



#########################################################################################################
                            # 3 step model fitting for depression #
#########################################################################################################
### MODEL 1 - no growth (intercept only) "random intercept-only model" - predicts no growth

# Loadings for all indicators on the intercept factor are fixed to equal 1.0.
# Intercept represents the factor mean, which is also the predicted average depression score
# over all years 1-4

noGrowth.model <- '
# specify intercept
# fix all loadings to 1.0
 Intercept =~ 1*depression_T1 + 1*depression_T2 + 1*depression_T3 + 1*depression_T4
# fix error variance for r1 to zero
 depression_T1 ~~ 0*depression_T1 '

#########################################################################################################
### MODEL 2 - latent basis growth model ("level and shape model")

# (curve fitting, level and shape)
# two growth factors: intercept (level) and shape

# loadings of all repeated measures of depression are fixed to equal 1.0, like in the
# random intercept-only model above. here, onnly looking at T1 to T4 change (overall shape)
# the basis model predicts growth trajectories that are not strictly linear - allows for
# linear or curvilinear change. the shape factor will represent the pattern
# this is called "non-linear curve fitting" 
# unstandardized loadings for the shape factor are called basis coefficients
# two of these are fixed to equal constraints:
# one is specifying T1 as 0 defines the intercept [depression] factor mean)
# second is defining the random variation around the initial level
# the basis coefficients define the shape factor mean as the average change in depression
# between T1 and T4. it also scales the growth factor Shape so that a 1-unit change in 
# time refers to the whole period of observation, or T1-T4 inclusive. so the loadings are 
# interpreted as proportions of the total overall change that has occurred up to and 
# including the corresponding measurement
# i.e., .70 for T3 would mean that .70, or 70% of the total increase in depression from T1-T4
# has occurred by T3 
# the predicted average depression score  is the sum of the initial mean at T1 plus the proportion 
# of total change over T1-4 that has occurred up to and including the point of measurement
# the covariance represents the association between intercept and shape
# covariance indicates that higher initial levels of depression at T1 predict a higher rate of
# subsequent change between T1-4. so those who start at higher levels change the most over time
# a negative covariance indicates the opposite: Higher initial standing predicts less change over 4 timepoints
# a factor covariance of zero indicates that initial level has nothing to do with the rate of subsequent change

# maccallum-rmsea for model 2
# exact fit test
# power at N = 432
semTools::findRMSEApower(0, .05, 4, 432, .05, 1)
## [1] 0.3437725
# minimum N for power at least .80
semTools::findRMSEAsamplesize(0, .05, 4, .80, .05, 1)
## [1] 1195
basis.model <- '
 Intercept =~ 1*depression_T1 + 1*depression_T2 + 1*depression_T3 + 1*depression_T4
# specify shape, first and last loadings fixed
 Shape =~ 0*depression_T1 + depression_T2 + depression_T3 + 1*depression_T4
 depression_T1 ~~ 0*depression_T1 '

#########################################################################################################
### MODEL 3 - linear growth model with only continuous covariates
# these assume change is strictly linear - essentially constrained versions of basis growth models 
# but on the same variables. the coefficients are all fixed to equal constraints that correspond
# to times of measurement (none are free parameters)
# the mean for the intercept factor is the average depression score at T1, and its variance
# is the random variation around this mean initial level. The linear factor mean is the average amount
# of increase in depression per time point, which is assumed to be the same between all pairs of adjacent
# measurement occasions

linear.model <- '
 Intercept =~ 1*depression_T1 + 1*depression_T2 + 1*depression_T3 + 1*depression_T4 
# all loadings fixed to constants
 Linear =~ 0*depression_T1 + 1*depression_T2 + 2*depression_T3 + 3*depression_T4
 depression_T1 ~~ 0*depression_T1 
 # TVCs
                depression_T1 ~ CASI_ADHD_CSum
                depression_T2 ~ CASI_ADHD_CSum_T2
                depression_T3 ~ CASI_ADHD_CSum_T3
                depression_T4 ~ CASI_ADHDCSum_T4'

# fit model 1 to data
noGrowth <- lavaan::growth(noGrowth.model, data=mydata, missing = "fiml", estimator = "mlr")

# fit model 2 to data
basis <- lavaan::growth(basis.model, data=mydata, missing = "fiml", estimator = "mlr")

# fit model 3 to data
linear <- lavaan::growth(linear.model, data=mydata, missing = "fiml", estimator = "mlr")

#########################################################################################################
# model chi-squares and chi-square difference tests
anova(noGrowth, basis)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##          Df    AIC    BIC    Chisq Chisq diff Df diff Pr(>Chisq)    
## basis     4 1522.3 1563.7   6.4599                                  
## noGrowth  9 1688.2 1708.9 182.3534     163.07       5  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(basis, linear)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##        Df     AIC     BIC   Chisq Chisq diff Df diff Pr(>Chisq)    
## basis   4 1522.32 1563.67  6.4599                                  
## linear 18  264.91  289.43 55.1570     41.232      14  0.0001635 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# model 1 parameter estimates, global fit statistics,
# residuals
lavaan::summary(noGrowth, fit.measures = TRUE, estimates = TRUE)
## lavaan 0.6.17 ended normally after 23 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##                                                   Used       Total
##   Number of observations                           462         540
##   Number of missing patterns                        14            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                               182.353     168.281
##   Degrees of freedom                                 9           9
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.084
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                                59.362      50.010
##   Degrees of freedom                                 6           6
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.187
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.000       0.000
##   Tucker-Lewis Index (TLI)                      -1.166      -1.413
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.000
##   Robust Tucker-Lewis Index (TLI)                           -0.407
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -839.105    -839.105
##   Scaling correction factor                                  1.009
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)       -747.929    -747.929
##   Scaling correction factor                                  1.057
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                1688.211    1688.211
##   Bayesian (BIC)                              1708.889    1708.889
##   Sample-size adjusted Bayesian (SABIC)       1693.020    1693.020
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.204       0.196
##   90 Percent confidence interval - lower         0.179       0.171
##   90 Percent confidence interval - upper         0.231       0.221
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    1.000       1.000
##                                                                   
##   Robust RMSEA                                               0.430
##   90 Percent confidence interval - lower                     0.362
##   90 Percent confidence interval - upper                     0.502
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.866       0.866
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     depression_T1     1.000                           
##     depression_T2     1.000                           
##     depression_T3     1.000                           
##     depression_T4     1.000                           
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Intercept         1.199    0.032   37.043    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .depression_T1     0.000                           
##    .depression_T2     0.333    0.047    7.009    0.000
##    .depression_T3     0.475    0.055    8.566    0.000
##    .depression_T4     0.390    0.056    6.992    0.000
##     Intercept         0.457    0.027   17.042    0.000
lavaan::fitted(noGrowth)
## $cov
##               dpr_T1 dpr_T2 dpr_T3 dpr_T4
## depression_T1  0.457                     
## depression_T2  0.457  0.790              
## depression_T3  0.457  0.457  0.932       
## depression_T4  0.457  0.457  0.457  0.847
## 
## $mean
## depression_T1 depression_T2 depression_T3 depression_T4 
##         1.199         1.199         1.199         1.199
lavaan::residuals(noGrowth, type = "standardized")
## $type
## [1] "standardized"
## 
## $cov
##               dpr_T1 dpr_T2 dpr_T3 dpr_T4
## depression_T1  0.894                     
## depression_T2 -3.667 -2.505              
## depression_T3 -3.643 -4.853 -2.493       
## depression_T4 -3.194 -3.718 -3.676 -2.107
## 
## $mean
## depression_T1 depression_T2 depression_T3 depression_T4 
##        -0.363         1.161        -0.819         0.929
lavaan::residuals(noGrowth, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##               dpr_T1 dpr_T2 dpr_T3 dpr_T4
## depression_T1  0.000                     
## depression_T2 -0.308  0.000              
## depression_T3 -0.301 -0.285  0.000       
## depression_T4 -0.253 -0.123 -0.089  0.000
## 
## $mean
## depression_T1 depression_T2 depression_T3 depression_T4 
##        -0.005         0.108        -0.068         0.090
#standardized estimates
standardizedSolution(noGrowth, type = "std.all", pvalue = TRUE)
##              lhs op           rhs est.std    se      z pvalue ci.lower ci.upper
## 1      Intercept =~ depression_T1   1.000 0.000     NA     NA    1.000    1.000
## 2      Intercept =~ depression_T2   0.761 0.023 33.804      0    0.717    0.805
## 3      Intercept =~ depression_T3   0.700 0.021 32.650      0    0.658    0.742
## 4      Intercept =~ depression_T4   0.734 0.025 29.277      0    0.685    0.784
## 5  depression_T1 ~~ depression_T1   0.000 0.000     NA     NA    0.000    0.000
## 6  depression_T2 ~~ depression_T2   0.421 0.034 12.309      0    0.354    0.488
## 7  depression_T3 ~~ depression_T3   0.510 0.030 16.964      0    0.451    0.568
## 8  depression_T4 ~~ depression_T4   0.461 0.037 12.496      0    0.388    0.533
## 9      Intercept ~~     Intercept   1.000 0.000     NA     NA    1.000    1.000
## 10 depression_T1 ~1                 0.000 0.000     NA     NA    0.000    0.000
## 11 depression_T2 ~1                 0.000 0.000     NA     NA    0.000    0.000
## 12 depression_T3 ~1                 0.000 0.000     NA     NA    0.000    0.000
## 13 depression_T4 ~1                 0.000 0.000     NA     NA    0.000    0.000
## 14     Intercept ~1                 1.773 0.075 23.720      0    1.626    1.919
#unstandardized estimates
parameterEstimates(noGrowth)
##              lhs op           rhs   est    se      z pvalue ci.lower ci.upper
## 1      Intercept =~ depression_T1 1.000 0.000     NA     NA    1.000    1.000
## 2      Intercept =~ depression_T2 1.000 0.000     NA     NA    1.000    1.000
## 3      Intercept =~ depression_T3 1.000 0.000     NA     NA    1.000    1.000
## 4      Intercept =~ depression_T4 1.000 0.000     NA     NA    1.000    1.000
## 5  depression_T1 ~~ depression_T1 0.000 0.000     NA     NA    0.000    0.000
## 6  depression_T2 ~~ depression_T2 0.333 0.047  7.009      0    0.240    0.426
## 7  depression_T3 ~~ depression_T3 0.475 0.055  8.566      0    0.366    0.584
## 8  depression_T4 ~~ depression_T4 0.390 0.056  6.992      0    0.281    0.500
## 9      Intercept ~~     Intercept 0.457 0.027 17.042      0    0.405    0.510
## 10 depression_T1 ~1               0.000 0.000     NA     NA    0.000    0.000
## 11 depression_T2 ~1               0.000 0.000     NA     NA    0.000    0.000
## 12 depression_T3 ~1               0.000 0.000     NA     NA    0.000    0.000
## 13 depression_T4 ~1               0.000 0.000     NA     NA    0.000    0.000
## 14     Intercept ~1               1.199 0.032 37.043      0    1.135    1.262
# model 2 parameter estimates, global fit statistics,
# residuals
# retained model
lavaan::summary(basis, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6.17 ended normally after 36 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##                                                   Used       Total
##   Number of observations                           462         540
##   Number of missing patterns                        14            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 6.460       5.927
##   Degrees of freedom                                 4           4
##   P-value (Chi-square)                           0.167       0.205
##   Scaling correction factor                                  1.090
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                                59.362      50.010
##   Degrees of freedom                                 6           6
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.187
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.954       0.956
##   Tucker-Lewis Index (TLI)                       0.931       0.934
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.977
##   Robust Tucker-Lewis Index (TLI)                            0.965
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -751.159    -751.159
##   Scaling correction factor                                  1.044
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)       -747.929    -747.929
##   Scaling correction factor                                  1.057
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                1522.318    1522.318
##   Bayesian (BIC)                              1563.673    1563.673
##   Sample-size adjusted Bayesian (SABIC)       1531.936    1531.936
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.036       0.032
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.086       0.081
##   P-value H_0: RMSEA <= 0.050                    0.605       0.664
##   P-value H_0: RMSEA >= 0.080                    0.079       0.053
##                                                                   
##   Robust RMSEA                                               0.068
##   90 Percent confidence interval - lower                     0.000
##   90 Percent confidence interval - upper                     0.233
##   P-value H_0: Robust RMSEA <= 0.050                         0.359
##   P-value H_0: Robust RMSEA >= 0.080                         0.550
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.066       0.066
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     depression_T1     1.000                           
##     depression_T2     1.000                           
##     depression_T3     1.000                           
##     depression_T4     1.000                           
##   Shape =~                                            
##     depression_T1     0.000                           
##     depression_T2     1.056    0.193    5.472    0.000
##     depression_T3     1.243    0.231    5.371    0.000
##     depression_T4     1.000                           
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~~                                        
##     Shape            -0.277    0.046   -6.028    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Intercept         1.199    0.034   34.854    0.000
##     Shape             0.018    0.039    0.466    0.641
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .depression_T1     0.000                           
##    .depression_T2     0.176    0.027    6.623    0.000
##    .depression_T3     0.255    0.049    5.232    0.000
##    .depression_T4     0.241    0.045    5.368    0.000
##     Intercept         0.487    0.029   16.572    0.000
##     Shape             0.205    0.064    3.198    0.001
## 
## R-Square:
##                    Estimate
##     depression_T1     1.000
##     depression_T2     0.427
##     depression_T3     0.312
##     depression_T4     0.365
lavaan::standardizedSolution(basis)
##              lhs op           rhs est.std    se       z pvalue ci.lower
## 1      Intercept =~ depression_T1   1.000 0.000      NA     NA    1.000
## 2      Intercept =~ depression_T2   1.259 0.085  14.802  0.000    1.092
## 3      Intercept =~ depression_T3   1.145 0.070  16.279  0.000    1.007
## 4      Intercept =~ depression_T4   1.132 0.073  15.476  0.000    0.989
## 5          Shape =~ depression_T1   0.000 0.000      NA     NA    0.000
## 6          Shape =~ depression_T2   0.862 0.151   5.726  0.000    0.567
## 7          Shape =~ depression_T3   0.923 0.163   5.658  0.000    0.603
## 8          Shape =~ depression_T4   0.734 0.144   5.103  0.000    0.452
## 9  depression_T1 ~~ depression_T1   0.000 0.000      NA     NA    0.000
## 10 depression_T2 ~~ depression_T2   0.573 0.098   5.871  0.000    0.382
## 11 depression_T3 ~~ depression_T3   0.688 0.101   6.785  0.000    0.489
## 12 depression_T4 ~~ depression_T4   0.635 0.087   7.270  0.000    0.464
## 13     Intercept ~~     Intercept   1.000 0.000      NA     NA    1.000
## 14         Shape ~~         Shape   1.000 0.000      NA     NA    1.000
## 15     Intercept ~~         Shape  -0.876 0.052 -16.973  0.000   -0.977
## 16 depression_T1 ~1                 0.000 0.000      NA     NA    0.000
## 17 depression_T2 ~1                 0.000 0.000      NA     NA    0.000
## 18 depression_T3 ~1                 0.000 0.000      NA     NA    0.000
## 19 depression_T4 ~1                 0.000 0.000      NA     NA    0.000
## 20     Intercept ~1                 1.718 0.074  23.101  0.000    1.572
## 21         Shape ~1                 0.040 0.085   0.472  0.637   -0.127
##    ci.upper
## 1     1.000
## 2     1.425
## 3     1.283
## 4     1.276
## 5     0.000
## 6     1.157
## 7     1.243
## 8     1.016
## 9     0.000
## 10    0.764
## 11    0.886
## 12    0.806
## 13    1.000
## 14    1.000
## 15   -0.775
## 16    0.000
## 17    0.000
## 18    0.000
## 19    0.000
## 20    1.864
## 21    0.208
#print(lavaan::parameterEstimates(basis), nd = 5)

#standardized estimates
standardizedSolution(basis, type = "std.all",  se= TRUE, pvalue = TRUE)
##              lhs op           rhs est.std    se       z pvalue ci.lower
## 1      Intercept =~ depression_T1   1.000 0.000      NA     NA    1.000
## 2      Intercept =~ depression_T2   1.259 0.085  14.802  0.000    1.092
## 3      Intercept =~ depression_T3   1.145 0.070  16.279  0.000    1.007
## 4      Intercept =~ depression_T4   1.132 0.073  15.476  0.000    0.989
## 5          Shape =~ depression_T1   0.000 0.000      NA     NA    0.000
## 6          Shape =~ depression_T2   0.862 0.151   5.726  0.000    0.567
## 7          Shape =~ depression_T3   0.923 0.163   5.658  0.000    0.603
## 8          Shape =~ depression_T4   0.734 0.144   5.103  0.000    0.452
## 9  depression_T1 ~~ depression_T1   0.000 0.000      NA     NA    0.000
## 10 depression_T2 ~~ depression_T2   0.573 0.098   5.871  0.000    0.382
## 11 depression_T3 ~~ depression_T3   0.688 0.101   6.785  0.000    0.489
## 12 depression_T4 ~~ depression_T4   0.635 0.087   7.270  0.000    0.464
## 13     Intercept ~~     Intercept   1.000 0.000      NA     NA    1.000
## 14         Shape ~~         Shape   1.000 0.000      NA     NA    1.000
## 15     Intercept ~~         Shape  -0.876 0.052 -16.973  0.000   -0.977
## 16 depression_T1 ~1                 0.000 0.000      NA     NA    0.000
## 17 depression_T2 ~1                 0.000 0.000      NA     NA    0.000
## 18 depression_T3 ~1                 0.000 0.000      NA     NA    0.000
## 19 depression_T4 ~1                 0.000 0.000      NA     NA    0.000
## 20     Intercept ~1                 1.718 0.074  23.101  0.000    1.572
## 21         Shape ~1                 0.040 0.085   0.472  0.637   -0.127
##    ci.upper
## 1     1.000
## 2     1.425
## 3     1.283
## 4     1.276
## 5     0.000
## 6     1.157
## 7     1.243
## 8     1.016
## 9     0.000
## 10    0.764
## 11    0.886
## 12    0.806
## 13    1.000
## 14    1.000
## 15   -0.775
## 16    0.000
## 17    0.000
## 18    0.000
## 19    0.000
## 20    1.864
## 21    0.208
#unstandardized estimates
parameterEstimates(basis)
##              lhs op           rhs    est    se      z pvalue ci.lower ci.upper
## 1      Intercept =~ depression_T1  1.000 0.000     NA     NA    1.000    1.000
## 2      Intercept =~ depression_T2  1.000 0.000     NA     NA    1.000    1.000
## 3      Intercept =~ depression_T3  1.000 0.000     NA     NA    1.000    1.000
## 4      Intercept =~ depression_T4  1.000 0.000     NA     NA    1.000    1.000
## 5          Shape =~ depression_T1  0.000 0.000     NA     NA    0.000    0.000
## 6          Shape =~ depression_T2  1.056 0.193  5.472  0.000    0.678    1.435
## 7          Shape =~ depression_T3  1.243 0.231  5.371  0.000    0.789    1.696
## 8          Shape =~ depression_T4  1.000 0.000     NA     NA    1.000    1.000
## 9  depression_T1 ~~ depression_T1  0.000 0.000     NA     NA    0.000    0.000
## 10 depression_T2 ~~ depression_T2  0.176 0.027  6.623  0.000    0.124    0.228
## 11 depression_T3 ~~ depression_T3  0.255 0.049  5.232  0.000    0.160    0.351
## 12 depression_T4 ~~ depression_T4  0.241 0.045  5.368  0.000    0.153    0.329
## 13     Intercept ~~     Intercept  0.487 0.029 16.572  0.000    0.430    0.545
## 14         Shape ~~         Shape  0.205 0.064  3.198  0.001    0.079    0.330
## 15     Intercept ~~         Shape -0.277 0.046 -6.028  0.000   -0.367   -0.187
## 16 depression_T1 ~1                0.000 0.000     NA     NA    0.000    0.000
## 17 depression_T2 ~1                0.000 0.000     NA     NA    0.000    0.000
## 18 depression_T3 ~1                0.000 0.000     NA     NA    0.000    0.000
## 19 depression_T4 ~1                0.000 0.000     NA     NA    0.000    0.000
## 20     Intercept ~1                1.199 0.034 34.854  0.000    1.132    1.267
## 21         Shape ~1                0.018 0.039  0.466  0.641   -0.058    0.095
# implied covariances and means for observed variables
lavaan::fitted(basis)
## $cov
##               dpr_T1 dpr_T2 dpr_T3 dpr_T4
## depression_T1  0.487                     
## depression_T2  0.195  0.307              
## depression_T3  0.143  0.120  0.371       
## depression_T4  0.210  0.135  0.121  0.380
## 
## $mean
## depression_T1 depression_T2 depression_T3 depression_T4 
##         1.199         1.218         1.222         1.217
# implied means for latent growth factors
lavaan::lavInspect(basis, add.labels = TRUE, "mean.lv")
## Intercept     Shape 
##     1.199     0.018
# residuals
lavaan::residuals(basis, type = "raw")
## $type
## [1] "raw"
## 
## $cov
##               dpr_T1 dpr_T2 dpr_T3 dpr_T4
## depression_T1  0.000                     
## depression_T2 -0.025 -0.018              
## depression_T3  0.028 -0.038  0.008       
## depression_T4  0.001  0.012  0.043  0.014
## 
## $mean
## depression_T1 depression_T2 depression_T3 depression_T4 
##        -0.004         0.038        -0.065         0.038
lavaan::residuals(basis, type = "standardized")
## $type
## [1] "standardized"
## 
## $cov
##               dpr_T1 dpr_T2 dpr_T3 dpr_T4
## depression_T1 -0.264                     
## depression_T2 -1.741 -1.125              
## depression_T3  2.285 -1.622  1.089       
## depression_T4  0.049  0.274  1.349  0.798
## 
## $mean
## depression_T1 depression_T2 depression_T3 depression_T4 
##        -1.808         1.119        -1.734         0.806
lavaan::residuals(basis, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##               dpr_T1 dpr_T2 dpr_T3 dpr_T4
## depression_T1  0.000                     
## depression_T2 -0.051  0.000              
## depression_T3  0.062 -0.108  0.000       
## depression_T4 -0.007  0.041  0.102  0.000
## 
## $mean
## depression_T1 depression_T2 depression_T3 depression_T4 
##        -0.006         0.071        -0.106         0.061
# model 3 parameter estimates, global fit statistics,
# residuals
lavaan::summary(linear, fit.measures = TRUE, estimates = TRUE)
## lavaan 0.6.17 ended normally after 55 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        12
## 
##                                                   Used       Total
##   Number of observations                            57         540
##   Number of missing patterns                         1            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                55.157      47.517
##   Degrees of freedom                                18          18
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.161
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                                96.733      85.070
##   Degrees of freedom                                22          22
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.137
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.503       0.532
##   Tucker-Lewis Index (TLI)                       0.392       0.428
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.502
##   Robust Tucker-Lewis Index (TLI)                            0.391
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -120.456    -120.456
##   Scaling correction factor                                  1.254
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)        -92.878     -92.878
##   Scaling correction factor                                  1.198
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                 264.912     264.912
##   Bayesian (BIC)                               289.429     289.429
##   Sample-size adjusted Bayesian (SABIC)        251.706     251.706
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.190       0.170
##   90 Percent confidence interval - lower         0.134       0.116
##   90 Percent confidence interval - upper         0.249       0.225
##   P-value H_0: RMSEA <= 0.050                    0.000       0.001
##   P-value H_0: RMSEA >= 0.080                    0.999       0.995
##                                                                   
##   Robust RMSEA                                               0.183
##   90 Percent confidence interval - lower                     0.120
##   90 Percent confidence interval - upper                     0.247
##   P-value H_0: Robust RMSEA <= 0.050                         0.001
##   P-value H_0: Robust RMSEA >= 0.080                         0.995
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.180       0.180
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     depression_T1     1.000                           
##     depression_T2     1.000                           
##     depression_T3     1.000                           
##     depression_T4     1.000                           
##   Linear =~                                           
##     depression_T1     0.000                           
##     depression_T2     1.000                           
##     depression_T3     2.000                           
##     depression_T4     3.000                           
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   depression_T1 ~                                     
##     CASI_ADHD_CSum    0.066    0.022    2.951    0.003
##   depression_T2 ~                                     
##     CASI_ADHD_CS_T    0.083    0.019    4.399    0.000
##   depression_T3 ~                                     
##     CASI_ADHD_CS_T    0.066    0.013    5.035    0.000
##   depression_T4 ~                                     
##     CASI_ADHDCS_T4    0.076    0.019    4.018    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~~                                        
##     Linear           -0.069    0.018   -3.838    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Intercept         0.635    0.285    2.226    0.026
##     Linear           -0.241    0.167   -1.439    0.150
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .depression_T1     0.000                           
##    .depression_T2     0.154    0.028    5.463    0.000
##    .depression_T3     0.126    0.032    3.943    0.000
##    .depression_T4     0.226    0.052    4.307    0.000
##     Intercept         0.178    0.049    3.626    0.000
##     Linear            0.027    0.008    3.202    0.001
lavaan::fitted(linear) 
## $cov
##                   dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## depression_T1      0.217                                                   
## depression_T2      0.127  0.276                                            
## depression_T3      0.045  0.051  0.179                                     
## depression_T4     -0.027  0.007  0.009  0.288                              
## CASI_ADHD_CSum     0.586  0.267  0.056  0.010         8.857                
## CASI_ADHD_CSum_T2  0.214  0.656  0.298  0.278         3.229           7.917
## CASI_ADHD_CSum_T3  0.057  0.376  0.651  0.185         0.861           4.546
## CASI_ADHDCSum_T4   0.009  0.304  0.160  0.715         0.133           3.675
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## depression_T1                               
## depression_T2                               
## depression_T3                               
## depression_T4                               
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           9.921           
## CASI_ADHDCSum_T4            2.447      9.469
## 
## $mean
##     depression_T1     depression_T2     depression_T3     depression_T4 
##             1.504             1.419             1.440             1.419 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##            13.140            12.368            19.614            19.930
lavaan::residuals(linear, type = "raw")
## $type
## [1] "raw"
## 
## $cov
##                   dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## depression_T1      0.015                                                   
## depression_T2     -0.057 -0.113                                            
## depression_T3     -0.043 -0.042  0.025                                     
## depression_T4      0.091  0.041  0.059 -0.072                              
## CASI_ADHD_CSum     0.111  0.137  0.178  0.166         0.000                
## CASI_ADHD_CSum_T2 -0.097 -0.250  0.231  0.089         0.000           0.000
## CASI_ADHD_CSum_T3 -0.086 -0.327  0.363  0.171         0.000           0.000
## CASI_ADHDCSum_T4  -0.096  0.068  0.102 -0.295         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## depression_T1                               
## depression_T2                               
## depression_T3                               
## depression_T4                               
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##     depression_T1     depression_T2     depression_T3     depression_T4 
##             0.000             0.016            -0.019             0.015 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
lavaan::residuals(linear, type = "standardized")
## $type
## [1] "standardized"
## 
## $cov
##                   dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## depression_T1      0.278                                                   
## depression_T2     -0.988 -1.410                                            
## depression_T3     -1.190 -1.501  1.103                                     
## depression_T4      2.204  1.043  2.019 -1.158                              
## CASI_ADHD_CSum     1.002  0.878  1.466  0.804         0.000                
## CASI_ADHD_CSum_T2 -0.325 -1.037  2.054  0.356         0.000           0.000
## CASI_ADHD_CSum_T3 -0.282 -1.433  3.118  0.705         0.000           0.000
## CASI_ADHDCSum_T4  -0.439  0.503  0.888 -2.000         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## depression_T1                               
## depression_T2                               
## depression_T3                               
## depression_T4                               
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##     depression_T1     depression_T2     depression_T3     depression_T4 
##             0.000             0.988            -2.307             1.208 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
lavaan::residuals(linear, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##                   dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## depression_T1      0.000                                                   
## depression_T2     -0.157  0.000                                            
## depression_T3     -0.220 -0.178  0.000                                     
## depression_T4      0.394  0.231  0.282  0.000                              
## CASI_ADHD_CSum     0.064  0.165  0.130  0.121         0.000                
## CASI_ADHD_CSum_T2 -0.077 -0.086  0.166  0.096         0.000           0.000
## CASI_ADHD_CSum_T3 -0.058 -0.189  0.224  0.134         0.000           0.000
## CASI_ADHDCSum_T4  -0.065  0.111  0.065 -0.139         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## depression_T1                               
## depression_T2                               
## depression_T3                               
## depression_T4                               
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##     depression_T1     depression_T2     depression_T3     depression_T4 
##             0.000             0.038            -0.042             0.033 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
#standardized estimates
standardizedSolution(linear, type = "std.all",  se= TRUE, pvalue = TRUE)
##                  lhs op               rhs est.std    se       z pvalue ci.lower
## 1          Intercept =~     depression_T1   0.906 0.064  14.109  0.000    0.780
## 2          Intercept =~     depression_T2   0.803 0.088   9.149  0.000    0.631
## 3          Intercept =~     depression_T3   0.996 0.133   7.462  0.000    0.734
## 4          Intercept =~     depression_T4   0.786 0.134   5.887  0.000    0.524
## 5             Linear =~     depression_T1   0.000 0.000      NA     NA    0.000
## 6             Linear =~     depression_T2   0.312 0.053   5.828  0.000    0.207
## 7             Linear =~     depression_T3   0.774 0.160   4.827  0.000    0.460
## 8             Linear =~     depression_T4   0.916 0.130   7.027  0.000    0.661
## 9      depression_T1 ~~     depression_T1   0.000 0.000      NA     NA    0.000
## 10     depression_T1  ~    CASI_ADHD_CSum   0.423 0.138   3.072  0.002    0.153
## 11     depression_T2  ~ CASI_ADHD_CSum_T2   0.443 0.092   4.821  0.000    0.263
## 12     depression_T3  ~ CASI_ADHD_CSum_T3   0.488 0.095   5.153  0.000    0.302
## 13     depression_T4  ~  CASI_ADHDCSum_T4   0.433 0.094   4.609  0.000    0.249
## 14     depression_T2 ~~     depression_T2   0.558 0.056  10.039  0.000    0.449
## 15     depression_T3 ~~     depression_T3   0.699 0.135   5.181  0.000    0.435
## 16     depression_T4 ~~     depression_T4   0.783 0.134   5.856  0.000    0.521
## 17         Intercept ~~         Intercept   1.000 0.000      NA     NA    1.000
## 18            Linear ~~            Linear   1.000 0.000      NA     NA    1.000
## 19         Intercept ~~            Linear  -0.991 0.062 -15.994  0.000   -1.113
## 20    CASI_ADHD_CSum ~~    CASI_ADHD_CSum   1.000 0.000      NA     NA    1.000
## 21    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2   0.386 0.000      NA     NA    0.386
## 22    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3   0.092 0.000      NA     NA    0.092
## 23    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4   0.014 0.000      NA     NA    0.014
## 24 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2   1.000 0.000      NA     NA    1.000
## 25 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3   0.513 0.000      NA     NA    0.513
## 26 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4   0.424 0.000      NA     NA    0.424
## 27 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3   1.000 0.000      NA     NA    1.000
## 28 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4   0.252 0.000      NA     NA    0.252
## 29  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4   1.000 0.000      NA     NA    1.000
## 30     depression_T1 ~1                     0.000 0.000      NA     NA    0.000
## 31     depression_T2 ~1                     0.000 0.000      NA     NA    0.000
## 32     depression_T3 ~1                     0.000 0.000      NA     NA    0.000
## 33     depression_T4 ~1                     0.000 0.000      NA     NA    0.000
## 34    CASI_ADHD_CSum ~1                     4.415 0.000      NA     NA    4.415
## 35 CASI_ADHD_CSum_T2 ~1                     4.396 0.000      NA     NA    4.396
## 36 CASI_ADHD_CSum_T3 ~1                     6.227 0.000      NA     NA    6.227
## 37  CASI_ADHDCSum_T4 ~1                     6.477 0.000      NA     NA    6.477
## 38         Intercept ~1                     1.506 0.657   2.292  0.022    0.218
## 39            Linear ~1                    -1.470 1.079  -1.361  0.173   -3.585
##    ci.upper
## 1     1.032
## 2     0.974
## 3     1.257
## 4     1.048
## 5     0.000
## 6     0.417
## 7     1.088
## 8     1.172
## 9     0.000
## 10    0.693
## 11    0.623
## 12    0.673
## 13    0.617
## 14    0.667
## 15    0.964
## 16    1.045
## 17    1.000
## 18    1.000
## 19   -0.870
## 20    1.000
## 21    0.386
## 22    0.092
## 23    0.014
## 24    1.000
## 25    0.513
## 26    0.424
## 27    1.000
## 28    0.252
## 29    1.000
## 30    0.000
## 31    0.000
## 32    0.000
## 33    0.000
## 34    4.415
## 35    4.396
## 36    6.227
## 37    6.477
## 38    2.794
## 39    0.646
#unstandardized estimates
parameterEstimates(linear)
##                  lhs op               rhs    est    se      z pvalue ci.lower
## 1          Intercept =~     depression_T1  1.000 0.000     NA     NA    1.000
## 2          Intercept =~     depression_T2  1.000 0.000     NA     NA    1.000
## 3          Intercept =~     depression_T3  1.000 0.000     NA     NA    1.000
## 4          Intercept =~     depression_T4  1.000 0.000     NA     NA    1.000
## 5             Linear =~     depression_T1  0.000 0.000     NA     NA    0.000
## 6             Linear =~     depression_T2  1.000 0.000     NA     NA    1.000
## 7             Linear =~     depression_T3  2.000 0.000     NA     NA    2.000
## 8             Linear =~     depression_T4  3.000 0.000     NA     NA    3.000
## 9      depression_T1 ~~     depression_T1  0.000 0.000     NA     NA    0.000
## 10     depression_T1  ~    CASI_ADHD_CSum  0.066 0.022  2.951  0.003    0.022
## 11     depression_T2  ~ CASI_ADHD_CSum_T2  0.083 0.019  4.399  0.000    0.046
## 12     depression_T3  ~ CASI_ADHD_CSum_T3  0.066 0.013  5.035  0.000    0.040
## 13     depression_T4  ~  CASI_ADHDCSum_T4  0.076 0.019  4.018  0.000    0.039
## 14     depression_T2 ~~     depression_T2  0.154 0.028  5.463  0.000    0.099
## 15     depression_T3 ~~     depression_T3  0.126 0.032  3.943  0.000    0.063
## 16     depression_T4 ~~     depression_T4  0.226 0.052  4.307  0.000    0.123
## 17         Intercept ~~         Intercept  0.178 0.049  3.626  0.000    0.082
## 18            Linear ~~            Linear  0.027 0.008  3.202  0.001    0.010
## 19         Intercept ~~            Linear -0.069 0.018 -3.838  0.000   -0.104
## 20    CASI_ADHD_CSum ~~    CASI_ADHD_CSum  8.857 0.000     NA     NA    8.857
## 21    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2  3.229 0.000     NA     NA    3.229
## 22    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3  0.861 0.000     NA     NA    0.861
## 23    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4  0.133 0.000     NA     NA    0.133
## 24 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2  7.917 0.000     NA     NA    7.917
## 25 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3  4.546 0.000     NA     NA    4.546
## 26 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4  3.675 0.000     NA     NA    3.675
## 27 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3  9.921 0.000     NA     NA    9.921
## 28 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4  2.447 0.000     NA     NA    2.447
## 29  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4  9.469 0.000     NA     NA    9.469
## 30     depression_T1 ~1                    0.000 0.000     NA     NA    0.000
## 31     depression_T2 ~1                    0.000 0.000     NA     NA    0.000
## 32     depression_T3 ~1                    0.000 0.000     NA     NA    0.000
## 33     depression_T4 ~1                    0.000 0.000     NA     NA    0.000
## 34    CASI_ADHD_CSum ~1                   13.140 0.000     NA     NA   13.140
## 35 CASI_ADHD_CSum_T2 ~1                   12.368 0.000     NA     NA   12.368
## 36 CASI_ADHD_CSum_T3 ~1                   19.614 0.000     NA     NA   19.614
## 37  CASI_ADHDCSum_T4 ~1                   19.930 0.000     NA     NA   19.930
## 38         Intercept ~1                    0.635 0.285  2.226  0.026    0.076
## 39            Linear ~1                   -0.241 0.167 -1.439  0.150   -0.569
##    ci.upper
## 1     1.000
## 2     1.000
## 3     1.000
## 4     1.000
## 5     0.000
## 6     1.000
## 7     2.000
## 8     3.000
## 9     0.000
## 10    0.110
## 11    0.120
## 12    0.091
## 13    0.112
## 14    0.210
## 15    0.188
## 16    0.328
## 17    0.274
## 18    0.043
## 19   -0.034
## 20    8.857
## 21    3.229
## 22    0.861
## 23    0.133
## 24    7.917
## 25    4.546
## 26    3.675
## 27    9.921
## 28    2.447
## 29    9.469
## 30    0.000
## 31    0.000
## 32    0.000
## 33    0.000
## 34   13.140
## 35   12.368
## 36   19.614
## 37   19.930
## 38    1.195
## 39    0.087
#########################################################################################################
#with all socio-demographic covariates (continuous and categorical)
#########################################################################################################

predict.model <- '
# latent growth factors
 Intercept =~ 1*depression_T1 + 1*depression_T2 + 1*depression_T3 + 1*depression_T4
 Linear =~ 0*depression_T1 + 1*depression_T2 + 2*depression_T3 + 3*depression_T4
# covariates
 Intercept ~ CASI_ADHD_CSum + CASI_ADHD_CSum_T2 + CASI_ADHD_CSum_T3 + 
           CASI_ADHDCSum_T4 + Academicperformance_total_T4 +
           Familyincome_T1r + Educationhousehold  +  Child_gender + Childagecategory
 Linear ~ CASI_ADHD_CSum + CASI_ADHD_CSum_T2 + CASI_ADHD_CSum_T3 + 
           CASI_ADHDCSum_T4 + Academicperformance_total_T4 +
           Familyincome_T1r + Educationhousehold  +  Child_gender + Childagecategory
# observed variables regressed on the time-varying covariate
                    depression_T1 ~ CASI_ADHD_CSum
                    depression_T2 ~ CASI_ADHD_CSum_T2
                    depression_T3 ~ CASI_ADHD_CSum_T3
                    depression_T4 ~ CASI_ADHDCSum_T4'

# fit prediction model to data
predict <- lavaan::growth(predict.model, data=mydata,, missing = "fiml", estimator = "mlr")
lavaan::summary(predict, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6.17 ended normally after 112 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        31
## 
##                                                   Used       Total
##   Number of observations                            56         540
##   Number of missing patterns                         1            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                23.738      30.323
##   Degrees of freedom                                19          19
##   P-value (Chi-square)                           0.206       0.048
##   Scaling correction factor                                  0.783
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                               148.778     174.747
##   Degrees of freedom                                42          42
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  0.851
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.956       0.915
##   Tucker-Lewis Index (TLI)                       0.902       0.811
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.929
##   Robust Tucker-Lewis Index (TLI)                            0.843
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)                -70.958     -70.958
##   Scaling correction factor                                  1.041
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)        -59.089     -59.089
##   Scaling correction factor                                  0.943
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                 203.916     203.916
##   Bayesian (BIC)                               266.702     266.702
##   Sample-size adjusted Bayesian (SABIC)        169.270     169.270
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.067       0.103
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.142       0.178
##   P-value H_0: RMSEA <= 0.050                    0.347       0.136
##   P-value H_0: RMSEA >= 0.080                    0.436       0.719
##                                                                   
##   Robust RMSEA                                               0.086
##   90 Percent confidence interval - lower                     0.000
##   90 Percent confidence interval - upper                     0.148
##   P-value H_0: Robust RMSEA <= 0.050                         0.184
##   P-value H_0: Robust RMSEA >= 0.080                         0.595
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.050       0.050
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     depression_T1     1.000                           
##     depression_T2     1.000                           
##     depression_T3     1.000                           
##     depression_T4     1.000                           
##   Linear =~                                           
##     depression_T1     0.000                           
##     depression_T2     1.000                           
##     depression_T3     2.000                           
##     depression_T4     3.000                           
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~                                         
##     CASI_ADHD_CSum    0.008    0.023    0.346    0.729
##     CASI_ADHD_CS_T   -0.007    0.018   -0.381    0.704
##     CASI_ADHD_CS_T    0.014    0.013    1.076    0.282
##     CASI_ADHDCS_T4    0.012    0.013    0.929    0.353
##     Acdmcprfrm__T4   -0.006    0.034   -0.186    0.853
##     Familyincm_T1r   -0.084    0.038   -2.200    0.028
##     Educationhshld   -0.135    0.071   -1.898    0.058
##     Child_gender      0.147    0.100    1.470    0.142
##     Childagecatgry   -0.031    0.072   -0.427    0.669
##   Linear ~                                            
##     CASI_ADHD_CSum   -0.002    0.014   -0.123    0.902
##     CASI_ADHD_CS_T    0.011    0.012    0.980    0.327
##     CASI_ADHD_CS_T    0.015    0.008    1.740    0.082
##     CASI_ADHDCS_T4   -0.009    0.010   -0.860    0.390
##     Acdmcprfrm__T4    0.006    0.021    0.282    0.778
##     Familyincm_T1r   -0.000    0.024   -0.020    0.984
##     Educationhshld    0.069    0.035    1.972    0.049
##     Child_gender     -0.024    0.063   -0.381    0.703
##     Childagecatgry    0.019    0.046    0.426    0.670
##   depression_T1 ~                                     
##     CASI_ADHD_CSum    0.057    0.030    1.905    0.057
##   depression_T2 ~                                     
##     CASI_ADHD_CS_T    0.069    0.020    3.423    0.001
##   depression_T3 ~                                     
##     CASI_ADHD_CS_T    0.050    0.016    3.141    0.002
##   depression_T4 ~                                     
##     CASI_ADHDCS_T4    0.059    0.026    2.278    0.023
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .Intercept ~~                                        
##    .Linear            0.010    0.012    0.827    0.408
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .Intercept         0.974    0.478    2.036    0.042
##    .Linear           -0.749    0.276   -2.717    0.007
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .depression_T1     0.166    0.056    2.972    0.003
##    .depression_T2     0.099    0.017    5.973    0.000
##    .depression_T3     0.107    0.027    3.920    0.000
##    .depression_T4     0.159    0.045    3.537    0.000
##    .Intercept        -0.035    0.027   -1.262    0.207
##    .Linear           -0.004    0.007   -0.510    0.610
## 
## R-Square:
##                    Estimate
##     depression_T1     0.241
##     depression_T2     0.383
##     depression_T3     0.396
##     depression_T4     0.304
##     Intercept            NA
##     Linear               NA
#standardized estimates
standardizedSolution(predict, type = "std.all",  se= TRUE, pvalue = TRUE)
##                             lhs op                          rhs est.std      se
## 1                     Intercept =~                depression_T1      NA      NA
## 2                     Intercept =~                depression_T2      NA      NA
## 3                     Intercept =~                depression_T3      NA      NA
## 4                     Intercept =~                depression_T4      NA      NA
## 5                        Linear =~                depression_T1   0.000   0.000
## 6                        Linear =~                depression_T2   0.060   0.401
## 7                        Linear =~                depression_T3   0.113   0.763
## 8                        Linear =~                depression_T4   0.149   1.005
## 9                     Intercept  ~               CASI_ADHD_CSum      NA      NA
## 10                    Intercept  ~            CASI_ADHD_CSum_T2      NA      NA
## 11                    Intercept  ~            CASI_ADHD_CSum_T3      NA      NA
## 12                    Intercept  ~             CASI_ADHDCSum_T4      NA      NA
## 13                    Intercept  ~ Academicperformance_total_T4      NA      NA
## 14                    Intercept  ~             Familyincome_T1r      NA      NA
## 15                    Intercept  ~           Educationhousehold      NA      NA
## 16                    Intercept  ~                 Child_gender      NA      NA
## 17                    Intercept  ~             Childagecategory      NA      NA
## 18                       Linear  ~               CASI_ADHD_CSum  -0.209   2.478
## 19                       Linear  ~            CASI_ADHD_CSum_T2   1.125   7.616
## 20                       Linear  ~            CASI_ADHD_CSum_T3   1.716  11.473
## 21                       Linear  ~             CASI_ADHDCSum_T4  -1.144   7.409
## 22                       Linear  ~ Academicperformance_total_T4   0.285   1.794
## 23                       Linear  ~             Familyincome_T1r  -0.020   0.959
## 24                       Linear  ~           Educationhousehold   2.122  13.902
## 25                       Linear  ~                 Child_gender  -0.503   3.399
## 26                       Linear  ~             Childagecategory   0.391   2.553
## 27                depression_T1  ~               CASI_ADHD_CSum   0.363   0.178
## 28                depression_T2  ~            CASI_ADHD_CSum_T2   0.406   0.111
## 29                depression_T3  ~            CASI_ADHD_CSum_T3   0.333   0.105
## 30                depression_T4  ~             CASI_ADHDCSum_T4   0.380   0.164
## 31                depression_T1 ~~                depression_T1   0.759   0.165
## 32                depression_T2 ~~                depression_T2   0.617   0.094
## 33                depression_T3 ~~                depression_T3   0.604   0.118
## 34                depression_T4 ~~                depression_T4   0.696   0.146
## 35                    Intercept ~~                    Intercept      NA      NA
## 36                       Linear ~~                       Linear  -6.245  95.789
## 37                    Intercept ~~                       Linear   0.927   0.444
## 38               CASI_ADHD_CSum ~~               CASI_ADHD_CSum   1.000   0.000
## 39               CASI_ADHD_CSum ~~            CASI_ADHD_CSum_T2   0.381   0.000
## 40               CASI_ADHD_CSum ~~            CASI_ADHD_CSum_T3   0.034   0.000
## 41               CASI_ADHD_CSum ~~             CASI_ADHDCSum_T4  -0.003   0.000
## 42               CASI_ADHD_CSum ~~ Academicperformance_total_T4  -0.169   0.000
## 43               CASI_ADHD_CSum ~~             Familyincome_T1r  -0.335   0.000
## 44               CASI_ADHD_CSum ~~           Educationhousehold  -0.269   0.000
## 45               CASI_ADHD_CSum ~~                 Child_gender   0.282   0.000
## 46               CASI_ADHD_CSum ~~             Childagecategory   0.100   0.000
## 47            CASI_ADHD_CSum_T2 ~~            CASI_ADHD_CSum_T2   1.000   0.000
## 48            CASI_ADHD_CSum_T2 ~~            CASI_ADHD_CSum_T3   0.337   0.000
## 49            CASI_ADHD_CSum_T2 ~~             CASI_ADHDCSum_T4   0.425   0.000
## 50            CASI_ADHD_CSum_T2 ~~ Academicperformance_total_T4   0.098   0.000
## 51            CASI_ADHD_CSum_T2 ~~             Familyincome_T1r  -0.286   0.000
## 52            CASI_ADHD_CSum_T2 ~~           Educationhousehold  -0.331   0.000
## 53            CASI_ADHD_CSum_T2 ~~                 Child_gender   0.083   0.000
## 54            CASI_ADHD_CSum_T2 ~~             Childagecategory   0.107   0.000
## 55            CASI_ADHD_CSum_T3 ~~            CASI_ADHD_CSum_T3   1.000   0.000
## 56            CASI_ADHD_CSum_T3 ~~             CASI_ADHDCSum_T4   0.217   0.000
## 57            CASI_ADHD_CSum_T3 ~~ Academicperformance_total_T4   0.015   0.000
## 58            CASI_ADHD_CSum_T3 ~~             Familyincome_T1r   0.073   0.000
## 59            CASI_ADHD_CSum_T3 ~~           Educationhousehold  -0.235   0.000
## 60            CASI_ADHD_CSum_T3 ~~                 Child_gender  -0.237   0.000
## 61            CASI_ADHD_CSum_T3 ~~             Childagecategory   0.154   0.000
## 62             CASI_ADHDCSum_T4 ~~             CASI_ADHDCSum_T4   1.000   0.000
## 63             CASI_ADHDCSum_T4 ~~ Academicperformance_total_T4   0.123   0.000
## 64             CASI_ADHDCSum_T4 ~~             Familyincome_T1r  -0.038   0.000
## 65             CASI_ADHDCSum_T4 ~~           Educationhousehold  -0.216   0.000
## 66             CASI_ADHDCSum_T4 ~~                 Child_gender  -0.168   0.000
## 67             CASI_ADHDCSum_T4 ~~             Childagecategory   0.238   0.000
## 68 Academicperformance_total_T4 ~~ Academicperformance_total_T4   1.000   0.000
## 69 Academicperformance_total_T4 ~~             Familyincome_T1r   0.190   0.000
## 70 Academicperformance_total_T4 ~~           Educationhousehold  -0.162   0.000
## 71 Academicperformance_total_T4 ~~                 Child_gender  -0.016   0.000
## 72 Academicperformance_total_T4 ~~             Childagecategory   0.006   0.000
## 73             Familyincome_T1r ~~             Familyincome_T1r   1.000   0.000
## 74             Familyincome_T1r ~~           Educationhousehold   0.243   0.000
## 75             Familyincome_T1r ~~                 Child_gender  -0.113   0.000
## 76             Familyincome_T1r ~~             Childagecategory  -0.004   0.000
## 77           Educationhousehold ~~           Educationhousehold   1.000   0.000
## 78           Educationhousehold ~~                 Child_gender   0.318   0.000
## 79           Educationhousehold ~~             Childagecategory   0.107   0.000
## 80                 Child_gender ~~                 Child_gender   1.000   0.000
## 81                 Child_gender ~~             Childagecategory   0.037   0.000
## 82             Childagecategory ~~             Childagecategory   1.000   0.000
## 83                depression_T1 ~1                                0.000   0.000
## 84                depression_T2 ~1                                0.000   0.000
## 85                depression_T3 ~1                                0.000   0.000
## 86                depression_T4 ~1                                0.000   0.000
## 87               CASI_ADHD_CSum ~1                                4.396   0.000
## 88            CASI_ADHD_CSum_T2 ~1                                5.139   0.000
## 89            CASI_ADHD_CSum_T3 ~1                                6.976   0.000
## 90             CASI_ADHDCSum_T4 ~1                                6.460   0.000
## 91 Academicperformance_total_T4 ~1                                2.644   0.000
## 92             Familyincome_T1r ~1                                2.685   0.000
## 93           Educationhousehold ~1                                6.238   0.000
## 94                 Child_gender ~1                                3.000   0.000
## 95             Childagecategory ~1                                5.855   0.000
## 96                    Intercept ~1                                   NA      NA
## 97                       Linear ~1                              -31.420 207.191
##         z pvalue ci.lower ci.upper
## 1      NA     NA       NA       NA
## 2      NA     NA       NA       NA
## 3      NA     NA       NA       NA
## 4      NA     NA       NA       NA
## 5      NA     NA    0.000    0.000
## 6   0.149  0.882   -0.726    0.845
## 7   0.148  0.882   -1.383    1.610
## 8   0.149  0.882   -1.820    2.118
## 9      NA     NA       NA       NA
## 10     NA     NA       NA       NA
## 11     NA     NA       NA       NA
## 12     NA     NA       NA       NA
## 13     NA     NA       NA       NA
## 14     NA     NA       NA       NA
## 15     NA     NA       NA       NA
## 16     NA     NA       NA       NA
## 17     NA     NA       NA       NA
## 18 -0.084  0.933   -5.066    4.648
## 19  0.148  0.883  -13.802   16.052
## 20  0.150  0.881  -20.771   24.203
## 21 -0.154  0.877  -15.665   13.377
## 22  0.159  0.874   -3.232    3.801
## 23 -0.021  0.984   -1.899    1.860
## 24  0.153  0.879  -25.126   29.371
## 25 -0.148  0.882   -7.165    6.158
## 26  0.153  0.878   -4.613    5.394
## 27  2.032  0.042    0.013    0.712
## 28  3.670  0.000    0.189    0.622
## 29  3.188  0.001    0.128    0.538
## 30  2.308  0.021    0.057    0.702
## 31  4.601  0.000    0.435    1.082
## 32  6.593  0.000    0.434    0.800
## 33  5.113  0.000    0.372    0.835
## 34  4.778  0.000    0.411    0.982
## 35     NA     NA       NA       NA
## 36 -0.065  0.948 -193.989  181.498
## 37  2.087  0.037    0.056    1.798
## 38     NA     NA    1.000    1.000
## 39     NA     NA    0.381    0.381
## 40     NA     NA    0.034    0.034
## 41     NA     NA   -0.003   -0.003
## 42     NA     NA   -0.169   -0.169
## 43     NA     NA   -0.335   -0.335
## 44     NA     NA   -0.269   -0.269
## 45     NA     NA    0.282    0.282
## 46     NA     NA    0.100    0.100
## 47     NA     NA    1.000    1.000
## 48     NA     NA    0.337    0.337
## 49     NA     NA    0.425    0.425
## 50     NA     NA    0.098    0.098
## 51     NA     NA   -0.286   -0.286
## 52     NA     NA   -0.331   -0.331
## 53     NA     NA    0.083    0.083
## 54     NA     NA    0.107    0.107
## 55     NA     NA    1.000    1.000
## 56     NA     NA    0.217    0.217
## 57     NA     NA    0.015    0.015
## 58     NA     NA    0.073    0.073
## 59     NA     NA   -0.235   -0.235
## 60     NA     NA   -0.237   -0.237
## 61     NA     NA    0.154    0.154
## 62     NA     NA    1.000    1.000
## 63     NA     NA    0.123    0.123
## 64     NA     NA   -0.038   -0.038
## 65     NA     NA   -0.216   -0.216
## 66     NA     NA   -0.168   -0.168
## 67     NA     NA    0.238    0.238
## 68     NA     NA    1.000    1.000
## 69     NA     NA    0.190    0.190
## 70     NA     NA   -0.162   -0.162
## 71     NA     NA   -0.016   -0.016
## 72     NA     NA    0.006    0.006
## 73     NA     NA    1.000    1.000
## 74     NA     NA    0.243    0.243
## 75     NA     NA   -0.113   -0.113
## 76     NA     NA   -0.004   -0.004
## 77     NA     NA    1.000    1.000
## 78     NA     NA    0.318    0.318
## 79     NA     NA    0.107    0.107
## 80     NA     NA    1.000    1.000
## 81     NA     NA    0.037    0.037
## 82     NA     NA    1.000    1.000
## 83     NA     NA    0.000    0.000
## 84     NA     NA    0.000    0.000
## 85     NA     NA    0.000    0.000
## 86     NA     NA    0.000    0.000
## 87     NA     NA    4.396    4.396
## 88     NA     NA    5.139    5.139
## 89     NA     NA    6.976    6.976
## 90     NA     NA    6.460    6.460
## 91     NA     NA    2.644    2.644
## 92     NA     NA    2.685    2.685
## 93     NA     NA    6.238    6.238
## 94     NA     NA    3.000    3.000
## 95     NA     NA    5.855    5.855
## 96     NA     NA       NA       NA
## 97 -0.152  0.879 -437.507  374.667
#unstandardized estimates
parameterEstimates(predict)
##                             lhs op                          rhs    est    se
## 1                     Intercept =~                depression_T1  1.000 0.000
## 2                     Intercept =~                depression_T2  1.000 0.000
## 3                     Intercept =~                depression_T3  1.000 0.000
## 4                     Intercept =~                depression_T4  1.000 0.000
## 5                        Linear =~                depression_T1  0.000 0.000
## 6                        Linear =~                depression_T2  1.000 0.000
## 7                        Linear =~                depression_T3  2.000 0.000
## 8                        Linear =~                depression_T4  3.000 0.000
## 9                     Intercept  ~               CASI_ADHD_CSum  0.008 0.023
## 10                    Intercept  ~            CASI_ADHD_CSum_T2 -0.007 0.018
## 11                    Intercept  ~            CASI_ADHD_CSum_T3  0.014 0.013
## 12                    Intercept  ~             CASI_ADHDCSum_T4  0.012 0.013
## 13                    Intercept  ~ Academicperformance_total_T4 -0.006 0.034
## 14                    Intercept  ~             Familyincome_T1r -0.084 0.038
## 15                    Intercept  ~           Educationhousehold -0.135 0.071
## 16                    Intercept  ~                 Child_gender  0.147 0.100
## 17                    Intercept  ~             Childagecategory -0.031 0.072
## 18                       Linear  ~               CASI_ADHD_CSum -0.002 0.014
## 19                       Linear  ~            CASI_ADHD_CSum_T2  0.011 0.012
## 20                       Linear  ~            CASI_ADHD_CSum_T3  0.015 0.008
## 21                       Linear  ~             CASI_ADHDCSum_T4 -0.009 0.010
## 22                       Linear  ~ Academicperformance_total_T4  0.006 0.021
## 23                       Linear  ~             Familyincome_T1r  0.000 0.024
## 24                       Linear  ~           Educationhousehold  0.069 0.035
## 25                       Linear  ~                 Child_gender -0.024 0.063
## 26                       Linear  ~             Childagecategory  0.019 0.046
## 27                depression_T1  ~               CASI_ADHD_CSum  0.057 0.030
## 28                depression_T2  ~            CASI_ADHD_CSum_T2  0.069 0.020
## 29                depression_T3  ~            CASI_ADHD_CSum_T3  0.050 0.016
## 30                depression_T4  ~             CASI_ADHDCSum_T4  0.059 0.026
## 31                depression_T1 ~~                depression_T1  0.166 0.056
## 32                depression_T2 ~~                depression_T2  0.099 0.017
## 33                depression_T3 ~~                depression_T3  0.107 0.027
## 34                depression_T4 ~~                depression_T4  0.159 0.045
## 35                    Intercept ~~                    Intercept -0.035 0.027
## 36                       Linear ~~                       Linear -0.004 0.007
## 37                    Intercept ~~                       Linear  0.010 0.012
## 38               CASI_ADHD_CSum ~~               CASI_ADHD_CSum  8.867 0.000
## 39               CASI_ADHD_CSum ~~            CASI_ADHD_CSum_T2  2.682 0.000
## 40               CASI_ADHD_CSum ~~            CASI_ADHD_CSum_T3  0.285 0.000
## 41               CASI_ADHD_CSum ~~             CASI_ADHDCSum_T4 -0.025 0.000
## 42               CASI_ADHD_CSum ~~ Academicperformance_total_T4 -0.573 0.000
## 43               CASI_ADHD_CSum ~~             Familyincome_T1r -0.941 0.000
## 44               CASI_ADHD_CSum ~~           Educationhousehold -0.585 0.000
## 45               CASI_ADHD_CSum ~~                 Child_gender  0.420 0.000
## 46               CASI_ADHD_CSum ~~             Childagecategory  0.143 0.000
## 47            CASI_ADHD_CSum_T2 ~~            CASI_ADHD_CSum_T2  5.599 0.000
## 48            CASI_ADHD_CSum_T2 ~~            CASI_ADHD_CSum_T3  2.220 0.000
## 49            CASI_ADHD_CSum_T2 ~~             CASI_ADHDCSum_T4  3.092 0.000
## 50            CASI_ADHD_CSum_T2 ~~ Academicperformance_total_T4  0.265 0.000
## 51            CASI_ADHD_CSum_T2 ~~             Familyincome_T1r -0.640 0.000
## 52            CASI_ADHD_CSum_T2 ~~           Educationhousehold -0.571 0.000
## 53            CASI_ADHD_CSum_T2 ~~                 Child_gender  0.098 0.000
## 54            CASI_ADHD_CSum_T2 ~~             Childagecategory  0.121 0.000
## 55            CASI_ADHD_CSum_T3 ~~            CASI_ADHD_CSum_T3  7.742 0.000
## 56            CASI_ADHD_CSum_T3 ~~             CASI_ADHDCSum_T4  1.855 0.000
## 57            CASI_ADHD_CSum_T3 ~~ Academicperformance_total_T4  0.046 0.000
## 58            CASI_ADHD_CSum_T3 ~~             Familyincome_T1r  0.191 0.000
## 59            CASI_ADHD_CSum_T3 ~~           Educationhousehold -0.477 0.000
## 60            CASI_ADHD_CSum_T3 ~~                 Child_gender -0.330 0.000
## 61            CASI_ADHD_CSum_T3 ~~             Childagecategory  0.206 0.000
## 62             CASI_ADHDCSum_T4 ~~             CASI_ADHDCSum_T4  9.467 0.000
## 63             CASI_ADHDCSum_T4 ~~ Academicperformance_total_T4  0.431 0.000
## 64             CASI_ADHDCSum_T4 ~~             Familyincome_T1r -0.112 0.000
## 65             CASI_ADHDCSum_T4 ~~           Educationhousehold -0.484 0.000
## 66             CASI_ADHDCSum_T4 ~~                 Child_gender -0.259 0.000
## 67             CASI_ADHDCSum_T4 ~~             Childagecategory  0.350 0.000
## 68 Academicperformance_total_T4 ~~ Academicperformance_total_T4  1.303 0.000
## 69 Academicperformance_total_T4 ~~             Familyincome_T1r  0.205 0.000
## 70 Academicperformance_total_T4 ~~           Educationhousehold -0.135 0.000
## 71 Academicperformance_total_T4 ~~                 Child_gender -0.009 0.000
## 72 Academicperformance_total_T4 ~~             Childagecategory  0.004 0.000
## 73             Familyincome_T1r ~~             Familyincome_T1r  0.892 0.000
## 74             Familyincome_T1r ~~           Educationhousehold  0.168 0.000
## 75             Familyincome_T1r ~~                 Child_gender -0.054 0.000
## 76             Familyincome_T1r ~~             Childagecategory -0.002 0.000
## 77           Educationhousehold ~~           Educationhousehold  0.533 0.000
## 78           Educationhousehold ~~                 Child_gender  0.116 0.000
## 79           Educationhousehold ~~             Childagecategory  0.037 0.000
## 80                 Child_gender ~~                 Child_gender  0.250 0.000
## 81                 Child_gender ~~             Childagecategory  0.009 0.000
## 82             Childagecategory ~~             Childagecategory  0.229 0.000
## 83                depression_T1 ~1                               0.000 0.000
## 84                depression_T2 ~1                               0.000 0.000
## 85                depression_T3 ~1                               0.000 0.000
## 86                depression_T4 ~1                               0.000 0.000
## 87               CASI_ADHD_CSum ~1                              13.089 0.000
## 88            CASI_ADHD_CSum_T2 ~1                              12.161 0.000
## 89            CASI_ADHD_CSum_T3 ~1                              19.411 0.000
## 90             CASI_ADHDCSum_T4 ~1                              19.875 0.000
## 91 Academicperformance_total_T4 ~1                               3.018 0.000
## 92             Familyincome_T1r ~1                               2.536 0.000
## 93           Educationhousehold ~1                               4.554 0.000
## 94                 Child_gender ~1                               1.500 0.000
## 95             Childagecategory ~1                               2.804 0.000
## 96                    Intercept ~1                               0.974 0.478
## 97                       Linear ~1                              -0.749 0.276
##         z pvalue ci.lower ci.upper
## 1      NA     NA    1.000    1.000
## 2      NA     NA    1.000    1.000
## 3      NA     NA    1.000    1.000
## 4      NA     NA    1.000    1.000
## 5      NA     NA    0.000    0.000
## 6      NA     NA    1.000    1.000
## 7      NA     NA    2.000    2.000
## 8      NA     NA    3.000    3.000
## 9   0.346  0.729   -0.037    0.053
## 10 -0.381  0.704   -0.042    0.029
## 11  1.076  0.282   -0.011    0.039
## 12  0.929  0.353   -0.013    0.036
## 13 -0.186  0.853   -0.072    0.060
## 14 -2.200  0.028   -0.159   -0.009
## 15 -1.898  0.058   -0.273    0.004
## 16  1.470  0.142   -0.049    0.344
## 17 -0.427  0.669   -0.172    0.111
## 18 -0.123  0.902   -0.028    0.025
## 19  0.980  0.327   -0.011    0.034
## 20  1.740  0.082   -0.002    0.031
## 21 -0.860  0.390   -0.029    0.011
## 22  0.282  0.778   -0.035    0.047
## 23 -0.020  0.984   -0.048    0.047
## 24  1.972  0.049    0.000    0.138
## 25 -0.381  0.703   -0.147    0.099
## 26  0.426  0.670   -0.070    0.109
## 27  1.905  0.057   -0.002    0.115
## 28  3.423  0.001    0.029    0.108
## 29  3.141  0.002    0.019    0.082
## 30  2.278  0.023    0.008    0.110
## 31  2.972  0.003    0.056    0.275
## 32  5.973  0.000    0.067    0.131
## 33  3.920  0.000    0.054    0.161
## 34  3.537  0.000    0.071    0.248
## 35 -1.262  0.207   -0.088    0.019
## 36 -0.510  0.610   -0.017    0.010
## 37  0.827  0.408   -0.014    0.035
## 38     NA     NA    8.867    8.867
## 39     NA     NA    2.682    2.682
## 40     NA     NA    0.285    0.285
## 41     NA     NA   -0.025   -0.025
## 42     NA     NA   -0.573   -0.573
## 43     NA     NA   -0.941   -0.941
## 44     NA     NA   -0.585   -0.585
## 45     NA     NA    0.420    0.420
## 46     NA     NA    0.143    0.143
## 47     NA     NA    5.599    5.599
## 48     NA     NA    2.220    2.220
## 49     NA     NA    3.092    3.092
## 50     NA     NA    0.265    0.265
## 51     NA     NA   -0.640   -0.640
## 52     NA     NA   -0.571   -0.571
## 53     NA     NA    0.098    0.098
## 54     NA     NA    0.121    0.121
## 55     NA     NA    7.742    7.742
## 56     NA     NA    1.855    1.855
## 57     NA     NA    0.046    0.046
## 58     NA     NA    0.191    0.191
## 59     NA     NA   -0.477   -0.477
## 60     NA     NA   -0.330   -0.330
## 61     NA     NA    0.206    0.206
## 62     NA     NA    9.467    9.467
## 63     NA     NA    0.431    0.431
## 64     NA     NA   -0.112   -0.112
## 65     NA     NA   -0.484   -0.484
## 66     NA     NA   -0.259   -0.259
## 67     NA     NA    0.350    0.350
## 68     NA     NA    1.303    1.303
## 69     NA     NA    0.205    0.205
## 70     NA     NA   -0.135   -0.135
## 71     NA     NA   -0.009   -0.009
## 72     NA     NA    0.004    0.004
## 73     NA     NA    0.892    0.892
## 74     NA     NA    0.168    0.168
## 75     NA     NA   -0.054   -0.054
## 76     NA     NA   -0.002   -0.002
## 77     NA     NA    0.533    0.533
## 78     NA     NA    0.116    0.116
## 79     NA     NA    0.037    0.037
## 80     NA     NA    0.250    0.250
## 81     NA     NA    0.009    0.009
## 82     NA     NA    0.229    0.229
## 83     NA     NA    0.000    0.000
## 84     NA     NA    0.000    0.000
## 85     NA     NA    0.000    0.000
## 86     NA     NA    0.000    0.000
## 87     NA     NA   13.089   13.089
## 88     NA     NA   12.161   12.161
## 89     NA     NA   19.411   19.411
## 90     NA     NA   19.875   19.875
## 91     NA     NA    3.018    3.018
## 92     NA     NA    2.536    2.536
## 93     NA     NA    4.554    4.554
## 94     NA     NA    1.500    1.500
## 95     NA     NA    2.804    2.804
## 96  2.036  0.042    0.036    1.911
## 97 -2.717  0.007   -1.290   -0.209
semPaths(predict,what = "path", whatLabels = "est",  edge.label.cex=.7,
                 intercepts = TRUE, edge.color = "black", nCharNodes = 0, nCharEdges=0,
                 sizeLat = 6, sizeMan=9, exoVar = FALSE, exoCov = FALSE,
                 shapeInt = "circle", covAtResiduals = FALSE)

# predicted means and covariances for observed variables
lavaan::fitted(predict)
## $cov
##                              dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm
## depression_T1                 0.219                                   
## depression_T2                 0.036  0.160                            
## depression_T3                 0.023  0.047  0.177                     
## depression_T4                 0.029  0.055  0.056  0.229              
## CASI_ADHD_CSum                0.779  0.428  0.227  0.181         8.867
## CASI_ADHD_CSum_T2             0.342  0.600  0.354  0.451         2.682
## CASI_ADHD_CSum_T3             0.124  0.361  0.700  0.520         0.285
## CASI_ADHDCSum_T4              0.136  0.310  0.152  0.578        -0.025
## Academicperformance_total_T4 -0.042  0.008 -0.008  0.014        -0.573
## Familyincome_T1r             -0.162 -0.141 -0.075 -0.080        -0.941
## Educationhousehold           -0.115 -0.095 -0.054 -0.033        -0.585
## Child_gender                  0.045  0.027  0.004  0.005         0.420
## Childagecategory              0.005  0.013  0.023  0.041         0.143
##                              CASI_ADHD_CS_T2 CASI_ADHD_CS_T3 CASI_ADHDC Ac__T4
## depression_T1                                                                 
## depression_T2                                                                 
## depression_T3                                                                 
## depression_T4                                                                 
## CASI_ADHD_CSum                                                                
## CASI_ADHD_CSum_T2                      5.599                                  
## CASI_ADHD_CSum_T3                      2.220           7.742                  
## CASI_ADHDCSum_T4                       3.092           1.855      9.467       
## Academicperformance_total_T4           0.265           0.046      0.431  1.303
## Familyincome_T1r                      -0.640           0.191     -0.112  0.205
## Educationhousehold                    -0.571          -0.477     -0.484 -0.135
## Child_gender                           0.098          -0.330     -0.259 -0.009
## Childagecategory                       0.121           0.206      0.350  0.004
##                              Fml_T1 Edctnh Chld_g Chldgc
## depression_T1                                           
## depression_T2                                           
## depression_T3                                           
## depression_T4                                           
## CASI_ADHD_CSum                                          
## CASI_ADHD_CSum_T2                                       
## CASI_ADHD_CSum_T3                                       
## CASI_ADHDCSum_T4                                        
## Academicperformance_total_T4                            
## Familyincome_T1r              0.892                     
## Educationhousehold            0.168  0.533              
## Child_gender                 -0.054  0.116  0.250       
## Childagecategory             -0.002  0.037  0.009  0.229
## 
## $mean
##                depression_T1                depression_T2 
##                        1.526                        1.443 
##                depression_T3                depression_T4 
##                        1.414                        1.436 
##               CASI_ADHD_CSum            CASI_ADHD_CSum_T2 
##                       13.089                       12.161 
##            CASI_ADHD_CSum_T3             CASI_ADHDCSum_T4 
##                       19.411                       19.875 
## Academicperformance_total_T4             Familyincome_T1r 
##                        3.018                        2.536 
##           Educationhousehold                 Child_gender 
##                        4.554                        1.500 
##             Childagecategory 
##                        2.804
# predicted means for factors
lavaan::lavInspect(predict, add.labels = TRUE, "mean.lv")
## Intercept    Linear 
##     0.781    -0.173
lavaan::lavInspect(predict, add.labels = TRUE, "cor.lv")
##           Intrcp Linear
## Intercept      1       
## Linear       NaN      1
# residuals
lavaan::residuals(predict, type = "raw")
## $type
## [1] "raw"
## 
## $cov
##                              dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm
## depression_T1                -0.012                                   
## depression_T2                 0.020 -0.003                            
## depression_T3                -0.003 -0.027  0.018                     
## depression_T4                 0.026 -0.012  0.019 -0.013              
## CASI_ADHD_CSum               -0.005  0.019 -0.031  0.021         0.000
## CASI_ADHD_CSum_T2             0.042 -0.042  0.009  0.014         0.000
## CASI_ADHD_CSum_T3             0.106 -0.169  0.160 -0.068         0.000
## CASI_ADHDCSum_T4             -0.155  0.107  0.068 -0.125         0.000
## Academicperformance_total_T4 -0.012  0.006  0.010 -0.013         0.000
## Familyincome_T1r              0.032 -0.049  0.045 -0.019         0.000
## Educationhousehold           -0.002  0.004 -0.005  0.003         0.000
## Child_gender                  0.000  0.017 -0.038  0.028         0.000
## Childagecategory             -0.008  0.008 -0.001 -0.003         0.000
##                              CASI_ADHD_CS_T2 CASI_ADHD_CS_T3 CASI_ADHDC Ac__T4
## depression_T1                                                                 
## depression_T2                                                                 
## depression_T3                                                                 
## depression_T4                                                                 
## CASI_ADHD_CSum                                                                
## CASI_ADHD_CSum_T2                      0.000                                  
## CASI_ADHD_CSum_T3                      0.000           0.000                  
## CASI_ADHDCSum_T4                       0.000           0.000      0.000       
## Academicperformance_total_T4           0.000           0.000      0.000  0.000
## Familyincome_T1r                       0.000           0.000      0.000  0.000
## Educationhousehold                     0.000           0.000      0.000  0.000
## Child_gender                           0.000           0.000      0.000  0.000
## Childagecategory                       0.000           0.000      0.000  0.000
##                              Fml_T1 Edctnh Chld_g Chldgc
## depression_T1                                           
## depression_T2                                           
## depression_T3                                           
## depression_T4                                           
## CASI_ADHD_CSum                                          
## CASI_ADHD_CSum_T2                                       
## CASI_ADHD_CSum_T3                                       
## CASI_ADHDCSum_T4                                        
## Academicperformance_total_T4                            
## Familyincome_T1r              0.000                     
## Educationhousehold            0.000  0.000              
## Child_gender                  0.000  0.000  0.000       
## Childagecategory              0.000  0.000  0.000  0.000
## 
## $mean
##                depression_T1                depression_T2 
##                        0.000                        0.003 
##                depression_T3                depression_T4 
##                       -0.008                        0.006 
##               CASI_ADHD_CSum            CASI_ADHD_CSum_T2 
##                        0.000                        0.000 
##            CASI_ADHD_CSum_T3             CASI_ADHDCSum_T4 
##                        0.000                        0.000 
## Academicperformance_total_T4             Familyincome_T1r 
##                        0.000                        0.000 
##           Educationhousehold                 Child_gender 
##                        0.000                        0.000 
##             Childagecategory 
##                        0.000
lavaan::residuals(predict, type = "standardized.mplus")
## $type
## [1] "standardized.mplus"
## 
## $cov
##                              dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm
## depression_T1                    NA                                   
## depression_T2                 2.412     NA                            
## depression_T3                -0.179     NA  1.027                     
## depression_T4                 2.383 -0.758  3.088     NA              
## CASI_ADHD_CSum               -0.099  0.347 -0.423  0.215         0.000
## CASI_ADHD_CSum_T2             0.689     NA     NA  0.176         0.000
## CASI_ADHD_CSum_T3             1.353 -4.099  2.932 -0.859         0.000
## CASI_ADHDCSum_T4             -1.726  1.605     NA -2.093         0.000
## Academicperformance_total_T4 -0.319  0.212  0.374 -0.426         0.000
## Familyincome_T1r              1.182 -2.677  2.991 -0.542         0.000
## Educationhousehold           -0.088  0.203 -0.362  0.146         0.000
## Child_gender                  0.009  1.189 -2.436  2.435         0.000
## Childagecategory             -1.119  0.570 -0.048 -0.231         0.000
##                              CASI_ADHD_CS_T2 CASI_ADHD_CS_T3 CASI_ADHDC Ac__T4
## depression_T1                                                                 
## depression_T2                                                                 
## depression_T3                                                                 
## depression_T4                                                                 
## CASI_ADHD_CSum                                                                
## CASI_ADHD_CSum_T2                      0.000                                  
## CASI_ADHD_CSum_T3                      0.000           0.000                  
## CASI_ADHDCSum_T4                       0.000           0.000      0.000       
## Academicperformance_total_T4           0.000           0.000      0.000  0.000
## Familyincome_T1r                       0.000           0.000      0.000  0.000
## Educationhousehold                     0.000           0.000      0.000  0.000
## Child_gender                           0.000           0.000      0.000  0.000
## Childagecategory                       0.000           0.000      0.000  0.000
##                              Fml_T1 Edctnh Chld_g Chldgc
## depression_T1                                           
## depression_T2                                           
## depression_T3                                           
## depression_T4                                           
## CASI_ADHD_CSum                                          
## CASI_ADHD_CSum_T2                                       
## CASI_ADHD_CSum_T3                                       
## CASI_ADHDCSum_T4                                        
## Academicperformance_total_T4                            
## Familyincome_T1r              0.000                     
## Educationhousehold            0.000  0.000              
## Child_gender                  0.000  0.000  0.000       
## Childagecategory              0.000  0.000  0.000  0.000
## 
## $mean
##                depression_T1                depression_T2 
##                           NA                           NA 
##                depression_T3                depression_T4 
##                           NA                           NA 
##               CASI_ADHD_CSum            CASI_ADHD_CSum_T2 
##                            0                            0 
##            CASI_ADHD_CSum_T3             CASI_ADHDCSum_T4 
##                            0                            0 
## Academicperformance_total_T4             Familyincome_T1r 
##                            0                            0 
##           Educationhousehold                 Child_gender 
##                            0                            0 
##             Childagecategory 
##                            0
lavaan::residuals(predict, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##                              dpr_T1 dpr_T2 dpr_T3 dpr_T4 CASI_ADHD_CSm
## depression_T1                 0.000                                   
## depression_T2                 0.118  0.000                            
## depression_T3                -0.017 -0.167  0.000                     
## depression_T4                 0.129 -0.053  0.085  0.000              
## CASI_ADHD_CSum                0.012  0.019 -0.032  0.019         0.000
## CASI_ADHD_CSum_T2             0.048 -0.040 -0.008  0.024         0.000
## CASI_ADHD_CSum_T3             0.087 -0.150  0.101 -0.041         0.000
## CASI_ADHDCSum_T4             -0.108  0.090  0.045 -0.076         0.000
## Academicperformance_total_T4 -0.025  0.014  0.021 -0.024         0.000
## Familyincome_T1r              0.064 -0.135  0.118 -0.047         0.000
## Educationhousehold           -0.016  0.013 -0.008  0.006         0.000
## Child_gender                  0.006  0.088 -0.171  0.121         0.000
## Childagecategory             -0.038  0.042 -0.010 -0.010         0.000
##                              CASI_ADHD_CS_T2 CASI_ADHD_CS_T3 CASI_ADHDC Ac__T4
## depression_T1                                                                 
## depression_T2                                                                 
## depression_T3                                                                 
## depression_T4                                                                 
## CASI_ADHD_CSum                                                                
## CASI_ADHD_CSum_T2                      0.000                                  
## CASI_ADHD_CSum_T3                      0.000           0.000                  
## CASI_ADHDCSum_T4                       0.000           0.000      0.000       
## Academicperformance_total_T4           0.000           0.000      0.000  0.000
## Familyincome_T1r                       0.000           0.000      0.000  0.000
## Educationhousehold                     0.000           0.000      0.000  0.000
## Child_gender                           0.000           0.000      0.000  0.000
## Childagecategory                       0.000           0.000      0.000  0.000
##                              Fml_T1 Edctnh Chld_g Chldgc
## depression_T1                                           
## depression_T2                                           
## depression_T3                                           
## depression_T4                                           
## CASI_ADHD_CSum                                          
## CASI_ADHD_CSum_T2                                       
## CASI_ADHD_CSum_T3                                       
## CASI_ADHDCSum_T4                                        
## Academicperformance_total_T4                            
## Familyincome_T1r              0.000                     
## Educationhousehold            0.000  0.000              
## Child_gender                  0.000  0.000  0.000       
## Childagecategory              0.000  0.000  0.000  0.000
## 
## $mean
##                depression_T1                depression_T2 
##                        0.001                        0.009 
##                depression_T3                depression_T4 
##                       -0.019                        0.014 
##               CASI_ADHD_CSum            CASI_ADHD_CSum_T2 
##                        0.000                        0.000 
##            CASI_ADHD_CSum_T3             CASI_ADHDCSum_T4 
##                        0.000                        0.000 
## Academicperformance_total_T4             Familyincome_T1r 
##                        0.000                        0.000 
##           Educationhousehold                 Child_gender 
##                        0.000                        0.000 
##             Childagecategory 
##                        0.000
#########################################################################################################
#########################################################################################################
#########################################################################################################


#########################################################################################################
                            # 3 step model fitting for anxiety #
#########################################################################################################
### MODEL 1 - no growth (intercept only) "random intercept-only model" - predicts no growth

# Loadings for all indicators on the intercept factor are fixed to equal 1.0.
# Intercept represents the factor mean, which is also the predicted average anxiety score
# over all years 1-4

noGrowth.model1 <- '
# specify intercept
# fix all loadings to 1.0
 Intercept =~ 1*anxiety_T1 + 1*anxiety_T2 + 1*anxiety_T3 + 1*anxiety_T4
# fix error variance for r1 to zero
 anxiety_T1 ~~ 0*anxiety_T1 '

#########################################################################################################
### MODEL 2 - latent basis growth model ("level and shape model")

# (curve fitting, level and shape)
# two growth factors: intercept (level) and shape

# loadings of all repeated measures of anxiety are fixed to equal 1.0, like in the
# random intercept-only model above. here, onnly looking at T1 to T4 change (overall shape)
# the basis model predicts growth trajectories that are not strictly linear - allows for
# linear or curvilinear change. the shape factor will represent the pattern
# this is called "non-linear curve fitting" 
# unstandardized loadings for the shape factor are called basis coefficients
# two of these are fixed to equal constraints:
# one is specifying T1 as 0 defines the intercept [anxiety] factor mean)
# second is defining the random variation around the initial level
# the basis coefficients define the shape factor mean as the average change in anxiety
# between T1 and T4. it also scales the growth factor Shape so that a 1-unit change in 
# time refers to the whole period of observation, or T1-T4 inclusive. so the loadings are 
# interpreted as proportions of the total overall change that has occurred up to and 
# including the corresponding measurement
# i.e., .70 for T3 would mean that .70, or 70% of the total increase in anxiety from T1-T4
# has occurred by T3 
# the predicted average anxiety score  is the sum of the initial mean at T1 plus the proportion 
# of total change over T1-4 that has occurred up to and including the point of measurement
# the covariance represents the association between intercept and shape
# covariance indicates that higher initial levels of anxiety at T1 predict a higher rate of
# subsequent change between T1-4. so those who start at higher levels change the most over time
# a negative covariance indicates the opposite: Higher initial standing predicts less change over 4 timepoints
# a factor covariance of zero indicates that initial level has nothing to do with the rate of subsequent change

# maccallum-rmsea for model 2
# exact fit test
# power at N = 432
semTools::findRMSEApower(0, .05, 4, 432, .05, 1)
## [1] 0.3437725
# minimum N for power at least .80
semTools::findRMSEAsamplesize(0, .05, 4, .80, .05, 1)
## [1] 1195
basis.model1 <- '
 Intercept =~ 1*anxiety_T1 + 1*anxiety_T2 + 1*anxiety_T3 + 1*anxiety_T4
# specify shape, first and last loadings fixed
 Shape =~ 0*anxiety_T1 + anxiety_T2 + anxiety_T3 + 1*anxiety_T4
 anxiety_T1 ~~ 0*anxiety_T1 '

#########################################################################################################
### MODEL 3 - linear growth model with only continuous covariates
# these assume change is strictly linear - essentially constrained versions of basis growth models 
# but on the same variables. the coefficients are all fixed to equal constraints that correspond
# to times of measurement (none are free parameters)
# the mean for the intercept factor is the average anxiety score at T1, and its variance
# is the random variation around this mean initial level. The linear factor mean is the average amount
# of increase in anxiety per time point, which is assumed to be the same between all pairs of adjacent
# measurement occasions

linear.model1 <- '
 Intercept =~ 1*anxiety_T1 + 1*anxiety_T2 + 1*anxiety_T3 + 1*anxiety_T4 
# all loadings fixed to constants
 Linear =~ 0*anxiety_T1 + 1*anxiety_T2 + 2*anxiety_T3 + 3*anxiety_T4
 anxiety_T1 ~~ 0*anxiety_T1 
 # TVCs
                anxiety_T1 ~ CASI_ADHD_CSum
                anxiety_T2 ~ CASI_ADHD_CSum_T2
                anxiety_T3 ~ CASI_ADHD_CSum_T3
                anxiety_T4 ~ CASI_ADHDCSum_T4'

# fit model 1 to data
noGrowth1 <- lavaan::growth(noGrowth.model1, data=mydata, missing = "fiml", estimator = "mlr")

# fit model 2 to data
basis1 <- lavaan::growth(basis.model1, data=mydata, missing = "fiml", estimator = "mlr")

# fit model 3 to data
linear1 <- lavaan::growth(linear.model1, data=mydata, missing = "fiml", estimator = "mlr")

#########################################################################################################
# model chi-squares and chi-square difference tests
anova(noGrowth1, basis1)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##           Df    AIC    BIC   Chisq Chisq diff Df diff Pr(>Chisq)    
## basis1     4 1175.5 1216.9  11.656                                  
## noGrowth1  9 1336.3 1357.0 182.411     136.43       5  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(basis1, linear1)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##         Df     AIC     BIC  Chisq Chisq diff Df diff Pr(>Chisq)    
## basis1   4 1175.52 1216.88 11.656                                  
## linear1 18  127.72  152.23 80.843     65.835      14  1.085e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# model 1 parameter estimates, global fit statistics,
# residuals
lavaan::summary(noGrowth1, fit.measures = TRUE, estimates = TRUE)
## lavaan 0.6.17 ended normally after 23 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##                                                   Used       Total
##   Number of observations                           462         540
##   Number of missing patterns                        14            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                               182.410     162.677
##   Degrees of freedom                                 9           9
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.121
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                               122.337      99.669
##   Degrees of freedom                                 6           6
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.227
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.000       0.000
##   Tucker-Lewis Index (TLI)                       0.006      -0.094
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.010
##   Robust Tucker-Lewis Index (TLI)                            0.340
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -663.139    -663.139
##   Scaling correction factor                                  1.335
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)       -571.934    -571.934
##   Scaling correction factor                                  1.198
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                1336.279    1336.279
##   Bayesian (BIC)                              1356.956    1356.956
##   Sample-size adjusted Bayesian (SABIC)       1341.088    1341.088
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.204       0.192
##   90 Percent confidence interval - lower         0.179       0.168
##   90 Percent confidence interval - upper         0.231       0.217
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    1.000       1.000
##                                                                   
##   Robust RMSEA                                               0.452
##   90 Percent confidence interval - lower                     0.382
##   90 Percent confidence interval - upper                     0.525
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.702       0.702
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     anxiety_T1        1.000                           
##     anxiety_T2        1.000                           
##     anxiety_T3        1.000                           
##     anxiety_T4        1.000                           
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Intercept         1.266    0.028   45.588    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .anxiety_T1        0.000                           
##    .anxiety_T2        0.168    0.029    5.780    0.000
##    .anxiety_T3        0.249    0.029    8.680    0.000
##    .anxiety_T4        0.258    0.051    5.018    0.000
##     Intercept         0.340    0.022   15.454    0.000
lavaan::fitted(noGrowth1)
## $cov
##            anx_T1 anx_T2 anx_T3 anx_T4
## anxiety_T1  0.340                     
## anxiety_T2  0.340  0.508              
## anxiety_T3  0.340  0.340  0.589       
## anxiety_T4  0.340  0.340  0.340  0.598
## 
## $mean
## anxiety_T1 anxiety_T2 anxiety_T3 anxiety_T4 
##      1.266      1.266      1.266      1.266
lavaan::residuals(noGrowth1, type = "standardized")
## $type
## [1] "standardized"
## 
## $cov
##            anx_T1 anx_T2 anx_T3 anx_T4
## anxiety_T1  1.036                     
## anxiety_T2 -3.099 -2.154              
## anxiety_T3 -2.995 -3.487 -2.441       
## anxiety_T4 -2.468 -3.063 -2.930 -1.644
## 
## $mean
## anxiety_T1 anxiety_T2 anxiety_T3 anxiety_T4 
##     -0.453      1.719     -1.586      1.451
lavaan::residuals(noGrowth1, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##            anx_T1 anx_T2 anx_T3 anx_T4
## anxiety_T1  0.000                     
## anxiety_T2 -0.202  0.000              
## anxiety_T3 -0.154  0.011  0.000       
## anxiety_T4 -0.183  0.057  0.007  0.000
## 
## $mean
## anxiety_T1 anxiety_T2 anxiety_T3 anxiety_T4 
##     -0.006      0.147     -0.107      0.133
#standardized estimates
standardizedSolution(noGrowth1, type = "std.all",  se= TRUE, pvalue = TRUE)
##           lhs op        rhs est.std    se      z pvalue ci.lower ci.upper
## 1   Intercept =~ anxiety_T1   1.000 0.000     NA     NA    1.000    1.000
## 2   Intercept =~ anxiety_T2   0.818 0.023 34.860      0    0.772    0.864
## 3   Intercept =~ anxiety_T3   0.760 0.021 36.774      0    0.720    0.801
## 4   Intercept =~ anxiety_T4   0.754 0.033 22.813      0    0.690    0.819
## 5  anxiety_T1 ~~ anxiety_T1   0.000 0.000     NA     NA    0.000    0.000
## 6  anxiety_T2 ~~ anxiety_T2   0.331 0.038  8.609      0    0.255    0.406
## 7  anxiety_T3 ~~ anxiety_T3   0.422 0.031 13.440      0    0.361    0.484
## 8  anxiety_T4 ~~ anxiety_T4   0.431 0.050  8.641      0    0.333    0.529
## 9   Intercept ~~  Intercept   1.000 0.000     NA     NA    1.000    1.000
## 10 anxiety_T1 ~1              0.000 0.000     NA     NA    0.000    0.000
## 11 anxiety_T2 ~1              0.000 0.000     NA     NA    0.000    0.000
## 12 anxiety_T3 ~1              0.000 0.000     NA     NA    0.000    0.000
## 13 anxiety_T4 ~1              0.000 0.000     NA     NA    0.000    0.000
## 14  Intercept ~1              2.170 0.092 23.667      0    1.990    2.350
#unstandardized estimates
parameterEstimates(noGrowth1)
##           lhs op        rhs   est    se      z pvalue ci.lower ci.upper
## 1   Intercept =~ anxiety_T1 1.000 0.000     NA     NA    1.000    1.000
## 2   Intercept =~ anxiety_T2 1.000 0.000     NA     NA    1.000    1.000
## 3   Intercept =~ anxiety_T3 1.000 0.000     NA     NA    1.000    1.000
## 4   Intercept =~ anxiety_T4 1.000 0.000     NA     NA    1.000    1.000
## 5  anxiety_T1 ~~ anxiety_T1 0.000 0.000     NA     NA    0.000    0.000
## 6  anxiety_T2 ~~ anxiety_T2 0.168 0.029  5.780      0    0.111    0.225
## 7  anxiety_T3 ~~ anxiety_T3 0.249 0.029  8.680      0    0.193    0.305
## 8  anxiety_T4 ~~ anxiety_T4 0.258 0.051  5.018      0    0.157    0.359
## 9   Intercept ~~  Intercept 0.340 0.022 15.454      0    0.297    0.384
## 10 anxiety_T1 ~1            0.000 0.000     NA     NA    0.000    0.000
## 11 anxiety_T2 ~1            0.000 0.000     NA     NA    0.000    0.000
## 12 anxiety_T3 ~1            0.000 0.000     NA     NA    0.000    0.000
## 13 anxiety_T4 ~1            0.000 0.000     NA     NA    0.000    0.000
## 14  Intercept ~1            1.266 0.028 45.588      0    1.212    1.320
# model 2 parameter estimates, global fit statistics,
# residuals
# retained model
lavaan::summary(basis1, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6.17 ended normally after 35 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##                                                   Used       Total
##   Number of observations                           462         540
##   Number of missing patterns                        14            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                11.656      12.161
##   Degrees of freedom                                 4           4
##   P-value (Chi-square)                           0.020       0.016
##   Scaling correction factor                                  0.958
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                               122.337      99.669
##   Degrees of freedom                                 6           6
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.227
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.934       0.913
##   Tucker-Lewis Index (TLI)                       0.901       0.869
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.975
##   Robust Tucker-Lewis Index (TLI)                            0.963
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -577.762    -577.762
##   Scaling correction factor                                  1.293
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)       -571.934    -571.934
##   Scaling correction factor                                  1.198
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                1175.524    1175.524
##   Bayesian (BIC)                              1216.879    1216.879
##   Sample-size adjusted Bayesian (SABIC)       1185.142    1185.142
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.064       0.066
##   90 Percent confidence interval - lower         0.023       0.025
##   90 Percent confidence interval - upper         0.109       0.112
##   P-value H_0: RMSEA <= 0.050                    0.240       0.219
##   P-value H_0: RMSEA >= 0.080                    0.320       0.353
##                                                                   
##   Robust RMSEA                                               0.107
##   90 Percent confidence interval - lower                     0.000
##   90 Percent confidence interval - upper                     0.241
##   P-value H_0: Robust RMSEA <= 0.050                         0.209
##   P-value H_0: Robust RMSEA >= 0.080                         0.697
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.059       0.059
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     anxiety_T1        1.000                           
##     anxiety_T2        1.000                           
##     anxiety_T3        1.000                           
##     anxiety_T4        1.000                           
##   Shape =~                                            
##     anxiety_T1        0.000                           
##     anxiety_T2        1.028    0.193    5.336    0.000
##     anxiety_T3        0.983    0.212    4.634    0.000
##     anxiety_T4        1.000                           
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~~                                        
##     Shape            -0.183    0.036   -5.072    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Intercept         1.265    0.030   42.167    0.000
##     Shape             0.032    0.040    0.788    0.430
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .anxiety_T1        0.000                           
##    .anxiety_T2        0.052    0.018    2.883    0.004
##    .anxiety_T3        0.132    0.026    5.079    0.000
##    .anxiety_T4        0.128    0.027    4.776    0.000
##     Intercept         0.365    0.024   14.946    0.000
##     Shape             0.158    0.053    2.951    0.003
## 
## R-Square:
##                    Estimate
##     anxiety_T1        1.000
##     anxiety_T2        0.749
##     anxiety_T3        0.543
##     anxiety_T4        0.549
lavaan::standardizedSolution(basis1)
##           lhs op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1   Intercept =~ anxiety_T1   1.000 0.000      NA     NA    1.000    1.000
## 2   Intercept =~ anxiety_T2   1.328 0.098  13.603  0.000    1.137    1.520
## 3   Intercept =~ anxiety_T3   1.123 0.076  14.827  0.000    0.974    1.271
## 4   Intercept =~ anxiety_T4   1.133 0.064  17.686  0.000    1.007    1.258
## 5       Shape =~ anxiety_T1   0.000 0.000      NA     NA    0.000    0.000
## 6       Shape =~ anxiety_T2   0.897 0.177   5.067  0.000    0.550    1.245
## 7       Shape =~ anxiety_T3   0.726 0.131   5.527  0.000    0.468    0.983
## 8       Shape =~ anxiety_T4   0.745 0.143   5.195  0.000    0.464    1.026
## 9  anxiety_T1 ~~ anxiety_T1   0.000 0.000      NA     NA    0.000    0.000
## 10 anxiety_T2 ~~ anxiety_T2   0.251 0.081   3.115  0.002    0.093    0.409
## 11 anxiety_T3 ~~ anxiety_T3   0.457 0.069   6.632  0.000    0.322    0.592
## 12 anxiety_T4 ~~ anxiety_T4   0.451 0.080   5.613  0.000    0.293    0.608
## 13  Intercept ~~  Intercept   1.000 0.000      NA     NA    1.000    1.000
## 14      Shape ~~      Shape   1.000 0.000      NA     NA    1.000    1.000
## 15  Intercept ~~      Shape  -0.764 0.054 -14.035  0.000   -0.870   -0.657
## 16 anxiety_T1 ~1              0.000 0.000      NA     NA    0.000    0.000
## 17 anxiety_T2 ~1              0.000 0.000      NA     NA    0.000    0.000
## 18 anxiety_T3 ~1              0.000 0.000      NA     NA    0.000    0.000
## 19 anxiety_T4 ~1              0.000 0.000      NA     NA    0.000    0.000
## 20  Intercept ~1              2.094 0.091  23.047  0.000    1.916    2.272
## 21      Shape ~1              0.079 0.095   0.833  0.405   -0.107    0.266
#standardized estimates
standardizedSolution(basis1, type = "std.all",  se= TRUE, pvalue = TRUE)
##           lhs op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1   Intercept =~ anxiety_T1   1.000 0.000      NA     NA    1.000    1.000
## 2   Intercept =~ anxiety_T2   1.328 0.098  13.603  0.000    1.137    1.520
## 3   Intercept =~ anxiety_T3   1.123 0.076  14.827  0.000    0.974    1.271
## 4   Intercept =~ anxiety_T4   1.133 0.064  17.686  0.000    1.007    1.258
## 5       Shape =~ anxiety_T1   0.000 0.000      NA     NA    0.000    0.000
## 6       Shape =~ anxiety_T2   0.897 0.177   5.067  0.000    0.550    1.245
## 7       Shape =~ anxiety_T3   0.726 0.131   5.527  0.000    0.468    0.983
## 8       Shape =~ anxiety_T4   0.745 0.143   5.195  0.000    0.464    1.026
## 9  anxiety_T1 ~~ anxiety_T1   0.000 0.000      NA     NA    0.000    0.000
## 10 anxiety_T2 ~~ anxiety_T2   0.251 0.081   3.115  0.002    0.093    0.409
## 11 anxiety_T3 ~~ anxiety_T3   0.457 0.069   6.632  0.000    0.322    0.592
## 12 anxiety_T4 ~~ anxiety_T4   0.451 0.080   5.613  0.000    0.293    0.608
## 13  Intercept ~~  Intercept   1.000 0.000      NA     NA    1.000    1.000
## 14      Shape ~~      Shape   1.000 0.000      NA     NA    1.000    1.000
## 15  Intercept ~~      Shape  -0.764 0.054 -14.035  0.000   -0.870   -0.657
## 16 anxiety_T1 ~1              0.000 0.000      NA     NA    0.000    0.000
## 17 anxiety_T2 ~1              0.000 0.000      NA     NA    0.000    0.000
## 18 anxiety_T3 ~1              0.000 0.000      NA     NA    0.000    0.000
## 19 anxiety_T4 ~1              0.000 0.000      NA     NA    0.000    0.000
## 20  Intercept ~1              2.094 0.091  23.047  0.000    1.916    2.272
## 21      Shape ~1              0.079 0.095   0.833  0.405   -0.107    0.266
#unstandardized estimates
parameterEstimates(basis1)
##           lhs op        rhs    est    se      z pvalue ci.lower ci.upper
## 1   Intercept =~ anxiety_T1  1.000 0.000     NA     NA    1.000    1.000
## 2   Intercept =~ anxiety_T2  1.000 0.000     NA     NA    1.000    1.000
## 3   Intercept =~ anxiety_T3  1.000 0.000     NA     NA    1.000    1.000
## 4   Intercept =~ anxiety_T4  1.000 0.000     NA     NA    1.000    1.000
## 5       Shape =~ anxiety_T1  0.000 0.000     NA     NA    0.000    0.000
## 6       Shape =~ anxiety_T2  1.028 0.193  5.336  0.000    0.650    1.405
## 7       Shape =~ anxiety_T3  0.983 0.212  4.634  0.000    0.567    1.399
## 8       Shape =~ anxiety_T4  1.000 0.000     NA     NA    1.000    1.000
## 9  anxiety_T1 ~~ anxiety_T1  0.000 0.000     NA     NA    0.000    0.000
## 10 anxiety_T2 ~~ anxiety_T2  0.052 0.018  2.883  0.004    0.017    0.087
## 11 anxiety_T3 ~~ anxiety_T3  0.132 0.026  5.079  0.000    0.081    0.183
## 12 anxiety_T4 ~~ anxiety_T4  0.128 0.027  4.776  0.000    0.076    0.181
## 13  Intercept ~~  Intercept  0.365 0.024 14.946  0.000    0.317    0.413
## 14      Shape ~~      Shape  0.158 0.053  2.951  0.003    0.053    0.263
## 15  Intercept ~~      Shape -0.183 0.036 -5.072  0.000   -0.254   -0.112
## 16 anxiety_T1 ~1             0.000 0.000     NA     NA    0.000    0.000
## 17 anxiety_T2 ~1             0.000 0.000     NA     NA    0.000    0.000
## 18 anxiety_T3 ~1             0.000 0.000     NA     NA    0.000    0.000
## 19 anxiety_T4 ~1             0.000 0.000     NA     NA    0.000    0.000
## 20  Intercept ~1             1.265 0.030 42.167  0.000    1.206    1.324
## 21      Shape ~1             0.032 0.040  0.788  0.430   -0.047    0.110
semPaths(basis1,what = "path", whatLabels = "est",  edge.label.cex=.7,
                 intercepts = TRUE, edge.color = "black", nCharNodes = 0, nCharEdges=0,
                 sizeLat = 6, sizeMan=9, exoVar = FALSE, exoCov = FALSE,
                 shapeInt = "circle", covAtResiduals = FALSE)

# implied covariances and means for observed variables
lavaan::fitted(basis1)
## $cov
##            anx_T1 anx_T2 anx_T3 anx_T4
## anxiety_T1  0.365                     
## anxiety_T2  0.177  0.207              
## anxiety_T3  0.185  0.156  0.289       
## anxiety_T4  0.182  0.155  0.157  0.284
## 
## $mean
## anxiety_T1 anxiety_T2 anxiety_T3 anxiety_T4 
##      1.265      1.297      1.296      1.296
# implied means for latent growth factors
lavaan::lavInspect(basis1, add.labels = TRUE, "mean.lv")
## Intercept     Shape 
##     1.265     0.032
# residuals
lavaan::residuals(basis1, type = "raw")
## $type
## [1] "raw"
## 
## $cov
##            anx_T1 anx_T2 anx_T3 anx_T4
## anxiety_T1  0.000                     
## anxiety_T2 -0.010 -0.008              
## anxiety_T3  0.012 -0.004 -0.002       
## anxiety_T4  0.007  0.009  0.013  0.013
## 
## $mean
## anxiety_T1 anxiety_T2 anxiety_T3 anxiety_T4 
##     -0.002      0.035     -0.087      0.042
lavaan::residuals(basis1, type = "standardized")
## $type
## [1] "standardized"
## 
## $cov
##            anx_T1 anx_T2 anx_T3 anx_T4
## anxiety_T1  0.181                     
## anxiety_T2 -1.173 -0.579              
## anxiety_T3  1.114 -0.341 -0.124       
## anxiety_T4  0.411  0.541  0.585  0.546
## 
## $mean
## anxiety_T1 anxiety_T2 anxiety_T3 anxiety_T4 
##     -0.920      1.666     -3.091      1.133
lavaan::residuals(basis1, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##            anx_T1 anx_T2 anx_T3 anx_T4
## anxiety_T1  0.000                     
## anxiety_T2 -0.027  0.000              
## anxiety_T3  0.037 -0.004  0.000       
## anxiety_T4  0.007  0.033  0.034  0.000
## 
## $mean
## anxiety_T1 anxiety_T2 anxiety_T3 anxiety_T4 
##     -0.004      0.078     -0.162      0.077
# model 3 parameter estimates, global fit statistics,
# residuals
lavaan::summary(linear1, fit.measures = TRUE, estimates = TRUE)
## lavaan 0.6.17 ended normally after 64 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        12
## 
##                                                   Used       Total
##   Number of observations                            57         540
##   Number of missing patterns                         1            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                80.843      78.461
##   Degrees of freedom                                18          18
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.030
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                               139.834     137.466
##   Degrees of freedom                                22          22
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.017
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.467       0.476
##   Tucker-Lewis Index (TLI)                       0.348       0.360
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.468
##   Robust Tucker-Lewis Index (TLI)                            0.349
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)                -51.859     -51.859
##   Scaling correction factor                                  1.319
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)        -11.437     -11.437
##   Scaling correction factor                                  1.146
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                 127.717     127.717
##   Bayesian (BIC)                               152.234     152.234
##   Sample-size adjusted Bayesian (SABIC)        114.511     114.511
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.247       0.243
##   90 Percent confidence interval - lower         0.194       0.190
##   90 Percent confidence interval - upper         0.304       0.298
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    1.000       1.000
##                                                                   
##   Robust RMSEA                                               0.242
##   90 Percent confidence interval - lower                     0.185
##   90 Percent confidence interval - upper                     0.303
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.218       0.218
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     anxiety_T1        1.000                           
##     anxiety_T2        1.000                           
##     anxiety_T3        1.000                           
##     anxiety_T4        1.000                           
##   Linear =~                                           
##     anxiety_T1        0.000                           
##     anxiety_T2        1.000                           
##     anxiety_T3        2.000                           
##     anxiety_T4        3.000                           
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   anxiety_T1 ~                                        
##     CASI_ADHD_CSum    0.069    0.016    4.253    0.000
##   anxiety_T2 ~                                        
##     CASI_ADHD_CS_T    0.081    0.015    5.250    0.000
##   anxiety_T3 ~                                        
##     CASI_ADHD_CS_T    0.059    0.012    4.865    0.000
##   anxiety_T4 ~                                        
##     CASI_ADHDCS_T4    0.074    0.016    4.607    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~~                                        
##     Linear           -0.043    0.011   -3.822    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Intercept         0.677    0.207    3.269    0.001
##     Linear           -0.214    0.119   -1.796    0.072
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .anxiety_T1        0.000                           
##    .anxiety_T2        0.080    0.017    4.610    0.000
##    .anxiety_T3        0.055    0.013    4.344    0.000
##    .anxiety_T4        0.168    0.039    4.302    0.000
##     Intercept         0.094    0.022    4.264    0.000
##     Linear            0.020    0.006    3.265    0.001
lavaan::fitted(linear1) 
## $cov
##                   anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## anxiety_T1         0.136                                                   
## anxiety_T2         0.069  0.160                                            
## anxiety_T3         0.012  0.027  0.091                                     
## anxiety_T4        -0.034  0.004  0.010  0.236                              
## CASI_ADHD_CSum     0.608  0.260  0.051  0.010         8.857                
## CASI_ADHD_CSum_T2  0.222  0.638  0.268  0.273         3.229           7.917
## CASI_ADHD_CSum_T3  0.059  0.366  0.585  0.182         0.861           4.546
## CASI_ADHDCSum_T4   0.009  0.296  0.144  0.704         0.133           3.675
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## anxiety_T1                                  
## anxiety_T2                                  
## anxiety_T3                                  
## anxiety_T4                                  
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           9.921           
## CASI_ADHDCSum_T4            2.447      9.469
## 
## $mean
##        anxiety_T1        anxiety_T2        anxiety_T3        anxiety_T4 
##             1.579             1.460             1.405             1.517 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##            13.140            12.368            19.614            19.930
lavaan::residuals(linear1, type = "raw")
## $type
## [1] "raw"
## 
## $cov
##                   anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## anxiety_T1        -0.010                                                   
## anxiety_T2        -0.048 -0.057                                            
## anxiety_T3         0.006  0.013  0.027                                     
## anxiety_T4         0.071  0.052  0.013 -0.103                              
## CASI_ADHD_CSum    -0.074  0.005  0.028  0.267         0.000                
## CASI_ADHD_CSum_T2  0.057  0.002  0.146  0.203         0.000           0.000
## CASI_ADHD_CSum_T3  0.141 -0.135  0.237  0.039         0.000           0.000
## CASI_ADHDCSum_T4   0.092  0.114  0.139 -0.456         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## anxiety_T1                                  
## anxiety_T2                                  
## anxiety_T3                                  
## anxiety_T4                                  
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##        anxiety_T1        anxiety_T2        anxiety_T3        anxiety_T4 
##             0.000             0.003            -0.011             0.021 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
lavaan::residuals(linear1, type = "standardized")
## $type
## [1] "standardized"
## 
## $cov
##                   anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## anxiety_T1        -0.301                                                   
## anxiety_T2        -1.408 -1.052                                            
## anxiety_T3         0.464  1.187  3.771                                     
## anxiety_T4         2.248  2.445  0.541 -1.402                              
## CASI_ADHD_CSum    -1.045  0.065  0.292  1.921         0.000                
## CASI_ADHD_CSum_T2  0.431  0.021  1.458  1.235         0.000           0.000
## CASI_ADHD_CSum_T3  0.993 -1.514  2.951  0.223         0.000           0.000
## CASI_ADHDCSum_T4   0.630  1.430  1.242 -3.063         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## anxiety_T1                                  
## anxiety_T2                                  
## anxiety_T3                                  
## anxiety_T4                                  
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##        anxiety_T1        anxiety_T2        anxiety_T3        anxiety_T4 
##             0.000             0.188            -2.689             2.026 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
lavaan::residuals(linear1, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##                   anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm CASI_ADHD_CS_T2
## anxiety_T1         0.000                                                   
## anxiety_T2        -0.280  0.000                                            
## anxiety_T3         0.038  0.140  0.000                                     
## anxiety_T4         0.478  0.461  0.114  0.000                              
## CASI_ADHD_CSum    -0.048  0.059  0.020  0.249         0.000                
## CASI_ADHD_CSum_T2  0.066  0.142  0.112  0.264         0.000           0.000
## CASI_ADHD_CSum_T3  0.128 -0.062  0.144  0.074         0.000           0.000
## CASI_ADHDCSum_T4   0.085  0.175  0.112 -0.250         0.000           0.000
##                   CASI_ADHD_CS_T3 CASI_ADHDC
## anxiety_T1                                  
## anxiety_T2                                  
## anxiety_T3                                  
## anxiety_T4                                  
## CASI_ADHD_CSum                              
## CASI_ADHD_CSum_T2                           
## CASI_ADHD_CSum_T3           0.000           
## CASI_ADHDCSum_T4            0.000      0.000
## 
## $mean
##        anxiety_T1        anxiety_T2        anxiety_T3        anxiety_T4 
##             0.000             0.008            -0.033             0.058 
##    CASI_ADHD_CSum CASI_ADHD_CSum_T2 CASI_ADHD_CSum_T3  CASI_ADHDCSum_T4 
##             0.000             0.000             0.000             0.000
#standardized estimates
standardizedSolution(linear1, type = "std.all",  se= TRUE, pvalue = TRUE)
##                  lhs op               rhs est.std    se       z pvalue ci.lower
## 1          Intercept =~        anxiety_T1   0.833 0.070  11.919  0.000    0.696
## 2          Intercept =~        anxiety_T2   0.768 0.074  10.346  0.000    0.623
## 3          Intercept =~        anxiety_T3   1.015 0.138   7.382  0.000    0.746
## 4          Intercept =~        anxiety_T4   0.632 0.074   8.517  0.000    0.487
## 5             Linear =~        anxiety_T1   0.000 0.000      NA     NA    0.000
## 6             Linear =~        anxiety_T2   0.353 0.057   6.247  0.000    0.242
## 7             Linear =~        anxiety_T3   0.933 0.167   5.590  0.000    0.606
## 8             Linear =~        anxiety_T4   0.872 0.094   9.244  0.000    0.687
## 9         anxiety_T1 ~~        anxiety_T1   0.000 0.000      NA     NA    0.000
## 10        anxiety_T1  ~    CASI_ADHD_CSum   0.554 0.105   5.278  0.000    0.348
## 11        anxiety_T2  ~ CASI_ADHD_CSum_T2   0.568 0.088   6.417  0.000    0.394
## 12        anxiety_T3  ~ CASI_ADHD_CSum_T3   0.614 0.094   6.564  0.000    0.431
## 13        anxiety_T4  ~  CASI_ADHDCSum_T4   0.471 0.076   6.199  0.000    0.322
## 14        anxiety_T2 ~~        anxiety_T2   0.501 0.083   6.041  0.000    0.338
## 15        anxiety_T3 ~~        anxiety_T3   0.601 0.121   4.973  0.000    0.364
## 16        anxiety_T4 ~~        anxiety_T4   0.712 0.095   7.514  0.000    0.526
## 17         Intercept ~~         Intercept   1.000 0.000      NA     NA    1.000
## 18            Linear ~~            Linear   1.000 0.000      NA     NA    1.000
## 19         Intercept ~~            Linear  -0.992 0.043 -22.894  0.000   -1.077
## 20    CASI_ADHD_CSum ~~    CASI_ADHD_CSum   1.000 0.000      NA     NA    1.000
## 21    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2   0.386 0.000      NA     NA    0.386
## 22    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3   0.092 0.000      NA     NA    0.092
## 23    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4   0.014 0.000      NA     NA    0.014
## 24 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2   1.000 0.000      NA     NA    1.000
## 25 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3   0.513 0.000      NA     NA    0.513
## 26 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4   0.424 0.000      NA     NA    0.424
## 27 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3   1.000 0.000      NA     NA    1.000
## 28 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4   0.252 0.000      NA     NA    0.252
## 29  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4   1.000 0.000      NA     NA    1.000
## 30        anxiety_T1 ~1                     0.000 0.000      NA     NA    0.000
## 31        anxiety_T2 ~1                     0.000 0.000      NA     NA    0.000
## 32        anxiety_T3 ~1                     0.000 0.000      NA     NA    0.000
## 33        anxiety_T4 ~1                     0.000 0.000      NA     NA    0.000
## 34    CASI_ADHD_CSum ~1                     4.415 0.000      NA     NA    4.415
## 35 CASI_ADHD_CSum_T2 ~1                     4.396 0.000      NA     NA    4.396
## 36 CASI_ADHD_CSum_T3 ~1                     6.227 0.000      NA     NA    6.227
## 37  CASI_ADHDCSum_T4 ~1                     6.477 0.000      NA     NA    6.477
## 38         Intercept ~1                     2.206 0.695   3.176  0.001    0.845
## 39            Linear ~1                    -1.518 0.751  -2.023  0.043   -2.990
##    ci.upper
## 1     0.969
## 2     0.914
## 3     1.285
## 4     0.778
## 5     0.000
## 6     0.464
## 7     1.260
## 8     1.056
## 9     0.000
## 10    0.760
## 11    0.741
## 12    0.797
## 13    0.620
## 14    0.663
## 15    0.838
## 16    0.898
## 17    1.000
## 18    1.000
## 19   -0.907
## 20    1.000
## 21    0.386
## 22    0.092
## 23    0.014
## 24    1.000
## 25    0.513
## 26    0.424
## 27    1.000
## 28    0.252
## 29    1.000
## 30    0.000
## 31    0.000
## 32    0.000
## 33    0.000
## 34    4.415
## 35    4.396
## 36    6.227
## 37    6.477
## 38    3.567
## 39   -0.047
#unstandardized estimates
parameterEstimates(linear1)
##                  lhs op               rhs    est    se      z pvalue ci.lower
## 1          Intercept =~        anxiety_T1  1.000 0.000     NA     NA    1.000
## 2          Intercept =~        anxiety_T2  1.000 0.000     NA     NA    1.000
## 3          Intercept =~        anxiety_T3  1.000 0.000     NA     NA    1.000
## 4          Intercept =~        anxiety_T4  1.000 0.000     NA     NA    1.000
## 5             Linear =~        anxiety_T1  0.000 0.000     NA     NA    0.000
## 6             Linear =~        anxiety_T2  1.000 0.000     NA     NA    1.000
## 7             Linear =~        anxiety_T3  2.000 0.000     NA     NA    2.000
## 8             Linear =~        anxiety_T4  3.000 0.000     NA     NA    3.000
## 9         anxiety_T1 ~~        anxiety_T1  0.000 0.000     NA     NA    0.000
## 10        anxiety_T1  ~    CASI_ADHD_CSum  0.069 0.016  4.253  0.000    0.037
## 11        anxiety_T2  ~ CASI_ADHD_CSum_T2  0.081 0.015  5.250  0.000    0.051
## 12        anxiety_T3  ~ CASI_ADHD_CSum_T3  0.059 0.012  4.865  0.000    0.035
## 13        anxiety_T4  ~  CASI_ADHDCSum_T4  0.074 0.016  4.607  0.000    0.043
## 14        anxiety_T2 ~~        anxiety_T2  0.080 0.017  4.610  0.000    0.046
## 15        anxiety_T3 ~~        anxiety_T3  0.055 0.013  4.344  0.000    0.030
## 16        anxiety_T4 ~~        anxiety_T4  0.168 0.039  4.302  0.000    0.091
## 17         Intercept ~~         Intercept  0.094 0.022  4.264  0.000    0.051
## 18            Linear ~~            Linear  0.020 0.006  3.265  0.001    0.008
## 19         Intercept ~~            Linear -0.043 0.011 -3.822  0.000   -0.065
## 20    CASI_ADHD_CSum ~~    CASI_ADHD_CSum  8.857 0.000     NA     NA    8.857
## 21    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2  3.229 0.000     NA     NA    3.229
## 22    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3  0.861 0.000     NA     NA    0.861
## 23    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4  0.133 0.000     NA     NA    0.133
## 24 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2  7.917 0.000     NA     NA    7.917
## 25 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3  4.546 0.000     NA     NA    4.546
## 26 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4  3.675 0.000     NA     NA    3.675
## 27 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3  9.921 0.000     NA     NA    9.921
## 28 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4  2.447 0.000     NA     NA    2.447
## 29  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4  9.469 0.000     NA     NA    9.469
## 30        anxiety_T1 ~1                    0.000 0.000     NA     NA    0.000
## 31        anxiety_T2 ~1                    0.000 0.000     NA     NA    0.000
## 32        anxiety_T3 ~1                    0.000 0.000     NA     NA    0.000
## 33        anxiety_T4 ~1                    0.000 0.000     NA     NA    0.000
## 34    CASI_ADHD_CSum ~1                   13.140 0.000     NA     NA   13.140
## 35 CASI_ADHD_CSum_T2 ~1                   12.368 0.000     NA     NA   12.368
## 36 CASI_ADHD_CSum_T3 ~1                   19.614 0.000     NA     NA   19.614
## 37  CASI_ADHDCSum_T4 ~1                   19.930 0.000     NA     NA   19.930
## 38         Intercept ~1                    0.677 0.207  3.269  0.001    0.271
## 39            Linear ~1                   -0.214 0.119 -1.796  0.072   -0.448
##    ci.upper
## 1     1.000
## 2     1.000
## 3     1.000
## 4     1.000
## 5     0.000
## 6     1.000
## 7     2.000
## 8     3.000
## 9     0.000
## 10    0.100
## 11    0.111
## 12    0.083
## 13    0.106
## 14    0.114
## 15    0.080
## 16    0.244
## 17    0.138
## 18    0.032
## 19   -0.021
## 20    8.857
## 21    3.229
## 22    0.861
## 23    0.133
## 24    7.917
## 25    4.546
## 26    3.675
## 27    9.921
## 28    2.447
## 29    9.469
## 30    0.000
## 31    0.000
## 32    0.000
## 33    0.000
## 34   13.140
## 35   12.368
## 36   19.614
## 37   19.930
## 38    1.083
## 39    0.019
#########################################################################################################
#with socio-demographic covariates
#########################################################################################################

predict.model3 <- '
# latent growth factors
 Intercept =~ 1*anxiety_T1 + 1*anxiety_T2 + 1*anxiety_T3 + 1*anxiety_T4
 Linear =~ 0*anxiety_T1 + 1*anxiety_T2 + 2*anxiety_T3 + 3*anxiety_T4
# covariates
 Intercept ~ CASI_ADHD_CSum + CASI_ADHD_CSum_T2 + CASI_ADHD_CSum_T3 + 
           CASI_ADHDCSum_T4 + Academicperformance_total_T4 +
           Familyincome_T1r + Educationhousehold  +  Child_gender + Childagecategory
 Linear ~ CASI_ADHD_CSum + CASI_ADHD_CSum_T2 + CASI_ADHD_CSum_T3 + 
           CASI_ADHDCSum_T4 + Academicperformance_total_T4 +
           Familyincome_T1r + Educationhousehold  +  Child_gender + Childagecategory
# observed variables regressed on the time-varying covariate
                    anxiety_T1 ~ CASI_ADHD_CSum
                    anxiety_T2 ~ CASI_ADHD_CSum_T2
                    anxiety_T3 ~ CASI_ADHD_CSum_T3
                    anxiety_T4 ~ CASI_ADHDCSum_T4'

# fit prediction model to data
predict3 <- lavaan::growth(predict.model3, data=mydata, missing = "fiml", estimator = "mlr")
lavaan::summary(predict3, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6.17 ended normally after 124 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        31
## 
##                                                   Used       Total
##   Number of observations                            56         540
##   Number of missing patterns                         1            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                38.273      42.037
##   Degrees of freedom                                19          19
##   P-value (Chi-square)                           0.005       0.002
##   Scaling correction factor                                  0.910
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                               195.098     223.533
##   Degrees of freedom                                42          42
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  0.873
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.874       0.873
##   Tucker-Lewis Index (TLI)                       0.722       0.719
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.863
##   Robust Tucker-Lewis Index (TLI)                            0.698
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)                 -1.770      -1.770
##   Scaling correction factor                                  1.013
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)         17.367      17.367
##   Scaling correction factor                                  0.974
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                  65.539      65.539
##   Bayesian (BIC)                               128.325     128.325
##   Sample-size adjusted Bayesian (SABIC)         30.893      30.893
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.135       0.147
##   90 Percent confidence interval - lower         0.071       0.084
##   90 Percent confidence interval - upper         0.196       0.210
##   P-value H_0: RMSEA <= 0.050                    0.020       0.010
##   P-value H_0: RMSEA >= 0.080                    0.926       0.958
##                                                                   
##   Robust RMSEA                                               0.141
##   90 Percent confidence interval - lower                     0.085
##   90 Percent confidence interval - upper                     0.198
##   P-value H_0: Robust RMSEA <= 0.050                         0.007
##   P-value H_0: Robust RMSEA >= 0.080                         0.961
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.063       0.063
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     anxiety_T1        1.000                           
##     anxiety_T2        1.000                           
##     anxiety_T3        1.000                           
##     anxiety_T4        1.000                           
##   Linear =~                                           
##     anxiety_T1        0.000                           
##     anxiety_T2        1.000                           
##     anxiety_T3        2.000                           
##     anxiety_T4        3.000                           
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~                                         
##     CASI_ADHD_CSum   -0.023    0.015   -1.519    0.129
##     CASI_ADHD_CS_T   -0.020    0.014   -1.388    0.165
##     CASI_ADHD_CS_T    0.007    0.008    0.902    0.367
##     CASI_ADHDCS_T4    0.025    0.009    2.937    0.003
##     Acdmcprfrm__T4    0.042    0.024    1.725    0.085
##     Familyincm_T1r   -0.104    0.022   -4.677    0.000
##     Educationhshld   -0.023    0.048   -0.488    0.625
##     Child_gender     -0.028    0.063   -0.442    0.658
##     Childagecatgry   -0.050    0.045   -1.101    0.271
##   Linear ~                                            
##     CASI_ADHD_CSum    0.009    0.007    1.209    0.226
##     CASI_ADHD_CS_T    0.028    0.007    3.766    0.000
##     CASI_ADHD_CS_T    0.005    0.005    0.986    0.324
##     CASI_ADHDCS_T4   -0.019    0.007   -2.719    0.007
##     Acdmcprfrm__T4   -0.026    0.014   -1.816    0.069
##     Familyincm_T1r    0.037    0.014    2.715    0.007
##     Educationhshld   -0.006    0.026   -0.229    0.819
##     Child_gender      0.031    0.037    0.851    0.395
##     Childagecatgry    0.007    0.023    0.300    0.764
##   anxiety_T1 ~                                        
##     CASI_ADHD_CSum    0.089    0.022    4.042    0.000
##   anxiety_T2 ~                                        
##     CASI_ADHD_CS_T    0.086    0.016    5.281    0.000
##   anxiety_T3 ~                                        
##     CASI_ADHD_CS_T    0.050    0.014    3.477    0.001
##   anxiety_T4 ~                                        
##     CASI_ADHDCS_T4    0.056    0.022    2.580    0.010
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .Intercept ~~                                        
##    .Linear            0.015    0.007    2.102    0.036
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .Intercept         0.736    0.355    2.071    0.038
##    .Linear           -0.230    0.182   -1.266    0.205
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .anxiety_T1        0.118    0.035    3.345    0.001
##    .anxiety_T2        0.047    0.012    3.880    0.000
##    .anxiety_T3        0.058    0.010    5.536    0.000
##    .anxiety_T4        0.103    0.023    4.408    0.000
##    .Intercept        -0.029    0.014   -2.123    0.034
##    .Linear           -0.009    0.004   -2.130    0.033
## 
## R-Square:
##                    Estimate
##     anxiety_T1        0.188
##     anxiety_T2        0.564
##     anxiety_T3        0.444
##     anxiety_T4        0.241
##     Intercept            NA
##     Linear               NA
#standardized estimates
standardizedSolution(predict3, type = "std.all",  se= TRUE, pvalue = TRUE)
##                             lhs op                          rhs est.std    se
## 1                     Intercept =~                   anxiety_T1      NA    NA
## 2                     Intercept =~                   anxiety_T2      NA    NA
## 3                     Intercept =~                   anxiety_T3      NA    NA
## 4                     Intercept =~                   anxiety_T4      NA    NA
## 5                        Linear =~                   anxiety_T1      NA    NA
## 6                        Linear =~                   anxiety_T2      NA    NA
## 7                        Linear =~                   anxiety_T3      NA    NA
## 8                        Linear =~                   anxiety_T4      NA    NA
## 9                     Intercept  ~               CASI_ADHD_CSum      NA    NA
## 10                    Intercept  ~            CASI_ADHD_CSum_T2      NA    NA
## 11                    Intercept  ~            CASI_ADHD_CSum_T3      NA    NA
## 12                    Intercept  ~             CASI_ADHDCSum_T4      NA    NA
## 13                    Intercept  ~ Academicperformance_total_T4      NA    NA
## 14                    Intercept  ~             Familyincome_T1r      NA    NA
## 15                    Intercept  ~           Educationhousehold      NA    NA
## 16                    Intercept  ~                 Child_gender      NA    NA
## 17                    Intercept  ~             Childagecategory      NA    NA
## 18                       Linear  ~               CASI_ADHD_CSum      NA    NA
## 19                       Linear  ~            CASI_ADHD_CSum_T2      NA    NA
## 20                       Linear  ~            CASI_ADHD_CSum_T3      NA    NA
## 21                       Linear  ~             CASI_ADHDCSum_T4      NA    NA
## 22                       Linear  ~ Academicperformance_total_T4      NA    NA
## 23                       Linear  ~             Familyincome_T1r      NA    NA
## 24                       Linear  ~           Educationhousehold      NA    NA
## 25                       Linear  ~                 Child_gender      NA    NA
## 26                       Linear  ~             Childagecategory      NA    NA
## 27                   anxiety_T1  ~               CASI_ADHD_CSum   0.696 0.171
## 28                   anxiety_T2  ~            CASI_ADHD_CSum_T2   0.617 0.107
## 29                   anxiety_T3  ~            CASI_ADHD_CSum_T3   0.436 0.110
## 30                   anxiety_T4  ~             CASI_ADHDCSum_T4   0.469 0.181
## 31                   anxiety_T1 ~~                   anxiety_T1   0.812 0.136
## 32                   anxiety_T2 ~~                   anxiety_T2   0.436 0.100
## 33                   anxiety_T3 ~~                   anxiety_T3   0.556 0.075
## 34                   anxiety_T4 ~~                   anxiety_T4   0.759 0.124
## 35                    Intercept ~~                    Intercept      NA    NA
## 36                       Linear ~~                       Linear      NA    NA
## 37                    Intercept ~~                       Linear   0.917 0.063
## 38               CASI_ADHD_CSum ~~               CASI_ADHD_CSum   1.000 0.000
## 39               CASI_ADHD_CSum ~~            CASI_ADHD_CSum_T2   0.381 0.000
## 40               CASI_ADHD_CSum ~~            CASI_ADHD_CSum_T3   0.034 0.000
## 41               CASI_ADHD_CSum ~~             CASI_ADHDCSum_T4  -0.003 0.000
## 42               CASI_ADHD_CSum ~~ Academicperformance_total_T4  -0.169 0.000
## 43               CASI_ADHD_CSum ~~             Familyincome_T1r  -0.335 0.000
## 44               CASI_ADHD_CSum ~~           Educationhousehold  -0.269 0.000
## 45               CASI_ADHD_CSum ~~                 Child_gender   0.282 0.000
## 46               CASI_ADHD_CSum ~~             Childagecategory   0.100 0.000
## 47            CASI_ADHD_CSum_T2 ~~            CASI_ADHD_CSum_T2   1.000 0.000
## 48            CASI_ADHD_CSum_T2 ~~            CASI_ADHD_CSum_T3   0.337 0.000
## 49            CASI_ADHD_CSum_T2 ~~             CASI_ADHDCSum_T4   0.425 0.000
## 50            CASI_ADHD_CSum_T2 ~~ Academicperformance_total_T4   0.098 0.000
## 51            CASI_ADHD_CSum_T2 ~~             Familyincome_T1r  -0.286 0.000
## 52            CASI_ADHD_CSum_T2 ~~           Educationhousehold  -0.331 0.000
## 53            CASI_ADHD_CSum_T2 ~~                 Child_gender   0.083 0.000
## 54            CASI_ADHD_CSum_T2 ~~             Childagecategory   0.107 0.000
## 55            CASI_ADHD_CSum_T3 ~~            CASI_ADHD_CSum_T3   1.000 0.000
## 56            CASI_ADHD_CSum_T3 ~~             CASI_ADHDCSum_T4   0.217 0.000
## 57            CASI_ADHD_CSum_T3 ~~ Academicperformance_total_T4   0.015 0.000
## 58            CASI_ADHD_CSum_T3 ~~             Familyincome_T1r   0.073 0.000
## 59            CASI_ADHD_CSum_T3 ~~           Educationhousehold  -0.235 0.000
## 60            CASI_ADHD_CSum_T3 ~~                 Child_gender  -0.237 0.000
## 61            CASI_ADHD_CSum_T3 ~~             Childagecategory   0.154 0.000
## 62             CASI_ADHDCSum_T4 ~~             CASI_ADHDCSum_T4   1.000 0.000
## 63             CASI_ADHDCSum_T4 ~~ Academicperformance_total_T4   0.123 0.000
## 64             CASI_ADHDCSum_T4 ~~             Familyincome_T1r  -0.038 0.000
## 65             CASI_ADHDCSum_T4 ~~           Educationhousehold  -0.216 0.000
## 66             CASI_ADHDCSum_T4 ~~                 Child_gender  -0.168 0.000
## 67             CASI_ADHDCSum_T4 ~~             Childagecategory   0.238 0.000
## 68 Academicperformance_total_T4 ~~ Academicperformance_total_T4   1.000 0.000
## 69 Academicperformance_total_T4 ~~             Familyincome_T1r   0.190 0.000
## 70 Academicperformance_total_T4 ~~           Educationhousehold  -0.162 0.000
## 71 Academicperformance_total_T4 ~~                 Child_gender  -0.016 0.000
## 72 Academicperformance_total_T4 ~~             Childagecategory   0.006 0.000
## 73             Familyincome_T1r ~~             Familyincome_T1r   1.000 0.000
## 74             Familyincome_T1r ~~           Educationhousehold   0.243 0.000
## 75             Familyincome_T1r ~~                 Child_gender  -0.113 0.000
## 76             Familyincome_T1r ~~             Childagecategory  -0.004 0.000
## 77           Educationhousehold ~~           Educationhousehold   1.000 0.000
## 78           Educationhousehold ~~                 Child_gender   0.318 0.000
## 79           Educationhousehold ~~             Childagecategory   0.107 0.000
## 80                 Child_gender ~~                 Child_gender   1.000 0.000
## 81                 Child_gender ~~             Childagecategory   0.037 0.000
## 82             Childagecategory ~~             Childagecategory   1.000 0.000
## 83                   anxiety_T1 ~1                                0.000 0.000
## 84                   anxiety_T2 ~1                                0.000 0.000
## 85                   anxiety_T3 ~1                                0.000 0.000
## 86                   anxiety_T4 ~1                                0.000 0.000
## 87               CASI_ADHD_CSum ~1                                4.396 0.000
## 88            CASI_ADHD_CSum_T2 ~1                                5.139 0.000
## 89            CASI_ADHD_CSum_T3 ~1                                6.976 0.000
## 90             CASI_ADHDCSum_T4 ~1                                6.460 0.000
## 91 Academicperformance_total_T4 ~1                                2.644 0.000
## 92             Familyincome_T1r ~1                                2.685 0.000
## 93           Educationhousehold ~1                                6.238 0.000
## 94                 Child_gender ~1                                3.000 0.000
## 95             Childagecategory ~1                                5.855 0.000
## 96                    Intercept ~1                                   NA    NA
## 97                       Linear ~1                                   NA    NA
##         z pvalue ci.lower ci.upper
## 1      NA     NA       NA       NA
## 2      NA     NA       NA       NA
## 3      NA     NA       NA       NA
## 4      NA     NA       NA       NA
## 5      NA     NA       NA       NA
## 6      NA     NA       NA       NA
## 7      NA     NA       NA       NA
## 8      NA     NA       NA       NA
## 9      NA     NA       NA       NA
## 10     NA     NA       NA       NA
## 11     NA     NA       NA       NA
## 12     NA     NA       NA       NA
## 13     NA     NA       NA       NA
## 14     NA     NA       NA       NA
## 15     NA     NA       NA       NA
## 16     NA     NA       NA       NA
## 17     NA     NA       NA       NA
## 18     NA     NA       NA       NA
## 19     NA     NA       NA       NA
## 20     NA     NA       NA       NA
## 21     NA     NA       NA       NA
## 22     NA     NA       NA       NA
## 23     NA     NA       NA       NA
## 24     NA     NA       NA       NA
## 25     NA     NA       NA       NA
## 26     NA     NA       NA       NA
## 27  4.083  0.000    0.362    1.031
## 28  5.745  0.000    0.407    0.828
## 29  3.951  0.000    0.220    0.652
## 30  2.596  0.009    0.115    0.823
## 31  5.972  0.000    0.546    1.079
## 32  4.360  0.000    0.240    0.633
## 33  7.441  0.000    0.410    0.703
## 34  6.128  0.000    0.516    1.002
## 35     NA     NA       NA       NA
## 36     NA     NA       NA       NA
## 37 14.597  0.000    0.794    1.041
## 38     NA     NA    1.000    1.000
## 39     NA     NA    0.381    0.381
## 40     NA     NA    0.034    0.034
## 41     NA     NA   -0.003   -0.003
## 42     NA     NA   -0.169   -0.169
## 43     NA     NA   -0.335   -0.335
## 44     NA     NA   -0.269   -0.269
## 45     NA     NA    0.282    0.282
## 46     NA     NA    0.100    0.100
## 47     NA     NA    1.000    1.000
## 48     NA     NA    0.337    0.337
## 49     NA     NA    0.425    0.425
## 50     NA     NA    0.098    0.098
## 51     NA     NA   -0.286   -0.286
## 52     NA     NA   -0.331   -0.331
## 53     NA     NA    0.083    0.083
## 54     NA     NA    0.107    0.107
## 55     NA     NA    1.000    1.000
## 56     NA     NA    0.217    0.217
## 57     NA     NA    0.015    0.015
## 58     NA     NA    0.073    0.073
## 59     NA     NA   -0.235   -0.235
## 60     NA     NA   -0.237   -0.237
## 61     NA     NA    0.154    0.154
## 62     NA     NA    1.000    1.000
## 63     NA     NA    0.123    0.123
## 64     NA     NA   -0.038   -0.038
## 65     NA     NA   -0.216   -0.216
## 66     NA     NA   -0.168   -0.168
## 67     NA     NA    0.238    0.238
## 68     NA     NA    1.000    1.000
## 69     NA     NA    0.190    0.190
## 70     NA     NA   -0.162   -0.162
## 71     NA     NA   -0.016   -0.016
## 72     NA     NA    0.006    0.006
## 73     NA     NA    1.000    1.000
## 74     NA     NA    0.243    0.243
## 75     NA     NA   -0.113   -0.113
## 76     NA     NA   -0.004   -0.004
## 77     NA     NA    1.000    1.000
## 78     NA     NA    0.318    0.318
## 79     NA     NA    0.107    0.107
## 80     NA     NA    1.000    1.000
## 81     NA     NA    0.037    0.037
## 82     NA     NA    1.000    1.000
## 83     NA     NA    0.000    0.000
## 84     NA     NA    0.000    0.000
## 85     NA     NA    0.000    0.000
## 86     NA     NA    0.000    0.000
## 87     NA     NA    4.396    4.396
## 88     NA     NA    5.139    5.139
## 89     NA     NA    6.976    6.976
## 90     NA     NA    6.460    6.460
## 91     NA     NA    2.644    2.644
## 92     NA     NA    2.685    2.685
## 93     NA     NA    6.238    6.238
## 94     NA     NA    3.000    3.000
## 95     NA     NA    5.855    5.855
## 96     NA     NA       NA       NA
## 97     NA     NA       NA       NA
#unstandardized estimates
parameterEstimates(predict3)
##                             lhs op                          rhs    est    se
## 1                     Intercept =~                   anxiety_T1  1.000 0.000
## 2                     Intercept =~                   anxiety_T2  1.000 0.000
## 3                     Intercept =~                   anxiety_T3  1.000 0.000
## 4                     Intercept =~                   anxiety_T4  1.000 0.000
## 5                        Linear =~                   anxiety_T1  0.000 0.000
## 6                        Linear =~                   anxiety_T2  1.000 0.000
## 7                        Linear =~                   anxiety_T3  2.000 0.000
## 8                        Linear =~                   anxiety_T4  3.000 0.000
## 9                     Intercept  ~               CASI_ADHD_CSum -0.023 0.015
## 10                    Intercept  ~            CASI_ADHD_CSum_T2 -0.020 0.014
## 11                    Intercept  ~            CASI_ADHD_CSum_T3  0.007 0.008
## 12                    Intercept  ~             CASI_ADHDCSum_T4  0.025 0.009
## 13                    Intercept  ~ Academicperformance_total_T4  0.042 0.024
## 14                    Intercept  ~             Familyincome_T1r -0.104 0.022
## 15                    Intercept  ~           Educationhousehold -0.023 0.048
## 16                    Intercept  ~                 Child_gender -0.028 0.063
## 17                    Intercept  ~             Childagecategory -0.050 0.045
## 18                       Linear  ~               CASI_ADHD_CSum  0.009 0.007
## 19                       Linear  ~            CASI_ADHD_CSum_T2  0.028 0.007
## 20                       Linear  ~            CASI_ADHD_CSum_T3  0.005 0.005
## 21                       Linear  ~             CASI_ADHDCSum_T4 -0.019 0.007
## 22                       Linear  ~ Academicperformance_total_T4 -0.026 0.014
## 23                       Linear  ~             Familyincome_T1r  0.037 0.014
## 24                       Linear  ~           Educationhousehold -0.006 0.026
## 25                       Linear  ~                 Child_gender  0.031 0.037
## 26                       Linear  ~             Childagecategory  0.007 0.023
## 27                   anxiety_T1  ~               CASI_ADHD_CSum  0.089 0.022
## 28                   anxiety_T2  ~            CASI_ADHD_CSum_T2  0.086 0.016
## 29                   anxiety_T3  ~            CASI_ADHD_CSum_T3  0.050 0.014
## 30                   anxiety_T4  ~             CASI_ADHDCSum_T4  0.056 0.022
## 31                   anxiety_T1 ~~                   anxiety_T1  0.118 0.035
## 32                   anxiety_T2 ~~                   anxiety_T2  0.047 0.012
## 33                   anxiety_T3 ~~                   anxiety_T3  0.058 0.010
## 34                   anxiety_T4 ~~                   anxiety_T4  0.103 0.023
## 35                    Intercept ~~                    Intercept -0.029 0.014
## 36                       Linear ~~                       Linear -0.009 0.004
## 37                    Intercept ~~                       Linear  0.015 0.007
## 38               CASI_ADHD_CSum ~~               CASI_ADHD_CSum  8.867 0.000
## 39               CASI_ADHD_CSum ~~            CASI_ADHD_CSum_T2  2.682 0.000
## 40               CASI_ADHD_CSum ~~            CASI_ADHD_CSum_T3  0.285 0.000
## 41               CASI_ADHD_CSum ~~             CASI_ADHDCSum_T4 -0.025 0.000
## 42               CASI_ADHD_CSum ~~ Academicperformance_total_T4 -0.573 0.000
## 43               CASI_ADHD_CSum ~~             Familyincome_T1r -0.941 0.000
## 44               CASI_ADHD_CSum ~~           Educationhousehold -0.585 0.000
## 45               CASI_ADHD_CSum ~~                 Child_gender  0.420 0.000
## 46               CASI_ADHD_CSum ~~             Childagecategory  0.143 0.000
## 47            CASI_ADHD_CSum_T2 ~~            CASI_ADHD_CSum_T2  5.599 0.000
## 48            CASI_ADHD_CSum_T2 ~~            CASI_ADHD_CSum_T3  2.220 0.000
## 49            CASI_ADHD_CSum_T2 ~~             CASI_ADHDCSum_T4  3.092 0.000
## 50            CASI_ADHD_CSum_T2 ~~ Academicperformance_total_T4  0.265 0.000
## 51            CASI_ADHD_CSum_T2 ~~             Familyincome_T1r -0.640 0.000
## 52            CASI_ADHD_CSum_T2 ~~           Educationhousehold -0.571 0.000
## 53            CASI_ADHD_CSum_T2 ~~                 Child_gender  0.098 0.000
## 54            CASI_ADHD_CSum_T2 ~~             Childagecategory  0.121 0.000
## 55            CASI_ADHD_CSum_T3 ~~            CASI_ADHD_CSum_T3  7.742 0.000
## 56            CASI_ADHD_CSum_T3 ~~             CASI_ADHDCSum_T4  1.855 0.000
## 57            CASI_ADHD_CSum_T3 ~~ Academicperformance_total_T4  0.046 0.000
## 58            CASI_ADHD_CSum_T3 ~~             Familyincome_T1r  0.191 0.000
## 59            CASI_ADHD_CSum_T3 ~~           Educationhousehold -0.477 0.000
## 60            CASI_ADHD_CSum_T3 ~~                 Child_gender -0.330 0.000
## 61            CASI_ADHD_CSum_T3 ~~             Childagecategory  0.206 0.000
## 62             CASI_ADHDCSum_T4 ~~             CASI_ADHDCSum_T4  9.467 0.000
## 63             CASI_ADHDCSum_T4 ~~ Academicperformance_total_T4  0.431 0.000
## 64             CASI_ADHDCSum_T4 ~~             Familyincome_T1r -0.112 0.000
## 65             CASI_ADHDCSum_T4 ~~           Educationhousehold -0.484 0.000
## 66             CASI_ADHDCSum_T4 ~~                 Child_gender -0.259 0.000
## 67             CASI_ADHDCSum_T4 ~~             Childagecategory  0.350 0.000
## 68 Academicperformance_total_T4 ~~ Academicperformance_total_T4  1.303 0.000
## 69 Academicperformance_total_T4 ~~             Familyincome_T1r  0.205 0.000
## 70 Academicperformance_total_T4 ~~           Educationhousehold -0.135 0.000
## 71 Academicperformance_total_T4 ~~                 Child_gender -0.009 0.000
## 72 Academicperformance_total_T4 ~~             Childagecategory  0.004 0.000
## 73             Familyincome_T1r ~~             Familyincome_T1r  0.892 0.000
## 74             Familyincome_T1r ~~           Educationhousehold  0.168 0.000
## 75             Familyincome_T1r ~~                 Child_gender -0.054 0.000
## 76             Familyincome_T1r ~~             Childagecategory -0.002 0.000
## 77           Educationhousehold ~~           Educationhousehold  0.533 0.000
## 78           Educationhousehold ~~                 Child_gender  0.116 0.000
## 79           Educationhousehold ~~             Childagecategory  0.037 0.000
## 80                 Child_gender ~~                 Child_gender  0.250 0.000
## 81                 Child_gender ~~             Childagecategory  0.009 0.000
## 82             Childagecategory ~~             Childagecategory  0.229 0.000
## 83                   anxiety_T1 ~1                               0.000 0.000
## 84                   anxiety_T2 ~1                               0.000 0.000
## 85                   anxiety_T3 ~1                               0.000 0.000
## 86                   anxiety_T4 ~1                               0.000 0.000
## 87               CASI_ADHD_CSum ~1                              13.089 0.000
## 88            CASI_ADHD_CSum_T2 ~1                              12.161 0.000
## 89            CASI_ADHD_CSum_T3 ~1                              19.411 0.000
## 90             CASI_ADHDCSum_T4 ~1                              19.875 0.000
## 91 Academicperformance_total_T4 ~1                               3.018 0.000
## 92             Familyincome_T1r ~1                               2.536 0.000
## 93           Educationhousehold ~1                               4.554 0.000
## 94                 Child_gender ~1                               1.500 0.000
## 95             Childagecategory ~1                               2.804 0.000
## 96                    Intercept ~1                               0.736 0.355
## 97                       Linear ~1                              -0.230 0.182
##         z pvalue ci.lower ci.upper
## 1      NA     NA    1.000    1.000
## 2      NA     NA    1.000    1.000
## 3      NA     NA    1.000    1.000
## 4      NA     NA    1.000    1.000
## 5      NA     NA    0.000    0.000
## 6      NA     NA    1.000    1.000
## 7      NA     NA    2.000    2.000
## 8      NA     NA    3.000    3.000
## 9  -1.519  0.129   -0.054    0.007
## 10 -1.388  0.165   -0.048    0.008
## 11  0.902  0.367   -0.009    0.023
## 12  2.937  0.003    0.008    0.042
## 13  1.725  0.085   -0.006    0.089
## 14 -4.677  0.000   -0.147   -0.060
## 15 -0.488  0.625   -0.117    0.070
## 16 -0.442  0.658   -0.150    0.095
## 17 -1.101  0.271   -0.138    0.039
## 18  1.209  0.226   -0.005    0.022
## 19  3.766  0.000    0.013    0.042
## 20  0.986  0.324   -0.005    0.016
## 21 -2.719  0.007   -0.033   -0.005
## 22 -1.816  0.069   -0.054    0.002
## 23  2.715  0.007    0.010    0.064
## 24 -0.229  0.819   -0.056    0.045
## 25  0.851  0.395   -0.041    0.103
## 26  0.300  0.764   -0.038    0.052
## 27  4.042  0.000    0.046    0.132
## 28  5.281  0.000    0.054    0.118
## 29  3.477  0.001    0.022    0.079
## 30  2.580  0.010    0.013    0.099
## 31  3.345  0.001    0.049    0.186
## 32  3.880  0.000    0.023    0.071
## 33  5.536  0.000    0.037    0.078
## 34  4.408  0.000    0.057    0.148
## 35 -2.123  0.034   -0.056   -0.002
## 36 -2.130  0.033   -0.018   -0.001
## 37  2.102  0.036    0.001    0.029
## 38     NA     NA    8.867    8.867
## 39     NA     NA    2.682    2.682
## 40     NA     NA    0.285    0.285
## 41     NA     NA   -0.025   -0.025
## 42     NA     NA   -0.573   -0.573
## 43     NA     NA   -0.941   -0.941
## 44     NA     NA   -0.585   -0.585
## 45     NA     NA    0.420    0.420
## 46     NA     NA    0.143    0.143
## 47     NA     NA    5.599    5.599
## 48     NA     NA    2.220    2.220
## 49     NA     NA    3.092    3.092
## 50     NA     NA    0.265    0.265
## 51     NA     NA   -0.640   -0.640
## 52     NA     NA   -0.571   -0.571
## 53     NA     NA    0.098    0.098
## 54     NA     NA    0.121    0.121
## 55     NA     NA    7.742    7.742
## 56     NA     NA    1.855    1.855
## 57     NA     NA    0.046    0.046
## 58     NA     NA    0.191    0.191
## 59     NA     NA   -0.477   -0.477
## 60     NA     NA   -0.330   -0.330
## 61     NA     NA    0.206    0.206
## 62     NA     NA    9.467    9.467
## 63     NA     NA    0.431    0.431
## 64     NA     NA   -0.112   -0.112
## 65     NA     NA   -0.484   -0.484
## 66     NA     NA   -0.259   -0.259
## 67     NA     NA    0.350    0.350
## 68     NA     NA    1.303    1.303
## 69     NA     NA    0.205    0.205
## 70     NA     NA   -0.135   -0.135
## 71     NA     NA   -0.009   -0.009
## 72     NA     NA    0.004    0.004
## 73     NA     NA    0.892    0.892
## 74     NA     NA    0.168    0.168
## 75     NA     NA   -0.054   -0.054
## 76     NA     NA   -0.002   -0.002
## 77     NA     NA    0.533    0.533
## 78     NA     NA    0.116    0.116
## 79     NA     NA    0.037    0.037
## 80     NA     NA    0.250    0.250
## 81     NA     NA    0.009    0.009
## 82     NA     NA    0.229    0.229
## 83     NA     NA    0.000    0.000
## 84     NA     NA    0.000    0.000
## 85     NA     NA    0.000    0.000
## 86     NA     NA    0.000    0.000
## 87     NA     NA   13.089   13.089
## 88     NA     NA   12.161   12.161
## 89     NA     NA   19.411   19.411
## 90     NA     NA   19.875   19.875
## 91     NA     NA    3.018    3.018
## 92     NA     NA    2.536    2.536
## 93     NA     NA    4.554    4.554
## 94     NA     NA    1.500    1.500
## 95     NA     NA    2.804    2.804
## 96  2.071  0.038    0.040    1.432
## 97 -1.266  0.205   -0.586    0.126
# predicted means and covariances for observed variables
lavaan::fitted(predict3)
## $cov
##                              anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm
## anxiety_T1                    0.145                                   
## anxiety_T2                    0.013  0.108                            
## anxiety_T3                    0.015  0.039  0.103                     
## anxiety_T4                    0.043  0.059  0.030  0.135              
## CASI_ADHD_CSum                0.599  0.190  0.123  0.257         8.867
## CASI_ADHD_CSum_T2             0.242  0.593  0.333  0.503         2.682
## CASI_ADHD_CSum_T3             0.071  0.306  0.575  0.359         0.285
## CASI_ADHDCSum_T4              0.221  0.387  0.113  0.449        -0.025
## Academicperformance_total_T4  0.004  0.047 -0.004 -0.013        -0.573
## Familyincome_T1r             -0.137 -0.106 -0.038 -0.052        -0.941
## Educationhousehold           -0.083 -0.084 -0.063 -0.070        -0.585
## Child_gender                  0.012 -0.002 -0.012  0.005         0.420
## Childagecategory              0.005  0.003  0.004  0.014         0.143
##                              CASI_ADHD_CS_T2 CASI_ADHD_CS_T3 CASI_ADHDC Ac__T4
## anxiety_T1                                                                    
## anxiety_T2                                                                    
## anxiety_T3                                                                    
## anxiety_T4                                                                    
## CASI_ADHD_CSum                                                                
## CASI_ADHD_CSum_T2                      5.599                                  
## CASI_ADHD_CSum_T3                      2.220           7.742                  
## CASI_ADHDCSum_T4                       3.092           1.855      9.467       
## Academicperformance_total_T4           0.265           0.046      0.431  1.303
## Familyincome_T1r                      -0.640           0.191     -0.112  0.205
## Educationhousehold                    -0.571          -0.477     -0.484 -0.135
## Child_gender                           0.098          -0.330     -0.259 -0.009
## Childagecategory                       0.121           0.206      0.350  0.004
##                              Fml_T1 Edctnh Chld_g Chldgc
## anxiety_T1                                              
## anxiety_T2                                              
## anxiety_T3                                              
## anxiety_T4                                              
## CASI_ADHD_CSum                                          
## CASI_ADHD_CSum_T2                                       
## CASI_ADHD_CSum_T3                                       
## CASI_ADHDCSum_T4                                        
## Academicperformance_total_T4                            
## Familyincome_T1r              0.892                     
## Educationhousehold            0.168  0.533              
## Child_gender                 -0.054  0.116  0.250       
## Childagecategory             -0.002  0.037  0.009  0.229
## 
## $mean
##                   anxiety_T1                   anxiety_T2 
##                        1.573                        1.456 
##                   anxiety_T3                   anxiety_T4 
##                        1.393                        1.532 
##               CASI_ADHD_CSum            CASI_ADHD_CSum_T2 
##                       13.089                       12.161 
##            CASI_ADHD_CSum_T3             CASI_ADHDCSum_T4 
##                       19.411                       19.875 
## Academicperformance_total_T4             Familyincome_T1r 
##                        3.018                        2.536 
##           Educationhousehold                 Child_gender 
##                        4.554                        1.500 
##             Childagecategory 
##                        2.804
semPaths(predict3,what = "path", whatLabels = "est",  edge.label.cex=.7,
                 intercepts = TRUE, edge.color = "black", nCharNodes = 0, nCharEdges=0,
                 sizeLat = 6, sizeMan=9, exoVar = FALSE, exoCov = FALSE,
                 shapeInt = "circle", covAtResiduals = FALSE)

# predicted means annd correlations for factors
lavaan::lavInspect(predict3, add.labels = TRUE, "mean.lv")
## Intercept    Linear 
##     0.408     0.003
lavaan::lavInspect(predict3, add.labels = TRUE, "cor.lv")
##           Intrcp Linear
## Intercept      1       
## Linear       NaN      1
# residuals
lavaan::residuals(predict3, type = "raw")
## $type
## [1] "raw"
## 
## $cov
##                              anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm
## anxiety_T1                   -0.017                                   
## anxiety_T2                    0.008 -0.006                            
## anxiety_T3                    0.002 -0.001  0.013                     
## anxiety_T4                   -0.005  0.000 -0.005 -0.001              
## CASI_ADHD_CSum               -0.060  0.064 -0.069  0.036         0.000
## CASI_ADHD_CSum_T2             0.024 -0.008 -0.016  0.025         0.000
## CASI_ADHD_CSum_T3             0.115 -0.135  0.159 -0.091         0.000
## CASI_ADHDCSum_T4             -0.122  0.013  0.147 -0.185         0.000
## Academicperformance_total_T4 -0.031  0.004  0.037 -0.046         0.000
## Familyincome_T1r              0.017 -0.020  0.024 -0.014         0.000
## Educationhousehold           -0.028  0.022 -0.011 -0.002         0.000
## Child_gender                 -0.016  0.026 -0.039  0.028         0.000
## Childagecategory             -0.023  0.007  0.016 -0.024         0.000
##                              CASI_ADHD_CS_T2 CASI_ADHD_CS_T3 CASI_ADHDC Ac__T4
## anxiety_T1                                                                    
## anxiety_T2                                                                    
## anxiety_T3                                                                    
## anxiety_T4                                                                    
## CASI_ADHD_CSum                                                                
## CASI_ADHD_CSum_T2                      0.000                                  
## CASI_ADHD_CSum_T3                      0.000           0.000                  
## CASI_ADHDCSum_T4                       0.000           0.000      0.000       
## Academicperformance_total_T4           0.000           0.000      0.000  0.000
## Familyincome_T1r                       0.000           0.000      0.000  0.000
## Educationhousehold                     0.000           0.000      0.000  0.000
## Child_gender                           0.000           0.000      0.000  0.000
## Childagecategory                       0.000           0.000      0.000  0.000
##                              Fml_T1 Edctnh Chld_g Chldgc
## anxiety_T1                                              
## anxiety_T2                                              
## anxiety_T3                                              
## anxiety_T4                                              
## CASI_ADHD_CSum                                          
## CASI_ADHD_CSum_T2                                       
## CASI_ADHD_CSum_T3                                       
## CASI_ADHDCSum_T4                                        
## Academicperformance_total_T4                            
## Familyincome_T1r              0.000                     
## Educationhousehold            0.000  0.000              
## Child_gender                  0.000  0.000  0.000       
## Childagecategory              0.000  0.000  0.000  0.000
## 
## $mean
##                   anxiety_T1                   anxiety_T2 
##                        0.005                        0.001 
##                   anxiety_T3                   anxiety_T4 
##                       -0.008                        0.009 
##               CASI_ADHD_CSum            CASI_ADHD_CSum_T2 
##                        0.000                        0.000 
##            CASI_ADHD_CSum_T3             CASI_ADHDCSum_T4 
##                        0.000                        0.000 
## Academicperformance_total_T4             Familyincome_T1r 
##                        0.000                        0.000 
##           Educationhousehold                 Child_gender 
##                        0.000                        0.000 
##             Childagecategory 
##                        0.000
lavaan::residuals(predict3, type = "cor.bollen")
## $type
## [1] "cor.bollen"
## 
## $cov
##                              anx_T1 anx_T2 anx_T3 anx_T4 CASI_ADHD_CSm
## anxiety_T1                    0.000                                   
## anxiety_T2                    0.079  0.000                            
## anxiety_T3                    0.016 -0.024  0.000                     
## anxiety_T4                   -0.015  0.011 -0.053  0.000              
## CASI_ADHD_CSum               -0.022  0.072 -0.075  0.033         0.000
## CASI_ADHD_CSum_T2             0.045  0.010 -0.045  0.030         0.000
## CASI_ADHD_CSum_T3             0.120 -0.142  0.131 -0.089         0.000
## CASI_ADHDCSum_T4             -0.099  0.023  0.134 -0.163         0.000
## Academicperformance_total_T4 -0.075  0.013  0.095 -0.111         0.000
## Familyincome_T1r              0.026 -0.076  0.083 -0.042         0.000
## Educationhousehold           -0.126  0.083 -0.031 -0.008         0.000
## Child_gender                 -0.085  0.160 -0.226  0.153         0.000
## Childagecategory             -0.131  0.046  0.098 -0.138         0.000
##                              CASI_ADHD_CS_T2 CASI_ADHD_CS_T3 CASI_ADHDC Ac__T4
## anxiety_T1                                                                    
## anxiety_T2                                                                    
## anxiety_T3                                                                    
## anxiety_T4                                                                    
## CASI_ADHD_CSum                                                                
## CASI_ADHD_CSum_T2                      0.000                                  
## CASI_ADHD_CSum_T3                      0.000           0.000                  
## CASI_ADHDCSum_T4                       0.000           0.000      0.000       
## Academicperformance_total_T4           0.000           0.000      0.000  0.000
## Familyincome_T1r                       0.000           0.000      0.000  0.000
## Educationhousehold                     0.000           0.000      0.000  0.000
## Child_gender                           0.000           0.000      0.000  0.000
## Childagecategory                       0.000           0.000      0.000  0.000
##                              Fml_T1 Edctnh Chld_g Chldgc
## anxiety_T1                                              
## anxiety_T2                                              
## anxiety_T3                                              
## anxiety_T4                                              
## CASI_ADHD_CSum                                          
## CASI_ADHD_CSum_T2                                       
## CASI_ADHD_CSum_T3                                       
## CASI_ADHDCSum_T4                                        
## Academicperformance_total_T4                            
## Familyincome_T1r              0.000                     
## Educationhousehold            0.000  0.000              
## Child_gender                  0.000  0.000  0.000       
## Childagecategory              0.000  0.000  0.000  0.000
## 
## $mean
##                   anxiety_T1                   anxiety_T2 
##                        0.013                        0.002 
##                   anxiety_T3                   anxiety_T4 
##                       -0.024                        0.025 
##               CASI_ADHD_CSum            CASI_ADHD_CSum_T2 
##                        0.000                        0.000 
##            CASI_ADHD_CSum_T3             CASI_ADHDCSum_T4 
##                        0.000                        0.000 
## Academicperformance_total_T4             Familyincome_T1r 
##                        0.000                        0.000 
##           Educationhousehold                 Child_gender 
##                        0.000                        0.000 
##             Childagecategory 
##                        0.000
#########################################################################################################
#########################################################################################################
                                                            # OLD - PROOF OF CONCEPT # 
#########################################################################################################

cgm.dep = '
    # intercept and slope with fixed coefficients
    Intercept =~  1*depression_T1 + 1*depression_T2 + 1*depression_T3 + 1*depression_T4
    Slope =~ 0*depression_T1 + 1*depression_T2 + 2*depression_T3 + 3*depression_T4
    Intercept ~ CASI_ADHD_CSum
        Slope ~ CASI_ADHD_CSum
        depression_T1 ~~ 0*depression_T1 #this is new
        '

growth.fit <- lavaan::growth(cgm.dep, data=mydata, missing = "fiml", estimator = "mlr")
summary(growth.fit)
## lavaan 0.6.17 ended normally after 29 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##                                                   Used       Total
##   Number of observations                           432         540
##   Number of missing patterns                         8            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                42.375      35.514
##   Degrees of freedom                                 8           8
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.193
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     depression_T1     1.000                           
##     depression_T2     1.000                           
##     depression_T3     1.000                           
##     depression_T4     1.000                           
##   Slope =~                                            
##     depression_T1     0.000                           
##     depression_T2     1.000                           
##     depression_T3     2.000                           
##     depression_T4     3.000                           
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~                                         
##     CASI_ADHD_CSum    0.098    0.008   12.015    0.000
##   Slope ~                                             
##     CASI_ADHD_CSum   -0.028    0.006   -4.697    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .Intercept ~~                                        
##    .Slope            -0.087    0.014   -6.426    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .Intercept         0.103    0.089    1.167    0.243
##    .Slope             0.321    0.079    4.068    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .depression_T1     0.000                           
##    .depression_T2     0.240    0.039    6.163    0.000
##    .depression_T3     0.243    0.034    7.213    0.000
##    .depression_T4     0.174    0.052    3.353    0.001
##    .Intercept         0.321    0.027   11.966    0.000
##    .Slope             0.039    0.007    5.392    0.000
fitMeasures(growth.fit)
##                          npar                          fmin 
##                        10.000                         0.049 
##                         chisq                            df 
##                        42.375                         8.000 
##                        pvalue                  chisq.scaled 
##                         0.000                        35.514 
##                     df.scaled                 pvalue.scaled 
##                         8.000                         0.000 
##          chisq.scaling.factor                baseline.chisq 
##                         1.193                       221.110 
##                   baseline.df               baseline.pvalue 
##                        10.000                         0.000 
##         baseline.chisq.scaled            baseline.df.scaled 
##                       170.520                        10.000 
##        baseline.pvalue.scaled baseline.chisq.scaling.factor 
##                         0.000                         1.297 
##                           cfi                           tli 
##                         0.837                         0.796 
##                    cfi.scaled                    tli.scaled 
##                         0.829                         0.786 
##                    cfi.robust                    tli.robust 
##                         0.722                         0.652 
##                          nnfi                           rfi 
##                         0.796                         0.760 
##                           nfi                          pnfi 
##                         0.808                         0.647 
##                           ifi                           rni 
##                         0.839                         0.837 
##                   nnfi.scaled                    rfi.scaled 
##                         0.786                         0.740 
##                    nfi.scaled                   pnfi.scaled 
##                         0.792                         0.633 
##                    ifi.scaled                    rni.scaled 
##                         0.831                         0.829 
##                   nnfi.robust                    rni.robust 
##                         0.652                         0.722 
##                          logl             unrestricted.logl 
##                      -586.631                      -565.443 
##                           aic                           bic 
##                      1193.261                      1233.945 
##                        ntotal                          bic2 
##                       432.000                      1202.211 
##             scaling.factor.h1             scaling.factor.h0 
##                         1.163                         1.138 
##                         rmsea                rmsea.ci.lower 
##                         0.100                         0.071 
##                rmsea.ci.upper                rmsea.ci.level 
##                         0.130                         0.900 
##                  rmsea.pvalue                rmsea.close.h0 
##                         0.003                         0.050 
##         rmsea.notclose.pvalue             rmsea.notclose.h0 
##                         0.880                         0.080 
##                  rmsea.scaled         rmsea.ci.lower.scaled 
##                         0.089                         0.063 
##         rmsea.ci.upper.scaled           rmsea.pvalue.scaled 
##                         0.117                         0.009 
##  rmsea.notclose.pvalue.scaled                  rmsea.robust 
##                         0.737                         0.210 
##         rmsea.ci.lower.robust         rmsea.ci.upper.robust 
##                         0.123                         0.303 
##           rmsea.pvalue.robust  rmsea.notclose.pvalue.robust 
##                         0.003                         0.990 
##                           rmr                    rmr_nomean 
##                         0.134                         0.154 
##                          srmr                  srmr_bentler 
##                         0.246                         0.246 
##           srmr_bentler_nomean                          crmr 
##                         0.283                         0.113 
##                   crmr_nomean                    srmr_mplus 
##                         0.136                         0.258 
##             srmr_mplus_nomean                         cn_05 
##                         0.251                       159.091 
##                         cn_01                           gfi 
##                       205.813                         0.969 
##                          agfi                          pgfi 
##                         0.923                         0.388 
##                           mfi                          ecvi 
##                         0.961                         0.144
graph_sem(model = growth.fit)

parameterEstimates(growth.fit)
##               lhs op            rhs    est    se      z pvalue ci.lower
## 1       Intercept =~  depression_T1  1.000 0.000     NA     NA    1.000
## 2       Intercept =~  depression_T2  1.000 0.000     NA     NA    1.000
## 3       Intercept =~  depression_T3  1.000 0.000     NA     NA    1.000
## 4       Intercept =~  depression_T4  1.000 0.000     NA     NA    1.000
## 5           Slope =~  depression_T1  0.000 0.000     NA     NA    0.000
## 6           Slope =~  depression_T2  1.000 0.000     NA     NA    1.000
## 7           Slope =~  depression_T3  2.000 0.000     NA     NA    2.000
## 8           Slope =~  depression_T4  3.000 0.000     NA     NA    3.000
## 9       Intercept  ~ CASI_ADHD_CSum  0.098 0.008 12.015  0.000    0.082
## 10          Slope  ~ CASI_ADHD_CSum -0.028 0.006 -4.697  0.000   -0.039
## 11  depression_T1 ~~  depression_T1  0.000 0.000     NA     NA    0.000
## 12  depression_T2 ~~  depression_T2  0.240 0.039  6.163  0.000    0.164
## 13  depression_T3 ~~  depression_T3  0.243 0.034  7.213  0.000    0.177
## 14  depression_T4 ~~  depression_T4  0.174 0.052  3.353  0.001    0.072
## 15      Intercept ~~      Intercept  0.321 0.027 11.966  0.000    0.269
## 16          Slope ~~          Slope  0.039 0.007  5.392  0.000    0.025
## 17      Intercept ~~          Slope -0.087 0.014 -6.426  0.000   -0.114
## 18 CASI_ADHD_CSum ~~ CASI_ADHD_CSum 16.373 0.000     NA     NA   16.373
## 19  depression_T1 ~1                 0.000 0.000     NA     NA    0.000
## 20  depression_T2 ~1                 0.000 0.000     NA     NA    0.000
## 21  depression_T3 ~1                 0.000 0.000     NA     NA    0.000
## 22  depression_T4 ~1                 0.000 0.000     NA     NA    0.000
## 23 CASI_ADHD_CSum ~1                11.106 0.000     NA     NA   11.106
## 24      Intercept ~1                 0.103 0.089  1.167  0.243   -0.070
## 25          Slope ~1                 0.321 0.079  4.068  0.000    0.166
##    ci.upper
## 1     1.000
## 2     1.000
## 3     1.000
## 4     1.000
## 5     0.000
## 6     1.000
## 7     2.000
## 8     3.000
## 9     0.114
## 10   -0.016
## 11    0.000
## 12    0.316
## 13    0.309
## 14    0.276
## 15    0.374
## 16    0.054
## 17   -0.061
## 18   16.373
## 19    0.000
## 20    0.000
## 21    0.000
## 22    0.000
## 23   11.106
## 24    0.277
## 25    0.476
standardizedSolution(growth.fit, type = "std.all",  se= TRUE, pvalue = TRUE)
##               lhs op            rhs est.std    se      z pvalue ci.lower
## 1       Intercept =~  depression_T1   1.000 0.000     NA     NA    1.000
## 2       Intercept =~  depression_T2   0.971 0.048 20.342   0.00    0.878
## 3       Intercept =~  depression_T3   1.090 0.067 16.260   0.00    0.958
## 4       Intercept =~  depression_T4   1.202 0.081 14.814   0.00    1.043
## 5           Slope =~  depression_T1   0.000 0.000     NA     NA    0.000
## 6           Slope =~  depression_T2   0.321 0.040  8.067   0.00    0.243
## 7           Slope =~  depression_T3   0.720 0.097  7.436   0.00    0.531
## 8           Slope =~  depression_T4   1.192 0.131  9.078   0.00    0.935
## 9       Intercept  ~ CASI_ADHD_CSum   0.572 0.043 13.327   0.00    0.488
## 10          Slope  ~ CASI_ADHD_CSum  -0.493 0.081 -6.082   0.00   -0.652
## 11  depression_T1 ~~  depression_T1   0.000 0.000     NA     NA    0.000
## 12  depression_T2 ~~  depression_T2   0.474 0.047 10.172   0.00    0.383
## 13  depression_T3 ~~  depression_T3   0.605 0.081  7.503   0.00    0.447
## 14  depression_T4 ~~  depression_T4   0.528 0.151  3.486   0.00    0.231
## 15      Intercept ~~      Intercept   0.673 0.049 13.725   0.00    0.577
## 16          Slope ~~          Slope   0.757 0.080  9.448   0.00    0.600
## 17      Intercept ~~          Slope  -0.775 0.079 -9.811   0.00   -0.930
## 18 CASI_ADHD_CSum ~~ CASI_ADHD_CSum   1.000 0.000     NA     NA    1.000
## 19  depression_T1 ~1                  0.000 0.000     NA     NA    0.000
## 20  depression_T2 ~1                  0.000 0.000     NA     NA    0.000
## 21  depression_T3 ~1                  0.000 0.000     NA     NA    0.000
## 22  depression_T4 ~1                  0.000 0.000     NA     NA    0.000
## 23 CASI_ADHD_CSum ~1                  2.745 0.000     NA     NA    2.745
## 24      Intercept ~1                  0.150 0.130  1.150   0.25   -0.105
## 25          Slope ~1                  1.407 0.279  5.036   0.00    0.859
##    ci.upper
## 1     1.000
## 2     1.065
## 3     1.221
## 4     1.361
## 5     0.000
## 6     0.399
## 7     0.910
## 8     1.450
## 9     0.656
## 10   -0.334
## 11    0.000
## 12    0.566
## 13    0.763
## 14    0.825
## 15    0.769
## 16    0.913
## 17   -0.621
## 18    1.000
## 19    0.000
## 20    0.000
## 21    0.000
## 22    0.000
## 23    2.745
## 24    0.405
## 25    1.954
#########################################################################################################

#########################################################################################################
#########################################################################################################
#########################################################################################################


#########################################################################################################
                                                            # OLD - PROOF OF CONCEPT # 
#relaxing constrains to allow for full info from TVCs
#########################################################################################################

#sample model code

# model <- '
#   # intercept and slope with fixed coefficients
#     i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4
#     s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4
#   # regressions that affect the latent growth factors
#     i ~ x1 + x2
#     s ~ x1 + x2
#   # time-varying covariates
#     t1 ~ c1
#     t2 ~ c2
#     t3 ~ c3
#     t4 ~ c4
# '

cgm.dep = '
    # intercept and slope with fixed coefficients
    Intercept =~  1*depression_T1 + 1*depression_T2 + 1*depression_T3 + 1*depression_T4
    Slope =~ 0*depression_T1 + 1*depression_T2 + 2*depression_T3 + 3*depression_T4
    # regressions of covariates that affect the latent growth factors
    Intercept ~ CASI_ADHD_CSum
        Slope ~ CASI_ADHD_CSum
        # time-varying covariates
                    anxiety_T1 ~ CASI_ADHD_CSum
                    anxiety_T2 ~ CASI_ADHD_CSum_T2
                    anxiety_T3 ~ CASI_ADHD_CSum_T3
                    anxiety_T4 ~ CASI_ADHDCSum_T4'

growth.fit <- lavaan::growth(cgm.dep, data=mydata, missing = "fiml", estimator = "mlr")
summary(growth.fit)
## lavaan 0.6.17 ended normally after 138 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        33
## 
##                                                   Used       Total
##   Number of observations                            57         540
##   Number of missing patterns                         1            
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                               180.018     197.573
##   Degrees of freedom                                43          43
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  0.911
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept =~                                        
##     depression_T1     1.000                           
##     depression_T2     1.000                           
##     depression_T3     1.000                           
##     depression_T4     1.000                           
##   Slope =~                                            
##     depression_T1     0.000                           
##     depression_T2     1.000                           
##     depression_T3     2.000                           
##     depression_T4     3.000                           
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Intercept ~                                         
##     CASI_ADHD_CSum    0.089    0.013    6.861    0.000
##   Slope ~                                             
##     CASI_ADHD_CSum   -0.025    0.011   -2.211    0.027
##   anxiety_T1 ~                                        
##     CASI_ADHD_CSum    0.117    0.004   30.885    0.000
##   anxiety_T2 ~                                        
##     CASI_ADHD_CS_T    0.116    0.004   32.182    0.000
##   anxiety_T3 ~                                        
##     CASI_ADHD_CS_T    0.071    0.002   45.729    0.000
##   anxiety_T4 ~                                        
##     CASI_ADHDCS_T4    0.075    0.003   29.936    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .Intercept ~~                                        
##    .Slope             0.006    0.017    0.334    0.739
##    .anxiety_T1        0.050    0.019    2.704    0.007
##    .anxiety_T2        0.018    0.026    0.708    0.479
##    .anxiety_T3        0.027    0.012    2.239    0.025
##    .anxiety_T4        0.027    0.017    1.601    0.109
##  .Slope ~~                                            
##    .anxiety_T1       -0.011    0.009   -1.182    0.237
##    .anxiety_T2       -0.002    0.009   -0.237    0.812
##    .anxiety_T3        0.000    0.006    0.079    0.937
##    .anxiety_T4        0.001    0.009    0.153    0.878
##  .anxiety_T1 ~~                                       
##    .anxiety_T2        0.003    0.011    0.287    0.774
##    .anxiety_T3        0.001    0.009    0.160    0.873
##    .anxiety_T4       -0.000    0.018   -0.024    0.981
##  .anxiety_T2 ~~                                       
##    .anxiety_T3        0.013    0.008    1.692    0.091
##    .anxiety_T4        0.003    0.013    0.250    0.802
##  .anxiety_T3 ~~                                       
##    .anxiety_T4       -0.001    0.011   -0.129    0.897
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .Intercept         0.280    0.179    1.561    0.118
##    .Slope             0.309    0.157    1.972    0.049
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .depression_T1     0.171    0.059    2.888    0.004
##    .depression_T2     0.140    0.027    5.260    0.000
##    .depression_T3     0.151    0.038    3.922    0.000
##    .depression_T4     0.135    0.049    2.740    0.006
##    .anxiety_T1        0.124    0.031    4.019    0.000
##    .anxiety_T2        0.062    0.020    3.157    0.002
##    .anxiety_T3        0.052    0.010    5.022    0.000
##    .anxiety_T4        0.150    0.026    5.803    0.000
##    .Intercept         0.006    0.043    0.131    0.896
##    .Slope             0.004    0.008    0.501    0.617
fitMeasures(growth.fit)
##                          npar                          fmin 
##                        33.000                         1.579 
##                         chisq                            df 
##                       180.018                        43.000 
##                        pvalue                  chisq.scaled 
##                         0.000                       197.573 
##                     df.scaled                 pvalue.scaled 
##                        43.000                         0.000 
##          chisq.scaling.factor                baseline.chisq 
##                         0.911                       323.866 
##                   baseline.df               baseline.pvalue 
##                        60.000                         0.000 
##         baseline.chisq.scaled            baseline.df.scaled 
##                       351.638                        60.000 
##        baseline.pvalue.scaled baseline.chisq.scaling.factor 
##                         0.000                         0.921 
##                           cfi                           tli 
##                         0.481                         0.275 
##                    cfi.scaled                    tli.scaled 
##                         0.470                         0.260 
##                    cfi.robust                    tli.robust 
##                         0.488                         0.286 
##                          nnfi                           rfi 
##                         0.275                         0.224 
##                           nfi                          pnfi 
##                         0.444                         0.318 
##                           ifi                           rni 
##                         0.512                         0.481 
##                   nnfi.scaled                    rfi.scaled 
##                         0.260                         0.216 
##                    nfi.scaled                   pnfi.scaled 
##                         0.438                         0.314 
##                    ifi.scaled                    rni.scaled 
##                         0.499                         0.470 
##                   nnfi.robust                    rni.robust 
##                         0.286                         0.488 
##                          logl             unrestricted.logl 
##                      -150.674                       -60.665 
##                           aic                           bic 
##                       367.348                       434.769 
##                        ntotal                          bic2 
##                        57.000                       331.031 
##             scaling.factor.h1             scaling.factor.h0 
##                         1.029                         1.182 
##                         rmsea                rmsea.ci.lower 
##                         0.236                         0.201 
##                rmsea.ci.upper                rmsea.ci.level 
##                         0.273                         0.900 
##                  rmsea.pvalue                rmsea.close.h0 
##                         0.000                         0.050 
##         rmsea.notclose.pvalue             rmsea.notclose.h0 
##                         1.000                         0.080 
##                  rmsea.scaled         rmsea.ci.lower.scaled 
##                         0.251                         0.215 
##         rmsea.ci.upper.scaled           rmsea.pvalue.scaled 
##                         0.289                         0.000 
##  rmsea.notclose.pvalue.scaled                  rmsea.robust 
##                         1.000                         0.234 
##         rmsea.ci.lower.robust         rmsea.ci.upper.robust 
##                         0.197                         0.271 
##           rmsea.pvalue.robust  rmsea.notclose.pvalue.robust 
##                         0.000                         1.000 
##                           rmr                    rmr_nomean 
##                         0.175                         0.187 
##                          srmr                  srmr_bentler 
##                         0.233                         0.233 
##           srmr_bentler_nomean                          crmr 
##                         0.249                         0.183 
##                   crmr_nomean                    srmr_mplus 
##                         0.197                         0.302 
##             srmr_mplus_nomean                         cn_05 
##                         0.233                        19.778 
##                         cn_01                           gfi 
##                        22.360                         0.977 
##                          agfi                          pgfi 
##                         0.952                         0.467 
##                           mfi                          ecvi 
##                         0.301                         4.316
graph_sem(model = growth.fit)

parameterEstimates(growth.fit)
##                  lhs op               rhs    est    se      z pvalue ci.lower
## 1          Intercept =~     depression_T1  1.000 0.000     NA     NA    1.000
## 2          Intercept =~     depression_T2  1.000 0.000     NA     NA    1.000
## 3          Intercept =~     depression_T3  1.000 0.000     NA     NA    1.000
## 4          Intercept =~     depression_T4  1.000 0.000     NA     NA    1.000
## 5              Slope =~     depression_T1  0.000 0.000     NA     NA    0.000
## 6              Slope =~     depression_T2  1.000 0.000     NA     NA    1.000
## 7              Slope =~     depression_T3  2.000 0.000     NA     NA    2.000
## 8              Slope =~     depression_T4  3.000 0.000     NA     NA    3.000
## 9          Intercept  ~    CASI_ADHD_CSum  0.089 0.013  6.861  0.000    0.064
## 10             Slope  ~    CASI_ADHD_CSum -0.025 0.011 -2.211  0.027   -0.047
## 11        anxiety_T1  ~    CASI_ADHD_CSum  0.117 0.004 30.885  0.000    0.110
## 12        anxiety_T2  ~ CASI_ADHD_CSum_T2  0.116 0.004 32.182  0.000    0.109
## 13        anxiety_T3  ~ CASI_ADHD_CSum_T3  0.071 0.002 45.729  0.000    0.068
## 14        anxiety_T4  ~  CASI_ADHDCSum_T4  0.075 0.003 29.936  0.000    0.071
## 15     depression_T1 ~~     depression_T1  0.171 0.059  2.888  0.004    0.055
## 16     depression_T2 ~~     depression_T2  0.140 0.027  5.260  0.000    0.088
## 17     depression_T3 ~~     depression_T3  0.151 0.038  3.922  0.000    0.075
## 18     depression_T4 ~~     depression_T4  0.135 0.049  2.740  0.006    0.038
## 19        anxiety_T1 ~~        anxiety_T1  0.124 0.031  4.019  0.000    0.063
## 20        anxiety_T2 ~~        anxiety_T2  0.062 0.020  3.157  0.002    0.023
## 21        anxiety_T3 ~~        anxiety_T3  0.052 0.010  5.022  0.000    0.032
## 22        anxiety_T4 ~~        anxiety_T4  0.150 0.026  5.803  0.000    0.100
## 23         Intercept ~~         Intercept  0.006 0.043  0.131  0.896   -0.078
## 24             Slope ~~             Slope  0.004 0.008  0.501  0.617   -0.011
## 25         Intercept ~~             Slope  0.006 0.017  0.334  0.739   -0.028
## 26         Intercept ~~        anxiety_T1  0.050 0.019  2.704  0.007    0.014
## 27         Intercept ~~        anxiety_T2  0.018 0.026  0.708  0.479   -0.032
## 28         Intercept ~~        anxiety_T3  0.027 0.012  2.239  0.025    0.003
## 29         Intercept ~~        anxiety_T4  0.027 0.017  1.601  0.109   -0.006
## 30             Slope ~~        anxiety_T1 -0.011 0.009 -1.182  0.237   -0.029
## 31             Slope ~~        anxiety_T2 -0.002 0.009 -0.237  0.812   -0.020
## 32             Slope ~~        anxiety_T3  0.000 0.006  0.079  0.937   -0.011
## 33             Slope ~~        anxiety_T4  0.001 0.009  0.153  0.878   -0.017
## 34        anxiety_T1 ~~        anxiety_T2  0.003 0.011  0.287  0.774   -0.018
## 35        anxiety_T1 ~~        anxiety_T3  0.001 0.009  0.160  0.873   -0.016
## 36        anxiety_T1 ~~        anxiety_T4  0.000 0.018 -0.024  0.981   -0.036
## 37        anxiety_T2 ~~        anxiety_T3  0.013 0.008  1.692  0.091   -0.002
## 38        anxiety_T2 ~~        anxiety_T4  0.003 0.013  0.250  0.802   -0.022
## 39        anxiety_T3 ~~        anxiety_T4 -0.001 0.011 -0.129  0.897   -0.023
## 40    CASI_ADHD_CSum ~~    CASI_ADHD_CSum  8.857 0.000     NA     NA    8.857
## 41    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T2  3.229 0.000     NA     NA    3.229
## 42    CASI_ADHD_CSum ~~ CASI_ADHD_CSum_T3  0.861 0.000     NA     NA    0.861
## 43    CASI_ADHD_CSum ~~  CASI_ADHDCSum_T4  0.133 0.000     NA     NA    0.133
## 44 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T2  7.917 0.000     NA     NA    7.917
## 45 CASI_ADHD_CSum_T2 ~~ CASI_ADHD_CSum_T3  4.546 0.000     NA     NA    4.546
## 46 CASI_ADHD_CSum_T2 ~~  CASI_ADHDCSum_T4  3.675 0.000     NA     NA    3.675
## 47 CASI_ADHD_CSum_T3 ~~ CASI_ADHD_CSum_T3  9.921 0.000     NA     NA    9.921
## 48 CASI_ADHD_CSum_T3 ~~  CASI_ADHDCSum_T4  2.447 0.000     NA     NA    2.447
## 49  CASI_ADHDCSum_T4 ~~  CASI_ADHDCSum_T4  9.469 0.000     NA     NA    9.469
## 50     depression_T1 ~1                    0.000 0.000     NA     NA    0.000
## 51     depression_T2 ~1                    0.000 0.000     NA     NA    0.000
## 52     depression_T3 ~1                    0.000 0.000     NA     NA    0.000
## 53     depression_T4 ~1                    0.000 0.000     NA     NA    0.000
## 54        anxiety_T1 ~1                    0.000 0.000     NA     NA    0.000
## 55        anxiety_T2 ~1                    0.000 0.000     NA     NA    0.000
## 56        anxiety_T3 ~1                    0.000 0.000     NA     NA    0.000
## 57        anxiety_T4 ~1                    0.000 0.000     NA     NA    0.000
## 58    CASI_ADHD_CSum ~1                   13.140 0.000     NA     NA   13.140
## 59 CASI_ADHD_CSum_T2 ~1                   12.368 0.000     NA     NA   12.368
## 60 CASI_ADHD_CSum_T3 ~1                   19.614 0.000     NA     NA   19.614
## 61  CASI_ADHDCSum_T4 ~1                   19.930 0.000     NA     NA   19.930
## 62         Intercept ~1                    0.280 0.179  1.561  0.118   -0.072
## 63             Slope ~1                    0.309 0.157  1.972  0.049    0.002
##    ci.upper
## 1     1.000
## 2     1.000
## 3     1.000
## 4     1.000
## 5     0.000
## 6     1.000
## 7     2.000
## 8     3.000
## 9     0.115
## 10   -0.003
## 11    0.125
## 12    0.123
## 13    0.074
## 14    0.080
## 15    0.287
## 16    0.193
## 17    0.226
## 18    0.231
## 19    0.184
## 20    0.100
## 21    0.072
## 22    0.201
## 23    0.089
## 24    0.019
## 25    0.039
## 26    0.086
## 27    0.069
## 28    0.051
## 29    0.060
## 30    0.007
## 31    0.016
## 32    0.012
## 33    0.020
## 34    0.024
## 35    0.018
## 36    0.035
## 37    0.028
## 38    0.029
## 39    0.020
## 40    8.857
## 41    3.229
## 42    0.861
## 43    0.133
## 44    7.917
## 45    4.546
## 46    3.675
## 47    9.921
## 48    2.447
## 49    9.469
## 50    0.000
## 51    0.000
## 52    0.000
## 53    0.000
## 54    0.000
## 55    0.000
## 56    0.000
## 57    0.000
## 58   13.140
## 59   12.368
## 60   19.614
## 61   19.930
## 62    0.632
## 63    0.617
#########################################################################################################