library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.5.1     ✔ stringr   1.5.1
## ✔ lubridate 1.9.4     ✔ tibble    3.2.1
## ✔ purrr     1.0.4     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(modsem)

library(lavaan)
## This is lavaan 0.6-19
## lavaan is FREE software! Please report any bugs.
library(ggplot2)

library(corrplot)
## corrplot 0.95 loaded
library(ggcorrplot)

library(psych)
## 
## Attaching package: 'psych'
## 
## The following object is masked from 'package:lavaan':
## 
##     cor2cov
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(tidyverse)

library(dplyr)

library(tidyr)

library(semTools)
##  
## ###############################################################################
## This is semTools 0.5-7
## All users of R (or SEM) are invited to submit functions or ideas for functions.
## ###############################################################################
## 
## Attaching package: 'semTools'
## 
## The following objects are masked from 'package:psych':
## 
##     reliability, skew
## 
## The following object is masked from 'package:readr':
## 
##     clipboard
library(stdmod)

library(semTools)

#read in data

setwd("~/Downloads/foldah")

ANES <- read.csv("ANES_cleanmerge.csv")

#RICLPM EPE + CA

RICLPM1 <- '
  # Create between components (random intercepts)
  RIepe =~ 1*ex_eff_w1 + 1*ex_eff_w2 + 1*ex_eff_w3 
  RIca =~ 1*c_act_w1 + 1*c_act_w2 + 1*c_act_w3 
  
  # Create within-person centered variables
  wepe1 =~ 1*ex_eff_w1
  wepe2 =~ 1*ex_eff_w2
  wepe3 =~ 1*ex_eff_w3 

  wca1 =~ 1*c_act_w1
  wca2 =~ 1*c_act_w2
  wca3 =~ 1*c_act_w3
# Estimate lagged effects between within-person centered variables
  wepe2 + wca2 ~ wepe1 + wca1
  wepe3 + wca3 ~ wepe2 + wca2
  
  # Estimate covariance between within-person centered variables at first wave
  wepe1 ~~ wca1 # Covariance
  
  # Estimate covariances between residuals of within-person centered variables
  # (i.e., innovations)
  wepe2 ~~ wca2
  wepe3 ~~ wca3
  
  # Estimate variance and covariance of random intercepts
  RIepe ~~ RIepe
  RIca ~~ RIca
  RIepe ~~ RIca
  
  # Estimate (residual) variance of within-person centered variables
  wepe1 ~~ wepe1 # Variances
  wca1 ~~ wca1 
  wepe2 ~~ wepe2 # Residual variances
  wca2 ~~ wca2 
  wepe3 ~~ wepe3 
  wca3 ~~ wca3'

RICLPM1fit <- lavaan(RICLPM1, 
  data = ANES, 
  missing = 'ML',
  estimator = "ML",
  meanstructure = T, 
  int.ov.free = T)

