Create lavaan model objects
EU integration
EU_model1_unconstrained <- '
################
# 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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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 ~ weu_1 + wFeduc_a_1
weu_3 ~ weu_2 + wFeduc_a_2
weu_4 ~ weu_3 + wFeduc_a_3
weu_5 ~ weu_4 + wFeduc_a_4
weu_6 ~ weu_5 + wFeduc_a_5
weu_7 ~ weu_6 + wFeduc_a_6
weu_8 ~ weu_7 + wFeduc_a_7
weu_9 ~ weu_8 + wFeduc_a_8
weu_10 ~ weu_9 + wFeduc_a_9
weu_11 ~ weu_10 + wFeduc_a_10
wFeduc_a_2 ~ weu_1 + wFeduc_a_1
wFeduc_a_3 ~ weu_2 + wFeduc_a_2
wFeduc_a_4 ~ weu_3 + wFeduc_a_3
wFeduc_a_5 ~ weu_4 + wFeduc_a_4
wFeduc_a_6 ~ weu_5 + wFeduc_a_5
wFeduc_a_7 ~ weu_6 + wFeduc_a_6
wFeduc_a_8 ~ weu_7 + wFeduc_a_7
wFeduc_a_9 ~ weu_8 + wFeduc_a_8
wFeduc_a_10 ~ weu_9 + wFeduc_a_9
wFeduc_a_11 ~ weu_10 + wFeduc_a_10
# Estimate the covariance at the first wave.
weu_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ wFeduc_a_2
weu_3 ~~ wFeduc_a_3
weu_4 ~~ wFeduc_a_4
weu_5 ~~ wFeduc_a_5
weu_6 ~~ wFeduc_a_6
weu_7 ~~ wFeduc_a_7
weu_8 ~~ wFeduc_a_8
weu_9 ~~ wFeduc_a_9
weu_10 ~~ wFeduc_a_10
weu_11 ~~ wFeduc_a_11
# Estimate the variance
weu_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ weu_2
wFeduc_a_2 ~~ wFeduc_a_2
weu_3 ~~ weu_3
wFeduc_a_3 ~~ wFeduc_a_3
weu_4 ~~ weu_4
wFeduc_a_4 ~~ wFeduc_a_4
weu_5 ~~ vy*weu_5
wFeduc_a_5 ~~ wFeduc_a_5
weu_6 ~~ weu_6
wFeduc_a_6 ~~ wFeduc_a_6
weu_7 ~~ weu_7
wFeduc_a_7 ~~ wFeduc_a_7
weu_8 ~~ weu_8
wFeduc_a_8 ~~ wFeduc_a_8
weu_9 ~~ weu_9
wFeduc_a_9 ~~ wFeduc_a_9
weu_10 ~~ weu_10
wFeduc_a_10 ~~ wFeduc_a_10
weu_11 ~~ weu_11
wFeduc_a_11 ~~ 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
'
EU_model1_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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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 ~ a*weu_1 + b*wFeduc_a_1
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_2 ~ c*weu_1 + d*wFeduc_a_1
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_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ cov*wFeduc_a_2
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_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ vy*weu_2
wFeduc_a_2 ~~ vx*wFeduc_a_2
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_1 + 0*weu_1
'
EU_model1_constrained_lag_means <- '
################
# 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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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 ~ a*weu_1 + b*wFeduc_a_1
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_2 ~ c*weu_1 + d*wFeduc_a_1
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_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
weu_2 ~~ cov*wFeduc_a_2
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_1 ~~ weu_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
weu_2 ~~ vy*weu_2
wFeduc_a_2 ~~ vx*wFeduc_a_2
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_1 + 0*weu_1
#constrain grand means over time
eu_1 + eu_2 + eu_3 + eu_4 + eu_5 + eu_6 + eu_7 + eu_8 + eu_9 + eu_10 + eu_11 ~ my*1
Feduc_a_1 + Feduc_a_2 + Feduc_a_3 + Feduc_a_4 + Feduc_a_5 + Feduc_a_6 + Feduc_a_7 + Feduc_a_8 + Feduc_a_9 + Feduc_a_10 + Feduc_a_11 ~ mx*1
'
#save model specifications in list
eu_lavaan_models <- list(EU_model1_unconstrained,
EU_model1_constrained_lag,
EU_model1_constrained_lag_means
)
Cultural Inclusion
cult_model1_unconstrained <- '
################
# 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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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
wcult_2 ~ wcult_1 + wFeduc_a_1
wcult_3 ~ wcult_2 + wFeduc_a_2
wcult_4 ~ wcult_3 + wFeduc_a_3
wcult_5 ~ wcult_4 + wFeduc_a_4
wcult_6 ~ wcult_5 + wFeduc_a_5
wcult_7 ~ wcult_6 + wFeduc_a_6
wcult_8 ~ wcult_7 + wFeduc_a_7
wcult_9 ~ wcult_8 + wFeduc_a_8
wcult_10 ~ wcult_9 + wFeduc_a_9
wcult_11 ~ wcult_10 + wFeduc_a_10
wFeduc_a_2 ~ wcult_1 + wFeduc_a_1
wFeduc_a_3 ~ wcult_2 + wFeduc_a_2
wFeduc_a_4 ~ wcult_3 + wFeduc_a_3
wFeduc_a_5 ~ wcult_4 + wFeduc_a_4
wFeduc_a_6 ~ wcult_5 + wFeduc_a_5
wFeduc_a_7 ~ wcult_6 + wFeduc_a_6
wFeduc_a_8 ~ wcult_7 + wFeduc_a_7
wFeduc_a_9 ~ wcult_8 + wFeduc_a_8
wFeduc_a_10 ~ wcult_9 + wFeduc_a_9
wFeduc_a_11 ~ wcult_10 + wFeduc_a_10
# Estimate the covariance at the first wave.
wcult_1 ~~ wFeduc_a_1 # Covariance
# Estimate the covariances between the residuals
wcult_2 ~~ wFeduc_a_2
wcult_3 ~~ wFeduc_a_3
wcult_4 ~~ wFeduc_a_4
wcult_5 ~~ wFeduc_a_5
wcult_6 ~~ wFeduc_a_6
wcult_7 ~~ wFeduc_a_7
wcult_8 ~~ wFeduc_a_8
wcult_9 ~~ wFeduc_a_9
wcult_10 ~~ wFeduc_a_10
wcult_11 ~~ wFeduc_a_11
# Estimate the variance
wcult_1 ~~ wcult_1
wFeduc_a_1 ~~ wFeduc_a_1
# Estimate the residual variance
wcult_2 ~~ wcult_2
wFeduc_a_2 ~~ wFeduc_a_2
wcult_3 ~~ wcult_3
wFeduc_a_3 ~~ wFeduc_a_3
wcult_4 ~~ wcult_4
wFeduc_a_4 ~~ wFeduc_a_4
wcult_5 ~~ vy*wcult_5
wFeduc_a_5 ~~ wFeduc_a_5
wcult_6 ~~ wcult_6
wFeduc_a_6 ~~ wFeduc_a_6
wcult_7 ~~ wcult_7
wFeduc_a_7 ~~ wFeduc_a_7
wcult_8 ~~ wcult_8
wFeduc_a_8 ~~ wFeduc_a_8
wcult_9 ~~ wcult_9
wFeduc_a_9 ~~ wFeduc_a_9
wcult_10 ~~ wcult_10
wFeduc_a_10 ~~ wFeduc_a_10
wcult_11 ~~ wcult_11
wFeduc_a_11 ~~ 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
'
cult_model1_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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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 ~ a*wcult_1 + b*wFeduc_a_1
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_2 ~ c*wcult_1 + d*wFeduc_a_1
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_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
'
cult_model1_constrained_lag_means <- '
################
# 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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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 ~ a*wcult_1 + b*wFeduc_a_1
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_2 ~ c*wcult_1 + d*wFeduc_a_1
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_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
#constrain grand means over time
cult_1 + cult_2 + cult_3 + cult_4 + cult_5 + cult_6 + cult_7 + cult_8 + cult_9 + cult_10 + cult_11 ~ my*1
Feduc_a_1 + Feduc_a_2 + Feduc_a_3 + Feduc_a_4 + Feduc_a_5 + Feduc_a_6 + Feduc_a_7 + Feduc_a_8 + Feduc_a_9 + Feduc_a_10 + Feduc_a_11 ~ mx*1
'
#save model specifications in list
cult_lavaan_models <- list(cult_model1_unconstrained,
cult_model1_constrained_lag,
cult_model1_constrained_lag_means
)
Income Differences
inc_diff_model1_unconstrained <- '
################
# 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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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 ~ winc_diff_1 + wFeduc_a_1
winc_diff_3 ~ winc_diff_2 + wFeduc_a_2
winc_diff_4 ~ winc_diff_3 + wFeduc_a_3
winc_diff_5 ~ winc_diff_4 + wFeduc_a_4
winc_diff_6 ~ winc_diff_5 + wFeduc_a_5
winc_diff_7 ~ winc_diff_6 + wFeduc_a_6
winc_diff_8 ~ winc_diff_7 + wFeduc_a_7
winc_diff_9 ~ winc_diff_8 + wFeduc_a_8
winc_diff_10 ~ winc_diff_9 + wFeduc_a_9
winc_diff_11 ~ winc_diff_10 + wFeduc_a_10
wFeduc_a_2 ~ winc_diff_1 + wFeduc_a_1
wFeduc_a_3 ~ winc_diff_2 + wFeduc_a_2
wFeduc_a_4 ~ winc_diff_3 + wFeduc_a_3
wFeduc_a_5 ~ winc_diff_4 + wFeduc_a_4
wFeduc_a_6 ~ winc_diff_5 + wFeduc_a_5
wFeduc_a_7 ~ winc_diff_6 + wFeduc_a_6
wFeduc_a_8 ~ winc_diff_7 + wFeduc_a_7
wFeduc_a_9 ~ winc_diff_8 + wFeduc_a_8
wFeduc_a_10 ~ winc_diff_9 + wFeduc_a_9
wFeduc_a_11 ~ winc_diff_10 + 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 ~~ wFeduc_a_2
winc_diff_3 ~~ wFeduc_a_3
winc_diff_4 ~~ wFeduc_a_4
winc_diff_5 ~~ wFeduc_a_5
winc_diff_6 ~~ wFeduc_a_6
winc_diff_7 ~~ wFeduc_a_7
winc_diff_8 ~~ wFeduc_a_8
winc_diff_9 ~~ wFeduc_a_9
winc_diff_10 ~~ wFeduc_a_10
winc_diff_11 ~~ 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 ~~ winc_diff_2
wFeduc_a_2 ~~ wFeduc_a_2
winc_diff_3 ~~ winc_diff_3
wFeduc_a_3 ~~ wFeduc_a_3
winc_diff_4 ~~ winc_diff_4
wFeduc_a_4 ~~ wFeduc_a_4
winc_diff_5 ~~ vy*winc_diff_5
wFeduc_a_5 ~~ wFeduc_a_5
winc_diff_6 ~~ winc_diff_6
wFeduc_a_6 ~~ wFeduc_a_6
winc_diff_7 ~~ winc_diff_7
wFeduc_a_7 ~~ wFeduc_a_7
winc_diff_8 ~~ winc_diff_8
wFeduc_a_8 ~~ wFeduc_a_8
winc_diff_9 ~~ winc_diff_9
wFeduc_a_9 ~~ wFeduc_a_9
winc_diff_10 ~~ winc_diff_10
wFeduc_a_10 ~~ wFeduc_a_10
winc_diff_11 ~~ winc_diff_11
wFeduc_a_11 ~~ 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
'
inc_diff_model1_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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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 ~ a*winc_diff_1 + b*wFeduc_a_1
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_2 ~ c*winc_diff_1 + d*wFeduc_a_1
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_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
'
inc_diff_model1_constrained_lag_means <- '
################
# 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
# Set the residual variances of all FX variables to 0. I DONT UNDERSTAND THIS! no measurement error??
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
# Regression of random intercepts on z1
RIx + RIy ~ between_educ + between_age + between_origin + between_female# Constrained over time.
###############
# 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 ~ a*winc_diff_1 + b*wFeduc_a_1
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_2 ~ c*winc_diff_1 + d*wFeduc_a_1
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_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
#constrain grand means over time
inc_diff_1 + inc_diff_2 + inc_diff_3 + inc_diff_4 + inc_diff_5 + inc_diff_6 + inc_diff_7 + inc_diff_8 + inc_diff_9 + inc_diff_10 + inc_diff_11 ~ my*1
Feduc_a_1 + Feduc_a_2 + Feduc_a_3 + Feduc_a_4 + Feduc_a_5 + Feduc_a_6 + Feduc_a_7 + Feduc_a_8 + Feduc_a_9 + Feduc_a_10 + Feduc_a_11 ~ mx*1
'
#save model specifications in list
inc_diff_lavaan_models <- list(inc_diff_model1_unconstrained,
inc_diff_model1_constrained_lag,
inc_diff_model1_constrained_lag_means
)
Main analysis: estimate models (ML/ FIML)
lavaan_models_main <- list(eu_lavaan_models,
cult_lavaan_models,
inc_diff_lavaan_models)
# paralellize the estimation
numCores <- detectCores()
registerDoParallel(core = 3)
#initialize foreach loop
main_results <- foreach(a = 1:3) %:%
foreach(b = 1:3, .packages = c("tidyverse",
"lavaan")) %dopar% {
lavaan(
lavaan_models_main[[a]][[b]],
data = MyData,
missing = 'ML',
meanstructure = T,
int.ov.free = T
)
}
#stop parralellization
stopImplicitCluster()
#parallel computing
registerDoParallel(core = 3)
#store fit stats of all models
fit_list <- foreach(a=1:3) %:%
foreach(b=1:3,
.combine = rbind,
.packages = "lavaan") %dopar% {
lavInspect(main_results[[a]][[b]], what = "fit")
}
names(fit_list) <- c("EU models", "Cultural Inclusion models", "Income Difference models")
#stop parralellization
stopImplicitCluster()
Main analysis: estimate models (MLR)
# paralellize the estimation
numCores <- detectCores()
registerDoParallel(core = 3)
#initialize foreach loop
main_results_MLR <- foreach(a = 1:3) %:%
foreach(b = 1:3, .packages = c("tidyverse",
"lavaan")) %dopar% {
lavaan(
lavaan_models_main[[a]][[b]],
data = MyData,
estimator = 'MLR',
missing = "ML",
meanstructure = T,
int.ov.free = T
)
}
main_results_MLF <- foreach(a = 1:3) %:%
foreach(b = 1:3, .packages = c("tidyverse",
"lavaan")) %dopar% {
lavaan(
lavaan_models_main[[a]][[b]],
data = MyData,
estimator = 'MLF',
missing = "ML",
meanstructure = T,
int.ov.free = T
)
}
#stop parralellization
stopImplicitCluster()
#parallel computing
registerDoParallel(core = 3)
#store fit stats of all models
fit_list_MLR <- foreach(a=1:3) %:%
foreach(b=1:3,
.combine = rbind,
.packages = "lavaan") %dopar% {
lavInspect(main_results_MLR[[a]][[b]], what = "fit")
}
names(fit_list_MLR) <- c("EU models", "Cultural Inclusion models", "Income Difference models")
#stop parralellization
stopImplicitCluster()