View source: R/multilevel.invar.R
| multilevel.invar | R Documentation |
This function evaluates 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. By default,
the function evaluates configural and metric cross-level measurement invariance
by providing a table with model fit information (i.e., chi-square test, fit
indices and information criteria), and model comparison (i.e., chi-square
difference test, change in fit indices, and change in information criteria).
Additionally, variance-covariance coverage of the data, descriptive statistics,
parameter estimates, modification indices, residual correlation matrix, and
relative Opdyke distribution percentile matrix can be requested by specifying
the argument print.
multilevel.invar(data, ..., 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", "opdyke"),
print.fit = c("all", "standard", "scaled", "robust"),
mod.minval = 6.63, resid.minval = 0.1,
opdyke.prec = 1, opdyke.minmax = c(0.40, 0.60),
color = "b.red", style = c("regular", "bold", "italic"),
digits = 3, p.digits = 3, as.na = NULL, write = NULL,
append = TRUE, check = TRUE, output = TRUE)
data |
a data frame. If |
... |
an expression indicating the variable names in |
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. |
opdyke.prec |
a numeric value indicating the precision of the probability
density function calculations of the Opdyke distribution.
The default is |
opdyke.minmax |
a numeric vector with two elements indicating the
minimum and maximum percentile of the Opdyke distribution
that is considered to be acceptably close to the
observed correlation represented by the Opdyke distribution
median. Predicted correlation outside the range will be
color highlighted in line with to the argument |
color |
a character string indicating the text color for
highlighting absolute residual correlation coefficients
and standardized means equal or higher |
style |
a character vector indicating the font style for
highlighting absolute residual correlation coefficients
and standardized means equal or higher |
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 |
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). The relative Opdyke
distribution percentile matrix is based on the functions opdyke and
opdyke.percentiles provided in the R package opddyke by Dan McNeish (2026).
Takuya Yanagida takuya.yanagida@univie.ac.at
McNeish D (2026). opdyke: Opdyke Percentiles for Approximate Local Fit in Structural Equation Models. R package version 1.0.0. Retrieved from https://github.com/dmcneish18/opdyke
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: Specification using the argument '...'
multilevel.invar(Demo.twolevel, y1:y4, cluster = "cluster")
# Example 1b: Alternative specification with cluster variable 'cluster' in 'data'
multilevel.invar(Demo.twolevel[, c("y1", "y2", "y3", "y4", "cluster")], cluster = "cluster")
# Example 1c: Alternative specification with cluster variable 'cluster' not in 'data'
multilevel.invar(Demo.twolevel[, c("y1", "y2", "y3", "y4")], cluster = Demo.twolevel$cluster)
#—————————————————————————————————————————————————————————————————————————————
# Model Specification Using 'data' for an One-Factor Model
#——————————————————————————————————————
## Level of Measurement Invariance
# Example 2a: Configural invariance
multilevel.invar(Demo.twolevel, y1, y2, y3, y4, cluster = "cluster", invar = "config")
# Example 2b: Metric invariance
multilevel.invar(Demo.twolevel, y1, y2, y3, y4, cluster = "cluster", invar = "metric")
# Example 2c: Scalar invariance
multilevel.invar(Demo.twolevel, y1, y2, y3, y4, cluster = "cluster", invar = "scalar")
#——————————————————————————————————————
## Residual (Co-)Variance at the Within and Between Level
# Example 3a: Residual covariance between "y3" and "y4" at the Within level
multilevel.invar(Demo.twolevel, y1, y2, y3, y4, cluster = "cluster",
rescov = c("y3", "y4"))
# Example 3b: Residual variances of 'y1' at the Between level fixed at 0
multilevel.invar(Demo.twolevel, y1, y2, y3, y4, cluster = "cluster", fix.resid = "y1")
#——————————————————————————————————————
## Arguments 'print', 'mod.minval', 'resid.minval', and 'opdyke.minmax'
# Example 4a: Request all results
multilevel.invar(Demo.twolevel, y1:y6, cluster = "cluster", print = "all")
# Example 4b: Request modification indices with value equal or higher than 2
multilevel.invar(Demo.twolevel, y1:y6, cluster = "cluster", print = "modind",
mod.minval = 2)
# Example 4c: Highlight absolute residual correlation equal or higher than 0.05
multilevel.invar(Demo.twolevel, y1:y6, cluster = "cluster", print = "resid",
resid.minval = 0.05, color = "b.blue")
# Example 4d: Highlight Opdyke distribution percentiles outside 0.45 and 0.55
multilevel.invar(Demo.twolevel, y1:y6, cluster = "cluster", print = "opdyke",
opdyke.minmax = c(0.45, 0.55), color = "black", style = "bold")
#————————————————————————————————————————————————————————————————————————————
# lavaan Summary of the Estimated Model
# Example 5: lavaan model and summary of the estimated model
mod <- multilevel.invar(Demo.twolevel, y1, y2, y3, y4, cluster = "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 an 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 a Excel file
multilevel.invar(Demo.twolevel, y1, y2, y3, y4, cluster = "cluster", print = "all",
write = "Multilevel_Invariance.txt")
# Example 7b: Write Results into a Excel file
multilevel.invar(Demo.twolevel, y1, y2, y3, y4, cluster = "cluster", print = "all",
write = "Multilevel_Invariance.xlsx")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.