summary(RICLPM1fit, fit.measures = T, standardized = T, rsquare = T)
## lavaan 0.6-19 ended normally after 70 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##   Number of observations                          2171
##   Number of missing patterns                        12
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.487
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.485
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1757.420
##   Degrees of freedom                                15
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.004
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.004
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -7735.790
##   Loglikelihood unrestricted model (H1)      -7735.547
##                                                       
##   Akaike (AIC)                               15523.580
##   Bayesian (BIC)                             15671.337
##   Sample-size adjusted Bayesian (SABIC)      15588.731
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.050
##   P-value H_0: RMSEA <= 0.050                    0.950
##   P-value H_0: RMSEA >= 0.080                    0.001
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.051
##   P-value H_0: Robust RMSEA <= 0.050             0.944
##   P-value H_0: Robust RMSEA >= 0.080             0.002
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.003
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIepe =~                                                              
##     ex_eff_w1         1.000                               0.553    0.547
##     ex_eff_w2         1.000                               0.553    0.533
##     ex_eff_w3         1.000                               0.553    0.575
##   RIca =~                                                               
##     c_act_w1          1.000                               0.120    0.466
##     c_act_w2          1.000                               0.120    0.489
##     c_act_w3          1.000                               0.120    0.672
##   wepe1 =~                                                              
##     ex_eff_w1         1.000                               0.847    0.837
##   wepe2 =~                                                              
##     ex_eff_w2         1.000                               0.879    0.846
##   wepe3 =~                                                              
##     ex_eff_w3         1.000                               0.787    0.818
##   wca1 =~                                                               
##     c_act_w1          1.000                               0.228    0.885
##   wca2 =~                                                               
##     c_act_w2          1.000                               0.214    0.872
##   wca3 =~                                                               
##     c_act_w3          1.000                               0.132    0.740
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wepe2 ~                                                               
##     wepe1             0.083    0.039    2.115    0.034    0.080    0.080
##     wca1              0.265    0.117    2.265    0.024    0.068    0.068
##   wca2 ~                                                                
##     wepe1             0.003    0.007    0.380    0.704    0.010    0.010
##     wca1              0.278    0.028   10.081    0.000    0.297    0.297
##   wepe3 ~                                                               
##     wepe2             0.164    0.033    4.989    0.000    0.183    0.183
##     wca2             -0.135    0.119   -1.129    0.259   -0.037   -0.037
##   wca3 ~                                                                
##     wepe2             0.010    0.006    1.695    0.090    0.068    0.068
##     wca2              0.040    0.032    1.264    0.206    0.065    0.065
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wepe1 ~~                                                              
##     wca1              0.016    0.005    2.868    0.004    0.081    0.081
##  .wepe2 ~~                                                              
##    .wca2              0.015    0.005    2.849    0.004    0.086    0.086
##  .wepe3 ~~                                                              
##    .wca3             -0.006    0.004   -1.489    0.136   -0.056   -0.056
##   RIepe ~~                                                              
##     RIca              0.012    0.004    3.048    0.002    0.179    0.179
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .ex_eff_w1         2.595    0.022  119.380    0.000    2.595    2.566
##    .ex_eff_w2         2.412    0.022  107.996    0.000    2.412    2.322
##    .ex_eff_w3         2.241    0.021  106.263    0.000    2.241    2.329
##    .c_act_w1          0.213    0.006   38.577    0.000    0.213    0.829
##    .c_act_w2          0.171    0.005   32.614    0.000    0.171    0.700
##    .c_act_w3          0.081    0.004   20.773    0.000    0.081    0.455
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIepe             0.306    0.026   11.697    0.000    1.000    1.000
##     RIca              0.014    0.001   10.397    0.000    1.000    1.000
##     wepe1             0.717    0.032   22.243    0.000    1.000    1.000
##     wca1              0.052    0.002   26.794    0.000    1.000    1.000
##    .wepe2             0.764    0.037   20.843    0.000    0.988    0.988
##    .wca2              0.042    0.002   24.776    0.000    0.911    0.911
##    .wepe3             0.599    0.025   23.532    0.000    0.967    0.967
##    .wca3              0.017    0.001   13.128    0.000    0.990    0.990
##    .ex_eff_w1         0.000                               0.000    0.000
##    .ex_eff_w2         0.000                               0.000    0.000
##    .ex_eff_w3         0.000                               0.000    0.000
##    .c_act_w1          0.000                               0.000    0.000
##    .c_act_w2          0.000                               0.000    0.000
##    .c_act_w3          0.000                               0.000    0.000
## 
## R-Square:
##                    Estimate
##     wepe2             0.012
##     wca2              0.089
##     wepe3             0.033
##     wca3              0.010
##     ex_eff_w1         1.000
##     ex_eff_w2         1.000
##     ex_eff_w3         1.000
##     c_act_w1          1.000
##     c_act_w2          1.000
##     c_act_w3          1.000

#RICLPM CR + CA

RICLPM2 <- '
  # Create between components (random intercepts)
  RIcr =~ 1*c_ref_w1 + 1*c_ref_w2 + 1*c_ref_w3 
  RIca =~ 1*c_act_w1 + 1*c_act_w2 + 1*c_act_w3 
  
  # Create within-person centered variables
  wcr1 =~ 1*c_ref_w1
  wcr2 =~ 1*c_ref_w2
  wcr3 =~ 1*c_ref_w3 

  wca1 =~ 1*c_act_w1
  wca2 =~ 1*c_act_w2
  wca3 =~ 1*c_act_w3
