Set Working Directory, Load in Data, and Load Library for Functions
setwd("H:/Legacy/Data to Analyze")
dat <- read.csv("Legacy Survey Data 3 Waves.csv")
library(lavaan)
## This is lavaan 0.6-8
## lavaan is FREE software! Please report any bugs.
library(semTools)
##
## ###############################################################################
## This is semTools 0.5-4
## All users of R (or SEM) are invited to submit functions or ideas for functions.
## ###############################################################################
Reverse Code Variables
dat$W1_regfoc2 <- 6 - dat$W1_regfoc2
dat$W2_regfoc2 <- 6 - dat$W2_regfoc2
dat$W3_regfoc2 <- 6 - dat$W3_regfoc2
dat$W1_regfoc7 <- 6 - dat$W1_regfoc7
dat$W2_regfoc7 <- 6 - dat$W2_regfoc7
dat$W3_regfoc7 <- 6 - dat$W3_regfoc7
dat$W1_regfoc8 <- 6 - dat$W1_regfoc8
dat$W2_regfoc8 <- 6 - dat$W2_regfoc8
dat$W3_regfoc8 <- 6 - dat$W3_regfoc8
LONGITUDINAL INVARIANCE - REGULATORY FOCUS
CONFIGURAL - REGULATORY FOCUS (prevention orientation) - CFI = .985, df = 39
9: Reg Focus: How true (1-9) I am anxious that I will fall short of my responsibilities and obligations.
11: Reg Focus: How true (1-9) I often think about the person I am afraid I might become in the future.
13: Reg Focus: How true (1-9) I often imagine myself experiencing bad things that I fear might happen to me.
14: Reg Focus: How true (1-9) I frequently think about how I can prevent failures in my life.
config.regfoc <- '
RF_c1 =~ W1_regfoc9 + W1_regfoc11 + W1_regfoc13 + W1_regfoc14 #prevention
RF_c2 =~ W2_regfoc9 + W2_regfoc11 + W2_regfoc13 + W2_regfoc14 #prevetion
RF_c3 =~ W3_regfoc9 + W3_regfoc11 + W3_regfoc13 + W3_regfoc14 #prevention
'
longFacNames.rf <- list(RF = c("RF_c1","RF_c2", "RF_c3"))
syntax.config.regfoc <- measEq.syntax(configural.model = config.regfoc,
data = dat,
ID.fac = "std.lv",
longFacNames = longFacNames.rf)
## Fit a model to the data either in a subsequent step (recommended):
syntax.config.regfoc <- as.character(syntax.config.regfoc)
fit.config.regfoc <- cfa(syntax.config.regfoc,
data = dat,
missing = "ML",
std.lv = TRUE)
## Warning in lav_data_full(data = data, group = group, cluster = cluster, : lavaan WARNING: some cases are empty and will be ignored:
## 16 67 78 88 98 125 143 144 154 161 167 170 172 187 212 214 235 245 253 254 256 284 317 323 325 339 396 397 399 438 439 450 463 486 504 522
summary(fit.config.regfoc, fit.measures = TRUE)
## lavaan 0.6-8 ended normally after 80 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 51
##
## Used Total
## Number of observations 486 522
## Number of missing patterns 64
##
## Model Test User Model:
##
## Test statistic 61.978
## Degrees of freedom 39
## P-value (Chi-square) 0.011
##
## Model Test Baseline Model:
##
## Test statistic 1581.695
## Degrees of freedom 66
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.985
## Tucker-Lewis Index (TLI) 0.974
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -10514.526
## Loglikelihood unrestricted model (H1) -10483.538
##
## Akaike (AIC) 21131.053
## Bayesian (BIC) 21344.549
## Sample-size adjusted Bayesian (BIC) 21182.678
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.035
## 90 Percent confidence interval - lower 0.017
## 90 Percent confidence interval - upper 0.051
## P-value RMSEA <= 0.05 0.943
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.030
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## RF_c1 =~
## W1_rgf9 (l.1_) 1.756 0.129 13.634 0.000
## W1_rg11 (l.2_) 2.260 0.138 16.386 0.000
## W1_rg13 (l.3_) 2.533 0.132 19.123 0.000
## W1_rg14 (l.4_) 0.805 0.136 5.911 0.000
## RF_c2 =~
## W2_rgf9 (l.5_) 1.786 0.135 13.204 0.000
## W2_rg11 (l.6_) 2.073 0.142 14.636 0.000
## W2_rg13 (l.7_) 2.073 0.138 14.990 0.000
## W2_rg14 (l.8_) 0.455 0.143 3.189 0.001
## RF_c3 =~
## W3_rgf9 (l.9_) 1.890 0.133 14.229 0.000
## W3_rg11 (l.10) 2.314 0.134 17.265 0.000
## W3_rg13 (l.11) 2.142 0.133 16.104 0.000
## W3_rg14 (l.12) 1.334 0.142 9.408 0.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## .W1_regfoc9 ~~
## .W2_r9 (t.5_) 1.431 0.287 4.995 0.000
## .W3_r9 (t.9_1) 1.135 0.268 4.235 0.000
## .W1_regfoc11 ~~
## .W2_11 (t.6_) 0.549 0.273 2.012 0.044
## .W3_11 (t.10_2) 0.677 0.244 2.779 0.005
## .W1_regfoc13 ~~
## .W2_13 (t.7_) -0.232 0.240 -0.970 0.332
## .W3_13 (t.11_3) 0.038 0.222 0.173 0.863
## .W1_regfoc14 ~~
## .W2_14 (t.8_) 1.636 0.358 4.572 0.000
## .W3_14 (t.12_4) 1.464 0.355 4.124 0.000
## .W2_regfoc9 ~~
## .W3_r9 (t.9_5) 0.815 0.261 3.129 0.002
## .W2_regfoc11 ~~
## .W3_11 (t.10_6) 0.611 0.252 2.426 0.015
## .W2_regfoc13 ~~
## .W3_13 (t.11_7) 0.352 0.250 1.408 0.159
## .W2_regfoc14 ~~
## .W3_14 (t.12_8) 1.802 0.353 5.111 0.000
## RF_c1 ~~
## RF_c2 (p.2_) 0.475 0.055 8.702 0.000
## RF_c3 (p.3_1) 0.508 0.052 9.680 0.000
## RF_c2 ~~
## RF_c3 (p.3_2) 0.605 0.050 12.110 0.000
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|)
## .W1_rgf9 (nu.1) 4.230 0.134 31.620 0.000
## .W1_rg11 (nu.2) 4.819 0.143 33.601 0.000
## .W1_rg13 (nu.3) 4.556 0.137 33.241 0.000
## .W1_rg14 (nu.4) 5.956 0.128 46.373 0.000
## .W2_rgf9 (nu.5) 4.255 0.134 31.639 0.000
## .W2_rg11 (nu.6) 4.752 0.139 34.151 0.000
## .W2_rg13 (nu.7) 4.673 0.136 34.450 0.000
## .W2_rg14 (nu.8) 5.959 0.129 46.231 0.000
## .W3_rgf9 (nu.9) 4.687 0.139 33.621 0.000
## .W3_rg11 (n.10) 4.878 0.144 33.800 0.000
## .W3_rg13 (n.11) 4.642 0.141 32.994 0.000
## .W3_rg14 (n.12) 5.368 0.141 38.042 0.000
## RF_c1 (al.1) 0.000
## RF_c2 (al.2) 0.000
## RF_c3 (al.3) 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .W1_rgf9 (t.1_) 4.762 0.378 12.606 0.000
## .W1_rg11 (t.2_) 4.005 0.404 9.908 0.000
## .W1_rg13 (t.3_) 1.898 0.398 4.765 0.000
## .W1_rg14 (t.4_) 6.497 0.454 14.319 0.000
## .W2_rgf9 (t.5_) 4.095 0.381 10.746 0.000
## .W2_rg11 (t.6_) 3.457 0.401 8.613 0.000
## .W2_rg13 (t.7_) 3.008 0.383 7.858 0.000
## .W2_rg14 (t.8_) 6.329 0.459 13.790 0.000
## .W3_rgf9 (t.9_) 3.571 0.340 10.489 0.000
## .W3_rg11 (t.10) 2.388 0.333 7.170 0.000
## .W3_rg13 (t.11) 2.684 0.326 8.235 0.000
## .W3_rg14 (t.12) 5.397 0.438 12.337 0.000
## RF_c1 (p.1_) 1.000
## RF_c2 (p.2_) 1.000
## RF_c3 (p.3_) 1.000
Remaining invariance tests for regulatory focus
METRIC - REGULATORY FOCUS - CFI = .970, df = 45
## METRIC model: test equivalence of loadings
syntax.metric.rf <- measEq.syntax(configural.model = config.regfoc,
data = dat,
ID.fac = "std.lv",
longFacNames = longFacNames.rf,
long.equal = c("thresholds","loadings"))
## Fit a model to the data:
mod.metric.rf <- as.character(syntax.metric.rf)
fit.metric.rf <- cfa(mod.metric.rf,
data = dat,
missing = "ML")
## Warning in lav_data_full(data = data, group = group, cluster = cluster, : lavaan WARNING: some cases are empty and will be ignored:
## 16 67 78 88 98 125 143 144 154 161 167 170 172 187 212 214 235 245 253 254 256 284 317 323 325 339 396 397 399 438 439 450 463 486 504 522
summary(fit.metric.rf, fit.measures = TRUE)
## lavaan 0.6-8 ended normally after 77 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 53
## Number of equality constraints 8
##
## Used Total
## Number of observations 486 522
## Number of missing patterns 64
##
## Model Test User Model:
##
## Test statistic 90.286
## Degrees of freedom 45
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 1581.695
## Degrees of freedom 66
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.970
## Tucker-Lewis Index (TLI) 0.956
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -10528.680
## Loglikelihood unrestricted model (H1) -10483.538
##
## Akaike (AIC) 21147.361
## Bayesian (BIC) 21335.740
## Sample-size adjusted Bayesian (BIC) 21192.913
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.046
## 90 Percent confidence interval - lower 0.032
## 90 Percent confidence interval - upper 0.059
## P-value RMSEA <= 0.05 0.691
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.054
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## RF_c1 =~
## W1_rgf9 (l.1_) 1.884 0.107 17.684 0.000
## W1_rg11 (l.2_) 2.341 0.116 20.103 0.000
## W1_rg13 (l.3_) 2.341 0.116 20.227 0.000
## W1_rg14 (l.4_) 0.940 0.100 9.371 0.000
## RF_c2 =~
## W2_rgf9 (l.1_) 1.884 0.107 17.684 0.000
## W2_rg11 (l.2_) 2.341 0.116 20.103 0.000
## W2_rg13 (l.3_) 2.341 0.116 20.227 0.000
## W2_rg14 (l.4_) 0.940 0.100 9.371 0.000
## RF_c3 =~
## W3_rgf9 (l.1_) 1.884 0.107 17.684 0.000
## W3_rg11 (l.2_) 2.341 0.116 20.103 0.000
## W3_rg13 (l.3_) 2.341 0.116 20.227 0.000
## W3_rg14 (l.4_) 0.940 0.100 9.371 0.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## .W1_regfoc9 ~~
## .W2_r9 (t.5_) 1.388 0.288 4.811 0.000
## .W3_r9 (t.9_1) 1.114 0.269 4.136 0.000
## .W1_regfoc11 ~~
## .W2_11 (t.6_) 0.442 0.268 1.650 0.099
## .W3_11 (t.10_2) 0.600 0.244 2.460 0.014
## .W1_regfoc13 ~~
## .W2_13 (t.7_) -0.122 0.238 -0.511 0.609
## .W3_13 (t.11_3) 0.090 0.225 0.401 0.688
## .W1_regfoc14 ~~
## .W2_14 (t.8_) 1.656 0.364 4.553 0.000
## .W3_14 (t.12_4) 1.434 0.362 3.966 0.000
## .W2_regfoc9 ~~
## .W3_r9 (t.9_5) 0.836 0.262 3.190 0.001
## .W2_regfoc11 ~~
## .W3_11 (t.10_6) 0.593 0.252 2.349 0.019
## .W2_regfoc13 ~~
## .W3_13 (t.11_7) 0.332 0.253 1.311 0.190
## .W2_regfoc14 ~~
## .W3_14 (t.12_8) 1.649 0.357 4.614 0.000
## RF_c1 ~~
## RF_c2 (p.2_) 0.429 0.054 7.877 0.000
## RF_c3 (p.3_1) 0.503 0.059 8.508 0.000
## RF_c2 ~~
## RF_c3 (p.3_2) 0.530 0.072 7.332 0.000
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|)
## .W1_rgf9 (nu.1) 4.230 0.137 30.980 0.000
## .W1_rg11 (nu.2) 4.817 0.144 33.443 0.000
## .W1_rg13 (nu.3) 4.557 0.134 34.070 0.000
## .W1_rg14 (nu.4) 5.955 0.130 45.790 0.000
## .W2_rgf9 (nu.5) 4.257 0.133 32.096 0.000
## .W2_rg11 (nu.6) 4.752 0.138 34.321 0.000
## .W2_rg13 (nu.7) 4.673 0.136 34.353 0.000
## .W2_rg14 (nu.8) 5.963 0.133 44.678 0.000
## .W3_rgf9 (nu.9) 4.684 0.138 33.931 0.000
## .W3_rg11 (n.10) 4.875 0.144 33.807 0.000
## .W3_rg13 (n.11) 4.640 0.145 31.950 0.000
## .W3_rg14 (n.12) 5.362 0.135 39.691 0.000
## RF_c1 (al.1) 0.000
## RF_c2 (al.2) 0.000
## RF_c3 (al.3) 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .W1_rgf9 (t.1_) 4.635 0.374 12.400 0.000
## .W1_rg11 (t.2_) 3.721 0.372 10.005 0.000
## .W1_rg13 (t.3_) 2.430 0.332 7.323 0.000
## .W1_rg14 (t.4_) 6.453 0.454 14.224 0.000
## .W2_rgf9 (t.5_) 4.266 0.369 11.572 0.000
## .W2_rg11 (t.6_) 3.346 0.364 9.202 0.000
## .W2_rg13 (t.7_) 3.022 0.349 8.667 0.000
## .W2_rg14 (t.8_) 6.328 0.467 13.544 0.000
## .W3_rgf9 (t.9_) 3.597 0.335 10.745 0.000
## .W3_rg11 (t.10) 2.464 0.326 7.569 0.000
## .W3_rg13 (t.11) 2.526 0.321 7.873 0.000
## .W3_rg14 (t.12) 5.651 0.450 12.563 0.000
## RF_c1 (p.1_) 1.000
## RF_c2 (p.2_) 0.791 0.093 8.551 0.000
## RF_c3 (p.3_) 0.959 0.108 8.844 0.000
SCALAR - REGULATORY FOCUS - CFI = .953, df = 51
## SCALAR model: test equivalence of intercepts, given equal loadings
syntax.scalar.rf <- measEq.syntax(configural.model = config.regfoc,
data = dat,
ID.fac = "std.lv",
longFacNames = longFacNames.rf,
long.equal = c("thresholds","loadings","intercepts"))
## Fit a model to the data:
mod.scalar.rf <- as.character(syntax.scalar.rf)
fit.scalar.rf <- cfa(mod.scalar.rf,
data = dat,
missing = "ML")
## Warning in lav_data_full(data = data, group = group, cluster = cluster, : lavaan WARNING: some cases are empty and will be ignored:
## 16 67 78 88 98 125 143 144 154 161 167 170 172 187 212 214 235 245 253 254 256 284 317 323 325 339 396 397 399 438 439 450 463 486 504 522
summary(fit.scalar.rf, fit.measures = TRUE)
## lavaan 0.6-8 ended normally after 76 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 55
## Number of equality constraints 16
##
## Used Total
## Number of observations 486 522
## Number of missing patterns 64
##
## Model Test User Model:
##
## Test statistic 122.598
## Degrees of freedom 51
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 1581.695
## Degrees of freedom 66
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.953
## Tucker-Lewis Index (TLI) 0.939
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -10544.837
## Loglikelihood unrestricted model (H1) -10483.538
##
## Akaike (AIC) 21167.673
## Bayesian (BIC) 21330.935
## Sample-size adjusted Bayesian (BIC) 21207.151
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.054
## 90 Percent confidence interval - lower 0.042
## 90 Percent confidence interval - upper 0.066
## P-value RMSEA <= 0.05 0.291
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.058
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## RF_c1 =~
## W1_rgf9 (l.1_) 1.887 0.107 17.650 0.000
## W1_rg11 (l.2_) 2.343 0.117 20.090 0.000
## W1_rg13 (l.3_) 2.344 0.116 20.206 0.000
## W1_rg14 (l.4_) 0.923 0.101 9.160 0.000
## RF_c2 =~
## W2_rgf9 (l.1_) 1.887 0.107 17.650 0.000
## W2_rg11 (l.2_) 2.343 0.117 20.090 0.000
## W2_rg13 (l.3_) 2.344 0.116 20.206 0.000
## W2_rg14 (l.4_) 0.923 0.101 9.160 0.000
## RF_c3 =~
## W3_rgf9 (l.1_) 1.887 0.107 17.650 0.000
## W3_rg11 (l.2_) 2.343 0.117 20.090 0.000
## W3_rg13 (l.3_) 2.344 0.116 20.206 0.000
## W3_rg14 (l.4_) 0.923 0.101 9.160 0.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## .W1_regfoc9 ~~
## .W2_r9 (t.5_) 1.394 0.291 4.799 0.000
## .W3_r9 (t.9_1) 1.092 0.272 4.009 0.000
## .W1_regfoc11 ~~
## .W2_11 (t.6_) 0.430 0.268 1.606 0.108
## .W3_11 (t.10_2) 0.594 0.244 2.428 0.015
## .W1_regfoc13 ~~
## .W2_13 (t.7_) -0.122 0.238 -0.513 0.608
## .W3_13 (t.11_3) 0.103 0.225 0.458 0.647
## .W1_regfoc14 ~~
## .W2_14 (t.8_) 1.681 0.368 4.563 0.000
## .W3_14 (t.12_4) 1.265 0.368 3.439 0.001
## .W2_regfoc9 ~~
## .W3_r9 (t.9_5) 0.837 0.266 3.141 0.002
## .W2_regfoc11 ~~
## .W3_11 (t.10_6) 0.590 0.253 2.333 0.020
## .W2_regfoc13 ~~
## .W3_13 (t.11_7) 0.332 0.254 1.308 0.191
## .W2_regfoc14 ~~
## .W3_14 (t.12_8) 1.550 0.364 4.259 0.000
## RF_c1 ~~
## RF_c2 (p.2_) 0.429 0.054 7.885 0.000
## RF_c3 (p.3_1) 0.502 0.059 8.505 0.000
## RF_c2 ~~
## RF_c3 (p.3_2) 0.530 0.072 7.345 0.000
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|)
## .W1_rgf9 (nu.1) 4.361 0.120 36.258 0.000
## .W1_rg11 (nu.2) 4.765 0.132 36.001 0.000
## .W1_rg13 (nu.3) 4.572 0.126 36.178 0.000
## .W1_rg14 (nu.4) 5.747 0.100 57.634 0.000
## .W2_rgf9 (nu.1) 4.361 0.120 36.258 0.000
## .W2_rg11 (nu.2) 4.765 0.132 36.001 0.000
## .W2_rg13 (nu.3) 4.572 0.126 36.178 0.000
## .W2_rg14 (nu.4) 5.747 0.100 57.634 0.000
## .W3_rgf9 (nu.1) 4.361 0.120 36.258 0.000
## .W3_rg11 (nu.2) 4.765 0.132 36.001 0.000
## .W3_rg13 (nu.3) 4.572 0.126 36.178 0.000
## .W3_rg14 (nu.4) 5.747 0.100 57.634 0.000
## RF_c1 (al.1) 0.000
## RF_c2 (al.2) 0.014 0.058 0.233 0.816
## RF_c3 (al.3) 0.052 0.059 0.869 0.385
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .W1_rgf9 (t.1_) 4.647 0.375 12.377 0.000
## .W1_rg11 (t.2_) 3.724 0.373 9.993 0.000
## .W1_rg13 (t.3_) 2.424 0.333 7.290 0.000
## .W1_rg14 (t.4_) 6.503 0.458 14.187 0.000
## .W2_rgf9 (t.5_) 4.281 0.370 11.555 0.000
## .W2_rg11 (t.6_) 3.347 0.364 9.186 0.000
## .W2_rg13 (t.7_) 3.029 0.350 8.656 0.000
## .W2_rg14 (t.8_) 6.366 0.471 13.515 0.000
## .W3_rgf9 (t.9_) 3.683 0.345 10.665 0.000
## .W3_rg11 (t.10) 2.472 0.328 7.537 0.000
## .W3_rg13 (t.11) 2.528 0.323 7.828 0.000
## .W3_rg14 (t.12) 5.828 0.469 12.420 0.000
## RF_c1 (p.1_) 1.000
## RF_c2 (p.2_) 0.790 0.092 8.550 0.000
## RF_c3 (p.3_) 0.954 0.108 8.831 0.000