Estimation of moderation analyses.
#library
library(tidyverse)
library(lavaan)
library(data.table)
library(doParallel)
library(parallel)
#get data and estimates
load("results/predicted_means/240816_pred-means-cleaned-df.Rdata")
load(file = "results/riclpm/240816_lavaan-main-results.Rdata")
#create between level variables
MyData <- pred_results$df_combined %>%
rowwise() %>%
mutate(between_educ = mean(c_across(cols = matches("^educ_[[:digit:]]{1,2}")),na.rm = T),
between_age = mean(c_across(cols = matches("^age_[[:digit:]]{1,2}")),na.rm = T),
between_female = mean(c_across(cols = matches("^female_[[:digit:]]{1,2}")),na.rm = T),
between_origin = mean(c_across(cols = matches("^origin_[[:digit:]]{1,2}")),na.rm = T)) %>%
ungroup()
#create dir for storing model objects
dir <- file.path("results", "riclpm", "moderation_models")
library(Hmisc) #used to create cuts in a variable
#create between mean
MyData <- MyData %>%
rowwise() %>%
mutate(pol_dis = mean(c_across(starts_with("Fpol")), na.rm = T)) %>%
ungroup()
#create different groups
MyData <- MyData %>%
mutate(pol_disc_rec = cut2(pol_dis, g = 4),
pol_disc_2 = cut2(pol_dis, g = 2))
EU_model6_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_1 + 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_1 =~ 1*eu_1
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_2 ~ c(a1, a1)*weu_1 + c(b1, b1)*wFeduc_a_1
weu_3 ~ c(a2, a2)*weu_2 + c(b2, b2)*wFeduc_a_2
weu_4 ~ c(a3, a3)*weu_3 + c(b3, b3)*wFeduc_a_3
weu_5 ~ c(a4, a4)*weu_4 + c(b4, b4)*wFeduc_a_4
weu_6 ~ c(a5, a5)*weu_5 + c(b5, b5)*wFeduc_a_5
weu_7 ~ c(a6, a6)*weu_6 + c(b6, b6)*wFeduc_a_6
weu_8 ~ c(a7, a7)*weu_7 + c(b7, b7)*wFeduc_a_7
weu_9 ~ c(a8, a8)*weu_8 + c(b8, b8)*wFeduc_a_8
weu_10 ~ c(a9, a9)*weu_9 + c(b9, b9)*wFeduc_a_9
weu_11 ~ c(a10, a10)*weu_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c1)*weu_1 + c(d1, d1)*wFeduc_a_1
wFeduc_a_3 ~ c(c2, c2)*weu_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*weu_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*weu_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*weu_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*weu_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*weu_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*weu_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*weu_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*weu_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ c(cov1, cov2)*wFeduc_a_2
weu_3 ~~ c(cov1, cov2)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
weu_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ c(vy1, vy2)*weu_2
wFeduc_a_2 ~~ c(vx1, vx2)*wFeduc_a_2
weu_3 ~~ c(vy1, vy2)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*weu_1
'
#create and store model
#create filename
filename <- file.path(dir, "EU_model6_constrained_groups_fit.Rdata")
#estimate model
if(!file.exists(filename)){
EU_model6_constrained_groups_fit <- #estimate model
lavaan(
EU_model6_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(EU_model6_constrained_groups_fit,
file = filename)
} else {
load(file = filename)
}
EU_model6_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_1 + 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_1 =~ 1*eu_1
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_2 ~ c(a1, a2)*weu_1 + c(b1, b2)*wFeduc_a_1
weu_3 ~ c(a1, a2)*weu_2 + c(b1, b2)*wFeduc_a_2
weu_4 ~ c(a1, a2)*weu_3 + c(b1, b2)*wFeduc_a_3
weu_5 ~ c(a1, a2)*weu_4 + c(b1, b2)*wFeduc_a_4
weu_6 ~ c(a1, a2)*weu_5 + c(b1, b2)*wFeduc_a_5
weu_7 ~ c(a1, a2)*weu_6 + c(b1, b2)*wFeduc_a_6
weu_8 ~ c(a1, a2)*weu_7 + c(b1, b2)*wFeduc_a_7
weu_9 ~ c(a1, a2)*weu_8 + c(b1, b2)*wFeduc_a_8
weu_10 ~ c(a1, a2)*weu_9 + c(b1, b2)*wFeduc_a_9
weu_11 ~ c(a1, a2)*weu_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2)*weu_1 + c(d1, d2)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2)*weu_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*weu_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*weu_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*weu_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*weu_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*weu_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*weu_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*weu_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*weu_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ c(cov1, cov2)*wFeduc_a_2
weu_3 ~~ c(cov1, cov2)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
weu_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ c(vy1, vy2)*weu_2
wFeduc_a_2 ~~ c(vx1, vx2)*wFeduc_a_2
weu_3 ~~ c(vy1, vy2)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*weu_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model6_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model6_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model6_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(EU_model6_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model6_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model6_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[1]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(EU_model6_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
fit_matrix_EU_m6_constrained_groups <- lavInspect(EU_model6_constrained_lag_groups_fit, what = "fit")
fit_matrix_EU_m6_unconstrained_groups <- lavInspect(EU_model6_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_eu_M6 <- rbind(fit_matrix_EU_m6_constrained_groups, fit_matrix_EU_m6_unconstrained_groups)
lavTestLRT(EU_model6_constrained_lag_groups_fit, EU_model6_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model6_unconstrained_groups_constrained_lag_fit 640 154924
155484 2870.0 EU_model6_constrained_lag_groups_fit 647 154935 155450
2895.2 Chisq diff Df diff
EU_model6_unconstrained_groups_constrained_lag_fit
EU_model6_constrained_lag_groups_fit 10.923 7 Pr(>Chisq)
EU_model6_unconstrained_groups_constrained_lag_fit
EU_model6_constrained_lag_groups_fit 0.142
cult_model6_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_1 + 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_1 =~ 1*cult_1
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_2 ~ c(a1, a1)*wcult_1 + c(b1, b1)*wFeduc_a_1
wcult_3 ~ c(a2, a2)*wcult_2 + c(b2, b2)*wFeduc_a_2
wcult_4 ~ c(a3, a3)*wcult_3 + c(b3, b3)*wFeduc_a_3
wcult_5 ~ c(a4, a4)*wcult_4 + c(b4, b4)*wFeduc_a_4
wcult_6 ~ c(a5, a5)*wcult_5 + c(b5, b5)*wFeduc_a_5
wcult_7 ~ c(a6, a6)*wcult_6 + c(b6, b6)*wFeduc_a_6
wcult_8 ~ c(a7, a7)*wcult_7 + c(b7, b7)*wFeduc_a_7
wcult_9 ~ c(a8, a8)*wcult_8 + c(b8, b8)*wFeduc_a_8
wcult_10 ~ c(a9, a9)*wcult_9 + c(b9, b9)*wFeduc_a_9
wcult_11 ~ c(a10, a10)*wcult_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c1)*wcult_1 + c(d1, d1)*wFeduc_a_1
wFeduc_a_3 ~ c(c2, c2)*wcult_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*wcult_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*wcult_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*wcult_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*wcult_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*wcult_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*wcult_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*wcult_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*wcult_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
wcult_2 ~~ cov*wFeduc_a_2
wcult_3 ~~ cov*wFeduc_a_3
wcult_4 ~~ cov*wFeduc_a_4
wcult_5 ~~ cov*wFeduc_a_5
wcult_6 ~~ cov*wFeduc_a_6
wcult_7 ~~ cov*wFeduc_a_7
wcult_8 ~~ cov*wFeduc_a_8
wcult_9 ~~ cov*wFeduc_a_9
wcult_10 ~~ cov*wFeduc_a_10
wcult_11 ~~ cov*wFeduc_a_11
# Estimate the variance
wcult_1 ~~ wcult_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
wcult_2 ~~ vy*wcult_2
wFeduc_a_2 ~~ vx*wFeduc_a_2
wcult_3 ~~ vy*wcult_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
wcult_4 ~~ vy*wcult_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
wcult_5 ~~ vy*wcult_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
wcult_6 ~~ vy*wcult_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
wcult_7 ~~ vy*wcult_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
wcult_8 ~~ vy*wcult_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
wcult_9 ~~ vy*wcult_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
wcult_10 ~~ vy*wcult_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
wcult_11 ~~ vy*wcult_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*wcult_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model6_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model6_constrained_groups_fit <-
lavaan(
cult_model6_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(cult_model6_constrained_groups_fit,
file = filename)
} else{
load(file = filename)
}
cult_model6_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_1 + 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_1 =~ 1*cult_1
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_2 ~ c(a1, a2)*wcult_1 + c(b1, b2)*wFeduc_a_1
wcult_3 ~ c(a1, a2)*wcult_2 + c(b1, b2)*wFeduc_a_2
wcult_4 ~ c(a1, a2)*wcult_3 + c(b1, b2)*wFeduc_a_3
wcult_5 ~ c(a1, a2)*wcult_4 + c(b1, b2)*wFeduc_a_4
wcult_6 ~ c(a1, a2)*wcult_5 + c(b1, b2)*wFeduc_a_5
wcult_7 ~ c(a1, a2)*wcult_6 + c(b1, b2)*wFeduc_a_6
wcult_8 ~ c(a1, a2)*wcult_7 + c(b1, b2)*wFeduc_a_7
wcult_9 ~ c(a1, a2)*wcult_8 + c(b1, b2)*wFeduc_a_8
wcult_10 ~ c(a1, a2)*wcult_9 + c(b1, b2)*wFeduc_a_9
wcult_11 ~ c(a1, a2)*wcult_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2)*wcult_1 + c(d1, d2)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2)*wcult_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*wcult_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*wcult_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*wcult_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*wcult_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*wcult_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*wcult_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*wcult_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*wcult_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
wcult_2 ~~ c(cov1, cov2)*wFeduc_a_2
wcult_3 ~~ c(cov1, cov2)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
wcult_1 ~~ wcult_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
wcult_2 ~~ c(vy1, vy2)*wcult_2
wFeduc_a_2 ~~ c(vx1, vx2)*wFeduc_a_2
wcult_3 ~~ c(vy1, vy2)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*wcult_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model6_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model6_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model6_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(cult_model6_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model6_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model6_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[2]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(cult_model6_constrained_lag_groups_fit,
file = filename)
} else{
load(file = filename)
}
fit_matrix_cult_m6_constrained_groups <- lavInspect(cult_model6_constrained_lag_groups_fit, what = "fit")
fit_matrix_cult_m6_unconstrained_groups <- lavInspect(cult_model6_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_cult_M1 <- rbind(fit_matrix_cult_m6_constrained_groups, fit_matrix_cult_m6_unconstrained_groups)
lavTestLRT(cult_model6_constrained_lag_groups_fit, cult_model6_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model6_unconstrained_groups_constrained_lag_fit 640 148457
149017 2541.9 cult_model6_constrained_lag_groups_fit 647 148471 148985
2569.4 Chisq diff Df diff
cult_model6_unconstrained_groups_constrained_lag_fit
cult_model6_constrained_lag_groups_fit 12.306 7 Pr(>Chisq)
cult_model6_unconstrained_groups_constrained_lag_fit
cult_model6_constrained_lag_groups_fit 0.09094 . — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
inc_diff_model6_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_1 + 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_1 =~ 1*inc_diff_1
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_2 ~ c(a1, a1)*winc_diff_1 + c(b1, b1)*wFeduc_a_1
winc_diff_3 ~ c(a2, a2)*winc_diff_2 + c(b2, b2)*wFeduc_a_2
winc_diff_4 ~ c(a3, a3)*winc_diff_3 + c(b3, b3)*wFeduc_a_3
winc_diff_5 ~ c(a4, a4)*winc_diff_4 + c(b4, b4)*wFeduc_a_4
winc_diff_6 ~ c(a5, a5)*winc_diff_5 + c(b5, b5)*wFeduc_a_5
winc_diff_7 ~ c(a6, a6)*winc_diff_6 + c(b6, b6)*wFeduc_a_6
winc_diff_8 ~ c(a7, a7)*winc_diff_7 + c(b7, b7)*wFeduc_a_7
winc_diff_9 ~ c(a8, a8)*winc_diff_8 + c(b8, b8)*wFeduc_a_8
winc_diff_10 ~ c(a9, a9)*winc_diff_9 + c(b9, b9)*wFeduc_a_9
winc_diff_11 ~ c(a10, a10)*winc_diff_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c1)*winc_diff_1 + c(d1, d1)*wFeduc_a_1
wFeduc_a_3 ~ c(c2, c2)*winc_diff_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*winc_diff_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*winc_diff_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*winc_diff_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*winc_diff_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*winc_diff_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*winc_diff_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*winc_diff_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*winc_diff_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
winc_diff_2 ~~ cov*wFeduc_a_2
winc_diff_3 ~~ cov*wFeduc_a_3
winc_diff_4 ~~ cov*wFeduc_a_4
winc_diff_5 ~~ cov*wFeduc_a_5
winc_diff_6 ~~ cov*wFeduc_a_6
winc_diff_7 ~~ cov*wFeduc_a_7
winc_diff_8 ~~ cov*wFeduc_a_8
winc_diff_9 ~~ cov*wFeduc_a_9
winc_diff_10 ~~ cov*wFeduc_a_10
winc_diff_11 ~~ cov*wFeduc_a_11
# Estimate the variance
winc_diff_1 ~~ winc_diff_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
winc_diff_2 ~~ vy*winc_diff_2
wFeduc_a_2 ~~ vx*wFeduc_a_2
winc_diff_3 ~~ vy*winc_diff_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
winc_diff_4 ~~ vy*winc_diff_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
winc_diff_5 ~~ vy*winc_diff_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
winc_diff_6 ~~ vy*winc_diff_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
winc_diff_7 ~~ vy*winc_diff_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
winc_diff_8 ~~ vy*winc_diff_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
winc_diff_9 ~~ vy*winc_diff_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
winc_diff_10 ~~ vy*winc_diff_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
winc_diff_11 ~~ vy*winc_diff_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*winc_diff_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model6_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model6_constrained_groups_fit <-
lavaan(
inc_diff_model6_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(inc_diff_model6_constrained_groups_fit,
file = filename)
} else {
load(file = filename)
}
inc_diff_model6_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_1 + 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_1 =~ 1*inc_diff_1
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_2 ~ c(a1, a2)*winc_diff_1 + c(b1, b2)*wFeduc_a_1
winc_diff_3 ~ c(a1, a2)*winc_diff_2 + c(b1, b2)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2)*winc_diff_3 + c(b1, b2)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2)*winc_diff_4 + c(b1, b2)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2)*winc_diff_5 + c(b1, b2)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2)*winc_diff_6 + c(b1, b2)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2)*winc_diff_7 + c(b1, b2)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2)*winc_diff_8 + c(b1, b2)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2)*winc_diff_9 + c(b1, b2)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2)*winc_diff_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2)*winc_diff_1 + c(d1, d2)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2)*winc_diff_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*winc_diff_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*winc_diff_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*winc_diff_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*winc_diff_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*winc_diff_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*winc_diff_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*winc_diff_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*winc_diff_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
winc_diff_2 ~~ c(cov1, cov2)*wFeduc_a_2
winc_diff_3 ~~ c(cov1, cov2)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
winc_diff_1 ~~ winc_diff_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
winc_diff_2 ~~ c(vy1, vy2)*winc_diff_2
wFeduc_a_2 ~~ c(vx1, vx2)*wFeduc_a_2
winc_diff_3 ~~ c(vy1, vy2)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*winc_diff_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model6_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model6_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model6_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(inc_diff_model6_unconstrained_groups_constrained_lag_fit,
file = filename)
} else
(load(file = filename)
)
[1] “inc_diff_model6_unconstrained_groups_constrained_lag_fit”
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model6_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model6_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[3]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(inc_diff_model6_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
fit_matrix_inc_diff_m6_constrained_groups <- lavInspect(inc_diff_model6_constrained_lag_groups_fit, what = "fit")
fit_matrix_inc_diff_m6_unconstrained_groups <- lavInspect(inc_diff_model6_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_inc_diff_M1 <- rbind(fit_matrix_inc_diff_m6_constrained_groups, fit_matrix_inc_diff_m6_unconstrained_groups)
lavTestLRT(inc_diff_model6_constrained_lag_groups_fit, inc_diff_model6_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model6_unconstrained_groups_constrained_lag_fit 640 149302
149862 inc_diff_model6_constrained_lag_groups_fit 647 149316 149830
Chisq Chisq diff
inc_diff_model6_unconstrained_groups_constrained_lag_fit 2696.3
inc_diff_model6_constrained_lag_groups_fit 2723.8 11.98 Df diff
Pr(>Chisq)
inc_diff_model6_unconstrained_groups_constrained_lag_fit
inc_diff_model6_constrained_lag_groups_fit 7 0.1012
#create between level variable
MyData <- MyData %>%
rowwise() %>%
mutate(rl_mean = mean(c_across(starts_with("Frl")), na.rm = T)) %>%
ungroup()
#create groups
MyData <- MyData %>%
mutate(rl_rec = cut2(rl_mean, g = 5),
rl_2 = cut2(rl_mean, g = 2))
EU_model7_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ c(a2, a2)*weu_2 + c(b2, b2)*wFeduc_a_2
weu_4 ~ c(a3, a3)*weu_3 + c(b3, b3)*wFeduc_a_3
weu_5 ~ c(a4, a4)*weu_4 + c(b4, b4)*wFeduc_a_4
weu_6 ~ c(a5, a5)*weu_5 + c(b5, b5)*wFeduc_a_5
weu_7 ~ c(a6, a6)*weu_6 + c(b6, b6)*wFeduc_a_6
weu_8 ~ c(a7, a7)*weu_7 + c(b7, b7)*wFeduc_a_7
weu_9 ~ c(a8, a8)*weu_8 + c(b8, b8)*wFeduc_a_8
weu_10 ~ c(a9, a9)*weu_9 + c(b9, b9)*wFeduc_a_9
weu_11 ~ c(a10, a10)*weu_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_3 ~ c(c2, c2)*weu_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*weu_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*weu_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*weu_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*weu_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*weu_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*weu_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*weu_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*weu_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ c(cov1, cov2)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ c(vy1, vy2)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model7_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model7_constrained_groups_fit <-
lavaan(
EU_model7_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(EU_model7_constrained_groups_fit,
file = filename)
} else {
load(file = filename)
}
EU_model7_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ c(a1, a2)*weu_2 + c(b1, b2)*wFeduc_a_2
weu_4 ~ c(a1, a2)*weu_3 + c(b1, b2)*wFeduc_a_3
weu_5 ~ c(a1, a2)*weu_4 + c(b1, b2)*wFeduc_a_4
weu_6 ~ c(a1, a2)*weu_5 + c(b1, b2)*wFeduc_a_5
weu_7 ~ c(a1, a2)*weu_6 + c(b1, b2)*wFeduc_a_6
weu_8 ~ c(a1, a2)*weu_7 + c(b1, b2)*wFeduc_a_7
weu_9 ~ c(a1, a2)*weu_8 + c(b1, b2)*wFeduc_a_8
weu_10 ~ c(a1, a2)*weu_9 + c(b1, b2)*wFeduc_a_9
weu_11 ~ c(a1, a2)*weu_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2)*weu_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*weu_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*weu_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*weu_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*weu_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*weu_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*weu_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*weu_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*weu_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ c(cov1, cov2)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ c(vy1, vy2)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model7_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model7_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model7_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(EU_model7_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
EU_model7_constrained_lag_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ a*weu_2 + b*wFeduc_a_2
weu_4 ~ a*weu_3 + b*wFeduc_a_3
weu_5 ~ a*weu_4 + b*wFeduc_a_4
weu_6 ~ a*weu_5 + b*wFeduc_a_5
weu_7 ~ a*weu_6 + b*wFeduc_a_6
weu_8 ~ a*weu_7 + b*wFeduc_a_7
weu_9 ~ a*weu_8 + b*wFeduc_a_8
weu_10 ~ a*weu_9 + b*wFeduc_a_9
weu_11 ~ a*weu_10 + b*wFeduc_a_10
wFeduc_a_3 ~ c*weu_2 + d*wFeduc_a_2
wFeduc_a_4 ~ c*weu_3 + d*wFeduc_a_3
wFeduc_a_5 ~ c*weu_4 + d*wFeduc_a_4
wFeduc_a_6 ~ c*weu_5 + d*wFeduc_a_5
wFeduc_a_7 ~ c*weu_6 + d*wFeduc_a_6
wFeduc_a_8 ~ c*weu_7 + d*wFeduc_a_7
wFeduc_a_9 ~ c*weu_8 + d*wFeduc_a_8
wFeduc_a_10 ~ c*weu_9 + d*wFeduc_a_9
wFeduc_a_11 ~ c*weu_10 + d*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ cov*wFeduc_a_3
weu_4 ~~ cov*wFeduc_a_4
weu_5 ~~ cov*wFeduc_a_5
weu_6 ~~ cov*wFeduc_a_6
weu_7 ~~ cov*wFeduc_a_7
weu_8 ~~ cov*wFeduc_a_8
weu_9 ~~ cov*wFeduc_a_9
weu_10 ~~ cov*wFeduc_a_10
weu_11 ~~ cov*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ vy*weu_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
weu_4 ~~ vy*weu_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
weu_5 ~~ vy*weu_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
weu_6 ~~ vy*weu_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
weu_7 ~~ vy*weu_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
weu_8 ~~ vy*weu_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
weu_9 ~~ vy*weu_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
weu_10 ~~ vy*weu_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
weu_11 ~~ vy*weu_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model7_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model7_constrained_lag_groups_fit <-
lavaan(
EU_model7_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(EU_model7_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
fit_matrix_EU_m7_constrained_groups <- lavInspect(EU_model7_constrained_lag_groups_fit, what = "fit")
fit_matrix_EU_m7_unconstrained_groups <- lavInspect(EU_model7_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_eu_M1 <- rbind(fit_matrix_EU_m7_constrained_groups, fit_matrix_EU_m7_unconstrained_groups)
lavTestLRT(EU_model7_constrained_lag_groups_fit, EU_model7_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model7_unconstrained_groups_constrained_lag_fit 538 138737
139269 3389.4 EU_model7_constrained_lag_groups_fit 545 138829 139315
3494.7 Chisq diff Df diff
EU_model7_unconstrained_groups_constrained_lag_fit
EU_model7_constrained_lag_groups_fit 46.715 7 Pr(>Chisq)
EU_model7_unconstrained_groups_constrained_lag_fit
EU_model7_constrained_lag_groups_fit 6.343e-08 *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
cult_model7_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ c(a2, a2)*wcult_2 + c(b2, b2)*wFeduc_a_2
wcult_4 ~ c(a3, a3)*wcult_3 + c(b3, b3)*wFeduc_a_3
wcult_5 ~ c(a4, a4)*wcult_4 + c(b4, b4)*wFeduc_a_4
wcult_6 ~ c(a5, a5)*wcult_5 + c(b5, b5)*wFeduc_a_5
wcult_7 ~ c(a6, a6)*wcult_6 + c(b6, b6)*wFeduc_a_6
wcult_8 ~ c(a7, a7)*wcult_7 + c(b7, b7)*wFeduc_a_7
wcult_9 ~ c(a8, a8)*wcult_8 + c(b8, b8)*wFeduc_a_8
wcult_10 ~ c(a9, a9)*wcult_9 + c(b9, b9)*wFeduc_a_9
wcult_11 ~ c(a10, a10)*wcult_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_3 ~ c(c2, c2)*wcult_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*wcult_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*wcult_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*wcult_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*wcult_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*wcult_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*wcult_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*wcult_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*wcult_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ c(cov1, cov2)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ c(vy1, vy2)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model7_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model7_constrained_groups_fit <-
lavaan(
cult_model7_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(cult_model7_constrained_groups_fit,
file = filename)
} else {
load(file = filename)
}
cult_model7_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ c(a1, a2)*wcult_2 + c(b1, b2)*wFeduc_a_2
wcult_4 ~ c(a1, a2)*wcult_3 + c(b1, b2)*wFeduc_a_3
wcult_5 ~ c(a1, a2)*wcult_4 + c(b1, b2)*wFeduc_a_4
wcult_6 ~ c(a1, a2)*wcult_5 + c(b1, b2)*wFeduc_a_5
wcult_7 ~ c(a1, a2)*wcult_6 + c(b1, b2)*wFeduc_a_6
wcult_8 ~ c(a1, a2)*wcult_7 + c(b1, b2)*wFeduc_a_7
wcult_9 ~ c(a1, a2)*wcult_8 + c(b1, b2)*wFeduc_a_8
wcult_10 ~ c(a1, a2)*wcult_9 + c(b1, b2)*wFeduc_a_9
wcult_11 ~ c(a1, a2)*wcult_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2)*wcult_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*wcult_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*wcult_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*wcult_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*wcult_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*wcult_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*wcult_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*wcult_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*wcult_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ c(cov1, cov2)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ c(vy1, vy2)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model7_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model7_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model7_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(cult_model7_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
cult_model7_constrained_lag_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ a*wcult_2 + b*wFeduc_a_2
wcult_4 ~ a*wcult_3 + b*wFeduc_a_3
wcult_5 ~ a*wcult_4 + b*wFeduc_a_4
wcult_6 ~ a*wcult_5 + b*wFeduc_a_5
wcult_7 ~ a*wcult_6 + b*wFeduc_a_6
wcult_8 ~ a*wcult_7 + b*wFeduc_a_7
wcult_9 ~ a*wcult_8 + b*wFeduc_a_8
wcult_10 ~ a*wcult_9 + b*wFeduc_a_9
wcult_11 ~ a*wcult_10 + b*wFeduc_a_10
wFeduc_a_3 ~ c*wcult_2 + d*wFeduc_a_2
wFeduc_a_4 ~ c*wcult_3 + d*wFeduc_a_3
wFeduc_a_5 ~ c*wcult_4 + d*wFeduc_a_4
wFeduc_a_6 ~ c*wcult_5 + d*wFeduc_a_5
wFeduc_a_7 ~ c*wcult_6 + d*wFeduc_a_6
wFeduc_a_8 ~ c*wcult_7 + d*wFeduc_a_7
wFeduc_a_9 ~ c*wcult_8 + d*wFeduc_a_8
wFeduc_a_10 ~ c*wcult_9 + d*wFeduc_a_9
wFeduc_a_11 ~ c*wcult_10 + d*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ cov*wFeduc_a_3
wcult_4 ~~ cov*wFeduc_a_4
wcult_5 ~~ cov*wFeduc_a_5
wcult_6 ~~ cov*wFeduc_a_6
wcult_7 ~~ cov*wFeduc_a_7
wcult_8 ~~ cov*wFeduc_a_8
wcult_9 ~~ cov*wFeduc_a_9
wcult_10 ~~ cov*wFeduc_a_10
wcult_11 ~~ cov*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ vy*wcult_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
wcult_4 ~~ vy*wcult_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
wcult_5 ~~ vy*wcult_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
wcult_6 ~~ vy*wcult_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
wcult_7 ~~ vy*wcult_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
wcult_8 ~~ vy*wcult_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
wcult_9 ~~ vy*wcult_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
wcult_10 ~~ vy*wcult_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
wcult_11 ~~ vy*wcult_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model7_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model7_constrained_lag_groups_fit <-
lavaan(
cult_model7_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(cult_model7_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
fit_matrix_cult_m7_constrained_groups <- lavInspect(cult_model7_constrained_lag_groups_fit, what = "fit")
fit_matrix_cult_m7_unconstrained_groups <- lavInspect(cult_model7_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_cult_M1 <- rbind(fit_matrix_cult_m7_constrained_groups, fit_matrix_cult_m7_unconstrained_groups)
lavTestLRT(cult_model7_constrained_lag_groups_fit, cult_model7_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model7_unconstrained_groups_constrained_lag_fit 538 132725
133257 3052.1 cult_model7_constrained_lag_groups_fit 545 132852 133338
3192.4 Chisq diff Df diff
cult_model7_unconstrained_groups_constrained_lag_fit
cult_model7_constrained_lag_groups_fit 65.711 7 Pr(>Chisq)
cult_model7_unconstrained_groups_constrained_lag_fit
cult_model7_constrained_lag_groups_fit 1.082e-11 *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
inc_diff_model7_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ c(a2, a2)*winc_diff_2 + c(b2, b2)*wFeduc_a_2
winc_diff_4 ~ c(a3, a3)*winc_diff_3 + c(b3, b3)*wFeduc_a_3
winc_diff_5 ~ c(a4, a4)*winc_diff_4 + c(b4, b4)*wFeduc_a_4
winc_diff_6 ~ c(a5, a5)*winc_diff_5 + c(b5, b5)*wFeduc_a_5
winc_diff_7 ~ c(a6, a6)*winc_diff_6 + c(b6, b6)*wFeduc_a_6
winc_diff_8 ~ c(a7, a7)*winc_diff_7 + c(b7, b7)*wFeduc_a_7
winc_diff_9 ~ c(a8, a8)*winc_diff_8 + c(b8, b8)*wFeduc_a_8
winc_diff_10 ~ c(a9, a9)*winc_diff_9 + c(b9, b9)*wFeduc_a_9
winc_diff_11 ~ c(a10, a10)*winc_diff_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_3 ~ c(c2, c2)*winc_diff_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*winc_diff_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*winc_diff_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*winc_diff_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*winc_diff_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*winc_diff_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*winc_diff_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*winc_diff_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*winc_diff_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ c(cov1, cov2)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ c(vy1, vy2)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model7_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model7_constrained_groups_fit <-
lavaan(
inc_diff_model7_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(inc_diff_model7_constrained_groups_fit,
file = filename)
} else{
load(file = filename)
}
inc_diff_model7_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ c(a1, a2)*winc_diff_2 + c(b1, b2)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2)*winc_diff_3 + c(b1, b2)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2)*winc_diff_4 + c(b1, b2)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2)*winc_diff_5 + c(b1, b2)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2)*winc_diff_6 + c(b1, b2)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2)*winc_diff_7 + c(b1, b2)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2)*winc_diff_8 + c(b1, b2)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2)*winc_diff_9 + c(b1, b2)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2)*winc_diff_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2)*winc_diff_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*winc_diff_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*winc_diff_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*winc_diff_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*winc_diff_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*winc_diff_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*winc_diff_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*winc_diff_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*winc_diff_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ c(cov1, cov2)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ c(vy1, vy2)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model7_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model7_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model7_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(inc_diff_model7_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
inc_diff_model7_constrained_lag_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ a*winc_diff_2 + b*wFeduc_a_2
winc_diff_4 ~ a*winc_diff_3 + b*wFeduc_a_3
winc_diff_5 ~ a*winc_diff_4 + b*wFeduc_a_4
winc_diff_6 ~ a*winc_diff_5 + b*wFeduc_a_5
winc_diff_7 ~ a*winc_diff_6 + b*wFeduc_a_6
winc_diff_8 ~ a*winc_diff_7 + b*wFeduc_a_7
winc_diff_9 ~ a*winc_diff_8 + b*wFeduc_a_8
winc_diff_10 ~ a*winc_diff_9 + b*wFeduc_a_9
winc_diff_11 ~ a*winc_diff_10 + b*wFeduc_a_10
wFeduc_a_3 ~ c*winc_diff_2 + d*wFeduc_a_2
wFeduc_a_4 ~ c*winc_diff_3 + d*wFeduc_a_3
wFeduc_a_5 ~ c*winc_diff_4 + d*wFeduc_a_4
wFeduc_a_6 ~ c*winc_diff_5 + d*wFeduc_a_5
wFeduc_a_7 ~ c*winc_diff_6 + d*wFeduc_a_6
wFeduc_a_8 ~ c*winc_diff_7 + d*wFeduc_a_7
wFeduc_a_9 ~ c*winc_diff_8 + d*wFeduc_a_8
wFeduc_a_10 ~ c*winc_diff_9 + d*wFeduc_a_9
wFeduc_a_11 ~ c*winc_diff_10 + d*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ cov*wFeduc_a_3
winc_diff_4 ~~ cov*wFeduc_a_4
winc_diff_5 ~~ cov*wFeduc_a_5
winc_diff_6 ~~ cov*wFeduc_a_6
winc_diff_7 ~~ cov*wFeduc_a_7
winc_diff_8 ~~ cov*wFeduc_a_8
winc_diff_9 ~~ cov*wFeduc_a_9
winc_diff_10 ~~ cov*wFeduc_a_10
winc_diff_11 ~~ cov*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ vy*winc_diff_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
winc_diff_4 ~~ vy*winc_diff_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
winc_diff_5 ~~ vy*winc_diff_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
winc_diff_6 ~~ vy*winc_diff_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
winc_diff_7 ~~ vy*winc_diff_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
winc_diff_8 ~~ vy*winc_diff_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
winc_diff_9 ~~ vy*winc_diff_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
winc_diff_10 ~~ vy*winc_diff_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
winc_diff_11 ~~ vy*winc_diff_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model7_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model7_constrained_lag_groups_fit <-
lavaan(
inc_diff_model7_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_2"
)
#save model
save(inc_diff_model7_constrained_lag_groups_fit,
file = filename)
} else{
load(file = filename)
}
fit_matrix_inc_diff_m7_constrained_groups <- lavInspect(inc_diff_model7_constrained_lag_groups_fit, what = "fit")
fit_matrix_inc_diff_m7_unconstrained_groups <- lavInspect(inc_diff_model7_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_inc_diff_M7 <- rbind(fit_matrix_inc_diff_m7_constrained_groups, fit_matrix_inc_diff_m7_unconstrained_groups)
lavTestLRT(inc_diff_model7_constrained_lag_groups_fit, inc_diff_model7_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model7_unconstrained_groups_constrained_lag_fit 538 133334
133866 inc_diff_model7_constrained_lag_groups_fit 545 133444 133930
Chisq Chisq diff
inc_diff_model7_unconstrained_groups_constrained_lag_fit 3224.7
inc_diff_model7_constrained_lag_groups_fit 3348.7 57.397 Df diff
Pr(>Chisq)
inc_diff_model7_unconstrained_groups_constrained_lag_fit
inc_diff_model7_constrained_lag_groups_fit 7 4.983e-10 *** — Signif.
codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’
1
#create Ave Sim beween measure
MyData <- MyData %>%
rowwise() %>%
mutate(ave_mean = mean(c_across(starts_with("Fav")), na.rm = T)) %>%
ungroup()
#create between scores
MyData <- MyData %>%
mutate(ave_rec = cut2(ave_mean, g = 5),
ave_2 = cut2(ave_mean, g = 2))
EU_model8_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_1 + 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_1 =~ 1*eu_1
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_2 ~ c(a1, a1)*weu_1 + c(b1, b1)*wFeduc_a_1
weu_3 ~ c(a2, a2)*weu_2 + c(b2, b2)*wFeduc_a_2
weu_4 ~ c(a3, a3)*weu_3 + c(b3, b3)*wFeduc_a_3
weu_5 ~ c(a4, a4)*weu_4 + c(b4, b4)*wFeduc_a_4
weu_6 ~ c(a5, a5)*weu_5 + c(b5, b5)*wFeduc_a_5
weu_7 ~ c(a6, a6)*weu_6 + c(b6, b6)*wFeduc_a_6
weu_8 ~ c(a7, a7)*weu_7 + c(b7, b7)*wFeduc_a_7
weu_9 ~ c(a8, a8)*weu_8 + c(b8, b8)*wFeduc_a_8
weu_10 ~ c(a9, a9)*weu_9 + c(b9, b9)*wFeduc_a_9
weu_11 ~ c(a10, a10)*weu_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c1)*weu_1 + c(d1, d1)*wFeduc_a_1
wFeduc_a_3 ~ c(c2, c2)*weu_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*weu_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*weu_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*weu_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*weu_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*weu_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*weu_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*weu_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*weu_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ c(cov1, cov2)*wFeduc_a_2
weu_3 ~~ c(cov1, cov2)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
weu_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ c(vy1, vy2)*weu_2
wFeduc_a_2 ~~ c(vx1, vx2)*wFeduc_a_2
weu_3 ~~ c(vy1, vy2)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*weu_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model8_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model8_constrained_groups_fit <-
lavaan(
EU_model8_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(EU_model8_constrained_groups_fit,
file = filename)
} else {
load(file = filename)
}
EU_model8_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_1 + 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_1 =~ 1*eu_1
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_2 ~ c(a1, a2)*weu_1 + c(b1, b2)*wFeduc_a_1
weu_3 ~ c(a1, a2)*weu_2 + c(b1, b2)*wFeduc_a_2
weu_4 ~ c(a1, a2)*weu_3 + c(b1, b2)*wFeduc_a_3
weu_5 ~ c(a1, a2)*weu_4 + c(b1, b2)*wFeduc_a_4
weu_6 ~ c(a1, a2)*weu_5 + c(b1, b2)*wFeduc_a_5
weu_7 ~ c(a1, a2)*weu_6 + c(b1, b2)*wFeduc_a_6
weu_8 ~ c(a1, a2)*weu_7 + c(b1, b2)*wFeduc_a_7
weu_9 ~ c(a1, a2)*weu_8 + c(b1, b2)*wFeduc_a_8
weu_10 ~ c(a1, a2)*weu_9 + c(b1, b2)*wFeduc_a_9
weu_11 ~ c(a1, a2)*weu_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2)*weu_1 + c(d1, d2)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2)*weu_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*weu_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*weu_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*weu_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*weu_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*weu_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*weu_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*weu_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*weu_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ c(cov1, cov2)*wFeduc_a_2
weu_3 ~~ c(cov1, cov2)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
weu_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ c(vy1, vy2)*weu_2
wFeduc_a_2 ~~ c(vx1, vx2)*wFeduc_a_2
weu_3 ~~ c(vy1, vy2)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*weu_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model8_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model8_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model8_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(EU_model8_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model8_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model8_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[1]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(EU_model8_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
fit_matrix_EU_m8_constrained_groups <- lavInspect(EU_model8_constrained_lag_groups_fit, what = "fit")
fit_matrix_EU_m8_unconstrained_groups <- lavInspect(EU_model8_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_eu_M8 <- rbind(fit_matrix_EU_m8_constrained_groups, fit_matrix_EU_m8_unconstrained_groups)
lavTestLRT(EU_model8_constrained_lag_groups_fit, EU_model8_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model8_unconstrained_groups_constrained_lag_fit 640 155224
155785 2862.5 EU_model8_constrained_lag_groups_fit 647 155236 155751
2888.1 Chisq diff Df diff
EU_model8_unconstrained_groups_constrained_lag_fit
EU_model8_constrained_lag_groups_fit 11.066 7 Pr(>Chisq)
EU_model8_unconstrained_groups_constrained_lag_fit
EU_model8_constrained_lag_groups_fit 0.1358
cult_model8_constrained_groups <-
' ################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_1 + 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_1 =~ 1*cult_1
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_2 ~ c(a1, a1)*wcult_1 + c(b1, b1)*wFeduc_a_1
wcult_3 ~ c(a2, a2)*wcult_2 + c(b2, b2)*wFeduc_a_2
wcult_4 ~ c(a3, a3)*wcult_3 + c(b3, b3)*wFeduc_a_3
wcult_5 ~ c(a4, a4)*wcult_4 + c(b4, b4)*wFeduc_a_4
wcult_6 ~ c(a5, a5)*wcult_5 + c(b5, b5)*wFeduc_a_5
wcult_7 ~ c(a6, a6)*wcult_6 + c(b6, b6)*wFeduc_a_6
wcult_8 ~ c(a7, a7)*wcult_7 + c(b7, b7)*wFeduc_a_7
wcult_9 ~ c(a8, a8)*wcult_8 + c(b8, b8)*wFeduc_a_8
wcult_10 ~ c(a9, a9)*wcult_9 + c(b9, b9)*wFeduc_a_9
wcult_11 ~ c(a10, a10)*wcult_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c1)*wcult_1 + c(d1, d1)*wFeduc_a_1
wFeduc_a_3 ~ c(c2, c2)*wcult_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*wcult_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*wcult_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*wcult_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*wcult_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*wcult_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*wcult_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*wcult_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*wcult_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
wcult_2 ~~ cov*wFeduc_a_2
wcult_3 ~~ cov*wFeduc_a_3
wcult_4 ~~ cov*wFeduc_a_4
wcult_5 ~~ cov*wFeduc_a_5
wcult_6 ~~ cov*wFeduc_a_6
wcult_7 ~~ cov*wFeduc_a_7
wcult_8 ~~ cov*wFeduc_a_8
wcult_9 ~~ cov*wFeduc_a_9
wcult_10 ~~ cov*wFeduc_a_10
wcult_11 ~~ cov*wFeduc_a_11
# Estimate the variance
wcult_1 ~~ wcult_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
wcult_2 ~~ vy*wcult_2
wFeduc_a_2 ~~ vx*wFeduc_a_2
wcult_3 ~~ vy*wcult_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
wcult_4 ~~ vy*wcult_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
wcult_5 ~~ vy*wcult_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
wcult_6 ~~ vy*wcult_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
wcult_7 ~~ vy*wcult_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
wcult_8 ~~ vy*wcult_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
wcult_9 ~~ vy*wcult_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
wcult_10 ~~ vy*wcult_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
wcult_11 ~~ vy*wcult_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*wcult_1'
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model8_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model8_constrained_groups_fit <-
lavaan(
cult_model8_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(cult_model8_constrained_groups_fit,
file = filename)
} else {
load(file = filename)
}
cult_model8_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_1 + 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_1 =~ 1*cult_1
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_2 ~ c(a1, a2)*wcult_1 + c(b1, b2)*wFeduc_a_1
wcult_3 ~ c(a1, a2)*wcult_2 + c(b1, b2)*wFeduc_a_2
wcult_4 ~ c(a1, a2)*wcult_3 + c(b1, b2)*wFeduc_a_3
wcult_5 ~ c(a1, a2)*wcult_4 + c(b1, b2)*wFeduc_a_4
wcult_6 ~ c(a1, a2)*wcult_5 + c(b1, b2)*wFeduc_a_5
wcult_7 ~ c(a1, a2)*wcult_6 + c(b1, b2)*wFeduc_a_6
wcult_8 ~ c(a1, a2)*wcult_7 + c(b1, b2)*wFeduc_a_7
wcult_9 ~ c(a1, a2)*wcult_8 + c(b1, b2)*wFeduc_a_8
wcult_10 ~ c(a1, a2)*wcult_9 + c(b1, b2)*wFeduc_a_9
wcult_11 ~ c(a1, a2)*wcult_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2)*wcult_1 + c(d1, d2)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2)*wcult_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*wcult_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*wcult_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*wcult_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*wcult_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*wcult_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*wcult_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*wcult_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*wcult_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
wcult_2 ~~ c(cov1, cov2)*wFeduc_a_2
wcult_3 ~~ c(cov1, cov2)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
wcult_1 ~~ wcult_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
wcult_2 ~~ c(vy1, vy2)*wcult_2
wFeduc_a_2 ~~ c(vx1, vx2)*wFeduc_a_2
wcult_3 ~~ c(vy1, vy2)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*wcult_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model8_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model8_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model8_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(cult_model8_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#create and store model
#create filename
filename <-
file.path(dir,
"cult_model8_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model8_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[2]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(cult_model8_constrained_lag_groups_fit,
file = filename)
} else{
load(file = filename)
}
fit_matrix_cult_m8_constrained_groups <- lavInspect(cult_model8_constrained_lag_groups_fit, what = "fit")
fit_matrix_cult_m8_unconstrained_groups <- lavInspect(cult_model8_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_cult_M8 <- rbind(fit_matrix_cult_m8_constrained_groups, fit_matrix_cult_m8_unconstrained_groups)
lavTestLRT(cult_model8_constrained_lag_groups_fit, cult_model8_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model8_unconstrained_groups_constrained_lag_fit 640 148728
149289 2585.3 cult_model8_constrained_lag_groups_fit 647 148737 149252
2608.1 Chisq diff Df diff
cult_model8_unconstrained_groups_constrained_lag_fit
cult_model8_constrained_lag_groups_fit 10.166 7 Pr(>Chisq)
cult_model8_unconstrained_groups_constrained_lag_fit
cult_model8_constrained_lag_groups_fit 0.1794
inc_diff_model8_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_1 + 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_1 =~ 1*inc_diff_1
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_2 ~ c(a1, a1)*winc_diff_1 + c(b1, b1)*wFeduc_a_1
winc_diff_3 ~ c(a2, a2)*winc_diff_2 + c(b2, b2)*wFeduc_a_2
winc_diff_4 ~ c(a3, a3)*winc_diff_3 + c(b3, b3)*wFeduc_a_3
winc_diff_5 ~ c(a4, a4)*winc_diff_4 + c(b4, b4)*wFeduc_a_4
winc_diff_6 ~ c(a5, a5)*winc_diff_5 + c(b5, b5)*wFeduc_a_5
winc_diff_7 ~ c(a6, a6)*winc_diff_6 + c(b6, b6)*wFeduc_a_6
winc_diff_8 ~ c(a7, a7)*winc_diff_7 + c(b7, b7)*wFeduc_a_7
winc_diff_9 ~ c(a8, a8)*winc_diff_8 + c(b8, b8)*wFeduc_a_8
winc_diff_10 ~ c(a9, a9)*winc_diff_9 + c(b9, b9)*wFeduc_a_9
winc_diff_11 ~ c(a10, a10)*winc_diff_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c1)*winc_diff_1 + c(d1, d1)*wFeduc_a_1
wFeduc_a_3 ~ c(c2, c2)*winc_diff_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*winc_diff_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*winc_diff_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*winc_diff_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*winc_diff_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*winc_diff_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*winc_diff_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*winc_diff_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*winc_diff_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
winc_diff_2 ~~ cov*wFeduc_a_2
winc_diff_3 ~~ cov*wFeduc_a_3
winc_diff_4 ~~ cov*wFeduc_a_4
winc_diff_5 ~~ cov*wFeduc_a_5
winc_diff_6 ~~ cov*wFeduc_a_6
winc_diff_7 ~~ cov*wFeduc_a_7
winc_diff_8 ~~ cov*wFeduc_a_8
winc_diff_9 ~~ cov*wFeduc_a_9
winc_diff_10 ~~ cov*wFeduc_a_10
winc_diff_11 ~~ cov*wFeduc_a_11
# Estimate the variance
winc_diff_1 ~~ winc_diff_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
winc_diff_2 ~~ vy*winc_diff_2
wFeduc_a_2 ~~ vx*wFeduc_a_2
winc_diff_3 ~~ vy*winc_diff_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
winc_diff_4 ~~ vy*winc_diff_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
winc_diff_5 ~~ vy*winc_diff_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
winc_diff_6 ~~ vy*winc_diff_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
winc_diff_7 ~~ vy*winc_diff_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
winc_diff_8 ~~ vy*winc_diff_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
winc_diff_9 ~~ vy*winc_diff_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
winc_diff_10 ~~ vy*winc_diff_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
winc_diff_11 ~~ vy*winc_diff_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*winc_diff_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model8_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model8_constrained_groups_fit <-
lavaan(
inc_diff_model8_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(inc_diff_model8_constrained_groups_fit,
file = filename)
} else {
load(file = filename)
}
inc_diff_model8_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_1 + 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_1 =~ 1*inc_diff_1
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_2 ~ c(a1, a2)*winc_diff_1 + c(b1, b2)*wFeduc_a_1
winc_diff_3 ~ c(a1, a2)*winc_diff_2 + c(b1, b2)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2)*winc_diff_3 + c(b1, b2)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2)*winc_diff_4 + c(b1, b2)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2)*winc_diff_5 + c(b1, b2)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2)*winc_diff_6 + c(b1, b2)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2)*winc_diff_7 + c(b1, b2)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2)*winc_diff_8 + c(b1, b2)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2)*winc_diff_9 + c(b1, b2)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2)*winc_diff_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2)*winc_diff_1 + c(d1, d2)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2)*winc_diff_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*winc_diff_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*winc_diff_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*winc_diff_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*winc_diff_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*winc_diff_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*winc_diff_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*winc_diff_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*winc_diff_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
winc_diff_2 ~~ c(cov1, cov2)*wFeduc_a_2
winc_diff_3 ~~ c(cov1, cov2)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
winc_diff_1 ~~ winc_diff_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
winc_diff_2 ~~ c(vy1, vy2)*winc_diff_2
wFeduc_a_2 ~~ c(vx1, vx2)*wFeduc_a_2
winc_diff_3 ~~ c(vy1, vy2)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*winc_diff_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model8_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model8_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model8_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(inc_diff_model8_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#create and store model
#create filename
filename <-
file.path(dir,
"inc_diff_model8_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model8_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[3]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_2"
)
#save model
save(inc_diff_model8_constrained_lag_groups_fit,
file = filename)
} else{
load(file = filename)
}
fit_matrix_inc_diff_m8_constrained_groups <- lavInspect(inc_diff_model8_constrained_lag_groups_fit, what = "fit")
fit_matrix_inc_diff_m8_unconstrained_groups <- lavInspect(inc_diff_model8_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_inc_diff_M8 <- rbind(fit_matrix_inc_diff_m8_constrained_groups, fit_matrix_inc_diff_m8_unconstrained_groups)
lavTestLRT(inc_diff_model8_constrained_lag_groups_fit, inc_diff_model8_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model8_unconstrained_groups_constrained_lag_fit 640 149584
150145 inc_diff_model8_constrained_lag_groups_fit 647 149596 150111
Chisq Chisq diff
inc_diff_model8_unconstrained_groups_constrained_lag_fit 2761.3
inc_diff_model8_constrained_lag_groups_fit 2787.0 11.179 Df diff
Pr(>Chisq)
inc_diff_model8_unconstrained_groups_constrained_lag_fit
inc_diff_model8_constrained_lag_groups_fit 7 0.131
EU_model9_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_1 + 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_1 =~ 1*eu_1
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_2 ~ c(a1, a2, a3, a4)*weu_1 + c(b1, b2, b3, b4)*wFeduc_a_1
weu_3 ~ c(a1, a2, a3, a4)*weu_2 + c(b1, b2, b3, b4)*wFeduc_a_2
weu_4 ~ c(a1, a2, a3, a4)*weu_3 + c(b1, b2, b3, b4)*wFeduc_a_3
weu_5 ~ c(a1, a2, a3, a4)*weu_4 + c(b1, b2, b3, b4)*wFeduc_a_4
weu_6 ~ c(a1, a2, a3, a4)*weu_5 + c(b1, b2, b3, b4)*wFeduc_a_5
weu_7 ~ c(a1, a2, a3, a4)*weu_6 + c(b1, b2, b3, b4)*wFeduc_a_6
weu_8 ~ c(a1, a2, a3, a4)*weu_7 + c(b1, b2, b3, b4)*wFeduc_a_7
weu_9 ~ c(a1, a2, a3, a4)*weu_8 + c(b1, b2, b3, b4)*wFeduc_a_8
weu_10 ~ c(a1, a2, a3, a4)*weu_9 + c(b1, b2, b3, b4)*wFeduc_a_9
weu_11 ~ c(a1, a2, a3, a4)*weu_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3, c4)*weu_1 + c(d1, d2, d3, d4)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3, c4)*weu_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*weu_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*weu_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*weu_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*weu_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*weu_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*weu_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*weu_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*weu_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_2
weu_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
weu_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ c(vy1, vy2, vy3, vy4)*weu_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_2
weu_3 ~~ c(vy1, vy2, vy3, vy4)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2, vy3, vy4)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2, vy3, vy4)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2, vy3, vy4)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2, vy3, vy4)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2, vy3, vy4)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2, vy3, vy4)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2, vy3, vy4)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2, vy3, vy4)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*weu_1
'
#create and store model
#create filename
filename <-
file.path(dir,
"EU_model9_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model9_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model9_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_rec"
)
#save model
save(EU_model9_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#file
filename <-
file.path(dir,
"EU_model9_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model9_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[1]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_rec"
)
#save model
save(EU_model9_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
lavTestLRT(EU_model9_constrained_lag_groups_fit, EU_model9_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model9_unconstrained_groups_constrained_lag_fit 1280 153392
154513 4055.7 EU_model9_constrained_lag_groups_fit 1301 154286 155269
4991.3 Chisq diff Df diff
EU_model9_unconstrained_groups_constrained_lag_fit
EU_model9_constrained_lag_groups_fit 389.85 21 Pr(>Chisq)
EU_model9_unconstrained_groups_constrained_lag_fit
EU_model9_constrained_lag_groups_fit < 2.2e-16 *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
cult_model9_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_1 + 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_1 =~ 1*cult_1
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_2 ~ c(a1, a2, a3, a4)*wcult_1 + c(b1, b2, b3, b4)*wFeduc_a_1
wcult_3 ~ c(a1, a2, a3, a4)*wcult_2 + c(b1, b2, b3, b4)*wFeduc_a_2
wcult_4 ~ c(a1, a2, a3, a4)*wcult_3 + c(b1, b2, b3, b4)*wFeduc_a_3
wcult_5 ~ c(a1, a2, a3, a4)*wcult_4 + c(b1, b2, b3, b4)*wFeduc_a_4
wcult_6 ~ c(a1, a2, a3, a4)*wcult_5 + c(b1, b2, b3, b4)*wFeduc_a_5
wcult_7 ~ c(a1, a2, a3, a4)*wcult_6 + c(b1, b2, b3, b4)*wFeduc_a_6
wcult_8 ~ c(a1, a2, a3, a4)*wcult_7 + c(b1, b2, b3, b4)*wFeduc_a_7
wcult_9 ~ c(a1, a2, a3, a4)*wcult_8 + c(b1, b2, b3, b4)*wFeduc_a_8
wcult_10 ~ c(a1, a2, a3, a4)*wcult_9 + c(b1, b2, b3, b4)*wFeduc_a_9
wcult_11 ~ c(a1, a2, a3, a4)*wcult_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3, c4)*wcult_1 + c(d1, d2, d3, d4)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3, c4)*wcult_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*wcult_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*wcult_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*wcult_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*wcult_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*wcult_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*wcult_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*wcult_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*wcult_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
wcult_2 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_2
wcult_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
wcult_1 ~~ wcult_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
wcult_2 ~~ c(vy1, vy2, vy3, vy4)*wcult_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_2
wcult_3 ~~ c(vy1, vy2, vy3, vy4)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2, vy3, vy4)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2, vy3, vy4)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2, vy3, vy4)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2, vy3, vy4)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2, vy3, vy4)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2, vy3, vy4)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2, vy3, vy4)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2, vy3, vy4)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*wcult_1
'
#filename
filename <-
file.path(dir,
"cult_model9_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model9_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model9_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_rec"
)
#save model
save(cult_model9_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#filename
filename <-
file.path(dir,
"cult_model9_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model9_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[2]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_rec"
)
#save model
save(cult_model9_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
lavTestLRT(cult_model9_constrained_lag_groups_fit, cult_model9_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model9_unconstrained_groups_constrained_lag_fit 1280 146913
148034 3725.8 cult_model9_constrained_lag_groups_fit 1301 147822 148805
4676.0 Chisq diff Df diff
cult_model9_unconstrained_groups_constrained_lag_fit
cult_model9_constrained_lag_groups_fit 412 21 Pr(>Chisq)
cult_model9_unconstrained_groups_constrained_lag_fit
cult_model9_constrained_lag_groups_fit < 2.2e-16 *** — Signif. codes:
0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
inc_diff_model9_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_1 + 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_1 =~ 1*inc_diff_1
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_2 ~ c(a1, a2, a3, a4)*winc_diff_1 + c(b1, b2, b3, b4)*wFeduc_a_1
winc_diff_3 ~ c(a1, a2, a3, a4)*winc_diff_2 + c(b1, b2, b3, b4)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2, a3, a4)*winc_diff_3 + c(b1, b2, b3, b4)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2, a3, a4)*winc_diff_4 + c(b1, b2, b3, b4)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2, a3, a4)*winc_diff_5 + c(b1, b2, b3, b4)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2, a3, a4)*winc_diff_6 + c(b1, b2, b3, b4)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2, a3, a4)*winc_diff_7 + c(b1, b2, b3, b4)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2, a3, a4)*winc_diff_8 + c(b1, b2, b3, b4)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2, a3, a4)*winc_diff_9 + c(b1, b2, b3, b4)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2, a3, a4)*winc_diff_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3, c4)*winc_diff_1 + c(d1, d2, d3, d4)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3, c4)*winc_diff_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*winc_diff_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*winc_diff_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*winc_diff_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*winc_diff_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*winc_diff_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*winc_diff_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*winc_diff_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*winc_diff_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
winc_diff_2 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_2
winc_diff_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
winc_diff_1 ~~ winc_diff_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
winc_diff_2 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_2
winc_diff_3 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*winc_diff_1
'
#filename
filename <-
file.path(dir,
"inc_diff_model9_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model9_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model9_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_rec"
)
#save model
save(inc_diff_model9_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#filename
filename <-
file.path(dir,
"inc_diff_model9_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model9_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[3]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "pol_disc_2"
)
#save model
save(inc_diff_model9_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
lavTestLRT(inc_diff_model9_constrained_lag_groups_fit, inc_diff_model9_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model9_constrained_lag_groups_fit 647 149316 149830
inc_diff_model9_unconstrained_groups_constrained_lag_fit 1280 147751
148872 Chisq Chisq diff inc_diff_model9_constrained_lag_groups_fit
2723.8
inc_diff_model9_unconstrained_groups_constrained_lag_fit 3853.4 957.27
Df diff Pr(>Chisq)
inc_diff_model9_constrained_lag_groups_fit
inc_diff_model9_unconstrained_groups_constrained_lag_fit 633 1.181e-15
*** — Signif. codes: 0 ‘’ 0.001 ’’ 0.01 ’’
0.05 ‘.’ 0.1 ’ ’ 1
MyData <- MyData %>%
mutate(rl_rec = cut2(rl_mean, g = 4),
rl_2 = cut2(rl_mean, g = 2))
EU_model10_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ c(a1, a2, a3, a4)*weu_2 + c(b1, b2, b3, b4)*wFeduc_a_2
weu_4 ~ c(a1, a2, a3, a4)*weu_3 + c(b1, b2, b3, b4)*wFeduc_a_3
weu_5 ~ c(a1, a2, a3, a4)*weu_4 + c(b1, b2, b3, b4)*wFeduc_a_4
weu_6 ~ c(a1, a2, a3, a4)*weu_5 + c(b1, b2, b3, b4)*wFeduc_a_5
weu_7 ~ c(a1, a2, a3, a4)*weu_6 + c(b1, b2, b3, b4)*wFeduc_a_6
weu_8 ~ c(a1, a2, a3, a4)*weu_7 + c(b1, b2, b3, b4)*wFeduc_a_7
weu_9 ~ c(a1, a2, a3, a4)*weu_8 + c(b1, b2, b3, b4)*wFeduc_a_8
weu_10 ~ c(a1, a2, a3, a4)*weu_9 + c(b1, b2, b3, b4)*wFeduc_a_9
weu_11 ~ c(a1, a2, a3, a4)*weu_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3, c4)*weu_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*weu_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*weu_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*weu_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*weu_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*weu_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*weu_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*weu_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*weu_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ c(vy1, vy2, vy3, vy4)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2, vy3, vy4)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2, vy3, vy4)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2, vy3, vy4)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2, vy3, vy4)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2, vy3, vy4)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2, vy3, vy4)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2, vy3, vy4)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2, vy3, vy4)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#filename
filename <-
file.path(dir,
"EU_model10_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model10_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model10_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_rec"
)
#save model
save(EU_model10_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#filename
filename <-
file.path(dir,
"EU_model10_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model10_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[1]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_rec"
)
#save model
save(EU_model10_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
lavTestLRT(EU_model10_constrained_lag_groups_fit, EU_model10_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model10_unconstrained_groups_constrained_lag_fit 1076 137643
138706 4422 EU_model10_constrained_lag_groups_fit 1301 150384 151363
6619 Chisq diff Df diff
EU_model10_unconstrained_groups_constrained_lag_fit
EU_model10_constrained_lag_groups_fit 1658.8 225 Pr(>Chisq)
EU_model10_unconstrained_groups_constrained_lag_fit
EU_model10_constrained_lag_groups_fit < 2.2e-16 *** — Signif. codes:
0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
cult_model10_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ c(a1, a2, a3, a4)*wcult_2 + c(b1, b2, b3, b4)*wFeduc_a_2
wcult_4 ~ c(a1, a2, a3, a4)*wcult_3 + c(b1, b2, b3, b4)*wFeduc_a_3
wcult_5 ~ c(a1, a2, a3, a4)*wcult_4 + c(b1, b2, b3, b4)*wFeduc_a_4
wcult_6 ~ c(a1, a2, a3, a4)*wcult_5 + c(b1, b2, b3, b4)*wFeduc_a_5
wcult_7 ~ c(a1, a2, a3, a4)*wcult_6 + c(b1, b2, b3, b4)*wFeduc_a_6
wcult_8 ~ c(a1, a2, a3, a4)*wcult_7 + c(b1, b2, b3, b4)*wFeduc_a_7
wcult_9 ~ c(a1, a2, a3, a4)*wcult_8 + c(b1, b2, b3, b4)*wFeduc_a_8
wcult_10 ~ c(a1, a2, a3, a4)*wcult_9 + c(b1, b2, b3, b4)*wFeduc_a_9
wcult_11 ~ c(a1, a2, a3, a4)*wcult_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3, c4)*wcult_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*wcult_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*wcult_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*wcult_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*wcult_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*wcult_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*wcult_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*wcult_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*wcult_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ c(vy1, vy2, vy3, vy4)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2, vy3, vy4)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2, vy3, vy4)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2, vy3, vy4)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2, vy3, vy4)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2, vy3, vy4)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2, vy3, vy4)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2, vy3, vy4)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2, vy3, vy4)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#filename
filename <-
file.path(dir,
"cult_model10_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model10_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model10_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_rec"
)
#save model
save(cult_model10_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#filename
filename <-
file.path(dir,
"cult_model10_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model10_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[2]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_rec"
)
#save model
save(cult_model10_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
lavTestLRT(cult_model10_constrained_lag_groups_fit, cult_model10_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model10_unconstrained_groups_constrained_lag_fit 1076 131663
132726 4114.2 cult_model10_constrained_lag_groups_fit 1301 143842 144821
6343.3 Chisq diff Df diff
cult_model10_unconstrained_groups_constrained_lag_fit
cult_model10_constrained_lag_groups_fit 1653.8 225 Pr(>Chisq)
cult_model10_unconstrained_groups_constrained_lag_fit
cult_model10_constrained_lag_groups_fit < 2.2e-16 *** — Signif.
codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’
1
inc_diff_model10_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ c(a1, a2, a3, a4)*winc_diff_2 + c(b1, b2, b3, b4)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2, a3, a4)*winc_diff_3 + c(b1, b2, b3, b4)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2, a3, a4)*winc_diff_4 + c(b1, b2, b3, b4)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2, a3, a4)*winc_diff_5 + c(b1, b2, b3, b4)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2, a3, a4)*winc_diff_6 + c(b1, b2, b3, b4)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2, a3, a4)*winc_diff_7 + c(b1, b2, b3, b4)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2, a3, a4)*winc_diff_8 + c(b1, b2, b3, b4)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2, a3, a4)*winc_diff_9 + c(b1, b2, b3, b4)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2, a3, a4)*winc_diff_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3, c4)*winc_diff_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*winc_diff_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*winc_diff_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*winc_diff_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*winc_diff_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*winc_diff_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*winc_diff_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*winc_diff_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*winc_diff_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#filename
filename <-
file.path(dir,
"inc_diff_model10_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model10_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model10_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_rec"
)
#save model
save(inc_diff_model10_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#filename
filename <-
file.path(dir,
"inc_diff_model10_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model10_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[3]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "rl_rec"
)
#save model
save(inc_diff_model10_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
lavTestLRT(inc_diff_model10_constrained_lag_groups_fit, inc_diff_model10_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model10_unconstrained_groups_constrained_lag_fit 1076 132279
133342 inc_diff_model10_constrained_lag_groups_fit 1301 144738 145717
Chisq Chisq diff
inc_diff_model10_unconstrained_groups_constrained_lag_fit 4284.6
inc_diff_model10_constrained_lag_groups_fit 6442.0 1665.7 Df diff
Pr(>Chisq)
inc_diff_model10_unconstrained_groups_constrained_lag_fit
inc_diff_model10_constrained_lag_groups_fit 225 < 2.2e-16
inc_diff_model10_unconstrained_groups_constrained_lag_fit
inc_diff_model10_constrained_lag_groups_fit *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
MyData <- MyData %>%
mutate(ave_rec = cut2(ave_mean, g = 4),
ave_2 = cut2(ave_mean, g = 2))
EU_model11_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_1 + 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_1 + 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_1 =~ 1*eu_1
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_2 ~ c(a1, a2, a3, a4)*weu_1 + c(b1, b2, b3, b4)*wFeduc_a_1
weu_3 ~ c(a1, a2, a3, a4)*weu_2 + c(b1, b2, b3, b4)*wFeduc_a_2
weu_4 ~ c(a1, a2, a3, a4)*weu_3 + c(b1, b2, b3, b4)*wFeduc_a_3
weu_5 ~ c(a1, a2, a3, a4)*weu_4 + c(b1, b2, b3, b4)*wFeduc_a_4
weu_6 ~ c(a1, a2, a3, a4)*weu_5 + c(b1, b2, b3, b4)*wFeduc_a_5
weu_7 ~ c(a1, a2, a3, a4)*weu_6 + c(b1, b2, b3, b4)*wFeduc_a_6
weu_8 ~ c(a1, a2, a3, a4)*weu_7 + c(b1, b2, b3, b4)*wFeduc_a_7
weu_9 ~ c(a1, a2, a3, a4)*weu_8 + c(b1, b2, b3, b4)*wFeduc_a_8
weu_10 ~ c(a1, a2, a3, a4)*weu_9 + c(b1, b2, b3, b4)*wFeduc_a_9
weu_11 ~ c(a1, a2, a3, a4)*weu_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3, c4)*weu_1 + c(d1, d2, d3, d4)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3, c4)*weu_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*weu_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*weu_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*weu_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*weu_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*weu_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*weu_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*weu_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*weu_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_2
weu_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
weu_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ c(vy1, vy2, vy3, vy4)*weu_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_2
weu_3 ~~ c(vy1, vy2, vy3, vy4)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2, vy3, vy4)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2, vy3, vy4)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2, vy3, vy4)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2, vy3, vy4)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2, vy3, vy4)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2, vy3, vy4)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2, vy3, vy4)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2, vy3, vy4)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*weu_1
'
#filename
filename <-
file.path(dir,
"EU_model11_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model11_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model11_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_rec"
)
#save model
save(EU_model11_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {
load(file = filename)
}
#filename
filename <-
file.path(dir,
"EU_model11_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model11_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[1]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_rec"
)
#save model
save(EU_model11_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
lavTestLRT(EU_model11_constrained_lag_groups_fit, EU_model11_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model11_unconstrained_groups_constrained_lag_fit 1280 153493
154613 4107.4 EU_model11_constrained_lag_groups_fit 1301 154605 155589
5261.3 Chisq diff Df diff
EU_model11_unconstrained_groups_constrained_lag_fit
EU_model11_constrained_lag_groups_fit 453.52 21 Pr(>Chisq)
EU_model11_unconstrained_groups_constrained_lag_fit
EU_model11_constrained_lag_groups_fit < 2.2e-16 *** — Signif. codes:
0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
cult_model11_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_1 + 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_1 =~ 1*cult_1
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_2 ~ c(a1, a2, a3, a4)*wcult_1 + c(b1, b2, b3, b4)*wFeduc_a_1
wcult_3 ~ c(a1, a2, a3, a4)*wcult_2 + c(b1, b2, b3, b4)*wFeduc_a_2
wcult_4 ~ c(a1, a2, a3, a4)*wcult_3 + c(b1, b2, b3, b4)*wFeduc_a_3
wcult_5 ~ c(a1, a2, a3, a4)*wcult_4 + c(b1, b2, b3, b4)*wFeduc_a_4
wcult_6 ~ c(a1, a2, a3, a4)*wcult_5 + c(b1, b2, b3, b4)*wFeduc_a_5
wcult_7 ~ c(a1, a2, a3, a4)*wcult_6 + c(b1, b2, b3, b4)*wFeduc_a_6
wcult_8 ~ c(a1, a2, a3, a4)*wcult_7 + c(b1, b2, b3, b4)*wFeduc_a_7
wcult_9 ~ c(a1, a2, a3, a4)*wcult_8 + c(b1, b2, b3, b4)*wFeduc_a_8
wcult_10 ~ c(a1, a2, a3, a4)*wcult_9 + c(b1, b2, b3, b4)*wFeduc_a_9
wcult_11 ~ c(a1, a2, a3, a4)*wcult_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3, c4)*wcult_1 + c(d1, d2, d3, d4)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3, c4)*wcult_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*wcult_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*wcult_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*wcult_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*wcult_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*wcult_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*wcult_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*wcult_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*wcult_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
wcult_2 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_2
wcult_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
wcult_1 ~~ wcult_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
wcult_2 ~~ c(vy1, vy2, vy3, vy4)*wcult_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_2
wcult_3 ~~ c(vy1, vy2, vy3, vy4)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2, vy3, vy4)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2, vy3, vy4)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2, vy3, vy4)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2, vy3, vy4)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2, vy3, vy4)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2, vy3, vy4)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2, vy3, vy4)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2, vy3, vy4)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*wcult_1
'
#filename
filename <-
file.path(dir,
"cult_model11_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model11_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model11_unconstrained_groups_constrained_lag,
estimator = 'MLR',
data = MyData,
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_rec"
)
#save model
save(cult_model11_unconstrained_groups_constrained_lag_fit,
file = filename)
} else
(load(file = filename)
)
[1] “cult_model11_unconstrained_groups_constrained_lag_fit”
#filename
filename <-
file.path(dir,
"cult_model11_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model11_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[2]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_rec"
)
#save model
save(cult_model11_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(cult_model11_constrained_lag_groups_fit, cult_model11_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model11_unconstrained_groups_constrained_lag_fit 1280 147004
148124 3915.4 cult_model11_constrained_lag_groups_fit 1301 148108 149092
5061.9 Chisq diff Df diff
cult_model11_unconstrained_groups_constrained_lag_fit
cult_model11_constrained_lag_groups_fit 477 21 Pr(>Chisq)
cult_model11_unconstrained_groups_constrained_lag_fit
cult_model11_constrained_lag_groups_fit < 2.2e-16 *** — Signif.
codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’
1
inc_diff_model11_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_1 + 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_1 =~ 1*inc_diff_1
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_2 ~ c(a1, a2, a3, a4)*winc_diff_1 + c(b1, b2, b3, b4)*wFeduc_a_1
winc_diff_3 ~ c(a1, a2, a3, a4)*winc_diff_2 + c(b1, b2, b3, b4)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2, a3, a4)*winc_diff_3 + c(b1, b2, b3, b4)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2, a3, a4)*winc_diff_4 + c(b1, b2, b3, b4)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2, a3, a4)*winc_diff_5 + c(b1, b2, b3, b4)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2, a3, a4)*winc_diff_6 + c(b1, b2, b3, b4)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2, a3, a4)*winc_diff_7 + c(b1, b2, b3, b4)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2, a3, a4)*winc_diff_8 + c(b1, b2, b3, b4)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2, a3, a4)*winc_diff_9 + c(b1, b2, b3, b4)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2, a3, a4)*winc_diff_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3, c4)*winc_diff_1 + c(d1, d2, d3, d4)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3, c4)*winc_diff_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*winc_diff_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*winc_diff_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*winc_diff_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*winc_diff_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*winc_diff_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*winc_diff_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*winc_diff_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*winc_diff_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
winc_diff_2 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_2
winc_diff_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
winc_diff_1 ~~ winc_diff_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
winc_diff_2 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_2
winc_diff_3 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*winc_diff_1
'
#filename
filename <-
file.path(dir,
"inc_diff_model11_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model11_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model11_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_rec"
)
#save model
save(inc_diff_model11_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"inc_diff_model11_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model11_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[3]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "ave_rec"
)
#save model
save(inc_diff_model11_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(inc_diff_model11_constrained_lag_groups_fit, inc_diff_model11_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model11_unconstrained_groups_constrained_lag_fit 1280 147852
148973 inc_diff_model11_constrained_lag_groups_fit 1301 148958 149942
Chisq Chisq diff
inc_diff_model11_unconstrained_groups_constrained_lag_fit 3975.9
inc_diff_model11_constrained_lag_groups_fit 5123.6 476.48 Df diff
Pr(>Chisq)
inc_diff_model11_unconstrained_groups_constrained_lag_fit
inc_diff_model11_constrained_lag_groups_fit 21 < 2.2e-16
inc_diff_model11_unconstrained_groups_constrained_lag_fit
inc_diff_model11_constrained_lag_groups_fit *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
# Create z score variables
MyData <- MyData %>%
mutate(
sd_pol = sd(pol_dis, na.rm = T),
z_pol = as.numeric((pol_dis - mean(pol_dis, na.rm = T))/sd_pol),
sd_rl = sd(rl_mean, na.rm = T),
z_rl = (rl_mean - mean(rl_mean, na.rm = T))/sd_rl,
sd_ave = sd(ave_mean, na.rm = T),
z_ave = (ave_mean - mean(ave_mean, na.rm = T))/sd_ave
)
#create three groups variables
MyData <- MyData %>%
mutate(across(.cols = c(z_pol,
z_rl,
z_ave),
.fns = ~ case_when(
.x < -1 ~ 1,
.x > -1 & .x < 1 ~ 2,
.x > 1 ~ 3),
.names = "cat_{.col}"))
EU_model12_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_1 + 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_1 =~ 1*eu_1
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_2 ~ c(a1, a2, a3)*weu_1 + c(b1, b2, b3)*wFeduc_a_1
weu_3 ~ c(a1, a2, a3)*weu_2 + c(b1, b2, b3)*wFeduc_a_2
weu_4 ~ c(a1, a2, a3)*weu_3 + c(b1, b2, b3)*wFeduc_a_3
weu_5 ~ c(a1, a2, a3)*weu_4 + c(b1, b2, b3)*wFeduc_a_4
weu_6 ~ c(a1, a2, a3)*weu_5 + c(b1, b2, b3)*wFeduc_a_5
weu_7 ~ c(a1, a2, a3)*weu_6 + c(b1, b2, b3)*wFeduc_a_6
weu_8 ~ c(a1, a2, a3)*weu_7 + c(b1, b2, b3)*wFeduc_a_7
weu_9 ~ c(a1, a2, a3)*weu_8 + c(b1, b2, b3)*wFeduc_a_8
weu_10 ~ c(a1, a2, a3)*weu_9 + c(b1, b2, b3)*wFeduc_a_9
weu_11 ~ c(a1, a2, a3)*weu_10 + c(b1, b2, b3)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3)*weu_1 + c(d1, d2, d3)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3)*weu_2 + c(d1, d2, d3)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3)*weu_3 + c(d1, d2, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3)*weu_4 + c(d1, d2, d3)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3)*weu_5 + c(d1, d2, d3)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3)*weu_6 + c(d1, d2, d3)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3)*weu_7 + c(d1, d2, d3)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3)*weu_8 + c(d1, d2, d3)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3)*weu_9 + c(d1, d2, d3)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3)*weu_10 + c(d1, d2, d3)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ c(cov1, cov2, cov3)*wFeduc_a_2
weu_3 ~~ c(cov1, cov2, cov3)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2, cov3)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2, cov3)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2, cov3)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2, cov3)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2, cov3)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2, cov3)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2, cov3)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2, cov3)*wFeduc_a_11
# Estimate the variance
weu_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ c(vy1, vy2, vy3)*weu_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3)*wFeduc_a_2
weu_3 ~~ c(vy1, vy2, vy3)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2, vy3)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2, vy3)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2, vy3)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2, vy3)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2, vy3)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2, vy3)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2, vy3)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2, vy3)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*weu_1
'
#filename
filename <-
file.path(dir,
"EU_model12_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model12_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model12_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_pol"
)
#save model
save(EU_model12_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"EU_model12_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model12_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[1]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_pol"
)
#save model
save(EU_model12_constrained_lag_groups_fit,
file = filename)
} else {
load(file = filename)
}
lavTestLRT(EU_model12_constrained_lag_groups_fit, EU_model12_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model12_unconstrained_groups_constrained_lag_fit 960 153471
154312 3444.5 EU_model12_constrained_lag_groups_fit 974 154141 154890
4142.1 Chisq diff Df diff
EU_model12_unconstrained_groups_constrained_lag_fit
EU_model12_constrained_lag_groups_fit 389.5 14 Pr(>Chisq)
EU_model12_unconstrained_groups_constrained_lag_fit
EU_model12_constrained_lag_groups_fit < 2.2e-16 *** — Signif. codes:
0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
cult_model12_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_1 + 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_1 =~ 1*cult_1
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_2 ~ c(a1, a2, a3)*wcult_1 + c(b1, b2, b3)*wFeduc_a_1
wcult_3 ~ c(a1, a2, a3)*wcult_2 + c(b1, b2, b3)*wFeduc_a_2
wcult_4 ~ c(a1, a2, a3)*wcult_3 + c(b1, b2, b3)*wFeduc_a_3
wcult_5 ~ c(a1, a2, a3)*wcult_4 + c(b1, b2, b3)*wFeduc_a_4
wcult_6 ~ c(a1, a2, a3)*wcult_5 + c(b1, b2, b3)*wFeduc_a_5
wcult_7 ~ c(a1, a2, a3)*wcult_6 + c(b1, b2, b3)*wFeduc_a_6
wcult_8 ~ c(a1, a2, a3)*wcult_7 + c(b1, b2, b3)*wFeduc_a_7
wcult_9 ~ c(a1, a2, a3)*wcult_8 + c(b1, b2, b3)*wFeduc_a_8
wcult_10 ~ c(a1, a2, a3)*wcult_9 + c(b1, b2, b3)*wFeduc_a_9
wcult_11 ~ c(a1, a2, a3)*wcult_10 + c(b1, b2, b3)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3)*wcult_1 + c(d1, d2, d3)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3)*wcult_2 + c(d1, d2, d3)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3)*wcult_3 + c(d1, d2, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3)*wcult_4 + c(d1, d2, d3)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3)*wcult_5 + c(d1, d2, d3)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3)*wcult_6 + c(d1, d2, d3)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3)*wcult_7 + c(d1, d2, d3)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3)*wcult_8 + c(d1, d2, d3)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3)*wcult_9 + c(d1, d2, d3)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3)*wcult_10 + c(d1, d2, d3)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
wcult_2 ~~ c(cov1, cov2, cov3)*wFeduc_a_2
wcult_3 ~~ c(cov1, cov2, cov3)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2, cov3)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2, cov3)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2, cov3)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2, cov3)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2, cov3)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2, cov3)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2, cov3)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2, cov3)*wFeduc_a_11
# Estimate the variance
wcult_1 ~~ wcult_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
wcult_2 ~~ c(vy1, vy2, vy3)*wcult_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3)*wFeduc_a_2
wcult_3 ~~ c(vy1, vy2, vy3)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2, vy3)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2, vy3)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2, vy3)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2, vy3)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2, vy3)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2, vy3)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2, vy3)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2, vy3)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*wcult_1
'
#filename
filename <-
file.path(dir,
"cult_model12_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model12_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model12_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_pol"
)
#save model
save(cult_model12_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"cult_model12_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model12_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[2]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_pol"
)
#save model
save(cult_model12_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(cult_model12_constrained_lag_groups_fit, cult_model12_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model12_unconstrained_groups_constrained_lag_fit 960 146978
147818 3166.3 cult_model12_constrained_lag_groups_fit 974 147680 148429
3897.1 Chisq diff Df diff
cult_model12_unconstrained_groups_constrained_lag_fit
cult_model12_constrained_lag_groups_fit 425.72 14 Pr(>Chisq)
cult_model12_unconstrained_groups_constrained_lag_fit
cult_model12_constrained_lag_groups_fit < 2.2e-16 *** — Signif.
codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’
1
inc_diff_model12_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_1 + 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_1 + 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_1 ~~ 0*Feduc_a_1
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_1 =~ 1*Feduc_a_1
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_1 =~ 1*inc_diff_1
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_2 ~ c(a1, a2, a3)*winc_diff_1 + c(b1, b2, b3)*wFeduc_a_1
winc_diff_3 ~ c(a1, a2, a3)*winc_diff_2 + c(b1, b2, b3)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2, a3)*winc_diff_3 + c(b1, b2, b3)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2, a3)*winc_diff_4 + c(b1, b2, b3)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2, a3)*winc_diff_5 + c(b1, b2, b3)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2, a3)*winc_diff_6 + c(b1, b2, b3)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2, a3)*winc_diff_7 + c(b1, b2, b3)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2, a3)*winc_diff_8 + c(b1, b2, b3)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2, a3)*winc_diff_9 + c(b1, b2, b3)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2, a3)*winc_diff_10 + c(b1, b2, b3)*wFeduc_a_10
wFeduc_a_2 ~ c(c1, c2, c3)*winc_diff_1 + c(d1, d2, d3)*wFeduc_a_1
wFeduc_a_3 ~ c(c1, c2, c3)*winc_diff_2 + c(d1, d2, d3)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3)*winc_diff_3 + c(d1, d2, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3)*winc_diff_4 + c(d1, d2, d3)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3)*winc_diff_5 + c(d1, d2, d3)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3)*winc_diff_6 + c(d1, d2, d3)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3)*winc_diff_7 + c(d1, d2, d3)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3)*winc_diff_8 + c(d1, d2, d3)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3)*winc_diff_9 + c(d1, d2, d3)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3)*winc_diff_10 + c(d1, d2, d3)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
winc_diff_2 ~~ c(cov1, cov2, cov3)*wFeduc_a_2
winc_diff_3 ~~ c(cov1, cov2, cov3)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2, cov3)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2, cov3)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2, cov3)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2, cov3)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2, cov3)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2, cov3)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2, cov3)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2, cov3)*wFeduc_a_11
# Estimate the variance
winc_diff_1 ~~ winc_diff_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
winc_diff_2 ~~ c(vy1, vy2, vy3)*winc_diff_2
wFeduc_a_2 ~~ c(vx1, vx2, vx3)*wFeduc_a_2
winc_diff_3 ~~ c(vy1, vy2, vy3)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2, vy3)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2, vy3)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2, vy3)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2, vy3)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2, vy3)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2, vy3)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2, vy3)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2, vy3)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_1 + 0*winc_diff_1
'
#filename
filename <-
file.path(dir,
"inc_diff_model12_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model12_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model12_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_pol"
)
#save model
save(inc_diff_model12_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"inc_diff_model12_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model12_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[3]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_pol"
)
#save model
save(inc_diff_model12_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(inc_diff_model12_constrained_lag_groups_fit, inc_diff_model12_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model12_unconstrained_groups_constrained_lag_fit 960 147766
148606 inc_diff_model12_constrained_lag_groups_fit 974 148483 149232
Chisq Chisq diff
inc_diff_model12_unconstrained_groups_constrained_lag_fit 3257.3
inc_diff_model12_constrained_lag_groups_fit 4002.4 414.88 Df diff
Pr(>Chisq)
inc_diff_model12_unconstrained_groups_constrained_lag_fit
inc_diff_model12_constrained_lag_groups_fit 14 < 2.2e-16
inc_diff_model12_unconstrained_groups_constrained_lag_fit
inc_diff_model12_constrained_lag_groups_fit *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
EU_model13_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ c(a1, a2, a3)*weu_2 + c(b1, b2, b3)*wFeduc_a_2
weu_4 ~ c(a1, a2, a3)*weu_3 + c(b1, b2, b3)*wFeduc_a_3
weu_5 ~ c(a1, a2, a3)*weu_4 + c(b1, b2, b3)*wFeduc_a_4
weu_6 ~ c(a1, a2, a3)*weu_5 + c(b1, b2, b3)*wFeduc_a_5
weu_7 ~ c(a1, a2, a3)*weu_6 + c(b1, b2, b3)*wFeduc_a_6
weu_8 ~ c(a1, a2, a3)*weu_7 + c(b1, b2, b3)*wFeduc_a_7
weu_9 ~ c(a1, a2, a3)*weu_8 + c(b1, b2, b3)*wFeduc_a_8
weu_10 ~ c(a1, a2, a3)*weu_9 + c(b1, b2, b3)*wFeduc_a_9
weu_11 ~ c(a1, a2, a3)*weu_10 + c(b1, b2, b3)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3)*weu_2 + c(d1, d2, d3)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3)*weu_3 + c(d1, d2, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3)*weu_4 + c(d1, d2, d3)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3)*weu_5 + c(d1, d2, d3)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3)*weu_6 + c(d1, d2, d3)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3)*weu_7 + c(d1, d2, d3)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3)*weu_8 + c(d1, d2, d3)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3)*weu_9 + c(d1, d2, d3)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3)*weu_10 + c(d1, d2, d3)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ c(cov1, cov2, cov3)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2, cov3)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2, cov3)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2, cov3)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2, cov3)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2, cov3)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2, cov3)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2, cov3)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2, cov3)*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ c(vy1, vy2, vy3)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2, vy3)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2, vy3)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2, vy3)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2, vy3)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2, vy3)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2, vy3)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2, vy3)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2, vy3)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#filename
filename <-
file.path(dir,
"EU_model13_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model13_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model13_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_rl"
)
#save model
save(EU_model13_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"EU_model13_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model13_constrained_lag_groups_fit <-
lavaan(
EU_model7_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_rl"
)
#save model
save(EU_model13_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(EU_model13_constrained_lag_groups_fit, EU_model13_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model13_unconstrained_groups_constrained_lag_fit 807 138966
139764 3232.6 EU_model13_constrained_lag_groups_fit 821 139470 140176
3763.9 Chisq diff Df diff
EU_model13_unconstrained_groups_constrained_lag_fit
EU_model13_constrained_lag_groups_fit 271.4 14 Pr(>Chisq)
EU_model13_unconstrained_groups_constrained_lag_fit
EU_model13_constrained_lag_groups_fit < 2.2e-16 *** — Signif. codes:
0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
cult_model13_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ c(a1, a2, a3)*wcult_2 + c(b1, b2, b3)*wFeduc_a_2
wcult_4 ~ c(a1, a2, a3)*wcult_3 + c(b1, b2, b3)*wFeduc_a_3
wcult_5 ~ c(a1, a2, a3)*wcult_4 + c(b1, b2, b3)*wFeduc_a_4
wcult_6 ~ c(a1, a2, a3)*wcult_5 + c(b1, b2, b3)*wFeduc_a_5
wcult_7 ~ c(a1, a2, a3)*wcult_6 + c(b1, b2, b3)*wFeduc_a_6
wcult_8 ~ c(a1, a2, a3)*wcult_7 + c(b1, b2, b3)*wFeduc_a_7
wcult_9 ~ c(a1, a2, a3)*wcult_8 + c(b1, b2, b3)*wFeduc_a_8
wcult_10 ~ c(a1, a2, a3)*wcult_9 + c(b1, b2, b3)*wFeduc_a_9
wcult_11 ~ c(a1, a2, a3)*wcult_10 + c(b1, b2, b3)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3)*wcult_2 + c(d1, d2, d3)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3)*wcult_3 + c(d1, d2, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3)*wcult_4 + c(d1, d2, d3)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3)*wcult_5 + c(d1, d2, d3)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3)*wcult_6 + c(d1, d2, d3)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3)*wcult_7 + c(d1, d2, d3)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3)*wcult_8 + c(d1, d2, d3)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3)*wcult_9 + c(d1, d2, d3)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3)*wcult_10 + c(d1, d2, d3)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ c(cov1, cov2, cov3)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2, cov3)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2, cov3)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2, cov3)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2, cov3)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2, cov3)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2, cov3)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2, cov3)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2, cov3)*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ c(vy1, vy2, vy3)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2, vy3)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2, vy3)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2, vy3)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2, vy3)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2, vy3)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2, vy3)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2, vy3)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2, vy3)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#filename
filename <-
file.path(dir,
"cult_model13_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model13_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model13_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_rl"
)
#save model
save(cult_model13_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"cult_model13_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model13_constrained_lag_groups_fit <-
lavaan(
cult_model7_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_rl"
)
#save model
save(cult_model13_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(cult_model13_constrained_lag_groups_fit, cult_model13_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model13_unconstrained_groups_constrained_lag_fit 807 132925
133723 2926.1 cult_model13_constrained_lag_groups_fit 821 133496 134202
3524.4 Chisq diff Df diff
cult_model13_unconstrained_groups_constrained_lag_fit
cult_model13_constrained_lag_groups_fit 339.39 14 Pr(>Chisq)
cult_model13_unconstrained_groups_constrained_lag_fit
cult_model13_constrained_lag_groups_fit < 2.2e-16 *** — Signif.
codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’
1
inc_diff_model13_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ c(a1, a2, a3)*winc_diff_2 + c(b1, b2, b3)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2, a3)*winc_diff_3 + c(b1, b2, b3)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2, a3)*winc_diff_4 + c(b1, b2, b3)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2, a3)*winc_diff_5 + c(b1, b2, b3)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2, a3)*winc_diff_6 + c(b1, b2, b3)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2, a3)*winc_diff_7 + c(b1, b2, b3)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2, a3)*winc_diff_8 + c(b1, b2, b3)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2, a3)*winc_diff_9 + c(b1, b2, b3)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2, a3)*winc_diff_10 + c(b1, b2, b3)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3)*winc_diff_2 + c(d1, d2, d3)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3)*winc_diff_3 + c(d1, d2, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3)*winc_diff_4 + c(d1, d2, d3)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3)*winc_diff_5 + c(d1, d2, d3)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3)*winc_diff_6 + c(d1, d2, d3)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3)*winc_diff_7 + c(d1, d2, d3)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3)*winc_diff_8 + c(d1, d2, d3)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3)*winc_diff_9 + c(d1, d2, d3)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3)*winc_diff_10 + c(d1, d2, d3)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ c(cov1, cov2, cov3)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2, cov3)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2, cov3)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2, cov3)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2, cov3)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2, cov3)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2, cov3)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2, cov3)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2, cov3)*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ c(vy1, vy2, vy3)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2, vy3)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2, vy3)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2, vy3)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2, vy3)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2, vy3)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2, vy3)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2, vy3)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2, vy3)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#filename
filename <-
file.path(dir,
"inc_diff_model13_unconstrained_groups_constrained_lag_fit")
#estimate model
if (!file.exists(filename)) {
inc_diff_model13_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model13_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_rl"
)
#save model
save(inc_diff_model13_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"inc_diff_model13_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model13_constrained_lag_groups_fit <-
lavaan(
cult_model7_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_rl"
)
#save model
save(inc_diff_model13_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(inc_diff_model13_constrained_lag_groups_fit, inc_diff_model13_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model13_unconstrained_groups_constrained_lag_fit 807 133558
134355 inc_diff_model13_constrained_lag_groups_fit 821 133496 134202
Chisq Chisq diff
inc_diff_model13_unconstrained_groups_constrained_lag_fit 3135.5
inc_diff_model13_constrained_lag_groups_fit 3524.4 107.45 Df diff
Pr(>Chisq)
inc_diff_model13_unconstrained_groups_constrained_lag_fit
inc_diff_model13_constrained_lag_groups_fit 14 < 2.2e-16
inc_diff_model13_unconstrained_groups_constrained_lag_fit
inc_diff_model13_constrained_lag_groups_fit *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
#filename
filename <-
file.path(dir,
"EU_model14_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model14_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model12_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_ave"
)
#save model
save(EU_model14_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"EU_model14_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model14_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[1]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_ave"
)
#save model
save(EU_model14_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(EU_model14_constrained_lag_groups_fit, EU_model14_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model14_unconstrained_groups_constrained_lag_fit 960 153484
154324 3403.3 EU_model14_constrained_lag_groups_fit 974 154432 155182
4379.9 Chisq diff Df diff
EU_model14_unconstrained_groups_constrained_lag_fit
EU_model14_constrained_lag_groups_fit 573.46 14 Pr(>Chisq)
EU_model14_unconstrained_groups_constrained_lag_fit
EU_model14_constrained_lag_groups_fit < 2.2e-16 *** — Signif. codes:
0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
#filename
filename <-
file.path(dir,
"cult_model14_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model14_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model12_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_ave"
)
#save model
save(cult_model14_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"cult_model14_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model14_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[2]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_ave"
)
#save model
save(cult_model14_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(cult_model14_constrained_lag_groups_fit, cult_model14_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model14_unconstrained_groups_constrained_lag_fit 960 146970
147811 3222.4 cult_model14_constrained_lag_groups_fit 974 147927 148676
4206.7 Chisq diff Df diff
cult_model14_unconstrained_groups_constrained_lag_fit
cult_model14_constrained_lag_groups_fit 585.02 14 Pr(>Chisq)
cult_model14_unconstrained_groups_constrained_lag_fit
cult_model14_constrained_lag_groups_fit < 2.2e-16 *** — Signif.
codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’
1
#filename
filename <-
file.path(dir,
"inc_diff_model14_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model14_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model12_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_ave"
)
#save model
save(inc_diff_model14_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"inc_diff_model14_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model14_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[3]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "cat_z_ave"
)
#save model
save(inc_diff_model14_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(inc_diff_model14_constrained_lag_groups_fit, inc_diff_model14_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model14_unconstrained_groups_constrained_lag_fit 960 147822
148663 inc_diff_model14_constrained_lag_groups_fit 974 148782 149532
Chisq Chisq diff
inc_diff_model14_unconstrained_groups_constrained_lag_fit 3369.5
inc_diff_model14_constrained_lag_groups_fit 4357.6 546.63 Df diff
Pr(>Chisq)
inc_diff_model14_unconstrained_groups_constrained_lag_fit
inc_diff_model14_constrained_lag_groups_fit 14 < 2.2e-16
inc_diff_model14_unconstrained_groups_constrained_lag_fit
inc_diff_model14_constrained_lag_groups_fit *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
MyData <- MyData %>%
rowwise() %>%
mutate(length_mean = mean(c_across(starts_with("Flength")), na.rm = T)) %>%
ungroup()
MyData <- MyData %>%
mutate(length_rec = cut2(length_mean, g = 4),
length_2 = cut2(length_mean, g = 2))
EU_model15_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ c(a1, a2, a3, a4)*weu_2 + c(b1, b2, b3, b4)*wFeduc_a_2
weu_4 ~ c(a1, a2, a3, a4)*weu_3 + c(b1, b2, b3, b4)*wFeduc_a_3
weu_5 ~ c(a1, a2, a3, a4)*weu_4 + c(b1, b2, b3, b4)*wFeduc_a_4
weu_6 ~ c(a1, a2, a3, a4)*weu_5 + c(b1, b2, b3, b4)*wFeduc_a_5
weu_7 ~ c(a1, a2, a3, a4)*weu_6 + c(b1, b2, b3, b4)*wFeduc_a_6
weu_8 ~ c(a1, a2, a3, a4)*weu_7 + c(b1, b2, b3, b4)*wFeduc_a_7
weu_9 ~ c(a1, a2, a3, a4)*weu_8 + c(b1, b2, b3, b4)*wFeduc_a_8
weu_10 ~ c(a1, a2, a3, a4)*weu_9 + c(b1, b2, b3, b4)*wFeduc_a_9
weu_11 ~ c(a1, a2, a3, a4)*weu_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3, c4)*weu_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*weu_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*weu_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*weu_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*weu_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*weu_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*weu_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*weu_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*weu_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ c(vy1, vy2, vy3, vy4)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2, vy3, vy4)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2, vy3, vy4)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2, vy3, vy4)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2, vy3, vy4)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2, vy3, vy4)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2, vy3, vy4)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2, vy3, vy4)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2, vy3, vy4)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#filename
filename <-
file.path(dir,
"EU_model15_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model15_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model15_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_rec"
)
#save model
save(EU_model15_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"EU_model15_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model15_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[1]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_rec"
)
#save model
save(EU_model15_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(EU_model15_constrained_lag_groups_fit, EU_model15_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model15_unconstrained_groups_constrained_lag_fit 1076 138628
139690 3608.0 EU_model15_constrained_lag_groups_fit 1301 151429 152407
5172.1 Chisq diff Df diff
EU_model15_unconstrained_groups_constrained_lag_fit
EU_model15_constrained_lag_groups_fit 1221.2 225 Pr(>Chisq)
EU_model15_unconstrained_groups_constrained_lag_fit
EU_model15_constrained_lag_groups_fit < 2.2e-16 *** — Signif. codes:
0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
cult_model15_unconstrained_groups_constrained_lag <-
'
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ c(a1, a2, a3, a4)*wcult_2 + c(b1, b2, b3, b4)*wFeduc_a_2
wcult_4 ~ c(a1, a2, a3, a4)*wcult_3 + c(b1, b2, b3, b4)*wFeduc_a_3
wcult_5 ~ c(a1, a2, a3, a4)*wcult_4 + c(b1, b2, b3, b4)*wFeduc_a_4
wcult_6 ~ c(a1, a2, a3, a4)*wcult_5 + c(b1, b2, b3, b4)*wFeduc_a_5
wcult_7 ~ c(a1, a2, a3, a4)*wcult_6 + c(b1, b2, b3, b4)*wFeduc_a_6
wcult_8 ~ c(a1, a2, a3, a4)*wcult_7 + c(b1, b2, b3, b4)*wFeduc_a_7
wcult_9 ~ c(a1, a2, a3, a4)*wcult_8 + c(b1, b2, b3, b4)*wFeduc_a_8
wcult_10 ~ c(a1, a2, a3, a4)*wcult_9 + c(b1, b2, b3, b4)*wFeduc_a_9
wcult_11 ~ c(a1, a2, a3, a4)*wcult_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3, c4)*wcult_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*wcult_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*wcult_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*wcult_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*wcult_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*wcult_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*wcult_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*wcult_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*wcult_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ c(vy1, vy2, vy3, vy4)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2, vy3, vy4)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2, vy3, vy4)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2, vy3, vy4)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2, vy3, vy4)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2, vy3, vy4)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2, vy3, vy4)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2, vy3, vy4)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2, vy3, vy4)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#filename
filename <-
file.path(dir,
"cult_model15_unconstrained_groups_constrained_lag_fit")
#estimate model
if (!file.exists(filename)) {
cult_model15_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model15_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_rec"
)
#save model
save(cult_model15_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"cult_model15_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model15_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[2]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_rec"
)
#save model
save(cult_model15_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(cult_model15_constrained_lag_groups_fit, cult_model15_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model15_unconstrained_groups_constrained_lag_fit 1076 132597
133659 3301.1 cult_model15_constrained_lag_groups_fit 1301 144845 145823
4897.7 Chisq diff Df diff
cult_model15_unconstrained_groups_constrained_lag_fit
cult_model15_constrained_lag_groups_fit 1244.7 225 Pr(>Chisq)
cult_model15_unconstrained_groups_constrained_lag_fit
cult_model15_constrained_lag_groups_fit < 2.2e-16 *** — Signif.
codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’
1
inc_diff_model15_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ c(a1, a2, a3, a4)*winc_diff_2 + c(b1, b2, b3, b4)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2, a3, a4)*winc_diff_3 + c(b1, b2, b3, b4)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2, a3, a4)*winc_diff_4 + c(b1, b2, b3, b4)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2, a3, a4)*winc_diff_5 + c(b1, b2, b3, b4)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2, a3, a4)*winc_diff_6 + c(b1, b2, b3, b4)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2, a3, a4)*winc_diff_7 + c(b1, b2, b3, b4)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2, a3, a4)*winc_diff_8 + c(b1, b2, b3, b4)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2, a3, a4)*winc_diff_9 + c(b1, b2, b3, b4)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2, a3, a4)*winc_diff_10 + c(b1, b2, b3, b4)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2, c3, c4)*winc_diff_2 + c(d1, d2, d3, d4)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2, c3, c4)*winc_diff_3 + c(d1, d2, d3, d4)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2, c3, c4)*winc_diff_4 + c(d1, d2, d3, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2, c3, c4)*winc_diff_5 + c(d1, d2, d3, d4)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2, c3, c4)*winc_diff_6 + c(d1, d2, d3, d4)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2, c3, c4)*winc_diff_7 + c(d1, d2, d3, d4)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2, c3, c4)*winc_diff_8 + c(d1, d2, d3, d4)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2, c3, c4)*winc_diff_9 + c(d1, d2, d3, d4)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2, c3, c4)*winc_diff_10 + c(d1, d2, d3, d4)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2, cov3, cov4)*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2, vy3, vy4)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2, vx3, vx4)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#filename
filename <-
file.path(dir,
"inc_diff_model15_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model15_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model15_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_rec"
)
#save model
save(inc_diff_model15_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
#filename
filename <-
file.path(dir,
"inc_diff_model15_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model15_constrained_lag_groups_fit <-
lavaan(
main_lavaan_results$`Lavaan model objects`[[3]][[2]],
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_rec"
)
#save model
save(inc_diff_model15_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
lavTestLRT(inc_diff_model15_constrained_lag_groups_fit, inc_diff_model15_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
inc_diff_model15_unconstrained_groups_constrained_lag_fit 1076 133147
134209 inc_diff_model15_constrained_lag_groups_fit 1301 145683 146661
Chisq Chisq diff
inc_diff_model15_unconstrained_groups_constrained_lag_fit 3438.1
inc_diff_model15_constrained_lag_groups_fit 4964.8 1221.8 Df diff
Pr(>Chisq)
inc_diff_model15_unconstrained_groups_constrained_lag_fit
inc_diff_model15_constrained_lag_groups_fit 225 < 2.2e-16
inc_diff_model15_unconstrained_groups_constrained_lag_fit
inc_diff_model15_constrained_lag_groups_fit *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
EU_model16_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ c(a2, a2)*weu_2 + c(b2, b2)*wFeduc_a_2
weu_4 ~ c(a3, a3)*weu_3 + c(b3, b3)*wFeduc_a_3
weu_5 ~ c(a4, a4)*weu_4 + c(b4, b4)*wFeduc_a_4
weu_6 ~ c(a5, a5)*weu_5 + c(b5, b5)*wFeduc_a_5
weu_7 ~ c(a6, a6)*weu_6 + c(b6, b6)*wFeduc_a_6
weu_8 ~ c(a7, a7)*weu_7 + c(b7, b7)*wFeduc_a_7
weu_9 ~ c(a8, a8)*weu_8 + c(b8, b8)*wFeduc_a_8
weu_10 ~ c(a9, a9)*weu_9 + c(b9, b9)*wFeduc_a_9
weu_11 ~ c(a10, a10)*weu_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_3 ~ c(c2, c2)*weu_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*weu_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*weu_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*weu_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*weu_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*weu_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*weu_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*weu_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*weu_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ c(cov1, cov2)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ c(vy1, vy2)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#filename
filename <-
file.path(dir,
"EU_model16_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model16_constrained_groups_fit <-
lavaan(
EU_model16_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(EU_model16_constrained_groups_fit,
file = filename)
} else {load(file = filename)
}
EU_model16_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ c(a1, a2)*weu_2 + c(b1, b2)*wFeduc_a_2
weu_4 ~ c(a1, a2)*weu_3 + c(b1, b2)*wFeduc_a_3
weu_5 ~ c(a1, a2)*weu_4 + c(b1, b2)*wFeduc_a_4
weu_6 ~ c(a1, a2)*weu_5 + c(b1, b2)*wFeduc_a_5
weu_7 ~ c(a1, a2)*weu_6 + c(b1, b2)*wFeduc_a_6
weu_8 ~ c(a1, a2)*weu_7 + c(b1, b2)*wFeduc_a_7
weu_9 ~ c(a1, a2)*weu_8 + c(b1, b2)*wFeduc_a_8
weu_10 ~ c(a1, a2)*weu_9 + c(b1, b2)*wFeduc_a_9
weu_11 ~ c(a1, a2)*weu_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2)*weu_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*weu_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*weu_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*weu_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*weu_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*weu_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*weu_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*weu_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*weu_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ c(cov1, cov2)*wFeduc_a_3
weu_4 ~~ c(cov1, cov2)*wFeduc_a_4
weu_5 ~~ c(cov1, cov2)*wFeduc_a_5
weu_6 ~~ c(cov1, cov2)*wFeduc_a_6
weu_7 ~~ c(cov1, cov2)*wFeduc_a_7
weu_8 ~~ c(cov1, cov2)*wFeduc_a_8
weu_9 ~~ c(cov1, cov2)*wFeduc_a_9
weu_10 ~~ c(cov1, cov2)*wFeduc_a_10
weu_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ c(vy1, vy2)*weu_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
weu_4 ~~ c(vy1, vy2)*weu_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
weu_5 ~~ c(vy1, vy2)*weu_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
weu_6 ~~ c(vy1, vy2)*weu_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
weu_7 ~~ c(vy1, vy2)*weu_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
weu_8 ~~ c(vy1, vy2)*weu_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
weu_9 ~~ c(vy1, vy2)*weu_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
weu_10 ~~ c(vy1, vy2)*weu_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
weu_11 ~~ c(vy1, vy2)*weu_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#filename
filename <-
file.path(dir,
"EU_model16_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model16_unconstrained_groups_constrained_lag_fit <-
lavaan(
EU_model16_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(EU_model16_unconstrained_groups_constrained_lag_fit,
file = filename)
} else
{load(file = filename)
}
EU_model16_constrained_lag_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*eu_2 + 1*eu_3 + 1*eu_4 + 1*eu_5 + 1*eu_6 + 1*eu_7 + 1*eu_8 + 1*eu_9 + 1*eu_10 + 1*eu_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
weu_2 =~ 1*eu_2
weu_3 =~ 1*eu_3
weu_4 =~ 1*eu_4
weu_5 =~ 1*eu_5
weu_6 =~ 1*eu_6
weu_7 =~ 1*eu_7
weu_8 =~ 1*eu_8
weu_9 =~ 1*eu_9
weu_10 =~ 1*eu_10
weu_11 =~ 1*eu_11
# Estimate the lagged effects (constrained)
weu_3 ~ a*weu_2 + b*wFeduc_a_2
weu_4 ~ a*weu_3 + b*wFeduc_a_3
weu_5 ~ a*weu_4 + b*wFeduc_a_4
weu_6 ~ a*weu_5 + b*wFeduc_a_5
weu_7 ~ a*weu_6 + b*wFeduc_a_6
weu_8 ~ a*weu_7 + b*wFeduc_a_7
weu_9 ~ a*weu_8 + b*wFeduc_a_8
weu_10 ~ a*weu_9 + b*wFeduc_a_9
weu_11 ~ a*weu_10 + b*wFeduc_a_10
wFeduc_a_3 ~ c*weu_2 + d*wFeduc_a_2
wFeduc_a_4 ~ c*weu_3 + d*wFeduc_a_3
wFeduc_a_5 ~ c*weu_4 + d*wFeduc_a_4
wFeduc_a_6 ~ c*weu_5 + d*wFeduc_a_5
wFeduc_a_7 ~ c*weu_6 + d*wFeduc_a_6
wFeduc_a_8 ~ c*weu_7 + d*wFeduc_a_7
wFeduc_a_9 ~ c*weu_8 + d*wFeduc_a_8
wFeduc_a_10 ~ c*weu_9 + d*wFeduc_a_9
wFeduc_a_11 ~ c*weu_10 + d*wFeduc_a_10
# Estimate the covariance at the first wave.
weu_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
weu_3 ~~ cov*wFeduc_a_3
weu_4 ~~ cov*wFeduc_a_4
weu_5 ~~ cov*wFeduc_a_5
weu_6 ~~ cov*wFeduc_a_6
weu_7 ~~ cov*wFeduc_a_7
weu_8 ~~ cov*wFeduc_a_8
weu_9 ~~ cov*wFeduc_a_9
weu_10 ~~ cov*wFeduc_a_10
weu_11 ~~ cov*wFeduc_a_11
# Estimate the variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
weu_3 ~~ vy*weu_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
weu_4 ~~ vy*weu_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
weu_5 ~~ vy*weu_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
weu_6 ~~ vy*weu_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
weu_7 ~~ vy*weu_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
weu_8 ~~ vy*weu_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
weu_9 ~~ vy*weu_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
weu_10 ~~ vy*weu_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
weu_11 ~~ vy*weu_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*weu_2
'
#filename
filename <-
file.path(dir,
"EU_model16_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
EU_model16_constrained_lag_groups_fit <-
lavaan(
EU_model16_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(EU_model16_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
fit_matrix_EU_m16_constrained_groups <- lavInspect(EU_model16_constrained_lag_groups_fit, what = "fit")
fit_matrix_EU_m16_unconstrained_groups <- lavInspect(EU_model16_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_eu_M16 <- rbind(fit_matrix_EU_m16_constrained_groups, fit_matrix_EU_m16_unconstrained_groups)
lavTestLRT(EU_model16_constrained_lag_groups_fit, EU_model16_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq EU_model16_unconstrained_groups_constrained_lag_fit 538 139960
140491 2322.1 EU_model16_constrained_lag_groups_fit 545 139998 140483
2373.3 Chisq diff Df diff
EU_model16_unconstrained_groups_constrained_lag_fit
EU_model16_constrained_lag_groups_fit 22.88 7 Pr(>Chisq)
EU_model16_unconstrained_groups_constrained_lag_fit
EU_model16_constrained_lag_groups_fit 0.001789 ** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
cult_model16_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ c(a2, a2)*wcult_2 + c(b2, b2)*wFeduc_a_2
wcult_4 ~ c(a3, a3)*wcult_3 + c(b3, b3)*wFeduc_a_3
wcult_5 ~ c(a4, a4)*wcult_4 + c(b4, b4)*wFeduc_a_4
wcult_6 ~ c(a5, a5)*wcult_5 + c(b5, b5)*wFeduc_a_5
wcult_7 ~ c(a6, a6)*wcult_6 + c(b6, b6)*wFeduc_a_6
wcult_8 ~ c(a7, a7)*wcult_7 + c(b7, b7)*wFeduc_a_7
wcult_9 ~ c(a8, a8)*wcult_8 + c(b8, b8)*wFeduc_a_8
wcult_10 ~ c(a9, a9)*wcult_9 + c(b9, b9)*wFeduc_a_9
wcult_11 ~ c(a10, a10)*wcult_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_3 ~ c(c2, c2)*wcult_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*wcult_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*wcult_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*wcult_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*wcult_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*wcult_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*wcult_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*wcult_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*wcult_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ c(cov1, cov2)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ c(vy1, vy2)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#filename
filename <-
file.path(dir,
"cult_model16_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model16_constrained_groups_fit <-
lavaan(
cult_model16_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(cult_model16_constrained_groups_fit,
file = filename)
} else {
load(file = filename)
}
cult_model16_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ c(a1, a2)*wcult_2 + c(b1, b2)*wFeduc_a_2
wcult_4 ~ c(a1, a2)*wcult_3 + c(b1, b2)*wFeduc_a_3
wcult_5 ~ c(a1, a2)*wcult_4 + c(b1, b2)*wFeduc_a_4
wcult_6 ~ c(a1, a2)*wcult_5 + c(b1, b2)*wFeduc_a_5
wcult_7 ~ c(a1, a2)*wcult_6 + c(b1, b2)*wFeduc_a_6
wcult_8 ~ c(a1, a2)*wcult_7 + c(b1, b2)*wFeduc_a_7
wcult_9 ~ c(a1, a2)*wcult_8 + c(b1, b2)*wFeduc_a_8
wcult_10 ~ c(a1, a2)*wcult_9 + c(b1, b2)*wFeduc_a_9
wcult_11 ~ c(a1, a2)*wcult_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2)*wcult_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*wcult_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*wcult_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*wcult_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*wcult_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*wcult_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*wcult_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*wcult_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*wcult_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ c(cov1, cov2)*wFeduc_a_3
wcult_4 ~~ c(cov1, cov2)*wFeduc_a_4
wcult_5 ~~ c(cov1, cov2)*wFeduc_a_5
wcult_6 ~~ c(cov1, cov2)*wFeduc_a_6
wcult_7 ~~ c(cov1, cov2)*wFeduc_a_7
wcult_8 ~~ c(cov1, cov2)*wFeduc_a_8
wcult_9 ~~ c(cov1, cov2)*wFeduc_a_9
wcult_10 ~~ c(cov1, cov2)*wFeduc_a_10
wcult_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ c(vy1, vy2)*wcult_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
wcult_4 ~~ c(vy1, vy2)*wcult_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
wcult_5 ~~ c(vy1, vy2)*wcult_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
wcult_6 ~~ c(vy1, vy2)*wcult_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
wcult_7 ~~ c(vy1, vy2)*wcult_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
wcult_8 ~~ c(vy1, vy2)*wcult_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
wcult_9 ~~ c(vy1, vy2)*wcult_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
wcult_10 ~~ c(vy1, vy2)*wcult_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
wcult_11 ~~ c(vy1, vy2)*wcult_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#filename
filename <-
file.path(dir,
"cult_model16_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model16_unconstrained_groups_constrained_lag_fit <-
lavaan(
cult_model16_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(cult_model16_unconstrained_groups_constrained_lag_fit,
file = filename)
} else {load(file = filename)
}
cult_model16_constrained_lag_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*cult_2 + 1*cult_3 + 1*cult_4 + 1*cult_5 + 1*cult_6 + 1*cult_7 + 1*cult_8 + 1*cult_9 + 1*cult_10 + 1*cult_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
wcult_2 =~ 1*cult_2
wcult_3 =~ 1*cult_3
wcult_4 =~ 1*cult_4
wcult_5 =~ 1*cult_5
wcult_6 =~ 1*cult_6
wcult_7 =~ 1*cult_7
wcult_8 =~ 1*cult_8
wcult_9 =~ 1*cult_9
wcult_10 =~ 1*cult_10
wcult_11 =~ 1*cult_11
# Estimate the lagged effects (constrained)
wcult_3 ~ a*wcult_2 + b*wFeduc_a_2
wcult_4 ~ a*wcult_3 + b*wFeduc_a_3
wcult_5 ~ a*wcult_4 + b*wFeduc_a_4
wcult_6 ~ a*wcult_5 + b*wFeduc_a_5
wcult_7 ~ a*wcult_6 + b*wFeduc_a_6
wcult_8 ~ a*wcult_7 + b*wFeduc_a_7
wcult_9 ~ a*wcult_8 + b*wFeduc_a_8
wcult_10 ~ a*wcult_9 + b*wFeduc_a_9
wcult_11 ~ a*wcult_10 + b*wFeduc_a_10
wFeduc_a_3 ~ c*wcult_2 + d*wFeduc_a_2
wFeduc_a_4 ~ c*wcult_3 + d*wFeduc_a_3
wFeduc_a_5 ~ c*wcult_4 + d*wFeduc_a_4
wFeduc_a_6 ~ c*wcult_5 + d*wFeduc_a_5
wFeduc_a_7 ~ c*wcult_6 + d*wFeduc_a_6
wFeduc_a_8 ~ c*wcult_7 + d*wFeduc_a_7
wFeduc_a_9 ~ c*wcult_8 + d*wFeduc_a_8
wFeduc_a_10 ~ c*wcult_9 + d*wFeduc_a_9
wFeduc_a_11 ~ c*wcult_10 + d*wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
wcult_3 ~~ cov*wFeduc_a_3
wcult_4 ~~ cov*wFeduc_a_4
wcult_5 ~~ cov*wFeduc_a_5
wcult_6 ~~ cov*wFeduc_a_6
wcult_7 ~~ cov*wFeduc_a_7
wcult_8 ~~ cov*wFeduc_a_8
wcult_9 ~~ cov*wFeduc_a_9
wcult_10 ~~ cov*wFeduc_a_10
wcult_11 ~~ cov*wFeduc_a_11
# Estimate the variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
wcult_3 ~~ vy*wcult_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
wcult_4 ~~ vy*wcult_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
wcult_5 ~~ vy*wcult_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
wcult_6 ~~ vy*wcult_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
wcult_7 ~~ vy*wcult_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
wcult_8 ~~ vy*wcult_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
wcult_9 ~~ vy*wcult_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
wcult_10 ~~ vy*wcult_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
wcult_11 ~~ vy*wcult_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*wcult_2
'
#filename
filename <-
file.path(dir,
"cult_model16_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
cult_model16_constrained_lag_groups_fit <-
lavaan(
cult_model16_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(cult_model16_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
fit_matrix_cult_m16_constrained_groups <- lavInspect(cult_model16_constrained_lag_groups_fit, what = "fit")
fit_matrix_cult_m16_unconstrained_groups <- lavInspect(cult_model16_unconstrained_groups_constrained_lag_fit, what = "fit")
fit_matrix_cult_M16 <- rbind(fit_matrix_cult_m16_constrained_groups, fit_matrix_cult_m16_unconstrained_groups)
lavTestLRT(cult_model16_constrained_lag_groups_fit, cult_model16_unconstrained_groups_constrained_lag_fit)
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan->lavTestLRT():
lavaan NOTE: The “Chisq” column contains standard test statistics, not
the robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics. Df AIC BIC
Chisq cult_model16_unconstrained_groups_constrained_lag_fit 538 133950
134481 2049.3 cult_model16_constrained_lag_groups_fit 545 134016 134502
2129.1 Chisq diff Df diff
cult_model16_unconstrained_groups_constrained_lag_fit
cult_model16_constrained_lag_groups_fit 38.052 7 Pr(>Chisq)
cult_model16_unconstrained_groups_constrained_lag_fit
cult_model16_constrained_lag_groups_fit 2.962e-06 *** — Signif. codes: 0
‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
inc_diff_model16_constrained_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1* Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ c(a2, a2)*winc_diff_2 + c(b2, b2)*wFeduc_a_2
winc_diff_4 ~ c(a3, a3)*winc_diff_3 + c(b3, b3)*wFeduc_a_3
winc_diff_5 ~ c(a4, a4)*winc_diff_4 + c(b4, b4)*wFeduc_a_4
winc_diff_6 ~ c(a5, a5)*winc_diff_5 + c(b5, b5)*wFeduc_a_5
winc_diff_7 ~ c(a6, a6)*winc_diff_6 + c(b6, b6)*wFeduc_a_6
winc_diff_8 ~ c(a7, a7)*winc_diff_7 + c(b7, b7)*wFeduc_a_7
winc_diff_9 ~ c(a8, a8)*winc_diff_8 + c(b8, b8)*wFeduc_a_8
winc_diff_10 ~ c(a9, a9)*winc_diff_9 + c(b9, b9)*wFeduc_a_9
winc_diff_11 ~ c(a10, a10)*winc_diff_10 + c(b10, b10)*wFeduc_a_10
wFeduc_a_3 ~ c(c2, c2)*winc_diff_2 + c(d2, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c3, c3)*winc_diff_3 + c(d3, d3)*wFeduc_a_3
wFeduc_a_5 ~ c(c4, c4)*winc_diff_4 + c(d4, d4)*wFeduc_a_4
wFeduc_a_6 ~ c(c5, c5)*winc_diff_5 + c(d5, d5)*wFeduc_a_5
wFeduc_a_7 ~ c(c6, c6)*winc_diff_6 + c(d6, d6)*wFeduc_a_6
wFeduc_a_8 ~ c(c7, c7)*winc_diff_7 + c(d7, d7)*wFeduc_a_7
wFeduc_a_9 ~ c(c8, c8)*winc_diff_8 + c(d8, d8)*wFeduc_a_8
wFeduc_a_10 ~ c(c9, c9)*winc_diff_9 + c(d9, d9)*wFeduc_a_9
wFeduc_a_11 ~ c(c10, c10)*winc_diff_10 + c(d10, d10)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ c(cov1, cov2)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ c(vy1, vy2)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#filename
filename <-
file.path(dir,
"inc_diff_model16_constrained_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model16_constrained_groups_fit <-
lavaan(
inc_diff_model16_constrained_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(inc_diff_model16_constrained_groups_fit,
file = filename)
} else {load(file = filename)
}
inc_diff_model16_unconstrained_groups_constrained_lag <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ c(a1, a2)*winc_diff_2 + c(b1, b2)*wFeduc_a_2
winc_diff_4 ~ c(a1, a2)*winc_diff_3 + c(b1, b2)*wFeduc_a_3
winc_diff_5 ~ c(a1, a2)*winc_diff_4 + c(b1, b2)*wFeduc_a_4
winc_diff_6 ~ c(a1, a2)*winc_diff_5 + c(b1, b2)*wFeduc_a_5
winc_diff_7 ~ c(a1, a2)*winc_diff_6 + c(b1, b2)*wFeduc_a_6
winc_diff_8 ~ c(a1, a2)*winc_diff_7 + c(b1, b2)*wFeduc_a_7
winc_diff_9 ~ c(a1, a2)*winc_diff_8 + c(b1, b2)*wFeduc_a_8
winc_diff_10 ~ c(a1, a2)*winc_diff_9 + c(b1, b2)*wFeduc_a_9
winc_diff_11 ~ c(a1, a2)*winc_diff_10 + c(b1, b2)*wFeduc_a_10
wFeduc_a_3 ~ c(c1, c2)*winc_diff_2 + c(d1, d2)*wFeduc_a_2
wFeduc_a_4 ~ c(c1, c2)*winc_diff_3 + c(d1, d2)*wFeduc_a_3
wFeduc_a_5 ~ c(c1, c2)*winc_diff_4 + c(d1, d2)*wFeduc_a_4
wFeduc_a_6 ~ c(c1, c2)*winc_diff_5 + c(d1, d2)*wFeduc_a_5
wFeduc_a_7 ~ c(c1, c2)*winc_diff_6 + c(d1, d2)*wFeduc_a_6
wFeduc_a_8 ~ c(c1, c2)*winc_diff_7 + c(d1, d2)*wFeduc_a_7
wFeduc_a_9 ~ c(c1, c2)*winc_diff_8 + c(d1, d2)*wFeduc_a_8
wFeduc_a_10 ~ c(c1, c2)*winc_diff_9 + c(d1, d2)*wFeduc_a_9
wFeduc_a_11 ~ c(c1, c2)*winc_diff_10 + c(d1, d2)*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ c(cov1, cov2)*wFeduc_a_3
winc_diff_4 ~~ c(cov1, cov2)*wFeduc_a_4
winc_diff_5 ~~ c(cov1, cov2)*wFeduc_a_5
winc_diff_6 ~~ c(cov1, cov2)*wFeduc_a_6
winc_diff_7 ~~ c(cov1, cov2)*wFeduc_a_7
winc_diff_8 ~~ c(cov1, cov2)*wFeduc_a_8
winc_diff_9 ~~ c(cov1, cov2)*wFeduc_a_9
winc_diff_10 ~~ c(cov1, cov2)*wFeduc_a_10
winc_diff_11 ~~ c(cov1, cov2)*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ c(vy1, vy2)*winc_diff_3
wFeduc_a_3 ~~ c(vx1, vx2)*wFeduc_a_3
winc_diff_4 ~~ c(vy1, vy2)*winc_diff_4
wFeduc_a_4 ~~ c(vx1, vx2)*wFeduc_a_4
winc_diff_5 ~~ c(vy1, vy2)*winc_diff_5
wFeduc_a_5 ~~ c(vx1, vx2)*wFeduc_a_5
winc_diff_6 ~~ c(vy1, vy2)*winc_diff_6
wFeduc_a_6 ~~ c(vx1, vx2)*wFeduc_a_6
winc_diff_7 ~~ c(vy1, vy2)*winc_diff_7
wFeduc_a_7 ~~ c(vx1, vx2)*wFeduc_a_7
winc_diff_8 ~~ c(vy1, vy2)*winc_diff_8
wFeduc_a_8 ~~ c(vx1, vx2)*wFeduc_a_8
winc_diff_9 ~~ c(vy1, vy2)*winc_diff_9
wFeduc_a_9 ~~ c(vx1, vx2)*wFeduc_a_9
winc_diff_10 ~~ c(vy1, vy2)*winc_diff_10
wFeduc_a_10 ~~ c(vx1, vx2)*wFeduc_a_10
winc_diff_11 ~~ c(vy1, vy2)*winc_diff_11
wFeduc_a_11 ~~ c(vx1, vx2)*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#filename
filename <-
file.path(dir,
"inc_diff_model16_unconstrained_groups_constrained_lag_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model16_unconstrained_groups_constrained_lag_fit <-
lavaan(
inc_diff_model16_unconstrained_groups_constrained_lag,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(inc_diff_model16_unconstrained_groups_constrained_lag_fit,
file = filename)
} else
(load(file = filename)
)
inc_diff_model16_constrained_lag_groups <- '
################
# BETWEEN PART #
###############
# Create between components (random intercepts)
RIx =~ 1*Feduc_a_2 + 1*Feduc_a_3 + 1*Feduc_a_4 + 1*Feduc_a_5 + 1*Feduc_a_6 + 1*Feduc_a_7 + 1*Feduc_a_8 + 1*Feduc_a_9 + 1*Feduc_a_10 + 1*Feduc_a_11
RIy =~ 1*inc_diff_2 + 1*inc_diff_3 + 1*inc_diff_4 + 1*inc_diff_5 + 1*inc_diff_6 + 1*inc_diff_7 + 1*inc_diff_8 + 1*inc_diff_9 + 1*inc_diff_10 + 1*inc_diff_11
# Estimate the variance and covariance of the random intercepts.
RIx ~~ RIx
RIy ~~ RIy
RIx ~~ RIy
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
# Set the residual variances of all FX variables to 0.
Feduc_a_2 ~~ 0*Feduc_a_2
Feduc_a_3 ~~ 0*Feduc_a_3
Feduc_a_4 ~~ 0*Feduc_a_4
Feduc_a_5 ~~ 0*Feduc_a_5
Feduc_a_6 ~~ 0*Feduc_a_6
Feduc_a_7 ~~ 0*Feduc_a_7
Feduc_a_8 ~~ 0*Feduc_a_8
Feduc_a_9 ~~ 0*Feduc_a_9
Feduc_a_10 ~~ 0*Feduc_a_10
Feduc_a_11 ~~ 0*Feduc_a_11
###############
# WITHIN PART #
###############
# Create within-person centered variables.
wFeduc_a_2 =~ 1*Feduc_a_2
wFeduc_a_3 =~ 1*Feduc_a_3
wFeduc_a_4 =~ 1*Feduc_a_4
wFeduc_a_5 =~ 1*Feduc_a_5
wFeduc_a_6 =~ 1*Feduc_a_6
wFeduc_a_7 =~ 1*Feduc_a_7
wFeduc_a_8 =~ 1*Feduc_a_8
wFeduc_a_9 =~ 1*Feduc_a_9
wFeduc_a_10 =~ 1*Feduc_a_10
wFeduc_a_11 =~ 1*Feduc_a_11
winc_diff_2 =~ 1*inc_diff_2
winc_diff_3 =~ 1*inc_diff_3
winc_diff_4 =~ 1*inc_diff_4
winc_diff_5 =~ 1*inc_diff_5
winc_diff_6 =~ 1*inc_diff_6
winc_diff_7 =~ 1*inc_diff_7
winc_diff_8 =~ 1*inc_diff_8
winc_diff_9 =~ 1*inc_diff_9
winc_diff_10 =~ 1*inc_diff_10
winc_diff_11 =~ 1*inc_diff_11
# Estimate the lagged effects (constrained)
winc_diff_3 ~ a*winc_diff_2 + b*wFeduc_a_2
winc_diff_4 ~ a*winc_diff_3 + b*wFeduc_a_3
winc_diff_5 ~ a*winc_diff_4 + b*wFeduc_a_4
winc_diff_6 ~ a*winc_diff_5 + b*wFeduc_a_5
winc_diff_7 ~ a*winc_diff_6 + b*wFeduc_a_6
winc_diff_8 ~ a*winc_diff_7 + b*wFeduc_a_7
winc_diff_9 ~ a*winc_diff_8 + b*wFeduc_a_8
winc_diff_10 ~ a*winc_diff_9 + b*wFeduc_a_9
winc_diff_11 ~ a*winc_diff_10 + b*wFeduc_a_10
wFeduc_a_3 ~ c*winc_diff_2 + d*wFeduc_a_2
wFeduc_a_4 ~ c*winc_diff_3 + d*wFeduc_a_3
wFeduc_a_5 ~ c*winc_diff_4 + d*wFeduc_a_4
wFeduc_a_6 ~ c*winc_diff_5 + d*wFeduc_a_5
wFeduc_a_7 ~ c*winc_diff_6 + d*wFeduc_a_6
wFeduc_a_8 ~ c*winc_diff_7 + d*wFeduc_a_7
wFeduc_a_9 ~ c*winc_diff_8 + d*wFeduc_a_8
wFeduc_a_10 ~ c*winc_diff_9 + d*wFeduc_a_9
wFeduc_a_11 ~ c*winc_diff_10 + d*wFeduc_a_10
# Estimate the covariance at the first wave.
winc_diff_2 ~~ wFeduc_a_2 # Covariance
# Estimate the covariances between the residuals
winc_diff_3 ~~ cov*wFeduc_a_3
winc_diff_4 ~~ cov*wFeduc_a_4
winc_diff_5 ~~ cov*wFeduc_a_5
winc_diff_6 ~~ cov*wFeduc_a_6
winc_diff_7 ~~ cov*wFeduc_a_7
winc_diff_8 ~~ cov*wFeduc_a_8
winc_diff_9 ~~ cov*wFeduc_a_9
winc_diff_10 ~~ cov*wFeduc_a_10
winc_diff_11 ~~ cov*wFeduc_a_11
# Estimate the variance
winc_diff_2 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
# Estimate the residual variance
winc_diff_3 ~~ vy*winc_diff_3
wFeduc_a_3 ~~ vx*wFeduc_a_3
winc_diff_4 ~~ vy*winc_diff_4
wFeduc_a_4 ~~ vx*wFeduc_a_4
winc_diff_5 ~~ vy*winc_diff_5
wFeduc_a_5 ~~ vx*wFeduc_a_5
winc_diff_6 ~~ vy*winc_diff_6
wFeduc_a_6 ~~ vx*wFeduc_a_6
winc_diff_7 ~~ vy*winc_diff_7
wFeduc_a_7 ~~ vx*wFeduc_a_7
winc_diff_8 ~~ vy*winc_diff_8
wFeduc_a_8 ~~ vx*wFeduc_a_8
winc_diff_9 ~~ vy*winc_diff_9
wFeduc_a_9 ~~ vx*wFeduc_a_9
winc_diff_10 ~~ vy*winc_diff_10
wFeduc_a_10 ~~ vx*wFeduc_a_10
winc_diff_11 ~~ vy*winc_diff_11
wFeduc_a_11 ~~ vx*wFeduc_a_11
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Set correlations between the between-factors (random intercepts) and within-
# factors at wave 1 at 0.
RIx + RIy ~~ 0*wFeduc_a_2 + 0*winc_diff_2
'
#filename
filename <-
file.path(dir,
"inc_diff_model16_constrained_lag_groups_fit.Rdata")
#estimate model
if (!file.exists(filename)) {
inc_diff_model16_constrained_lag_groups_fit <-
lavaan(
inc_diff_model16_constrained_lag_groups,
data = MyData,
estimator = 'MLR',
missing = 'ML',
meanstructure = T,
int.ov.free = T,
group = "length_2"
)
#save model
save(inc_diff_model16_constrained_lag_groups_fit,
file = filename)
} else {load(file = filename)
}
save.image(file = "results/riclpm/24-08-21_lavaan-moderation-results.Rdata")
Copyright © 2024 Jeroense Thijmen