# Estimate lagged effects between within-person centered variables
  wcr2 + wca2 ~ wcr1 + wca1
  wcr3 + wca3 ~ wcr2 + wca2
  
  # Estimate covariance between within-person centered variables at first wave
  wcr1 ~~ wca1 # Covariance
  
  # Estimate covariances between residuals of within-person centered variables
  # (i.e., innovations)
  wcr2 ~~ wca2
  wcr3 ~~ wca3
  
  # Estimate variance and covariance of random intercepts
  RIcr ~~ RIcr
  RIca ~~ RIca
  RIcr ~~ RIca
  
  # Estimate (residual) variance of within-person centered variables
  wcr1 ~~ wcr1 # Variances
  wca1 ~~ wca1 
  wcr2 ~~ wcr2 # Residual variances
  wca2 ~~ wca2 
  wcr3 ~~ wcr3 
  wca3 ~~ wca3'

RICLPM2fit <- lavaan(RICLPM2, 
  data = ANES, 
  missing = 'ML',
  estimator = "ML",
  meanstructure = T, 
  int.ov.free = T)

summary(RICLPM2fit, fit.measures = T, standardized = T, rsquare = T)
## lavaan 0.6-19 ended normally after 69 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##   Number of observations                          2171
##   Number of missing patterns                        12
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 3.902
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.048
## 
## Model Test Baseline Model:
## 
##   Test statistic                              4427.216
##   Degrees of freedom                                15
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.999
##   Tucker-Lewis Index (TLI)                       0.990
##                                                       
##   Robust Comparative Fit Index (CFI)             0.999
##   Robust Tucker-Lewis Index (TLI)                0.990
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -7698.006
##   Loglikelihood unrestricted model (H1)      -7696.055
##                                                       
##   Akaike (AIC)                               15448.011
##   Bayesian (BIC)                             15595.768
##   Sample-size adjusted Bayesian (SABIC)      15513.162
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.037
##   90 Percent confidence interval - lower         0.003
##   90 Percent confidence interval - upper         0.078
##   P-value H_0: RMSEA <= 0.050                    0.638
##   P-value H_0: RMSEA >= 0.080                    0.040
##                                                       
##   Robust RMSEA                                   0.037
##   90 Percent confidence interval - lower         0.003
##   90 Percent confidence interval - upper         0.079
##   P-value H_0: Robust RMSEA <= 0.050             0.621
##   P-value H_0: Robust RMSEA >= 0.080             0.047
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.008
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIcr =~                                                               
##     c_ref_w1          1.000                               0.974    0.793
##     c_ref_w2          1.000                               0.974    0.769
##     c_ref_w3          1.000                               0.974    0.803
##   RIca =~                                                               
##     c_act_w1          1.000                               0.120    0.466
##     c_act_w2          1.000                               0.120    0.489
##     c_act_w3          1.000                               0.120    0.671
##   wcr1 =~                                                               
##     c_ref_w1          1.000                               0.749    0.610
##   wcr2 =~                                                               
##     c_ref_w2          1.000                               0.809    0.639
##   wcr3 =~                                                               
##     c_ref_w3          1.000                               0.723    0.596
##   wca1 =~                                                               
##     c_act_w1          1.000                               0.227    0.885
##   wca2 =~                                                               
##     c_act_w2          1.000                               0.214    0.872
##   wca3 =~                                                               
##     c_act_w3          1.000                               0.132    0.741
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr2 ~                                                                
##     wcr1              0.212    0.055    3.827    0.000    0.196    0.196
##     wca1              0.264    0.110    2.407    0.016    0.074    0.074
##   wca2 ~                                                                
##     wcr1              0.057    0.011    5.337    0.000    0.200    0.200
##     wca1              0.260    0.027    9.572    0.000    0.276    0.276
##   wcr3 ~                                                                
##     wcr2              0.265    0.040    6.607    0.000    0.297    0.297
##     wca2              0.638    0.129    4.951    0.000    0.188    0.188
##   wca3 ~                                                                
##     wcr2              0.003    0.007    0.429    0.668    0.019    0.019
##     wca2              0.043    0.033    1.306    0.192    0.069    0.069
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr1 ~~                                                               
##     wca1              0.017    0.006    2.902    0.004    0.099    0.099
##  .wcr2 ~~                                                               
##    .wca2              0.038    0.006    6.839    0.000    0.243    0.243
##  .wcr3 ~~                                                               
##    .wca3              0.005    0.003    1.394    0.163    0.052    0.052
##   RIcr ~~                                                               
##     RIca              0.031    0.005    6.258    0.000    0.267    0.267
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .c_ref_w1          3.041    0.026  115.113    0.000    3.041    2.474
##    .c_ref_w2          3.280    0.027  120.430    0.000    3.280    2.590
##    .c_ref_w3          3.161    0.026  119.929    0.000    3.161    2.606
##    .c_act_w1          0.213    0.006   38.655    0.000    0.213    0.831
##    .c_act_w2          0.171    0.005   32.606    0.000    0.171    0.700
##    .c_act_w3          0.081    0.004   20.755    0.000    0.081    0.454
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIcr              0.949    0.043   21.953    0.000    1.000    1.000
##     RIca              0.014    0.001   10.388    0.000    1.000    1.000
##     wcr1              0.562    0.035   16.072    0.000    1.000    1.000
##     wca1              0.052    0.002   26.640    0.000    1.000    1.000
##    .wcr2              0.624    0.039   16.024    0.000    0.953    0.953
##    .wca2              0.040    0.002   24.295    0.000    0.873    0.873
##    .wcr3              0.441    0.022   20.436    0.000    0.844    0.844
##    .wca3              0.017    0.001   13.274    0.000    0.994    0.994
##    .c_ref_w1          0.000                               0.000    0.000
##    .c_ref_w2          0.000                               0.000    0.000
##    .c_ref_w3          0.000                               0.000    0.000
##    .c_act_w1          0.000                               0.000    0.000
##    .c_act_w2          0.000                               0.000    0.000
##    .c_act_w3          0.000                               0.000    0.000
## 
## R-Square:
##                    Estimate
##     wcr2              0.047
##     wca2              0.127
##     wcr3              0.156
##     wca3              0.006
##     c_ref_w1          1.000
##     c_ref_w2          1.000
##     c_ref_w3          1.000
##     c_act_w1          1.000
##     c_act_w2          1.000
##     c_act_w3          1.000

