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)

library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric

#read in data

setwd("~/Downloads/foldah")

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

#clean data

ANES <- ANES %>%
  mutate(across(
    .cols = starts_with("V2"),
    .fns = ~replace(., . %in% c(-9, -8, -7, -6, -5, -4, -2, -1), NA)
  ))

ANES <- ANES %>%
  mutate(across(
    .cols = starts_with("V1"),
    .fns = ~replace(., . %in% c(-9, -8, -7, -6, -5, -4, -2, -1), NA)
  ))

#Critical Reflection Scale

#reverse coding measure of belief in slavery's legacy
ANES$CR_slav_w1 <- dplyr::recode(ANES$V162212,
                                         `1` = 5,
                                         `2` = 4,
                                         `3` = 3,
                                         `4` = 2,
                                         `5` = 1)

#renaming measure of if black people would be equal if they work their way up
ANES$CR_wrk_w1 <- ANES$V162214

#same for 2020
ANES$CR_slav_w2 <- dplyr::recode(ANES$V202301,
                                         `1` = 5,
                                         `2` = 4,
                                         `3` = 3,
                                         `4` = 2,
                                         `5` = 1)


ANES$CR_wrk_w2 <- ANES$V202303

#same for 2024

ANES$CR_slav_w3 <- dplyr::recode(ANES$V242301,
                                         `1` = 5,
                                         `2` = 4,
                                         `3` = 3,
                                         `4` = 2,
                                         `5` = 1)

ANES$CR_wrk_w3 <-ANES$V242303


ANES$c_ref_w1 <- ((ANES$CR_wrk_w1 + ANES$CR_slav_w1)/2)

ANES$c_ref_w2 <- ((ANES$CR_wrk_w2 + ANES$CR_slav_w2)/2)

ANES$c_ref_w3 <- ((ANES$CR_wrk_w3 + ANES$CR_slav_w3)/2)

#Critical Action Scale

#Contact rep?
ANES$CA_rep_w1 <- ifelse(ANES$V162019 == 1, 1, 0)

#Attend protest?
ANES$CA_pro_w1 <- ifelse(ANES$V162018a == 1, 1, 0)

#Participate in community organizing?
ANES$CA_org_w1 <- ifelse(ANES$V162195 == 1, 1, 0)

ANES$CA_mtn_w1 <- ifelse(ANES$V162196 == 1, 1, 0)

#Petition?
ANES$CA_pet_w1 <- ifelse(ANES$V162018b == 1, 1, 0)

#boycott?
ANES$CA_byc_w1 <- ifelse(ANES$V162141 == 1, 0, 1)


#same for 2020
ANES$CA_rep_w2 <- ifelse(ANES$V202030 == 1, 1, 0)

ANES$CA_pro_w2 <- ifelse(ANES$V202025 == 1, 1, 0)

ANES$CA_org_w2 <- ifelse(ANES$V202031 == 1, 1, 0)

ANES$CA_mtn_w2 <- ifelse(ANES$V202032 == 1, 1, 0)

ANES$CA_pet_w2 <- ifelse(ANES$V202026 == 1, 1, 0)

ANES$CA_byc_w2 <- ifelse(ANES$V242037 == 1, 0, 1)

#same for 2024

ANES$CA_rep_w3 <- ifelse(ANES$V242036 == 1, 1, 0)

ANES$CA_pro_w3 <- ifelse(ANES$V242029 == 1, 1, 0)

ANES$CA_org_w3 <- ifelse(ANES$V242034 == 1, 1, 0)

ANES$CA_mtn_w3 <- ifelse(ANES$V242034 == 1, 1, 0)

ANES$CA_pet_w3 <- ifelse(ANES$V242030 == 1, 1, 0)

ANES$CA_byc_w3 <- ifelse(ANES$V242037 == 1, 1, 0)


ANES$c_act_w1 <- ((ANES$CA_org_w1 + ANES$CA_mtn_w1 + ANES$CA_pro_w1 + ANES$CA_rep_w1)/4)

ANES$c_act_w2 <- ((ANES$CA_org_w2 + ANES$CA_mtn_w2 + ANES$CA_pro_w2 + ANES$CA_rep_w2)/4)

ANES$c_act_w3 <- ((ANES$CA_mtn_w3 + ANES$CA_pro_w3 + ANES$CA_rep_w3)/3)

#External Efficacy Scale

#Ptx care what you think?
ANES$EPE_care_w1 <- ANES$V162215

#Do you have a say in ptx?
ANES$EPE_say_w1 <- ANES$V162216

#Same for 2020
ANES$EPE_say_w2 <- ANES$V202213

ANES$EPE_care_w2 <- ANES$V202212

#Same for 2024
ANES$EPE_say_w3 <- ANES$V242201

ANES$EPE_care_w3 <- ANES$V242200

ANES$ex_eff_w1 <- ((ANES$EPE_say_w1 + ANES$EPE_care_w1)/2)

ANES$ex_eff_w2 <- ((ANES$EPE_say_w2 + ANES$EPE_care_w2)/2)

ANES$ex_eff_w3 <- ((ANES$EPE_say_w3 + ANES$EPE_care_w3)/2)

#Internal Efficacy

#Are ptx complicated?
ANES$IPE_comp_w1 <- ANES$V162217


#Do you understand ptx?
ANES$IPE_und_w1 <- dplyr::recode(ANES$V162218,
                                         `1` = 5,
                                         `2` = 4,
                                         `3` = 3,
                                         `4` = 2,
                                         `5` = 1)


#Same for 2020
ANES$IPE_comp_w2 <- ANES$V202214
ANES$IPE_und_w2 <- dplyr::recode(ANES$V202215,
                                         `1` = 5,
                                         `2` = 4,
                                         `3` = 3,
                                         `4` = 2,
                                         `5` = 1)

#Same for 2024 
ANES$IPE_comp_w3 <- ANES$V242202
ANES$IPE_und_w3 <- dplyr::recode(ANES$V242203,
                                         `1` = 5,
                                         `2` = 4,
                                         `3` = 3,
                                         `4` = 2,
                                         `5` = 1)

ANES$in_eff_w1 <- ((ANES$IPE_und_w1 + ANES$IPE_comp_w1)/2)

ANES$in_eff_w2 <- ((ANES$IPE_und_w2 + ANES$IPE_comp_w2)/2)

