library(psych)
library(lavaan)
## This is lavaan 0.6-15
## lavaan is FREE software! Please report any bugs.
##
## Attaching package: 'lavaan'
## The following object is masked from 'package:psych':
##
## cor2cov
library(semTools)
##
## ###############################################################################
## This is semTools 0.5-6
## All users of R (or SEM) are invited to submit functions or ideas for functions.
## ###############################################################################
##
## Attaching package: 'semTools'
## The following objects are masked from 'package:psych':
##
## reliability, skew
library(semPlot)
library(tibble)
library(haven)
#read in data
data <- read_sav('/Users/misschelsita/Documents/Spring 2023/PSY214/HW2_Data/WLS_HW2_Groups.sav')
# Descriptives: gender (1=male, 2=female)
# there are more females than males who particpated
Gender <- factor(data$sexrsp, levels = 1:2, labels = c("Male", "Female"))
summary(Gender)
## Male Female
## 2834 3318
# running Descriptives: age
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
data <- mutate(data, Age = 103-(data$byear))
psych::describe(data$age_survey)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6152 64.91 0.72 65 64.88 0 63 68 5 0.28 0.57 0.01
#average years of education
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.4
## ✔ ggplot2 3.4.2 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ ggplot2::%+%() masks psych::%+%()
## ✖ ggplot2::alpha() masks psych::alpha()
## ✖ readr::clipboard() masks semTools::clipboard()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data$educ92 <- as.numeric(data$educ92)
psych::describe(data$educ92)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 5978 13.73 2.31 12 13.34 0 12 21 9 1.03 -0.23 0.03
# Nationality on Father's side
glimpse(data$ge096fa)
## dbl+lbl [1:6152] 14, 4, 2, 14, 14, 14, 14, 14, 14, 5, 7, 14, 6, 11, ...
## @ label : chr "original nationality - father's side"
## @ format.spss: chr "F8.0"
## @ labels : Named num [1:53] -30 -5 -4 -3 -2 -1 1 2 3 4 ...
## ..- attr(*, "names")= chr [1:53] "not part of mosaq" "partial interview" "not ascertained" "refused" ...
data$ge096fa <- as.factor(data$ge096fa)
summary(data$ge096fa)
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## 528 96 41 390 476 136 107 153 5 70 68 202 4 2935 390 176
## 17 18 19 20 22 23 24 25 26 27 28 29 30 32 33 34
## 35 14 38 4 18 8 77 3 6 19 42 2 1 1 1 1
## 35 36 37 38 39 40 41 42 NA's
## 3 11 8 15 8 16 9 4 31
# Nationality on Mother's side
glimpse(data$ge095ma)
## dbl+lbl [1:6152] 4, 1, 41, 4, 14, 14, 16, 14, 4, 14, 14, NA, 14, 11, 1...
## @ label : chr "original nationality - mother's side"
## @ format.spss: chr "F8.0"
## @ labels : Named num [1:53] -30 -5 -4 -3 -2 -1 1 2 3 4 ...
## ..- attr(*, "names")= chr [1:53] "not part of mosaq" "partial interview" "not ascertained" "refused" ...
data$ge095ma <- as.factor(data$ge095ma)
summary(data$ge095ma)
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## 524 79 34 430 485 129 92 142 23 66 68 189 11 2649 440 164
## 17 18 19 20 22 23 24 25 26 27 28 30 32 33 35 36
## 39 26 51 3 43 7 60 4 6 25 33 1 1 1 1 10
## 37 38 39 40 41 42 43 44 47 NA's
## 7 47 23 23 27 9 3 1 1 175
#item means, SDs, Skewness etc...
#Factor 1
describe(data$in401rer) # mean is super low
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6140 1.92 0.68 2 1.92 0 1 5 4 0.41 0.34 0.01
describe(data$in406rer)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6141 1.84 0.68 2 1.84 0 1 5 4 0.51 0.55 0.01
#Factor 2
describe(data$in403rer)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6124 2.41 0.72 2 2.41 0 1 5 4 0.42 0.4 0.01
describe(data$in404rer)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6139 2.3 0.71 2 2.3 0 1 5 4 0.61 0.86 0.01
describe(data$in405rer)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6130 2.22 0.67 2 2.22 0 1 5 4 0.76 1.4 0.01
data$sexrsp <- as.numeric(data$sexrsp)
M_matter<- data[data$sexrsp =='1', ]
F_matter <- data[data$sexrsp =='2', ]
data$Gender <-data$sexrsp
data$Gender[data$Gender == "1"] <- "Male"
data$Gender[data$Gender == "2"] <- "Female"
table(data$Gender)
##
## Female Male
## 3318 2834
# majority females participated in the study
M_matter <- subset(data,sexrsp=="1")
F_matter <- subset(data,sexrsp=="2")
data$Gender<-data$sexrsp
data$Gender[data$Gender == "1"] <- "Male"
data$Gender[data$Gender == "2"] <- "Female"
table(data$Gender)
##
## Female Male
## 3318 2834
#running the descriptives for each item to compare the mean, sd, skew etc.
describe(F_matter)
## vars n mean sd median trimmed mad min
## idpub 1 3318 916873.93 9785.65 916791.5 916841.87 12615.44 900075
## sexrsp 2 3318 2.00 0.00 2.0 2.00 0.00 2
## byear 3 3318 38.92 0.45 39.0 38.96 0.00 37
## ia004yre 4 3318 2003.78 0.52 2004.0 2003.79 0.00 2003
## educ92 5 3233 13.38 2.03 12.0 13.01 0.00 12
## age_survey 6 3318 64.86 0.70 65.0 64.83 0.00 63
## ge095ma* 7 3225 11.69 6.74 14.0 11.46 1.48 1
## ge096fa* 8 3302 11.52 6.20 14.0 11.56 1.48 1
## in401rer 9 3308 1.87 0.69 2.0 1.82 0.00 1
## in402rer 10 3312 3.57 0.86 4.0 3.60 1.48 1
## in403rer 11 3304 2.44 0.74 2.0 2.42 1.48 1
## in404rer 12 3308 2.34 0.72 2.0 2.32 0.00 1
## in405rer 13 3301 2.25 0.67 2.0 2.23 0.00 1
## in406rer 14 3309 1.77 0.66 2.0 1.70 0.00 1
## Age 15 3318 64.08 0.45 64.0 64.04 0.00 63
## Gender* 16 3318 1.00 0.00 1.0 1.00 0.00 1
## max range skew kurtosis se
## idpub 933957 33882 0.02 -1.19 169.88
## sexrsp 2 0 NaN NaN 0.00
## byear 40 3 -0.90 3.69 0.01
## ia004yre 2005 2 -0.24 -0.09 0.01
## educ92 21 9 1.19 0.12 0.04
## age_survey 68 5 0.16 0.65 0.01
## ge095ma* 41 40 0.82 2.48 0.12
## ge096fa* 40 39 0.62 2.85 0.11
## in401rer 5 4 0.48 0.35 0.01
## in402rer 5 4 -0.37 0.02 0.01
## in403rer 5 4 0.39 0.38 0.01
## in404rer 5 4 0.58 0.74 0.01
## in405rer 5 4 0.69 1.12 0.01
## in406rer 5 4 0.54 0.51 0.01
## Age 66 3 0.90 3.69 0.01
## Gender* 1 0 NaN NaN 0.00
describe(M_matter)
## vars n mean sd median trimmed mad min max
## idpub 1 2834 916983.19 9782.44 917013 916995.83 12516.85 900021 933946
## sexrsp 2 2834 1.00 0.00 1 1.00 0.00 1 1
## byear 3 2834 38.80 0.53 39 38.86 0.00 37 40
## ia004yre 4 2834 2003.76 0.53 2004 2003.77 0.00 2003 2005
## educ92 5 2745 14.14 2.55 13 13.79 1.48 12 20
## age_survey 6 2834 64.96 0.75 65 64.93 0.00 63 68
## ge095ma* 7 2752 11.60 6.56 14 11.46 1.48 1 40
## ge096fa* 8 2819 11.34 6.00 14 11.46 1.48 1 39
## in401rer 9 2832 1.98 0.67 2 1.95 0.00 1 5
## in402rer 10 2830 3.64 0.81 4 3.66 0.00 1 5
## in403rer 11 2820 2.38 0.71 2 2.36 0.00 1 5
## in404rer 12 2831 2.24 0.69 2 2.24 0.00 1 5
## in405rer 13 2829 2.19 0.65 2 2.18 0.00 1 5
## in406rer 14 2832 1.92 0.68 2 1.88 0.00 1 5
## Age 15 2834 64.20 0.53 64 64.14 0.00 63 66
## Gender* 16 2834 1.00 0.00 1 1.00 0.00 1 1
## range skew kurtosis se
## idpub 33925 -0.01 -1.20 183.76
## sexrsp 0 NaN NaN 0.00
## byear 3 -1.06 2.04 0.01
## ia004yre 2 -0.19 -0.24 0.01
## educ92 8 0.79 -0.74 0.05
## age_survey 5 0.36 0.40 0.01
## ge095ma* 39 0.73 2.42 0.12
## ge096fa* 38 0.34 1.90 0.11
## in401rer 4 0.35 0.38 0.01
## in402rer 4 -0.48 0.26 0.02
## in403rer 4 0.46 0.41 0.01
## in404rer 4 0.63 1.01 0.01
## in405rer 4 0.85 1.78 0.01
## in406rer 4 0.48 0.62 0.01
## Age 3 1.06 2.04 0.01
## Gender* 0 NaN NaN 0.00
# females and males
# correlation matrix
mattering <- c("in401rer", "in406rer", "in403rer", "in404rer", "in405rer")
Femalematteringdata <-F_matter[mattering]
Malematteringdata <-M_matter[mattering]
#printing correlation matrix to be able to explore what variables are correlated with each other
#Females
corMatf <- cor(Femalematteringdata, use ="complete.obs", method = "pearson")
colnames(corMatf) <- c("Rely", "Count", "Ignore", "Awareness", "Presence")
rownames(corMatf) <- c("Rely", "Count", "Ignore", "Awareness", "Presence")
corMatf
## Rely Count Ignore Awareness Presence
## Rely 1.0000000 0.5799053 0.2172992 0.2240763 0.2456729
## Count 0.5799053 1.0000000 0.2279167 0.2875545 0.3019871
## Ignore 0.2172992 0.2279167 1.0000000 0.5054087 0.4641905
## Awareness 0.2240763 0.2875545 0.5054087 1.0000000 0.7304237
## Presence 0.2456729 0.3019871 0.4641905 0.7304237 1.0000000
#males
corMatm <- cor(Malematteringdata, use ="complete.obs", method = "pearson")
colnames(corMatm) <- c("Rely", "Count", "Ignore", "Awareness", "Presence")
rownames(corMatm) <- c("Rely", "Count", "Ignore", "Awareness", "Presence")
corMatm
## Rely Count Ignore Awareness Presence
## Rely 1.0000000 0.5578710 0.2716515 0.2715440 0.3004671
## Count 0.5578710 1.0000000 0.2956890 0.3315593 0.3661757
## Ignore 0.2716515 0.2956890 1.0000000 0.4811044 0.4349913
## Awareness 0.2715440 0.3315593 0.4811044 1.0000000 0.7082485
## Presence 0.3004671 0.3661757 0.4349913 0.7082485 1.0000000
# covariance matrix - there is still alot of covariance left for item 404
#females
covMatf <- cov(Femalematteringdata, use ="complete.obs", method = "pearson")
colnames(covMatf) <- c("Rely", "Count", "Ignore", "Awareness", "Presence")
rownames(covMatf) <- c("Rely", "Count", "Ignore", "Awareness", "Presence")
covMatf
## Rely Count Ignore Awareness Presence
## Rely 0.4719354 0.2628444 0.1098382 0.1108524 0.1136563
## Count 0.2628444 0.4353120 0.1106447 0.1366244 0.1341788
## Ignore 0.1098382 0.1106447 0.5413878 0.2677964 0.2300093
## Awareness 0.1108524 0.1366244 0.2677964 0.5185798 0.3542238
## Presence 0.1136563 0.1341788 0.2300093 0.3542238 0.4535134
#males
covMatm <- cov(Malematteringdata, use ="complete.obs", method = "pearson")
colnames(covMatm) <- c("Rely", "Count", "Ignore", "Awareness", "Presence")
rownames(covMatm) <- c("Rely", "Count", "Ignore", "Awareness", "Presence")
covMatm
## Rely Count Ignore Awareness Presence
## Rely 0.4424815 0.2536103 0.1274812 0.1244652 0.1306589
## Count 0.2536103 0.4670583 0.1425631 0.1561374 0.1635948
## Ignore 0.1274812 0.1425631 0.4977057 0.2338760 0.2006140
## Awareness 0.1244652 0.1561374 0.2338760 0.4748104 0.3190363
## Presence 0.1306589 0.1635948 0.2006140 0.3190363 0.4273549
Factorial Invariance with Identifying Constraints Configural Model (equate one set of lambdas per latent variable and one set of intercepts per latent)
ConfigModel <- '
! regressions
PersonalSupport =~ NA*in401rer + c(b1,b1)*in401rer + c(b21,b22)*in406rer
CommunityAwareness =~ NA*in403rer + c(b3,b3)*in403rer + c(b41,b42)*in404rer +
c(b51,b52)*in405rer
! residuals, variances and covariances
in401rer~~in401rer;
in406rer~~in406rer;
in403rer~~in403rer;
in404rer~~in404rer;
in405rer~~in405rer;
PersonalSupport ~~ c(1,NA)*PersonalSupport
CommunityAwareness ~~ c(1,NA)*CommunityAwareness
! intercepts (nu) & means (alphas)
in401rer~c(n1,n1)*1;
in406rer~c(n21,n22)*1;
in403rer~c(n3,n3)*1;
in404rer~c(n41,n42)*1;
in405rer~c(n51,n52)*1;
! Constrain Males to factor mean of 0, females are relative to males
PersonalSupport~c(a11, a12)*1;
CommunityAwareness~c(a21,a22)*1
a11 == 0
a21 == 0
'
ConfigOutput <- cfa(model=ConfigModel, data = data, group = "Gender")
summary(ConfigOutput, standardized = TRUE, fit.measures = TRUE)
## lavaan 0.6.15 ended normally after 64 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 38
## Number of equality constraints 6
##
## Number of observations per group: Used Total
## Male 2813 2834
## Female 3281 3318
##
## Model Test User Model:
##
## Test statistic 89.337
## Degrees of freedom 8
## P-value (Chi-square) 0.000
## Test statistic for each group:
## Male 58.569
## Female 30.769
##
## Model Test Baseline Model:
##
## Test statistic 9695.556
## Degrees of freedom 20
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.992
## Tucker-Lewis Index (TLI) 0.979
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -27007.305
## Loglikelihood unrestricted model (H1) NA
##
## Akaike (AIC) 54078.610
## Bayesian (BIC) 54293.492
## Sample-size adjusted Bayesian (SABIC) 54191.804
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.058
## 90 Percent confidence interval - lower 0.047
## 90 Percent confidence interval - upper 0.069
## P-value H_0: RMSEA <= 0.050 0.108
## P-value H_0: RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.020
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
##
## Group 1 [Male]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport =~
## in401rer (b1) 0.453 0.015 29.546 0.000 0.453 0.681
## in406rer (b21) 0.560 0.017 33.200 0.000 0.560 0.820
## CommunityAwareness =~
## in403rer (b3) 0.392 0.013 29.555 0.000 0.392 0.556
## in404rer (b41) 0.586 0.012 47.857 0.000 0.586 0.850
## in405rer (b51) 0.541 0.012 46.460 0.000 0.541 0.828
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport ~~
## CommuntyAwrnss 0.517 0.020 26.102 0.000 0.517 0.517
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (n1) 1.975 0.013 157.510 0.000 1.975 2.970
## .in406rer (n21) 1.916 0.013 148.757 0.000 1.916 2.805
## .in403rer (n3) 2.378 0.013 178.827 0.000 2.378 3.372
## .in404rer (n41) 2.243 0.013 172.660 0.000 2.243 3.255
## .in405rer (n51) 2.192 0.012 177.841 0.000 2.192 3.353
## PrsnlSpp (a11) 0.000 0.000 0.000
## CmmntyAw (a21) 0.000 NA 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer 0.237 0.012 20.555 0.000 0.237 0.537
## .in406rer 0.153 0.015 9.984 0.000 0.153 0.328
## .in403rer 0.344 0.010 34.335 0.000 0.344 0.691
## .in404rer 0.132 0.008 15.747 0.000 0.132 0.277
## .in405rer 0.134 0.007 18.060 0.000 0.134 0.314
## PersonalSupprt 1.000 1.000 1.000
## CommuntyAwrnss 1.000 1.000 1.000
##
##
## Group 2 [Female]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport =~
## in401rer (b1) 0.453 0.015 29.546 0.000 0.470 0.685
## in406rer (b22) 0.537 0.036 15.120 0.000 0.559 0.847
## CommunityAwareness =~
## in403rer (b3) 0.392 0.013 29.555 0.000 0.421 0.572
## in404rer (b42) 0.586 0.027 21.645 0.000 0.630 0.875
## in405rer (b52) 0.523 0.024 21.740 0.000 0.561 0.834
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport ~~
## CommuntyAwrnss 0.458 0.041 11.245 0.000 0.410 0.410
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (n1) 1.975 0.013 157.510 0.000 1.975 2.876
## .in406rer (n22) 1.889 0.020 92.559 0.000 1.889 2.864
## .in403rer (n3) 2.378 0.013 178.827 0.000 2.378 3.233
## .in404rer (n42) 2.253 0.026 85.840 0.000 2.253 3.129
## .in405rer (n52) 2.167 0.024 91.575 0.000 2.167 3.218
## PrsnlSpp (a12) -0.231 0.039 -5.910 0.000 -0.222 -0.222
## CmmntyAw (a22) 0.153 0.047 3.228 0.001 0.143 0.143
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer 0.250 0.013 18.654 0.000 0.250 0.531
## .in406rer 0.123 0.017 7.218 0.000 0.123 0.283
## .in403rer 0.364 0.010 37.126 0.000 0.364 0.672
## .in404rer 0.122 0.008 14.431 0.000 0.122 0.235
## .in405rer 0.138 0.007 19.332 0.000 0.138 0.305
## PersonalSupprt 1.080 0.105 10.275 0.000 1.000 1.000
## CommuntyAwrnss 1.154 0.104 11.057 0.000 1.000 1.000
##
## Constraints:
## |Slack|
## a11 - 0 0.000
## a21 - 0 0.000
Weak (Configural + equate all loadings/lambdas)
Weak.Model <- '
! regressions
PersonalSupport =~ NA*in401rer + c(b1,b1)*in401rer + c(b2,b2)*in406rer
CommunityAwareness =~ NA*in403rer + c(b3,b3)*in403rer + c(b4,b4)*in404rer +
c(b5,b5)*in405rer
! residuals, variances and covariances
in401rer~~in401rer;
in406rer~~in406rer;
in403rer~~in403rer;
in404rer~~in404rer;
in405rer~~in405rer;
PersonalSupport ~~ c(1,NA)*PersonalSupport
CommunityAwareness ~~ c(1,NA)*CommunityAwareness
! intercepts (nu) & means (alphas)
in401rer~c(n1,n1)*1;
in406rer~c(n21,n22)*1;
in403rer~c(n3,n3)*1;
in404rer~c(n41,n42)*1;
in405rer~c(n51,n52)*1;
! Constrain Males to factor mean of 0, females are relative to males
PersonalSupport~c(a11, a12)*1;
CommunityAwareness~c(a21,a22)*1
a11 == 0
a21 == 0
'
WeakOutput <- cfa(model=Weak.Model, data = data, group = "Gender")
summary(WeakOutput, standardized = TRUE, fit.measures = TRUE)
## lavaan 0.6.15 ended normally after 49 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 38
## Number of equality constraints 9
##
## Number of observations per group: Used Total
## Male 2813 2834
## Female 3281 3318
##
## Model Test User Model:
##
## Test statistic 90.833
## Degrees of freedom 11
## P-value (Chi-square) 0.000
## Test statistic for each group:
## Male 59.370
## Female 31.464
##
## Model Test Baseline Model:
##
## Test statistic 9695.556
## Degrees of freedom 20
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.992
## Tucker-Lewis Index (TLI) 0.985
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -27008.053
## Loglikelihood unrestricted model (H1) NA
##
## Akaike (AIC) 54074.106
## Bayesian (BIC) 54268.842
## Sample-size adjusted Bayesian (SABIC) 54176.688
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.049
## 90 Percent confidence interval - lower 0.040
## 90 Percent confidence interval - upper 0.058
## P-value H_0: RMSEA <= 0.050 0.563
## P-value H_0: RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.020
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
##
## Group 1 [Male]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport =~
## in401rer (b1) 0.457 0.013 35.478 0.000 0.457 0.687
## in406rer (b2) 0.555 0.014 38.550 0.000 0.555 0.813
## CommunityAwareness =~
## in403rer (b3) 0.395 0.010 39.484 0.000 0.395 0.559
## in404rer (b4) 0.591 0.011 54.693 0.000 0.591 0.855
## in405rer (b5) 0.535 0.010 53.263 0.000 0.535 0.822
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport ~~
## CommuntyAwrnss 0.517 0.020 26.371 0.000 0.517 0.517
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (n1) 1.975 0.013 157.298 0.000 1.975 2.966
## .in406rer (n21) 1.916 0.013 148.884 0.000 1.916 2.807
## .in403rer (n3) 2.378 0.013 178.477 0.000 2.378 3.365
## .in404rer (n41) 2.243 0.013 172.248 0.000 2.243 3.248
## .in405rer (n51) 2.192 0.012 178.517 0.000 2.192 3.366
## PrsnlSpp (a11) 0.000 0.000 0.000
## CmmntyAw (a21) 0.000 NA 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer 0.234 0.010 22.807 0.000 0.234 0.529
## .in406rer 0.158 0.013 12.368 0.000 0.158 0.338
## .in403rer 0.343 0.010 34.575 0.000 0.343 0.687
## .in404rer 0.128 0.007 17.462 0.000 0.128 0.268
## .in405rer 0.138 0.006 21.169 0.000 0.138 0.324
## PersonalSupprt 1.000 1.000 1.000
## CommuntyAwrnss 1.000 1.000 1.000
##
##
## Group 2 [Female]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport =~
## in401rer (b1) 0.457 0.013 35.478 0.000 0.465 0.677
## in406rer (b2) 0.555 0.014 38.550 0.000 0.564 0.855
## CommunityAwareness =~
## in403rer (b3) 0.395 0.010 39.484 0.000 0.418 0.570
## in404rer (b4) 0.591 0.011 54.693 0.000 0.625 0.870
## in405rer (b5) 0.535 0.010 53.263 0.000 0.566 0.839
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport ~~
## CommuntyAwrnss 0.440 0.027 16.171 0.000 0.409 0.409
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (n1) 1.975 0.013 157.298 0.000 1.975 2.879
## .in406rer (n22) 1.892 0.020 93.885 0.000 1.892 2.867
## .in403rer (n3) 2.378 0.013 178.477 0.000 2.378 3.238
## .in404rer (n42) 2.253 0.026 85.951 0.000 2.253 3.135
## .in405rer (n52) 2.165 0.024 90.403 0.000 2.165 3.206
## PrsnlSpp (a12) -0.229 0.038 -5.945 0.000 -0.225 -0.225
## CmmntyAw (a22) 0.152 0.047 3.236 0.001 0.143 0.143
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer 0.255 0.011 23.843 0.000 0.255 0.541
## .in406rer 0.117 0.013 8.966 0.000 0.117 0.269
## .in403rer 0.364 0.010 37.405 0.000 0.364 0.675
## .in404rer 0.126 0.007 16.885 0.000 0.126 0.243
## .in405rer 0.135 0.006 20.807 0.000 0.135 0.296
## PersonalSupprt 1.033 0.053 19.346 0.000 1.000 1.000
## CommuntyAwrnss 1.120 0.049 23.079 0.000 1.000 1.000
##
## Constraints:
## |Slack|
## a11 - 0 0.000
## a21 - 0 0.000
Strong (Weak + equate all sets of intercepts)
Strong.Model <- '
! regressions
PersonalSupport =~ NA*in401rer + c(b1,b1)*in401rer + c(b2,b2)*in406rer
CommunityAwareness =~ NA*in403rer + c(b3,b3)*in403rer + c(b4,b4)*in404rer +
c(b5,b5)*in405rer
! residuals, variances and covariances
in401rer~~in401rer;
in406rer~~in406rer;
in403rer~~in403rer;
in404rer~~in404rer;
in405rer~~in405rer;
PersonalSupport ~~ c(1,NA)*PersonalSupport
CommunityAwareness ~~ c(1,NA)*CommunityAwareness
! intercepts (nu) & means (alphas)
in401rer~c(n1,n1)*1;
in406rer~c(n2,n2)*1;
in403rer~c(n3,n3)*1;
in404rer~c(n4,n4)*1;
in405rer~c(n5,n5)*1;
! Constrain Males to factor mean of 0, females are relative to males
PersonalSupport~c(a11, a12)*1;
CommunityAwareness~c(a21,a22)*1
a11 == 0
a21 == 0
'
StrongOutput <- cfa(model=Strong.Model, data = data, group = "Gender")
summary(StrongOutput, standardized = TRUE, fit.measures = TRUE)
## lavaan 0.6.15 ended normally after 48 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 38
## Number of equality constraints 12
##
## Number of observations per group: Used Total
## Male 2813 2834
## Female 3281 3318
##
## Model Test User Model:
##
## Test statistic 100.371
## Degrees of freedom 14
## P-value (Chi-square) 0.000
## Test statistic for each group:
## Male 64.662
## Female 35.709
##
## Model Test Baseline Model:
##
## Test statistic 9695.556
## Degrees of freedom 20
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.991
## Tucker-Lewis Index (TLI) 0.987
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -27012.822
## Loglikelihood unrestricted model (H1) NA
##
## Akaike (AIC) 54077.643
## Bayesian (BIC) 54252.235
## Sample-size adjusted Bayesian (SABIC) 54169.614
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.045
## 90 Percent confidence interval - lower 0.037
## 90 Percent confidence interval - upper 0.053
## P-value H_0: RMSEA <= 0.050 0.829
## P-value H_0: RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.021
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
##
## Group 1 [Male]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport =~
## in401rer (b1) 0.454 0.013 36.083 0.000 0.454 0.682
## in406rer (b2) 0.559 0.014 39.286 0.000 0.559 0.818
## CommunityAwareness =~
## in403rer (b3) 0.396 0.010 39.564 0.000 0.396 0.560
## in404rer (b4) 0.592 0.011 54.806 0.000 0.592 0.857
## in405rer (b5) 0.534 0.010 53.251 0.000 0.534 0.820
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport ~~
## CommuntyAwrnss 0.516 0.020 26.299 0.000 0.516 0.516
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (n1) 1.982 0.011 175.148 0.000 1.982 2.979
## .in406rer (n2) 1.913 0.013 152.303 0.000 1.913 2.800
## .in403rer (n3) 2.380 0.011 217.822 0.000 2.380 3.368
## .in404rer (n4) 2.251 0.013 178.958 0.000 2.251 3.258
## .in405rer (n5) 2.180 0.012 188.102 0.000 2.180 3.351
## PrsnlSpp (a11) 0.000 0.000 0.000
## CmmntyAw (a21) 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer 0.237 0.010 23.451 0.000 0.237 0.535
## .in406rer 0.154 0.013 12.194 0.000 0.154 0.331
## .in403rer 0.343 0.010 34.571 0.000 0.343 0.687
## .in404rer 0.127 0.007 17.322 0.000 0.127 0.266
## .in405rer 0.139 0.006 21.378 0.000 0.139 0.327
## PersonalSupprt 1.000 1.000 1.000
## CommuntyAwrnss 1.000 1.000 1.000
##
##
## Group 2 [Female]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport =~
## in401rer (b1) 0.454 0.013 36.083 0.000 0.461 0.673
## in406rer (b2) 0.559 0.014 39.286 0.000 0.568 0.860
## CommunityAwareness =~
## in403rer (b3) 0.396 0.010 39.564 0.000 0.419 0.570
## in404rer (b4) 0.592 0.011 54.806 0.000 0.627 0.871
## in405rer (b5) 0.534 0.010 53.251 0.000 0.565 0.837
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport ~~
## CommuntyAwrnss 0.438 0.027 16.160 0.000 0.407 0.407
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (n1) 1.982 0.011 175.148 0.000 1.982 2.891
## .in406rer (n2) 1.913 0.013 152.303 0.000 1.913 2.897
## .in403rer (n3) 2.380 0.011 217.822 0.000 2.380 3.240
## .in404rer (n4) 2.251 0.013 178.958 0.000 2.251 3.131
## .in405rer (n5) 2.180 0.012 188.102 0.000 2.180 3.231
## PrsnlSpp (a12) -0.260 0.030 -8.634 0.000 -0.256 -0.256
## CmmntyAw (a22) 0.142 0.029 4.922 0.000 0.134 0.134
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer 0.257 0.010 24.607 0.000 0.257 0.548
## .in406rer 0.113 0.013 8.759 0.000 0.113 0.260
## .in403rer 0.364 0.010 37.402 0.000 0.364 0.675
## .in404rer 0.124 0.007 16.713 0.000 0.124 0.241
## .in405rer 0.136 0.006 21.054 0.000 0.136 0.300
## PersonalSupprt 1.033 0.053 19.348 0.000 1.000 1.000
## CommuntyAwrnss 1.121 0.049 23.077 0.000 1.000 1.000
##
## Constraints:
## |Slack|
## a11 - 0 0.000
## a21 - 0 0.000
Strict (Strong + equate all sets of residuals)
Strict.Model <- '
! regressions
PersonalSupport =~ in401rer + in406rer
CommunityAwareness =~ in403rer + in404rer + in405rer
! residuals, variances and covariances
in401rer~~e1*in401rer;
in406rer~~e2*in406rer;
in403rer~~e3*in403rer;
in404rer~~e4*in404rer;
in405rer~~e5*in405rer;
PersonalSupport ~~ c(1,NA)*PersonalSupport
CommunityAwareness ~~ c(1,NA)*CommunityAwareness
! intercepts (nu) & means (alphas)
in401rer~c(n1,n1)*1;
in406rer~c(n2,n2)*1;
in403rer~c(n3,n3)*1;
in404rer~c(n4,n4)*1;
in405rer~c(n5,n5)*1;
! Constrain Males to factor mean of 0, females are relative to males
PersonalSupport~c(a11, a12)*1;
CommunityAwareness~c(a21,a22)*1
a11 == 0
a21 == 0
'
StrictOutput <- cfa(model=Strict.Model, data = data, group = "Gender")
## Warning in lavaanify(model = FLAT, constraints = constraints, varTable = DataOV, : lavaan WARNING: using a single label per parameter in a multiple group
## setting implies imposing equality constraints across all the groups;
## If this is not intended, either remove the label(s), or use a vector
## of labels (one for each group);
## See the Multiple groups section in the man page of model.syntax.
summary(StrictOutput, standardized = TRUE, fit.measures = TRUE)
## lavaan 0.6.15 ended normally after 40 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 34
## Number of equality constraints 12
##
## Number of observations per group: Used Total
## Male 2813 2834
## Female 3281 3318
##
## Model Test User Model:
##
## Test statistic 1953.685
## Degrees of freedom 18
## P-value (Chi-square) 0.000
## Test statistic for each group:
## Male 1886.152
## Female 67.533
##
## Model Test Baseline Model:
##
## Test statistic 9695.556
## Degrees of freedom 20
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.800
## Tucker-Lewis Index (TLI) 0.778
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -27939.479
## Loglikelihood unrestricted model (H1) NA
##
## Akaike (AIC) 55922.958
## Bayesian (BIC) 56070.689
## Sample-size adjusted Bayesian (SABIC) 56000.779
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.188
## 90 Percent confidence interval - lower 0.181
## 90 Percent confidence interval - upper 0.195
## P-value H_0: RMSEA <= 0.050 0.000
## P-value H_0: RMSEA >= 0.080 1.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.517
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
##
## Group 1 [Male]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport =~
## in401rer 1.000 1.000 0.916
## in406rer 0.811 0.012 70.413 0.000 0.811 0.876
## CommunityAwareness =~
## in403rer 1.000 1.000 0.857
## in404rer 0.923 0.011 87.663 0.000 0.923 0.930
## in405rer 0.848 0.010 83.639 0.000 0.848 0.915
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport ~~
## CommuntyAwrnss 0.816 0.008 106.801 0.000 0.816 0.816
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (n1) 1.998 0.019 107.811 0.000 1.998 1.831
## .in406rer (n2) 1.910 0.017 115.007 0.000 1.910 2.065
## .in403rer (n3) 2.386 0.016 146.498 0.000 2.386 2.045
## .in404rer (n4) 2.259 0.017 129.593 0.000 2.259 2.276
## .in405rer (n5) 2.187 0.016 136.883 0.000 2.187 2.362
## PrsnlSpp (a11) 0.000 NA 0.000 0.000
## CmmntyAw (a21) 0.000 NA 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (e1) 0.191 0.009 21.838 0.000 0.191 0.161
## .in406rer (e2) 0.199 0.007 27.048 0.000 0.199 0.232
## .in403rer (e3) 0.361 0.008 48.054 0.000 0.361 0.265
## .in404rer (e4) 0.134 0.005 26.420 0.000 0.134 0.136
## .in405rer (e5) 0.139 0.004 31.145 0.000 0.139 0.163
## PrsnlSppr 1.000 1.000 1.000
## CmmntyAwr 1.000 1.000 1.000
##
##
## Group 2 [Female]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport =~
## in401rer 1.000 0.524 0.768
## in406rer 0.950 0.033 28.693 0.000 0.498 0.745
## CommunityAwareness =~
## in403rer 1.000 0.423 0.576
## in404rer 1.473 0.044 33.428 0.000 0.624 0.863
## in405rer 1.326 0.040 33.053 0.000 0.561 0.833
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PersonalSupport ~~
## CommuntyAwrnss 0.092 0.006 15.597 0.000 0.414 0.414
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (n1) 1.998 0.019 107.811 0.000 1.998 2.927
## .in406rer (n2) 1.910 0.017 115.007 0.000 1.910 2.858
## .in403rer (n3) 2.386 0.016 146.498 0.000 2.386 3.245
## .in404rer (n4) 2.259 0.017 129.593 0.000 2.259 3.124
## .in405rer (n5) 2.187 0.016 136.883 0.000 2.187 3.244
## PrsnlSpp (a12) -0.139 0.021 -6.704 0.000 -0.265 -0.265
## CmmntyAw (a22) 0.052 0.014 3.567 0.000 0.122 0.122
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .in401rer (e1) 0.191 0.009 21.838 0.000 0.191 0.411
## .in406rer (e2) 0.199 0.007 27.048 0.000 0.199 0.445
## .in403rer (e3) 0.361 0.008 48.054 0.000 0.361 0.668
## .in404rer (e4) 0.134 0.005 26.420 0.000 0.134 0.255
## .in405rer (e5) 0.139 0.004 31.145 0.000 0.139 0.307
## PrsnlSppr 0.275 0.013 20.486 0.000 1.000 1.000
## CmmntyAwr 0.179 0.011 16.874 0.000 1.000 1.000
##
## Constraints:
## |Slack|
## a11 - 0 0.000
## a21 - 0 0.000
#Retrieving session information
sessionInfo()
## R version 4.3.0 (2023-04-21)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Monterey 12.6
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: America/Los_Angeles
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0 purrr_1.0.1
## [5] readr_2.1.4 tidyr_1.3.0 ggplot2_3.4.2 tidyverse_2.0.0
## [9] dplyr_1.1.2 haven_2.5.2 tibble_3.2.1 semPlot_1.1.6
## [13] semTools_0.5-6 lavaan_0.6-15 psych_2.3.3
##
## loaded via a namespace (and not attached):
## [1] mnormt_2.1.1 pbapply_1.7-0 gridExtra_2.3 fdrtool_1.2.17
## [5] rlang_1.1.1 magrittr_2.0.3 rockchalk_1.8.157 compiler_4.3.0
## [9] png_0.1-8 vctrs_0.6.2 reshape2_1.4.4 OpenMx_2.21.8
## [13] quadprog_1.5-8 pkgconfig_2.0.3 fastmap_1.1.1 arm_1.13-1
## [17] backports_1.4.1 pbivnorm_0.6.0 utf8_1.2.3 rmarkdown_2.21
## [21] tzdb_0.3.0 nloptr_2.0.3 xfun_0.39 cachem_1.0.8
## [25] kutils_1.70 jsonlite_1.8.4 jpeg_0.1-10 parallel_4.3.0
## [29] cluster_2.1.4 R6_2.5.1 bslib_0.4.2 stringi_1.7.12
## [33] boot_1.3-28.1 rpart_4.1.19 jquerylib_0.1.4 Rcpp_1.0.10
## [37] knitr_1.42 base64enc_0.1-3 timechange_0.2.0 Matrix_1.5-4
## [41] splines_4.3.0 nnet_7.3-18 igraph_1.4.3 tidyselect_1.2.0
## [45] rstudioapi_0.14 abind_1.4-5 yaml_2.3.7 qgraph_1.9.4
## [49] lattice_0.21-8 plyr_1.8.8 withr_2.5.0 coda_0.19-4
## [53] evaluate_0.21 foreign_0.8-84 RcppParallel_5.1.7 zip_2.3.0
## [57] pillar_1.9.0 carData_3.0-5 checkmate_2.2.0 stats4_4.3.0
## [61] generics_0.1.3 hms_1.1.3 munsell_0.5.0 scales_1.2.1
## [65] minqa_1.2.5 gtools_3.9.4 xtable_1.8-4 glue_1.6.2
## [69] mi_1.1 Hmisc_5.0-1 tools_4.3.0 data.table_1.14.8
## [73] lme4_1.1-33 openxlsx_4.2.5.2 XML_3.99-0.14 grid_4.3.0
## [77] sem_3.1-15 colorspace_2.1-0 nlme_3.1-162 htmlTable_2.4.1
## [81] Formula_1.2-5 cli_3.6.1 fansi_1.0.4 corpcor_1.6.10
## [85] glasso_1.11 gtable_0.3.3 sass_0.4.6 digest_0.6.31
## [89] htmlwidgets_1.6.2 htmltools_0.5.5 lifecycle_1.0.3 lisrelToR_0.1.5
## [93] MASS_7.3-58.4
Fit Comparisons Across Models
Mod.Fit.Comp <- compareFit(ConfigOutput, WeakOutput, StrongOutput, StrictOutput)
summary(Mod.Fit.Comp)
## ################### Nested Model Comparison #########################
##
## Chi-Squared Difference Test
##
## Df AIC BIC Chisq Chisq diff RMSEA Df diff Pr(>Chisq)
## ConfigOutput 8 54079 54293 89.338
## WeakOutput 11 54074 54269 90.833 1.50 0.00000 3 0.68322
## StrongOutput 14 54078 54252 100.371 9.54 0.02674 3 0.02293 *
## StrictOutput 18 55923 56071 1953.685 1853.31 0.38953 4 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ####################### Model Fit Indices ###########################
## chisq df pvalue rmsea cfi tli srmr aic bic
## ConfigOutput 89.337† 8 .000 .058 .992 .979 .020† 54078.610 54293.492
## WeakOutput 90.833 11 .000 .049 .992† .985 .020 54074.106† 54268.842
## StrongOutput 100.371 14 .000 .045† .991 .987† .021 54077.643 54252.235†
## StrictOutput 1953.685 18 .000 .188 .800 .778 .517 55922.958 56070.689
##
## ################## Differences in Fit Indices #######################
## df rmsea cfi tli srmr aic bic
## WeakOutput - ConfigOutput 3 -0.009 0.000 0.006 0.000 -4.504 -24.649
## StrongOutput - WeakOutput 3 -0.004 -0.001 0.002 0.001 3.538 -16.607
## StrictOutput - StrongOutput 4 0.143 -0.191 -0.210 0.495 1845.314 1818.454
library(GAIPE)
CI.Conf <- CI.RMSEA(rmsea = .058, df = 8, N=6152, clevel = .95)
CI.Conf
## $Lower.CI
## [1] 0.04923478
##
## $RMSEA
## [1] 0.058
##
## $Upper.CI
## [1] 0.06709328
CI.Weak <- CI.RMSEA(rmsea = .049, df = 11, N=6152, clevel = .95)
CI.Weak
## $Lower.CI
## [1] 0.04148578
##
## $RMSEA
## [1] 0.049
##
## $Upper.CI
## [1] 0.056788
CI.Strong <- CI.RMSEA(rmsea = .045, df = 14, N=6152, clevel = .95)
CI.Strong
## $Lower.CI
## [1] 0.03831116
##
## $RMSEA
## [1] 0.045
##
## $Upper.CI
## [1] 0.05191808
CI.Strict <- CI.RMSEA(rmsea = .019, df = 18, N=6152, clevel = .95)
CI.Strict
## $Lower.CI
## [1] 0.0125472
##
## $RMSEA
## [1] 0.019
##
## $Upper.CI
## [1] 0.02559346