#RICLPM CR + EPE

RICLPM4 <- '
  # Create between components (random intercepts)
  RIcr =~ 1*c_ref_w1 + 1*c_ref_w2 + 1*c_ref_w3 
  RIepe =~ 1*ex_eff_w1 + 1*ex_eff_w2 + 1*ex_eff_w3 
  
  # Create within-person centered variables
  wcr1 =~ 1*c_ref_w1
  wcr2 =~ 1*c_ref_w2
  wcr3 =~ 1*c_ref_w3 

  wepe1 =~ 1*ex_eff_w1
  wepe2 =~ 1*ex_eff_w2
  wepe3 =~ 1*ex_eff_w3
# Estimate lagged effects between within-person centered variables
  wcr2 + wepe2 ~ wcr1 + wepe1
  wcr3 + wepe3 ~ wcr2 + wepe2
  
  # Estimate covariance between within-person centered variables at first wave
  wcr1 ~~ wepe1 # Covariance
  
  # Estimate covariances between residuals of within-person centered variables
  # (i.e., innovations)
  wcr2 ~~ wepe2
  wcr3 ~~ wepe3
  
  # Estimate variance and covariance of random intercepts
  RIcr ~~ RIcr
  RIepe ~~ RIepe
  RIcr ~~ RIepe
  
  # Estimate (residual) variance of within-person centered variables
  wcr1 ~~ wcr1 # Variances
  wepe1 ~~ wepe1 
  wcr2 ~~ wcr2 # Residual variances
  wepe2 ~~ wepe2 
  wcr3 ~~ wcr3 
  wepe3 ~~ wepe3'

RICLPM4fit <- lavaan(RICLPM4, 
  data = ANES, 
  missing = 'ML',
  estimator = "ML",
  meanstructure = T, 
  int.ov.free = T)

