View source: R/multilevel.invar.R
multilevel.invar | R Documentation |
This function is a wrapper function for evaluating configural, metric, and
scalar cross-level measurement invariance using multilevel confirmatory factor
analysis with continuous indicators by calling the cfa
function in the
R package lavaan.
multilevel.invar(..., data = NULL, cluster, model = NULL, rescov = NULL,
invar = c("config", "metric", "scalar"), fix.resid = NULL,
ident = c("marker", "var", "effect"),
estimator = c("ML", "MLR"), optim.method = c("nlminb", "em"),
missing = c("listwise", "fiml"),
print = c("all", "summary", "coverage", "descript", "fit",
"est", "modind", "resid"),
print.fit = c("all", "standard", "scaled", "robust"),
mod.minval = 6.63, resid.minval = 0.1, digits = 3, p.digits = 3,
as.na = NULL, write = NULL, append = TRUE, check = TRUE,
output = TRUE)
... |
a matrix or data frame. If |
data |
a data frame when specifying one or more variables in the
argument |
cluster |
either a character string indicating the variable name of
the cluster variable in |
model |
a character vector specifying the same factor structure
with one factor at the Within and Between Level, or a list
of character vectors for specifying the same measurement
model with more than one factor at the Within and Between
Level, e.g., |
rescov |
a character vector or a list of character vectors for specifying
residual covariances at the Within level, e.g. |
invar |
a character string indicating the level of measurement invariance
to be evaluated, i.e., |
fix.resid |
a character vector for specifying residual variances to be
fixed at 0 at the Between level for the configural and metric
invariance model, e.g., |
ident |
a character string indicating the method used for identifying
and scaling latent variables, i.e., |
estimator |
a character string indicating the estimator to be used:
|
optim.method |
a character string indicating the optimizer, i.e., |
missing |
a character string indicating how to deal with missing data,
i.e., |
print |
a character string or character vector indicating which
results to show on the console, i.e. |
print.fit |
a character string or character vector indicating which
version of the CFI, TLI, and RMSEA to show on the console,
i.e., |
mod.minval |
numeric value to filter modification indices and only
show modifications with a modification index value equal
or higher than this minimum value. By default, modification
indices equal or higher 6.63 are printed. Note that a
modification index value of 6.63 is equivalent to a
significance level of |
resid.minval |
numeric value indicating the minimum absolute residual correlation coefficients and standardized means to highlight in boldface. By default, absolute residual correlation coefficients and standardized means equal or higher 0.1 are highlighted. Note that highlighting can be disabled by setting the minimum value to 1. |
digits |
an integer value indicating the number of decimal places
to be used for displaying results. Note that information
criteria and chi-square test statistic is printed with
|
p.digits |
an integer value indicating the number of decimal places to be used for displaying the p-value. |
as.na |
a numeric vector indicating user-defined missing values,
i.e. these values are converted to |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
Returns an object of class misty.object
, which is a list with following
entries:
call |
function call |
type |
type of analysis |
data |
matrix or data frame specified in |
args |
specification of function arguments |
model |
list with specified model for the configural, metric, and scalar invariance model |
model.fit |
list with fitted lavaan object of the configural, metric, and scalar invariance model |
check |
list with the results of the convergence and model identification check for the configural, metric, and scalar invariance model |
result |
list with result tables, i.e., |
The function uses the functions lavTestLRT
provided in the R package
lavaan by Yves Rosseel (2012).
Takuya Yanagida takuya.yanagida@univie.ac.at
Rosseel, Y. (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48, 1-36. https://doi.org/10.18637/jss.v048.i02
multilevel.cfa
, multilevel.fit
, multilevel.omega
,
multilevel.cor
, multilevel.descript
## Not run:
# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")
#----------------------------------------------------------------------------
# Cluster variable specification
# Example 1a: Cluster variable 'cluster' in 'x'
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4", "cluster")], cluster = "cluster")
# Example 1b: Cluster variable 'cluster' not in 'x'
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")], cluster = Demo.twolevel$cluster)
# Example 1c: Alternative specification using the 'data' argument
multilevel.invar(y1:y4, data = Demo.twolevel, cluster = "cluster")
#----------------------------------------------------------------------------
# Model specification using 'x' for a one-factor model
#..........
# Level of measurement invariance
# Example 2a: Configural invariance
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, invar = "config")
# Example 2b: Metric invariance
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, invar = "metric")
# Example 2c: Scalar invariance
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, invar = "scalar")
#..........
# Residual covariance at the Within level and residual variance at the Between level
# Example 3a: Residual covariance between "y3" and "y4" at the Within level
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, rescov = c("y3", "y4"))
# Example 3b: Residual variances of 'y1' at the Between level fixed at 0
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, fix.resid = "y1")
#..........
# Example 4: Print all results
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, print = "all")
#..........
# Example 5: lavaan model and summary of the estimated model
mod <- multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, output = FALSE)
# lavaan syntax of the metric invariance model
mod$model$metric
# Fitted lavaan object of the metric invariance model
lavaan::summary(mod$model.fit$metric, standardized = TRUE, fit.measures = TRUE)
#----------------------------------------------------------------------------
# Model specification using 'model' for one or multiple factor model
# Example 6a: One-factor model
multilevel.invar(Demo.twolevel, cluster = "cluster", model = c("y1", "y2", "y3", "y4"))
# Example 6b: Two-factor model
multilevel.invar(Demo.twolevel, cluster = "cluster",
model = list(c("y1", "y2", "y3"), c("y4", "y5", "y6")))
#----------------------------------------------------------------------------
# Write results
# Example 7a: Write results into an Excel file
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, print = "all",
write = "Multilevel_Invariance.txt")
# Example 7b: Write results into an Excel file
multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, print = "all",
write = "Multilevel_Invariance.xlsx")
# Assign results into an object and write results into an Excel file
mod <- multilevel.invar(Demo.twolevel[,c("y1", "y2", "y3", "y4")],
cluster = Demo.twolevel$cluster, print = "all",
output = FALSE)
# Write results into an Excel file
write.result(mod, "Multilevel_Invariance.xlsx")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.