ANES$in_eff_w3 <- ((ANES$IPE_und_w3 + ANES$IPE_comp_w3)/2)

ANES$in_eff_trait <- ((ANES$in_eff_w1 + ANES$in_eff_w2 + ANES$in_eff_w3)/3)

#Demographic Variables

ANES$Black <- ifelse(ANES$V201549x == 2, 1, 0)

ANES$White <- ifelse(ANES$V201549x == 1, 1, 0)

ANES$Hispanic <- ifelse(ANES$V201549x == 3, 1, 0)

ANES$Asian <- ifelse(ANES$V201549x == 4, 1, 0)

ANES$Native <- ifelse(ANES$V201549x == 5, 1, 0)

ANES$Other <- ifelse(ANES$V201549x == 6, 1, 0)

ANES$Female <- ifelse(ANES$V201600 == 2, 1, 0)

#Mean split

ANES$in_eff_ms_w1 <- ifelse(ANES$in_eff_w1 > mean(ANES$in_eff_w1, na.rm = TRUE), 1, 0)

ANES$in_eff_ms_w2 <- ifelse(ANES$in_eff_w2 > mean(ANES$in_eff_w2, na.rm = TRUE), 1, 0)

ANES$in_eff_ms_w3 <- ifelse(ANES$in_eff_w3 > mean(ANES$in_eff_w3, na.rm = TRUE), 1, 0)

ANES$in_eff_trait_ms <- ifelse(ANES$in_eff_trait > mean(ANES$in_eff_trait, na.rm = TRUE), 1, 0)

ANES$ex_eff_trait <- ((ANES$ex_eff_w1 + ANES$ex_eff_w2 + ANES$ex_eff_w3)/3)


ANES$ex_eff_trait_ms <- ifelse(ANES$ex_eff_trait > mean(ANES$ex_eff_trait, na.rm = TRUE), 1, 0)

ANES_grouped <- subset(ANES, !is.na(in_eff_trait_ms))


ANES_grouped2 <- subset(ANES, !is.na(ex_eff_trait_ms))

#composite summaries