summary(RICLPM4fit, fit.measures = T, standardized = T, rsquare = T)
## lavaan 0.6-19 ended normally after 43 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##   Number of observations                          2171
##   Number of missing patterns                        17
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.054
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.817
## 
## Model Test Baseline Model:
## 
##   Test statistic                              4270.344
##   Degrees of freedom                                15
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.003
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.003
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -17340.570
##   Loglikelihood unrestricted model (H1)     -17340.543
##                                                       
##   Akaike (AIC)                               34733.139
##   Bayesian (BIC)                             34880.896
##   Sample-size adjusted Bayesian (SABIC)      34798.291
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.035
##   P-value H_0: RMSEA <= 0.050                    0.987
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.036
##   P-value H_0: Robust RMSEA <= 0.050             0.985
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.001
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIcr =~                                                               
##     c_ref_w1          1.000                               0.959    0.781
##     c_ref_w2          1.000                               0.959    0.757
##     c_ref_w3          1.000                               0.959    0.790
##   RIepe =~                                                              
##     ex_eff_w1         1.000                               0.551    0.545
##     ex_eff_w2         1.000                               0.551    0.530
##     ex_eff_w3         1.000                               0.551    0.573
##   wcr1 =~                                                               
##     c_ref_w1          1.000                               0.767    0.624
##   wcr2 =~                                                               
##     c_ref_w2          1.000                               0.827    0.653
##   wcr3 =~                                                               
##     c_ref_w3          1.000                               0.744    0.613
##   wepe1 =~                                                              
##     ex_eff_w1         1.000                               0.848    0.839
##   wepe2 =~                                                              
##     ex_eff_w2         1.000                               0.881    0.848
##   wepe3 =~                                                              
##     ex_eff_w3         1.000                               0.788    0.820
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr2 ~                                                                
##     wcr1              0.252    0.053    4.707    0.000    0.233    0.233
##     wepe1             0.069    0.031    2.207    0.027    0.070    0.070
##   wepe2 ~                                                               
##     wcr1              0.376    0.048    7.921    0.000    0.328    0.328
##     wepe1             0.066    0.037    1.772    0.076    0.063    0.063
##   wcr3 ~                                                                
##     wcr2              0.274    0.039    6.929    0.000    0.304    0.304
##     wepe2             0.193    0.033    5.899    0.000    0.228    0.228
##   wepe3 ~                                                               
##     wcr2             -0.008    0.035   -0.235    0.814   -0.009   -0.009
##     wepe2             0.166    0.034    4.827    0.000    0.185    0.185
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr1 ~~                                                               
##     wepe1             0.050    0.024    2.060    0.039    0.077    0.077
##  .wcr2 ~~                                                               
##    .wepe2             0.189    0.026    7.413    0.000    0.285    0.285
##  .wcr3 ~~                                                               
##    .wepe3            -0.013    0.016   -0.799    0.424   -0.025   -0.025
##   RIcr ~~                                                               
##     RIepe             0.055    0.024    2.292    0.022    0.105    0.105
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .c_ref_w1          3.041    0.026  115.174    0.000    3.041    2.476
##    .c_ref_w2          3.280    0.027  120.418    0.000    3.280    2.589
##    .c_ref_w3          3.161    0.026  119.839    0.000    3.161    2.604
##    .ex_eff_w1         2.596    0.022  119.396    0.000    2.596    2.566
##    .ex_eff_w2         2.412    0.022  107.976    0.000    2.412    2.321
##    .ex_eff_w3         2.241    0.021  106.311    0.000    2.241    2.330
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIcr              0.921    0.043   21.268    0.000    1.000    1.000
##     RIepe             0.304    0.026   11.560    0.000    1.000    1.000
##     wcr1              0.588    0.037   15.834    0.000    1.000    1.000
##     wepe1             0.719    0.032   22.155    0.000    1.000    1.000
##    .wcr2              0.641    0.038   17.027    0.000    0.938    0.938
##    .wepe2             0.687    0.036   18.938    0.000    0.885    0.885
##    .wcr3              0.447    0.021   20.855    0.000    0.808    0.808
##    .wepe3             0.601    0.025   23.615    0.000    0.967    0.967
##    .c_ref_w1          0.000                               0.000    0.000
##    .c_ref_w2          0.000                               0.000    0.000
##    .c_ref_w3          0.000                               0.000    0.000
##    .ex_eff_w1         0.000                               0.000    0.000
##    .ex_eff_w2         0.000                               0.000    0.000
##    .ex_eff_w3         0.000                               0.000    0.000
## 
## R-Square:
##                    Estimate
##     wcr2              0.062
##     wepe2             0.115
##     wcr3              0.192
##     wepe3             0.033
##     c_ref_w1          1.000
##     c_ref_w2          1.000
##     c_ref_w3          1.000
##     ex_eff_w1         1.000
##     ex_eff_w2         1.000
##     ex_eff_w3         1.000

#RICLPM CR + IPE

RICLPM6 <- '
  # Create between components (random intercepts)
  RIcr =~ 1*c_ref_w1 + 1*c_ref_w2 + 1*c_ref_w3 
  RIipe =~ 1*in_eff_w1 + 1*in_eff_w2 + 1*in_eff_w3 
  
  # Create within-person centered variables
  wcr1 =~ 1*c_ref_w1
  wcr2 =~ 1*c_ref_w2
  wcr3 =~ 1*c_ref_w3 

  wipe1 =~ 1*in_eff_w1
  wipe2 =~ 1*in_eff_w2
  wipe3 =~ 1*in_eff_w3 

