# NOT RUN {
data("YouthGratitude", package = "psychotools")
summary(YouthGratitude)
## modeling can be carried out using package lavaan
# }
# NOT RUN {
## remove cases with 'imputed' values (not in 1, ..., 9)
yg <- YouthGratitude[apply(YouthGratitude[, 4:28], 1, function(x) all(x <!-- %in% 1:9)), ] -->
## GQ-6
gq6_congeneric <- cfa(
'f1 =~ gq6_1 + gq6_2 + gq6_3 + gq6_4 + gq6_5',
data = yg, group = "agegroup", meanstructure = TRUE)
gq6_tauequivalent <- cfa(
'f1 =~ gq6_1 + gq6_2 + gq6_3 + gq6_4 + gq6_5',
data = yg, group = "agegroup", meanstructure = TRUE,
group.equal = "loadings")
gq6_parallel <- cfa(
'f1 =~ gq6_1 + gq6_2 + gq6_3 + gq6_4 + gq6_5',
data = yg, group = "agegroup", meanstructure = TRUE,
group.equal = c("loadings", "residuals", "lv.variances"))
anova(gq6_congeneric, gq6_tauequivalent, gq6_parallel)
t(sapply(
list(gq6_congeneric, gq6_tauequivalent, gq6_parallel),
function(m) fitMeasures(m)[c("chisq", "df", "cfi", "srmr")]
))
## GAC
gac_congeneric <- cfa(
'f1 =~ gac_1 + gac_2 + gac_3',
data = yg, group = "agegroup", meanstructure = TRUE)
gac_tauequivalent <- cfa(
'f1 =~ gac_1 + gac_2 + gac_3',
data = yg, group = "agegroup", meanstructure = TRUE,
group.equal = "loadings")
gac_parallel <- cfa(
'f1 =~ gac_1 + gac_2 + gac_3',
data = yg, group = "agegroup", meanstructure = TRUE,
group.equal = c("loadings", "residuals", "lv.variances"))
anova(gac_congeneric, gac_tauequivalent, gac_parallel)
t(sapply(
list(gac_congeneric, gac_tauequivalent, gac_parallel),
function(m) fitMeasures(m)[c("chisq", "df", "cfi", "srmr")]
))
## GRAT
grat_congeneric <- cfa(
'f1 =~ losd_2 + losd_3 + losd_4 + losd_5 + losd_6
f2 =~ sa_1 + sa_2 + sa_3 + sa_4 + sa_5 + sa_6
f3 =~ ao_1 + ao_2 + ao_3 + ao_4',
data = yg, group = "agegroup", meanstructure = TRUE)
grat_tauequivalent <- cfa(
'f1 =~ losd_2 + losd_3 + losd_4 + losd_5 + losd_6
f2 =~ sa_1 + sa_2 + sa_3 + sa_4 + sa_5 + sa_6
f3 =~ ao_1 + ao_2 + ao_3 + ao_4',
data = yg, group = "agegroup", meanstructure = TRUE,
group.equal = "loadings")
grat_parallel <- cfa(
'f1 =~ losd_2 + losd_3 + losd_4 + losd_5 + losd_6
f2 =~ sa_1 + sa_2 + sa_3 + sa_4 + sa_5 + sa_6
f3 =~ ao_1 + ao_2 + ao_3 + ao_4',
data = yg, group = "agegroup", meanstructure = TRUE,
group.equal = c("loadings", "residuals", "lv.variances"))
anova(grat_congeneric, grat_tauequivalent, grat_parallel)
t(sapply(
list(grat_congeneric, grat_tauequivalent, grat_parallel),
function(m) fitMeasures(m)[c("chisq", "df", "cfi", "srmr")]
))
# }
Run the code above in your browser using DataLab