summary(ANES$in_eff_w1)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   2.500   3.000   3.221   3.500   5.000      10
summary(ANES$in_eff_w2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    1.00    3.00    3.50    3.38    4.00    5.00       9
summary(ANES$in_eff_w3)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   3.000   3.500   3.354   4.000   5.000     113
summary(ANES$ex_eff_w1)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   2.000   2.500   2.595   3.500   5.000       7
summary(ANES$ex_eff_w2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   1.500   2.000   2.413   3.000   5.000       9
summary(ANES$ex_eff_w3)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   1.500   2.000   2.244   3.000   5.000     112
summary(ANES$c_ref_w1)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   2.000   3.000   3.042   4.000   5.000      11
summary(ANES$c_ref_w2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   2.500   3.000   3.283   4.500   5.000      16
summary(ANES$c_ref_w3)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   2.000   3.000   3.168   4.000   5.000     125
summary(ANES$c_act_w1)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##  0.0000  0.0000  0.0000  0.2134  0.5000  1.0000       7
summary(ANES$c_act_w2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##  0.0000  0.0000  0.0000  0.1715  0.2500  1.0000       2
summary(ANES$c_act_w3)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##  0.0000  0.0000  0.0000  0.0812  0.0000  1.0000     102

#RICLPM IPE Mod (this one worked)

RICLPMmod <- '
  # 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 ~ wcr1 + wca1
  wcr3 ~ c(g1, g2)*wca2
  wcr3 ~ wcr2
  wca2 ~ wca1
  wca3 ~ wca2
  wca2 ~ c(g1, g2)*wcr1
  wca3 ~ wcr2
  
  # 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'

RICLPMmodfit <- lavaan(RICLPMmod, 
  data = ANES_grouped, 
  missing = 'ML',
  estimator = "ML",
  meanstructure = T, 
  group = "in_eff_trait_ms",
  int.ov.free = T)

summary(RICLPMmodfit, fit.measures = T, standardized = T, rsquare = T)
## lavaan 0.6-19 ended normally after 122 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        52
##   Number of equality constraints                     2
## 
##   Number of observations per group:                   
##     0                                              948
##     1                                             1096
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                6
## 
## Model Test User Model:
##                                                       
##   Test statistic                                29.345
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.000
##   Test statistic for each group:
##     0                                            3.544
##     1                                           25.801
## 
## Model Test Baseline Model:
## 
##   Test statistic                              4076.133
##   Degrees of freedom                                30
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.994
##   Tucker-Lewis Index (TLI)                       0.953
##                                                       
##   Robust Comparative Fit Index (CFI)             0.994
##   Robust Tucker-Lewis Index (TLI)                0.953
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -7183.169
##   Loglikelihood unrestricted model (H1)      -7168.497
##                                                       
##   Akaike (AIC)                               14466.339
##   Bayesian (BIC)                             14747.472
##   Sample-size adjusted Bayesian (SABIC)      14588.618
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.079
##   90 Percent confidence interval - lower         0.054
##   90 Percent confidence interval - upper         0.107
##   P-value H_0: RMSEA <= 0.050                    0.031
##   P-value H_0: RMSEA >= 0.080                    0.506
##                                                       
##   Robust RMSEA                                   0.079
##   90 Percent confidence interval - lower         0.054
##   90 Percent confidence interval - upper         0.107
##   P-value H_0: Robust RMSEA <= 0.050             0.031
##   P-value H_0: Robust RMSEA >= 0.080             0.509
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.023
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIcr =~                                                               
##     c_ref_w1          1.000                               0.833    0.746
##     c_ref_w2          1.000                               0.833    0.693
##     c_ref_w3          1.000                               0.833    0.739
##   RIca =~                                                               
##     c_act_w1          1.000                               0.091    0.399
##     c_act_w2          1.000                               0.091    0.457
##     c_act_w3          1.000                               0.091    0.648
##   wcr1 =~                                                               
##     c_ref_w1          1.000                               0.744    0.666
##   wcr2 =~                                                               
##     c_ref_w2          1.000                               0.866    0.721
##   wcr3 =~                                                               
##     c_ref_w3          1.000                               0.759    0.674
##   wca1 =~                                                               
##     c_act_w1          1.000                               0.209    0.917
##   wca2 =~                                                               
##     c_act_w2          1.000                               0.177    0.889
##   wca3 =~                                                               
##     c_act_w3          1.000                               0.107    0.762
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr2 ~                                                                
##     wcr1              0.264    0.083    3.200    0.001    0.227    0.227
##     wca1              0.270    0.173    1.565    0.118    0.065    0.065
##   wcr3 ~                                                                
##     wca2      (g1)    0.020    0.011    1.796    0.072    0.005    0.005
##     wcr2              0.350    0.048    7.368    0.000    0.400    0.400
##   wca2 ~                                                                
##     wca1              0.228    0.036    6.350    0.000    0.269    0.269
##   wca3 ~                                                                
##     wca2             -0.017    0.052   -0.321    0.748   -0.028   -0.028
##   wca2 ~                                                                
##     wcr1      (g1)    0.020    0.011    1.796    0.072    0.084    0.084
##   wca3 ~                                                                
##     wcr2              0.006    0.008    0.774    0.439    0.048    0.048
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr1 ~~                                                               
##     wca1              0.005    0.007    0.681    0.496    0.033    0.033
##  .wcr2 ~~                                                               
##    .wca2              0.026    0.006    4.276    0.000    0.183    0.183
##  .wcr3 ~~                                                               
##    .wca3              0.005    0.004    1.458    0.145    0.073    0.073
##   RIcr ~~                                                               
##     RIca              0.019    0.005    3.791    0.000    0.248    0.248
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .c_ref_w1          2.880    0.036   79.384    0.000    2.880    2.580
##    .c_ref_w2          3.094    0.039   79.200    0.000    3.094    2.575
##    .c_ref_w3          3.028    0.037   82.623    0.000    3.028    2.688
##    .c_act_w1          0.159    0.007   21.435    0.000    0.159    0.697
##    .c_act_w2          0.113    0.006   17.538    0.000    0.113    0.570
##    .c_act_w3          0.051    0.005   11.210    0.000    0.051    0.364
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIcr              0.693    0.058   11.888    0.000    1.000    1.000
##     RIca              0.008    0.001    5.856    0.000    1.000    1.000
##     wcr1              0.553    0.053   10.481    0.000    1.000    1.000
##     wca1              0.044    0.002   18.862    0.000    1.000    1.000
##    .wcr2              0.708    0.055   12.887    0.000    0.943    0.943
##    .wca2              0.029    0.002   16.158    0.000    0.919    0.919
##    .wcr3              0.483    0.030   15.852    0.000    0.839    0.839
##    .wca3              0.011    0.001    7.595    0.000    0.998    0.998
##    .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.057
##     wca2              0.081
##     wcr3              0.161
##     wca3              0.002
##     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
## 
## 
## Group 2 [1]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIcr =~                                                               
##     c_ref_w1          1.000                               1.082    0.826
##     c_ref_w2          1.000                               1.082    0.828
##     c_ref_w3          1.000                               1.082    0.854
##   RIca =~                                                               
##     c_act_w1          1.000                               0.135    0.498
##     c_act_w2          1.000                               0.135    0.510
##     c_act_w3          1.000                               0.135    0.660
##   wcr1 =~                                                               
##     c_ref_w1          1.000                               0.738    0.564
##   wcr2 =~                                                               
##     c_ref_w2          1.000                               0.732    0.560
##   wcr3 =~                                                               
##     c_ref_w3          1.000                               0.660    0.521
##   wca1 =~                                                               
##     c_act_w1          1.000                               0.235    0.867
##   wca2 =~                                                               
##     c_act_w2          1.000                               0.228    0.860
##   wca3 =~                                                               
##     c_act_w3          1.000                               0.154    0.752
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr2 ~                                                                
##     wcr1              0.129    0.081    1.600    0.110    0.130    0.130
##     wca1             -0.099    0.140   -0.707    0.479   -0.032   -0.032
##   wcr3 ~                                                                
##     wca2      (g2)    0.016    0.015    1.045    0.296    0.005    0.005
##     wcr2              0.218    0.070    3.124    0.002    0.242    0.242
##   wca2 ~                                                                
##     wca1              0.223    0.042    5.361    0.000    0.230    0.230
##   wca3 ~                                                                
##     wca2              0.045    0.045    1.009    0.313    0.067    0.067
##   wca2 ~                                                                
##     wcr1      (g2)    0.016    0.015    1.045    0.296    0.051    0.051
##   wca3 ~                                                                
##     wcr2             -0.016    0.012   -1.326    0.185   -0.078   -0.078
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr1 ~~                                                               
##     wca1              0.009    0.008    1.086    0.278    0.051    0.051
##  .wcr2 ~~                                                               
##    .wca2              0.011    0.008    1.458    0.145    0.070    0.070
##  .wcr3 ~~                                                               
##    .wca3             -0.005    0.005   -0.893    0.372   -0.047   -0.047
##   RIcr ~~                                                               
##     RIca              0.052    0.008    6.926    0.000    0.357    0.357
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .c_ref_w1          3.194    0.040   80.659    0.000    3.194    2.438
##    .c_ref_w2          3.469    0.039   87.876    0.000    3.469    2.655
##    .c_ref_w3          3.294    0.038   85.966    0.000    3.294    2.599
##    .c_act_w1          0.263    0.008   32.071    0.000    0.263    0.969
##    .c_act_w2          0.223    0.008   27.846    0.000    0.223    0.841
##    .c_act_w3          0.107    0.006   17.363    0.000    0.107    0.525
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIcr              1.171    0.068   17.332    0.000    1.000    1.000
##     RIca              0.018    0.002    8.242    0.000    1.000    1.000
##     wcr1              0.545    0.048   11.455    0.000    1.000    1.000
##     wca1              0.055    0.003   18.863    0.000    1.000    1.000
##    .wcr2              0.527    0.061    8.642    0.000    0.982    0.982
##    .wca2              0.049    0.003   17.131    0.000    0.943    0.943
##    .wcr3              0.410    0.033   12.470    0.000    0.941    0.941
##    .wca3              0.023    0.002   10.921    0.000    0.990    0.990
##    .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.018
##     wca2              0.057
##     wcr3              0.059
##     wca3              0.010
##     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
constraints <- '
  wca2 ~ c(g1, g2)*wcr1
  g1 == g2
'
lavTestWald(RICLPMmodfit, constraints = constraints)
## $stat
## [1] 0.05142862
## 
## $df
## [1] 1
## 
## $p.value
## [1] 0.8205958
## 
## $se
## [1] "standard"
constraints2 <- '
  wcr2 ~ c(g1, g2)*wca2
  g1 == g2
'
lavTestWald(RICLPMmodfit, constraints = constraints2)
## $stat
## [1] 0.05142862
## 
## $df
## [1] 1
## 
## $p.value
## [1] 0.8205958
## 
## $se
## [1] "standard"

#RICLPM EPE Mod (doing it the same way as the IPE one in case consistency is important – i prefer just using the latent variable version)

RICLPMmod9 <- '
  # 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 ~ wcr1 + wca1
  wcr3 ~ wcr2 + wca2
  wca2 ~ wca1
  wca3 ~ wca2
  wca2 ~ c(g1, g2)*wcr1
  wca3 ~ wcr2
  
  # 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'

RICLPMmodfit9 <- lavaan(RICLPMmod9, 
  data = ANES_grouped2, 
  missing = 'ML',
  estimator = "ML",
  meanstructure = T, 
  group = "ex_eff_trait_ms",
  int.ov.free = T)

summary(RICLPMmodfit9, fit.measures = T, standardized = T, rsquare = T)
## lavaan 0.6-19 ended normally after 129 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        52
## 
##   Number of observations per group:                   
##     1                                              968
##     0                                             1078
##   Number of missing patterns per group:               
##     1                                                6
##     0                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 4.544
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.103
##   Test statistic for each group:
##     1                                            1.153
##     0                                            3.391
## 
## Model Test Baseline Model:
## 
##   Test statistic                              4246.786
##   Degrees of freedom                                30
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.999
##   Tucker-Lewis Index (TLI)                       0.991
##                                                       
##   Robust Comparative Fit Index (CFI)             0.999
##   Robust Tucker-Lewis Index (TLI)                0.991
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -7328.011
##   Loglikelihood unrestricted model (H1)      -7325.739
##                                                       
##   Akaike (AIC)                               14760.021
##   Bayesian (BIC)                             15052.451
##   Sample-size adjusted Bayesian (SABIC)      14887.243
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.035
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.079
##   P-value H_0: RMSEA <= 0.050                    0.643
##   P-value H_0: RMSEA >= 0.080                    0.048
##                                                       
##   Robust RMSEA                                   0.035
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.080
##   P-value H_0: Robust RMSEA <= 0.050             0.642
##   P-value H_0: Robust RMSEA >= 0.080             0.048
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.009
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [1]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIcr =~                                                               
##     c_ref_w1          1.000                               0.985    0.807
##     c_ref_w2          1.000                               0.985    0.799
##     c_ref_w3          1.000                               0.985    0.823
##   RIca =~                                                               
##     c_act_w1          1.000                               0.139    0.527
##     c_act_w2          1.000                               0.139    0.538
##     c_act_w3          1.000                               0.139    0.717
##   wcr1 =~                                                               
##     c_ref_w1          1.000                               0.720    0.590
##   wcr2 =~                                                               
##     c_ref_w2          1.000                               0.741    0.601
##   wcr3 =~                                                               
##     c_ref_w3          1.000                               0.680    0.568
##   wca1 =~                                                               
##     c_act_w1          1.000                               0.224    0.850
##   wca2 =~                                                               
##     c_act_w2          1.000                               0.217    0.843
##   wca3 =~                                                               
##     c_act_w3          1.000                               0.135    0.697
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr2 ~                                                                
##     wcr1              0.219    0.077    2.838    0.005    0.213    0.213
##     wca1              0.268    0.154    1.746    0.081    0.081    0.081
##   wcr3 ~                                                                
##     wcr2              0.169    0.070    2.401    0.016    0.184    0.184
##     wca2              0.815    0.202    4.027    0.000    0.260    0.260
##   wca2 ~                                                                
##     wca1              0.237    0.042    5.592    0.000    0.243    0.243
##   wca3 ~                                                                
##     wca2              0.016    0.051    0.305    0.760    0.025    0.025
##   wca2 ~                                                                
##     wcr1      (g1)    0.081    0.017    4.742    0.000    0.270    0.270
##   wca3 ~                                                                
##     wcr2             -0.009    0.013   -0.670    0.503   -0.048   -0.048
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr1 ~~                                                               
##     wca1              0.014    0.008    1.758    0.079    0.087    0.087
##  .wcr2 ~~                                                               
##    .wca2              0.041    0.008    5.032    0.000    0.284    0.284
##  .wcr3 ~~                                                               
##    .wca3             -0.001    0.005   -0.225    0.822   -0.014   -0.014
##   RIcr ~~                                                               
##     RIca              0.045    0.008    5.901    0.000    0.331    0.331
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .c_ref_w1          3.226    0.039   82.260    0.000    3.226    2.645
##    .c_ref_w2          3.479    0.040   87.816    0.000    3.479    2.823
##    .c_ref_w3          3.320    0.039   86.166    0.000    3.320    2.774
##    .c_act_w1          0.226    0.008   26.710    0.000    0.226    0.859
##    .c_act_w2          0.188    0.008   22.652    0.000    0.188    0.728
##    .c_act_w3          0.094    0.006   15.149    0.000    0.094    0.487
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIcr              0.970    0.060   16.155    0.000    1.000    1.000
##     RIca              0.019    0.002    9.013    0.000    1.000    1.000
##     wcr1              0.518    0.045   11.423    0.000    1.000    1.000
##     wca1              0.050    0.003   17.838    0.000    1.000    1.000
##    .wcr2              0.519    0.051   10.192    0.000    0.945    0.945
##    .wca2              0.040    0.003   15.473    0.000    0.857    0.857
##    .wcr3              0.401    0.032   12.391    0.000    0.866    0.866
##    .wca3              0.018    0.002    8.668    0.000    0.998    0.998
##    .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.055
##     wca2              0.143
##     wcr3              0.134
##     wca3              0.002
##     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
## 
## 
## Group 2 [0]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   RIcr =~                                                               
##     c_ref_w1          1.000                               0.952    0.779
##     c_ref_w2          1.000                               0.952    0.742
##     c_ref_w3          1.000                               0.952    0.780
##   RIca =~                                                               
##     c_act_w1          1.000                               0.097    0.386
##     c_act_w2          1.000                               0.097    0.418
##     c_act_w3          1.000                               0.097    0.596
##   wcr1 =~                                                               
##     c_ref_w1          1.000                               0.767    0.627
##   wcr2 =~                                                               
##     c_ref_w2          1.000                               0.861    0.671
##   wcr3 =~                                                               
##     c_ref_w3          1.000                               0.764    0.626
##   wca1 =~                                                               
##     c_act_w1          1.000                               0.232    0.922
##   wca2 =~                                                               
##     c_act_w2          1.000                               0.211    0.908
##   wca3 =~                                                               
##     c_act_w3          1.000                               0.131    0.803
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr2 ~                                                                
##     wcr1              0.191    0.082    2.336    0.020    0.170    0.170
##     wca1              0.233    0.158    1.477    0.140    0.063    0.063
##   wcr3 ~                                                                
##     wcr2              0.329    0.049    6.698    0.000    0.371    0.371
##     wca2              0.485    0.170    2.854    0.004    0.134    0.134
##   wca2 ~                                                                
##     wca1              0.268    0.036    7.386    0.000    0.295    0.295
##   wca3 ~                                                                
##     wca2              0.077    0.044    1.766    0.077    0.124    0.124
##   wca2 ~                                                                
##     wcr1      (g2)    0.034    0.014    2.362    0.018    0.123    0.123
##   wca3 ~                                                                
##     wcr2              0.010    0.008    1.271    0.204    0.067    0.067
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   wcr1 ~~                                                               
##     wca1              0.018    0.009    2.119    0.034    0.103    0.103
##  .wcr2 ~~                                                               
##    .wca2              0.034    0.008    4.274    0.000    0.204    0.204
##  .wcr3 ~~                                                               
##    .wca3              0.010    0.004    2.313    0.021    0.108    0.108
##   RIcr ~~                                                               
##     RIca              0.015    0.006    2.363    0.018    0.166    0.166
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .c_ref_w1          2.888    0.037   77.489    0.000    2.888    2.362
##    .c_ref_w2          3.127    0.039   79.903    0.000    3.127    2.435
##    .c_ref_w3          3.036    0.037   81.597    0.000    3.036    2.487
##    .c_act_w1          0.204    0.008   26.708    0.000    0.204    0.814
##    .c_act_w2          0.158    0.007   22.393    0.000    0.158    0.682
##    .c_act_w3          0.069    0.005   13.928    0.000    0.069    0.424
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     RIcr              0.907    0.063   14.407    0.000    1.000    1.000
##     RIca              0.009    0.002    5.150    0.000    1.000    1.000
##     wcr1              0.588    0.053   11.100    0.000    1.000    1.000
##     wca1              0.054    0.003   19.084    0.000    1.000    1.000
##    .wcr2              0.716    0.061   11.716    0.000    0.965    0.965
##    .wca2              0.039    0.002   18.027    0.000    0.890    0.890
##    .wcr3              0.480    0.030   16.115    0.000    0.821    0.821
##    .wca3              0.017    0.002   10.024    0.000    0.976    0.976
##    .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.035
##     wca2              0.110
##     wcr3              0.179
##     wca3              0.024
##     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
constraints <- '
  wca2 ~ c(g1, g2)*wcr1
  g1 == g2
'
lavTestWald(RICLPMmodfit9, constraints = constraints)
## $stat
## [1] 4.534277
## 
## $df
## [1] 1
## 
## $p.value
## [1] 0.0332225
## 
## $se
## [1] "standard"

#Moderation Model EPE (original – latent variables using modsem)

model_mod <- '
  # Latent variables
CR1 =~ 1*CR_slav_w1 + CR_wrk_w1
CR2 =~ 1*CR_slav_w2 + CR_wrk_w2
CR3 =~ 1*CR_slav_w3 + CR_wrk_w3

CA1 =~ 1*CA_pro_w1 + CA_rep_w1 + CA_org_w1 + CA_mtn_w1
CA2 =~ 1*CA_pro_w2 + CA_rep_w2 + CA_org_w2 + CA_mtn_w2
CA3 =~ 1*CA_pro_w3 + CA_rep_w3 + CA_mtn_w3

EPE1 =~ 1*EPE_say_w1 + EPE_care_w1
EPE2 =~ 1*EPE_say_w2 + EPE_care_w2

  # Regressions
  
  CA2 ~ CA1
  CA2 ~ CR1
  CR2 ~ CR1
  CR2 ~ CA1
  CA3 ~ CA2
  CA3 ~ CR2
  CR3 ~ CR2
  CR3 ~ CA2
  
  CA2 ~ CR1:EPE1
  CA2 ~ EPE1
  CA3 ~ CR2:EPE2
  CA3 ~ EPE2

    
  CA_rep_w1 ~~ CA_rep_w2
  CA_rep_w2 ~~ CA_rep_w3
  CA_rep_w1 ~~ CA_rep_w3
  
'

fit_mod <- modsem(model_mod, data = ANES, estimator = "WLSMV", ordered = c("CA_pro_w1", "CA_rep_w1", "CA_org_w1", "CA_mtn_w1", "CA_pro_w2", "CA_rep_w2", "CA_org_w2", "CA_mtn_w2", "CA_pro_w3", "CA_rep_w3", "CA_mtn_w3"), method = "dblcent")

summary(fit_mod, fit.measures = T, standardized = T, rsquare = T)
## modsem (version 1.0.6, approach = dblcent):
## lavaan 0.6-19 ended normally after 84 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                       115
## 
##                                                   Used       Total
##   Number of observations                          2020        2171
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                               871.368    1003.409
##   Degrees of freedom                               338         338
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.006
##   Shift parameter                                          136.900
##     simple second-order correction                                
## 
## Model Test Baseline Model:
## 
##   Test statistic                             23046.648    9374.685
##   Degrees of freedom                               406         406
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  2.524
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.976       0.926
##   Tucker-Lewis Index (TLI)                       0.972       0.911
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.028       0.031
##   90 Percent confidence interval - lower         0.026       0.029
##   90 Percent confidence interval - upper         0.030       0.033
##   P-value H_0: RMSEA <= 0.050                    1.000       1.000
##   P-value H_0: RMSEA >= 0.080                    0.000       0.000
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.052       0.052
## 
## Parameter Estimates:
## 
##   Parameterization                               Delta
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   CR1 =~                                                                
##     CR_slav_w1        1.000                               0.970    0.675
##     CR_wrk_w1         1.059    0.055   19.345    0.000    1.028    0.757
##   CR2 =~                                                                
##     CR_slav_w2        1.000                               1.110    0.764
##     CR_wrk_w2         1.047    0.052   20.172    0.000    1.162    0.842
##   CR3 =~                                                                
##     CR_slav_w3        1.000                               1.028    0.726
##     CR_wrk_w3         1.037    0.051   20.148    0.000    1.065    0.800
##   CA1 =~                                                                
##     CA_pro_w1         1.000                               0.709    0.709
##     CA_rep_w1         0.757    0.083    9.116    0.000    0.537    0.537
##     CA_org_w1         1.247    0.109   11.481    0.000    0.884    0.884
##     CA_mtn_w1         1.191    0.103   11.509    0.000    0.845    0.845
##   CA2 =~                                                                
##     CA_pro_w2         1.000                               0.724    0.724
##     CA_rep_w2         0.782    0.063   12.439    0.000    0.566    0.566
##     CA_org_w2         0.993    0.066   15.108    0.000    0.719    0.719
##     CA_mtn_w2         1.016    0.071   14.240    0.000    0.736    0.736
##   CA3 =~                                                                
##     CA_pro_w3         1.000                               0.656    0.656
##     CA_rep_w3         0.870    0.123    7.060    0.000    0.571    0.571
##     CA_mtn_w3         1.040    0.144    7.227    0.000    0.682    0.682
##   EPE1 =~                                                               
##     EPE_say_w1        1.000                               0.998    0.820
##     EPE_care_w1       0.724    0.060   12.036    0.000    0.723    0.675
##   EPE2 =~                                                               
##     EPE_say_w2        1.000                               1.151    0.941
##     EPE_care_w2       0.620    0.047   13.172    0.000    0.714    0.647
##   CR1EPE1 =~                                                            
##     CR_slv_1EPE__1    1.000                               1.014    0.544
##     CR_wrk_1EPE__1    0.930    0.056   16.732    0.000    0.943    0.534
##     CR_slv_1EPE__1    0.896    0.058   15.479    0.000    0.908    0.561
##     CR_wrk_1EPE__1    0.858    0.072   11.846    0.000    0.869    0.570
##   CR2EPE2 =~                                                            
##     CR_slv_2EPE__2    1.000                               1.138    0.620
##     CR_wrk_2EPE__2    0.969    0.043   22.472    0.000    1.103    0.648
##     CR_slv_2EPE__2    0.837    0.055   15.302    0.000    0.953    0.584
##     CR_wrk_2EPE__2    0.778    0.061   12.759    0.000    0.885    0.580
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   CA2 ~                                                                 
##     CA1               0.669    0.068    9.829    0.000    0.655    0.655
##     CR1               0.195    0.027    7.340    0.000    0.261    0.261
##   CR2 ~                                                                 
##     CR1               1.119    0.077   14.539    0.000    0.979    0.979
##     CA1              -0.015    0.042   -0.361    0.718   -0.010   -0.010
##   CA3 ~                                                                 
##     CA2               0.720    0.097    7.415    0.000    0.795    0.795
##     CR2              -0.016    0.033   -0.486    0.627   -0.027   -0.027
##   CR3 ~                                                                 
##     CR2               0.873    0.044   19.756    0.000    0.943    0.943
##     CA2               0.076    0.034    2.243    0.025    0.053    0.053
##   CA2 ~                                                                 
##     CR1EPE1           0.116    0.027    4.285    0.000    0.162    0.162
##     EPE1              0.008    0.023    0.363    0.717    0.011    0.011
##   CA3 ~                                                                 
##     CR2EPE2           0.037    0.033    1.136    0.256    0.065    0.065
##     EPE2              0.053    0.026    2.025    0.043    0.094    0.094
## 
## Covariances:
##                            Estimate  Std.Err  z-value  P(>|z|)   Std.lv
##  .CA_rep_w1 ~~                                                         
##    .CA_rep_w2                 0.364    0.039    9.392    0.000    0.364
##  .CA_rep_w2 ~~                                                         
##    .CA_rep_w3                 0.378    0.042    9.038    0.000    0.378
##  .CA_rep_w1 ~~                                                         
##    .CA_rep_w3                 0.355    0.044    8.065    0.000    0.355
##  .CR_wrk_w1EPE_say_w1 ~~                                               
##    .CR_slv_1EPE__1            0.000                               0.000
##  .CR_slav_w1EPE_say_w1 ~~                                              
##    .CR_wrk_1EPE__1            0.000                               0.000
##    .CR_slv_1EPE__1            0.740    0.066   11.294    0.000    0.740
##  .CR_slav_w1EPE_care_w1 ~~                                             
##    .CR_wrk_1EPE__1            0.609    0.057   10.695    0.000    0.609
##  .CR_slav_w1EPE_say_w1 ~~                                              
##    .CR_wrk_1EPE__1            0.882    0.074   11.880    0.000    0.882
##  .CR_wrk_w1EPE_say_w1 ~~                                               
##    .CR_wrk_1EPE__1            0.761    0.062   12.314    0.000    0.761
##  .CR_wrk_w2EPE_say_w2 ~~                                               
##    .CR_slv_2EPE__2            0.000                               0.000
##  .CR_slav_w2EPE_say_w2 ~~                                              
##    .CR_wrk_2EPE__2            0.000                               0.000
##    .CR_slv_2EPE__2            0.740    0.057   12.889    0.000    0.740
##  .CR_slav_w2EPE_care_w2 ~~                                             
##    .CR_wrk_2EPE__2            0.679    0.056   12.151    0.000    0.679
##  .CR_slav_w2EPE_say_w2 ~~                                              
##    .CR_wrk_2EPE__2            0.694    0.080    8.623    0.000    0.694
##  .CR_wrk_w2EPE_say_w2 ~~                                               
##    .CR_wrk_2EPE__2            0.538    0.048   11.279    0.000    0.538
##   CR1 ~~                                                               
##     CA1                       0.173    0.030    5.832    0.000    0.251
##     EPE1                      0.091    0.027    3.320    0.001    0.094
##     EPE2                      0.334    0.037    9.084    0.000    0.299
##     CR1EPE1                  -0.021    0.032   -0.652    0.515   -0.021
##     CR2EPE2                  -0.023    0.032   -0.730    0.466   -0.021
##   CA1 ~~                                                               
##     EPE1                      0.112    0.025    4.378    0.000    0.158
##     EPE2                      0.123    0.027    4.571    0.000    0.150
##     CR1EPE1                   0.028    0.029    0.969    0.332    0.039
##     CR2EPE2                   0.094    0.031    3.019    0.003    0.116
##   EPE1 ~~                                                              
##     EPE2                      0.532    0.046   11.602    0.000    0.462
##     CR1EPE1                   0.051    0.030    1.698    0.090    0.051
##     CR2EPE2                   0.141    0.038    3.732    0.000    0.124
##   EPE2 ~~                                                              
##     CR1EPE1                   0.103    0.037    2.799    0.005    0.088
##     CR2EPE2                   0.105    0.032    3.244    0.001    0.080
##   CR1EPE1 ~~                                                           
##     CR2EPE2                   0.653    0.062   10.513    0.000    0.566
##  .CR3 ~~                                                               
##    .CA3                       0.031    0.018    1.733    0.083    0.311
##   Std.all
##          
##     0.524
##          
##     0.558
##          
##     0.512
##          
##     0.000
##          
##     0.000
##     0.353
##          
##     0.363
##          
##     0.378
##          
##     0.407
##          
##     0.000
##          
##     0.000
##     0.388
##          
##     0.412
##          
##     0.371
##          
##     0.333
##          
##     0.251
##     0.094
##     0.299
##    -0.021
##    -0.021
##          
##     0.158
##     0.150
##     0.039
##     0.116
##          
##     0.462
##     0.051
##     0.124
##          
##     0.088
##     0.080
##          
##     0.566
##          
##     0.311
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .CR_slav_w1        3.042    0.032   93.784    0.000    3.042    2.114
##    .CR_wrk_w1         3.059    0.030  101.229    0.000    3.059    2.253
##    .CR_slav_w2        3.228    0.035   93.377    0.000    3.228    2.224
##    .CR_wrk_w2         3.369    0.032  105.100    0.000    3.369    2.444
##    .CR_slav_w3        3.066    0.032   95.994    0.000    3.066    2.167
##    .CR_wrk_w3         3.279    0.030  109.233    0.000    3.279    2.462
##    .EPE_say_w1        2.779    0.028  100.564    0.000    2.779    2.282
##    .EPE_care_w1       2.440    0.026   93.515    0.000    2.440    2.279
##    .EPE_say_w2        2.540    0.030   83.998    0.000    2.540    2.075
##    .EPE_care_w2       2.292    0.029   79.002    0.000    2.292    2.078
##    .CR_slv_1EPE__1   -0.022    0.041   -0.540    0.589   -0.022   -0.012
##    .CR_wrk_1EPE__1   -0.024    0.039   -0.609    0.543   -0.024   -0.014
##    .CR_slv_1EPE__1   -0.022    0.036   -0.610    0.542   -0.022   -0.014
##    .CR_wrk_1EPE__1   -0.028    0.034   -0.827    0.408   -0.028   -0.018
##    .CR_slv_2EPE__2   -0.011    0.041   -0.266    0.791   -0.011   -0.006
##    .CR_wrk_2EPE__2   -0.004    0.038   -0.115    0.909   -0.004   -0.003
##    .CR_slv_2EPE__2   -0.006    0.037   -0.171    0.864   -0.006   -0.004
##    .CR_wrk_2EPE__2    0.007    0.034    0.214    0.831    0.007    0.005
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     CA_pro_w1|t1      1.767    0.051   34.506    0.000    1.767    1.767
##     CA_rep_w1|t1      1.125    0.035   31.823    0.000    1.125    1.125
##     CA_org_w1|t1      0.336    0.028   11.811    0.000    0.336    0.336
##     CA_mtn_w1|t1      0.454    0.029   15.690    0.000    0.454    0.454
##     CA_pro_w2|t1      1.365    0.040   34.356    0.000    1.365    1.365
##     CA_rep_w2|t1      0.920    0.033   28.195    0.000    0.920    0.920
##     CA_org_w2|t1      0.730    0.031   23.727    0.000    0.730    0.730
##     CA_mtn_w2|t1      0.876    0.032   27.238    0.000    0.876    0.876
##     CA_pro_w3|t1      1.864    0.055   33.850    0.000    1.864    1.864
##     CA_rep_w3|t1      1.235    0.037   33.214    0.000    1.235    1.235
##     CA_mtn_w3|t1      1.251    0.037   33.386    0.000    1.251    1.251
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .CR_slav_w1        1.128    0.056   20.285    0.000    1.128    0.545
##    .CR_wrk_w1         0.786    0.047   16.769    0.000    0.786    0.427
##    .CR_slav_w2        0.876    0.041   21.424    0.000    0.876    0.416
##    .CR_wrk_w2         0.552    0.034   16.369    0.000    0.552    0.290
##    .CR_slav_w3        0.945    0.040   23.496    0.000    0.945    0.472
##    .CR_wrk_w3         0.638    0.033   19.084    0.000    0.638    0.360
##    .CA_pro_w1         0.497                               0.497    0.497
##    .CA_rep_w1         0.711                               0.711    0.711
##    .CA_org_w1         0.218                               0.218    0.218
##    .CA_mtn_w1         0.286                               0.286    0.286
##    .CA_pro_w2         0.476                               0.476    0.476
##    .CA_rep_w2         0.679                               0.679    0.679
##    .CA_org_w2         0.483                               0.483    0.483
##    .CA_mtn_w2         0.459                               0.459    0.459
##    .CA_pro_w3         0.570                               0.570    0.570
##    .CA_rep_w3         0.674                               0.674    0.674
##    .CA_mtn_w3         0.535                               0.535    0.535
##    .EPE_say_w1        0.486    0.075    6.488    0.000    0.486    0.328
##    .EPE_care_w1       0.623    0.043   14.571    0.000    0.623    0.544
##    .EPE_say_w2        0.173    0.085    2.024    0.043    0.173    0.115
##    .EPE_care_w2       0.707    0.039   18.324    0.000    0.707    0.581
##    .CR_slv_1EPE__1    2.445    0.107   22.871    0.000    2.445    0.704
##    .CR_wrk_1EPE__1    2.226    0.098   22.676    0.000    2.226    0.714
##    .CR_slv_1EPE__1    1.796    0.085   21.224    0.000    1.796    0.685
##    .CR_wrk_1EPE__1    1.571    0.076   20.750    0.000    1.571    0.675
##    .CR_slv_2EPE__2    2.074    0.108   19.224    0.000    2.074    0.616
##    .CR_wrk_2EPE__2    1.683    0.093   18.028    0.000    1.683    0.580
##    .CR_slv_2EPE__2    1.752    0.075   23.285    0.000    1.752    0.659
##    .CR_wrk_2EPE__2    1.549    0.066   23.476    0.000    1.549    0.664
##     CR1               0.942    0.100    9.381    0.000    1.000    1.000
##    .CR2               0.058    0.046    1.249    0.212    0.047    0.047
##    .CR3               0.071    0.021    3.405    0.001    0.068    0.068
##     CA1               0.503    0.082    6.110    0.000    1.000    1.000
##    .CA2               0.200    0.031    6.526    0.000    0.381    0.381
##    .CA3               0.140    0.048    2.892    0.004    0.326    0.326
##     EPE1              0.997    0.104    9.549    0.000    1.000    1.000
##     EPE2              1.326    0.126   10.562    0.000    1.000    1.000
##     CR1EPE1           1.028    0.112    9.137    0.000    1.000    1.000
##     CR2EPE2           1.295    0.123   10.548    0.000    1.000    1.000
## 
## R-Square:
##                    Estimate
##     CR_slav_w1        0.455
##     CR_wrk_w1         0.573
##     CR_slav_w2        0.584
##     CR_wrk_w2         0.710
##     CR_slav_w3        0.528
##     CR_wrk_w3         0.640
##     CA_pro_w1         0.503
##     CA_rep_w1         0.289
##     CA_org_w1         0.782
##     CA_mtn_w1         0.714
##     CA_pro_w2         0.524
##     CA_rep_w2         0.321
##     CA_org_w2         0.517
##     CA_mtn_w2         0.541
##     CA_pro_w3         0.430
##     CA_rep_w3         0.326
##     CA_mtn_w3         0.465
##     EPE_say_w1        0.672
##     EPE_care_w1       0.456
##     EPE_say_w2        0.885
##     EPE_care_w2       0.419
##     CR_slv_1EPE__1    0.296
##     CR_wrk_1EPE__1    0.286
##     CR_slv_1EPE__1    0.315
##     CR_wrk_1EPE__1    0.325
##     CR_slv_2EPE__2    0.384
##     CR_wrk_2EPE__2    0.420
##     CR_slv_2EPE__2    0.341
##     CR_wrk_2EPE__2    0.336
##     CR2               0.953
##     CR3               0.932
##     CA2               0.619
##     CA3               0.674
(mean(ANES$EPE_say_w1, na.rm = TRUE) + mean(ANES$EPE_care_w1, na.rm = TRUE))/2
## [1] 2.595843
ANES$EPE_comp_w1 <- ((ANES$EPE_say_w1 + ANES$EPE_care_w1)/2)

mean(ANES$EPE_comp_w1, na.rm = TRUE)
## [1] 2.595425
sd(ANES$EPE_comp_w1, na.rm = TRUE)
## [1] 1.011959
#simple slopes
simple_slopes(x = "CR1", z = "EPE1", y = "CA2", vals_z = c(-1.01, 0, 1.01), model = fit_mod)
## 
## Predicted CA2, given EPE1 = -1.01:
## -------------------------------------------------------------------------
##   CR1 | Predicted CA2 | Std.Error | z.value | p.value |     Conf.Interval 
## -------------------------------------------------------------------------
## -2.91 |       -0.2356 |     0.105 |   -2.23 |   0.025 | [-0.442, -0.0289] 
## -1.94 |       -0.1598 |     0.080 |   -1.99 |   0.047 | [-0.317, -0.0023] 
## -0.97 |       -0.0841 |     0.063 |   -1.34 |   0.180 | [-0.207,  0.0388] 
##  0.00 |       -0.0083 |     0.059 |   -0.14 |   0.889 | [-0.125,  0.1082] 
##  0.97 |        0.0675 |     0.073 |    0.93 |   0.353 | [-0.075,  0.2098] 
##  1.94 |        0.1433 |     0.096 |    1.50 |   0.134 | [-0.044,  0.3307] 
##  2.91 |        0.2191 |     0.123 |    1.78 |   0.075 | [-0.022,  0.4602] 
## 
## 
## Predicted CA2, given EPE1 = 0:
## -------------------------------------------------------------------------
##   CR1 | Predicted CA2 | Std.Error | z.value | p.value |     Conf.Interval 
## -------------------------------------------------------------------------
## -2.91 |       -0.5678 |     0.084 |   -6.73 |   0.000 | [-0.733, -0.4025] 
## -1.94 |       -0.3785 |     0.066 |   -5.70 |   0.000 | [-0.509, -0.2484] 
## -0.97 |       -0.1893 |     0.055 |   -3.43 |   0.001 | [-0.297, -0.0812] 
##  0.00 |        0.0000 |     0.055 |    0.00 |   1.000 | [-0.107,  0.1073] 
##  0.97 |        0.1893 |     0.065 |    2.89 |   0.004 | [ 0.061,  0.3176] 
##  1.94 |        0.3785 |     0.083 |    4.55 |   0.000 | [ 0.216,  0.5414] 
##  2.91 |        0.5678 |     0.104 |    5.45 |   0.000 | [ 0.364,  0.7720] 
## 
## 
## Predicted CA2, given EPE1 = 1.01:
## -------------------------------------------------------------------------
##   CR1 | Predicted CA2 | Std.Error | z.value | p.value |     Conf.Interval 
## -------------------------------------------------------------------------
## -2.91 |       -0.8999 |     0.124 |   -7.27 |   0.000 | [-1.143, -0.6572] 
## -1.94 |       -0.5972 |     0.090 |   -6.65 |   0.000 | [-0.773, -0.4212] 
## -0.97 |       -0.2944 |     0.064 |   -4.59 |   0.000 | [-0.420, -0.1687] 
##  0.00 |        0.0083 |     0.059 |    0.14 |   0.889 | [-0.108,  0.1243] 
##  0.97 |        0.3110 |     0.079 |    3.94 |   0.000 | [ 0.156,  0.4656] 
##  1.94 |        0.6137 |     0.111 |    5.54 |   0.000 | [ 0.397,  0.8309] 
##  2.91 |        0.9164 |     0.147 |    6.23 |   0.000 | [ 0.628,  1.2049]