# Estimate lagged effects between within-person centered variables
  wcr2 + wipe2 ~ wcr1 + wipe1
  wcr3 + wipe3 ~ wcr2 + wipe2
  
  # Estimate covariance between within-person centered variables at first wave
  wcr1 ~~ wipe1 # Covariance
  
  # Estimate covariances between residuals of within-person centered variables
  # (i.e., innovations)
  wcr2 ~~ wipe2
  wcr3 ~~ wipe3
  
  # Estimate variance and covariance of random intercepts
  RIcr ~~ RIcr
  RIipe ~~ RIipe
  RIcr ~~ RIipe
  
  # Estimate (residual) variance of within-person centered variables
  wcr1 ~~ wcr1 # Variances
  wipe1 ~~ wipe1 
  wcr2 ~~ wcr2 # Residual variances
  wipe2 ~~ wipe2 
  wcr3 ~~ wcr3 
  wipe3 ~~ wipe3'

RICLPM6fit <- lavaan(RICLPM6, 
  data = ANES, 
  missing = 'ML',
  estimator = "ML",
  meanstructure = T, 
  int.ov.free = T)
## Warning: lavaan->lav_data_full():  
##    some cases are empty and will be ignored: 887.
summary(RICLPM6fit, fit.measures = T, standardized = T, rsquare = T)
## lavaan 0.6-19 ended normally after 47 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##                                                   Used       Total
##   Number of observations                          2170        2171
##   Number of missing patterns                        17            
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 1.281
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.258
## 
## Model Test Baseline Model:
## 
##   Test statistic                              5366.744
##   Degrees of freedom                                15
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       0.999
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                0.999
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -15431.882
##   Loglikelihood unrestricted model (H1)     -15431.242
##                                                       
##   Akaike (AIC)                               30915.764
##   Bayesian (BIC)                             31063.509
##   Sample-size adjusted Bayesian (SABIC)      30980.904
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.011
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.060
##   P-value H_0: RMSEA <= 0.050                    0.885
##   P-value H_0: RMSEA >= 0.080                    0.005
##                                                       
##   Robust RMSEA                                   0.012
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.061
##   P-value H_0: Robust RMSEA <= 0.050             0.873
##   P-value H_0: Robust RMSEA >= 0.080             0.006
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.004
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIcr =~                                                               
##     c_ref_w1          1.000                               0.990    0.806
##     c_ref_w2          1.000                               0.990    0.781
##     c_ref_w3          1.000                               0.990    0.815
##   RIipe =~                                                              
##     in_eff_w1         1.000                               0.567    0.710
##     in_eff_w2         1.000                               0.567    0.689
##     in_eff_w3         1.000                               0.567    0.694
##   wcr1 =~                                                               
##     c_ref_w1          1.000                               0.726    0.592
##   wcr2 =~                                                               
##     c_ref_w2          1.000                               0.790    0.624
##   wcr3 =~                                                               
##     c_ref_w3          1.000                               0.704    0.580
##   wipe1 =~                                                              
##     in_eff_w1         1.000                               0.562    0.704
##   wipe2 =~                                                              
##     in_eff_w2         1.000                               0.596    0.724
##   wipe3 =~                                                              
##     in_eff_w3         1.000                               0.588    0.720
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr2 ~                                                                
##     wcr1              0.173    0.060    2.888    0.004    0.159    0.159
##     wipe1             0.074    0.058    1.276    0.202    0.053    0.053
##   wipe2 ~                                                               
##     wcr1              0.010    0.040    0.256    0.798    0.013    0.013
##     wipe1             0.145    0.053    2.758    0.006    0.137    0.137
##   wcr3 ~                                                                
##     wcr2              0.285    0.040    7.201    0.000    0.319    0.319
##     wipe2            -0.060    0.048   -1.255    0.210   -0.051   -0.051
##   wipe3 ~                                                               
##     wcr2              0.029    0.026    1.124    0.261    0.039    0.039
##     wipe2             0.282    0.037    7.525    0.000    0.286    0.286
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr1 ~~                                                               
##     wipe1             0.003    0.018    0.161    0.872    0.007    0.007
##  .wcr2 ~~                                                               
##    .wipe2             0.010    0.021    0.469    0.639    0.021    0.021
##  .wcr3 ~~                                                               
##    .wipe3             0.001    0.012    0.087    0.930    0.003    0.003
##   RIcr ~~                                                               
##     RIipe             0.120    0.021    5.803    0.000    0.214    0.214
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .c_ref_w1          3.041    0.026  115.240    0.000    3.041    2.477
##    .c_ref_w2          3.280    0.027  120.397    0.000    3.280    2.589
##    .c_ref_w3          3.161    0.026  119.741    0.000    3.161    2.602
##    .in_eff_w1         3.221    0.017  187.567    0.000    3.221    4.032
##    .in_eff_w2         3.378    0.018  191.015    0.000    3.378    4.105
##    .in_eff_w3         3.350    0.018  188.105    0.000    3.350    4.100
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIcr              0.980    0.044   22.329    0.000    1.000    1.000
##     RIipe             0.322    0.019   16.573    0.000    1.000    1.000
##     wcr1              0.527    0.034   15.539    0.000    1.000    1.000
##     wipe1             0.316    0.019   16.959    0.000    1.000    1.000
##    .wcr2              0.607    0.041   14.876    0.000    0.972    0.972
##    .wipe2             0.349    0.021   16.779    0.000    0.981    0.981
##    .wcr3              0.445    0.022   20.428    0.000    0.896    0.896
##    .wipe3             0.317    0.013   24.244    0.000    0.916    0.916
##    .c_ref_w1          0.000                               0.000    0.000
##    .c_ref_w2          0.000                               0.000    0.000
##    .c_ref_w3          0.000                               0.000    0.000
##    .in_eff_w1         0.000                               0.000    0.000
##    .in_eff_w2         0.000                               0.000    0.000
##    .in_eff_w3         0.000                               0.000    0.000
## 
## R-Square:
##                    Estimate
##     wcr2              0.028
##     wipe2             0.019
##     wcr3              0.104
##     wipe3             0.084
##     c_ref_w1          1.000
##     c_ref_w2          1.000
##     c_ref_w3          1.000
##     in_eff_w1         1.000
##     in_eff_w2         1.000
##     in_eff_w3         1.000

