
Compare Model Fit of Nested Dyadic Invariance Models
Source:R/outputInvarCompTab.R
outputInvarCompTab.RdoutputInvarCompTab() is used to compare the model fit of nested dyadic invariance models
in order from most parsimonious (residual) to least parsimonious (configural)
Usage
outputInvarCompTab(
mods,
parsimonyFirst = FALSE,
gtTab = FALSE,
writeTo = NULL,
fileName = NULL
)Arguments
- mods
A list of nested
lavaandyadic invariance models, in the order of residual, intercept, loading, configural- parsimonyFirst
A logical input indicating whether to prioritize the residual dyadic invariance (i.e. most parsimonious measurement model) as the baseline model for nested comparisons, or to prioritize the configural dyadic invariance (i.e. least parsimonious measurement model). Defaults to FALSE (i.e., configural dyadic invariance is the baseline model).
- gtTab
A logical input indicating whether to generate the table(s) in
gt::gt()table object format (TRUE). By default (FALSE), the table(s) are generated intibble::tibble()format. Users can also apply thewriteToargument if they wish to export thegt::gt()table object(s).- writeTo
A character string specifying a directory path to where the output file(s) should be saved. If set to
".", the file(s) will be written to the current working directory. The default isNULL, and examples use a temporary directory created bytempdir(). When dealing with tabular output,writeTois only relevant ifgtTab = TRUE.- fileName
A character string specifying a desired base name for the output file. The default is
NULL. The specified name will be automatically appended with the appropriate file extension (e.g.,.txtforlavaanscripts,.rtffor tabular output whengtTab = TRUE, or other extensions as appropriate for the output type). If a file with the same name already exists in the user's chosen directory, it will be overwritten.
Value
A tibble::tibble() if gtTab = FALSE (default), or gt::gt() object if gtTab = TRUE, of model fit statistics for each model, as well as the difference in fit statistics between each model and the previous model
Details
If
gtTab = TRUEandwriteTois specified, then output will simultaneously be saved as a.rtffile to the user's specified directory.If output file is successfully saved, a confirmation message will be printed to the console.
If a file with the same name already exists in the user's chosen directory, it will be overwritten.
Examples
dvn <- scrapeVarCross(
dat = commitmentQ, x_order = "spi",
x_stem = "sat.g", x_delim1 = ".", x_delim2 = "_", distinguish_1 = "1", distinguish_2 = "2"
)
#>
#> ── Variable Scraping Summary ──
#>
#> ✔ Successfully scraped 1 latent variable: sat.g
#> ℹ sat.g: 5 indicators for P1 (1), 5 indicators for P2 (2)
#> ℹ Total indicators: 10
sat.residual.script <- scriptCor(dvn,
lvname = "Sat",
constr_dy_meas = c("loadings", "intercepts", "residuals"), constr_dy_struct = "none"
)
sat.intercept.script <- scriptCor(dvn,
lvname = "Sat",
constr_dy_meas = c("loadings", "intercepts"), constr_dy_struct = "none"
)
sat.loading.script <- scriptCor(dvn,
lvname = "Sat",
constr_dy_meas = c("loadings"), constr_dy_struct = "none"
)
sat.config.script <- scriptCor(dvn,
lvname = "Sat",
constr_dy_meas = "none", constr_dy_struct = "none"
)
sat.residual.fit <- lavaan::cfa(sat.residual.script,
data = commitmentQ,
std.lv = FALSE, auto.fix.first = FALSE, meanstructure = TRUE
)
sat.intercept.fit <- lavaan::cfa(sat.intercept.script,
data = commitmentQ,
std.lv = FALSE, auto.fix.first = FALSE, meanstructure = TRUE
)
sat.loading.fit <- lavaan::cfa(sat.loading.script,
data = commitmentQ,
std.lv = FALSE, auto.fix.first = FALSE, meanstructure = TRUE
)
sat.config.fit <- lavaan::cfa(sat.config.script,
data = commitmentQ,
std.lv = FALSE, auto.fix.first = FALSE, meanstructure = TRUE
)
mods <- list(sat.residual.fit, sat.intercept.fit, sat.loading.fit, sat.config.fit)
outputInvarCompTab(mods,
parsimonyFirst = FALSE,
gtTab = TRUE, writeTo = tempdir(), fileName = "dCFA_Invar_Standard"
)
#> Output stored in: /tmp/RtmpIVCISQ/dCFA_Invar_Standard.rtf
mod
chisq
df
pvalue
aic
bic
rmsea
cfi
chisq_diff
df_diff
p_diff
aic_diff
bic_diff
rmsea_diff
cfi_diff
mods <- list(sat.config.fit, sat.loading.fit, sat.intercept.fit, sat.residual.fit)
outputInvarCompTab(mods,
parsimonyFirst = TRUE,
gtTab = TRUE, writeTo = tempdir(), fileName = "dCFA_Invar_Reverse"
)
#> Output stored in: /tmp/RtmpIVCISQ/dCFA_Invar_Reverse.rtf
mod
chisq
df
pvalue
aic
bic
rmsea
cfi
chisq_diff
df_diff
p_diff
aic_diff
bic_diff
rmsea_diff
cfi_diff