#RICLPM IPE + CA

RICLPM7 <- '
  # Create between components (random intercepts)
  RIipe =~ 1*in_eff_w1 + 1*in_eff_w2 + 1*in_eff_w3 
  RIca =~ 1*c_act_w1 + 1*c_act_w2 + 1*c_act_w3 
  
  # Create within-person centered variables
  wipe1 =~ 1*in_eff_w1
  wipe2 =~ 1*in_eff_w2
  wipe3 =~ 1*in_eff_w3 

  wca1 =~ 1*c_act_w1
  wca2 =~ 1*c_act_w2
  wca3 =~ 1*c_act_w3
# Estimate lagged effects between within-person centered variables
  wipe2 + wca2 ~ wipe1 + wca1
  wipe3 + wca3 ~ wipe2 + wca2
  
  # Estimate covariance between within-person centered variables at first wave
  wipe1 ~~ wca1 # Covariance
  
  # Estimate covariances between residuals of within-person centered variables
  # (i.e., innovations)
  wipe2 ~~ wca2
  wipe3 ~~ wca3
  
  # Estimate variance and covariance of random intercepts
  RIipe ~~ RIipe
  RIca ~~ RIca
  RIipe ~~ RIca
  
  # Estimate (residual) variance of within-person centered variables
  wipe1 ~~ wipe1 # Variances
  wca1 ~~ wca1 
  wipe2 ~~ wipe2 # Residual variances
  wca2 ~~ wca2 
  wipe3 ~~ wipe3 
  wca3 ~~ wca3'

RICLPM7fit <- lavaan(RICLPM7, 
  data = ANES, 
  missing = 'ML',
  estimator = "ML",
  meanstructure = T, 
  int.ov.free = T)

summary(RICLPM7fit, fit.measures = T, standardized = T, rsquare = T)
## lavaan 0.6-19 ended normally after 74 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        26
## 
##   Number of observations                          2171
##   Number of missing patterns                        13
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.302
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.129
## 
## Model Test Baseline Model:
## 
##   Test statistic                              3093.125
##   Degrees of freedom                                15
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       0.994
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                0.994
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -5707.744
##   Loglikelihood unrestricted model (H1)      -5706.593
##                                                       
##   Akaike (AIC)                               11467.488
##   Bayesian (BIC)                             11615.245
##   Sample-size adjusted Bayesian (SABIC)      11532.639
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.024
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.068
##   P-value H_0: RMSEA <= 0.050                    0.792
##   P-value H_0: RMSEA >= 0.080                    0.014
##                                                       
##   Robust RMSEA                                   0.025
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.069
##   P-value H_0: Robust RMSEA <= 0.050             0.776
##   P-value H_0: Robust RMSEA >= 0.080             0.017
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.006
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIipe =~                                                              
##     in_eff_w1         1.000                               0.555    0.696
##     in_eff_w2         1.000                               0.555    0.675
##     in_eff_w3         1.000                               0.555    0.679
##   RIca =~                                                               
##     c_act_w1          1.000                               0.120    0.465
##     c_act_w2          1.000                               0.120    0.488
##     c_act_w3          1.000                               0.120    0.670
##   wipe1 =~                                                              
##     in_eff_w1         1.000                               0.572    0.718
##   wipe2 =~                                                              
##     in_eff_w2         1.000                               0.607    0.738
##   wipe3 =~                                                              
##     in_eff_w3         1.000                               0.600    0.734
##   wca1 =~                                                               
##     c_act_w1          1.000                               0.227    0.885
##   wca2 =~                                                               
##     c_act_w2          1.000                               0.214    0.873
##   wca3 =~                                                               
##     c_act_w3          1.000                               0.132    0.742
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wipe2 ~                                                               
##     wipe1             0.159    0.051    3.088    0.002    0.149    0.149
##     wca1              0.277    0.084    3.287    0.001    0.104    0.104
##   wca2 ~                                                                
##     wipe1             0.053    0.012    4.304    0.000    0.141    0.141
##     wca1              0.256    0.027    9.306    0.000    0.272    0.272
##   wipe3 ~                                                               
##     wipe2             0.280    0.037    7.534    0.000    0.283    0.283
##     wca2              0.414    0.088    4.697    0.000    0.147    0.147
##   wca3 ~                                                                
##     wipe2             0.008    0.009    0.838    0.402    0.035    0.035
##     wca2              0.042    0.032    1.332    0.183    0.069    0.069
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wipe1 ~~                                                              
##     wca1              0.023    0.004    5.385    0.000    0.179    0.179
##  .wipe2 ~~                                                              
##    .wca2              0.020    0.004    5.112    0.000    0.168    0.168
##  .wipe3 ~~                                                              
##    .wca3              0.007    0.003    2.757    0.006    0.097    0.097
##   RIipe ~~                                                              
##     RIca              0.019    0.003    5.620    0.000    0.287    0.287
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .in_eff_w1         3.221    0.017  187.844    0.000    3.221    4.038
##    .in_eff_w2         3.378    0.018  191.006    0.000    3.378    4.104
##    .in_eff_w3         3.351    0.018  187.966    0.000    3.351    4.096
##    .c_act_w1          0.213    0.006   38.616    0.000    0.213    0.830
##    .c_act_w2          0.171    0.005   32.616    0.000    0.171    0.700
##    .c_act_w3          0.081    0.004   20.756    0.000    0.081    0.454
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIipe             0.309    0.020   15.811    0.000    1.000    1.000
##     RIca              0.014    0.001   10.235    0.000    1.000    1.000
##     wipe1             0.328    0.019   16.999    0.000    1.000    1.000
##     wca1              0.052    0.002   26.527    0.000    1.000    1.000
##    .wipe2             0.355    0.020   17.552    0.000    0.961    0.961
##    .wca2              0.041    0.002   24.835    0.000    0.893    0.893
##    .wipe3             0.317    0.013   24.454    0.000    0.880    0.880
##    .wca3              0.017    0.001   13.216    0.000    0.993    0.993
##    .in_eff_w1         0.000                               0.000    0.000
##    .in_eff_w2         0.000                               0.000    0.000
##    .in_eff_w3         0.000                               0.000    0.000
##    .c_act_w1          0.000                               0.000    0.000
##    .c_act_w2          0.000                               0.000    0.000
##    .c_act_w3          0.000                               0.000    0.000
## 
## R-Square:
##                    Estimate
##     wipe2             0.039
##     wca2              0.107
##     wipe3             0.120
##     wca3              0.007
##     in_eff_w1         1.000
##     in_eff_w2         1.000
##     in_eff_w3         1.000
##     c_act_w1          1.000
##     c_act_w2          1.000
##     c_act_w3          1.000