item.cfa: Confirmatory Factor Analysis

View source: R/item.cfa.R

item.cfaR Documentation

Confirmatory Factor Analysis

Description

This function is a wrapper function for conducting confirmatory factor analysis with continuous and/or ordered-categorical indicators by calling the cfa function in the R package lavaan. By default, the function provides a table with univariate sample statistics, model fit information, and parameter estimates. Additionally, variance-covariance coverage of the data, modification indices, residual correlation matrix, and relative Opdyke distribution percentile matrix can be requested by specifying the argument print.

Usage

item.cfa(data, ..., model = NULL, rescov = NULL, hierarch = FALSE,
         meanstructure = TRUE, ident = c("marker", "var", "effect"),
         parameterization = c("delta", "theta"), ordered = FALSE, cluster = NULL,
         estimator = c("ML", "MLM", "MLMV", "MLMVS", "MLF", "MLR",
                       "GLS", "WLS", "DWLS", "WLSM", "WLSMV", "WLSMVS",
                       "ULS", "ULSM", "ULSMV", "ULSMVS", "DLS", "PML"),
         test = c("none", "standard", "satorra.bentler", "scaled.shifted",
                  "mean.var.adjusted", "yuan.bentler", "yuan.bentler.mplus",
                  "browne.residual.adf", "browne.residual.nt",
                  "mean.var.adjusted.corrected", "scaled.shifted.corrected"),
         se = c("none", "standard", "robust.sem", "robust.huber.white"),
         missing = c("listwise", "pairwise", "fiml", "two.stage",
                     "robust.two.stage", "doubly.robust"),
         print = c("all", "summary", "coverage", "descript", "fit", "est",
                  "modind", "resid", "opdyke"),
         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)

Arguments

data

a data frame. If model = NULL, confirmatory factor analysis based on a measurement model with one factor labeled f comprising all variables in the data frame is conducted. Note that the cluster variable is excluded from data when specifying cluster. If model is specified, the data frame needs to contain all variables used in the argument model and the cluster variable when specifying cluster.

...

an expression indicating the variable names in data, e.g., item.cfa(x1, x2, x3, data = dat). Note that the operators +, -, ~, :, ::, and ! can also be used to select variables, see 'Details' in the df.subset function.

model

a character vector specifying a measurement model with one factor, or a list of character vectors for specifying a measurement model with more than one factor, e.g., model = c("x1", "x2", "x3", "x4") for specifying a measurement model with one factor labeled f comprising four indicators, or model = list(factor1 = c("x1", "x2", "x3", "x4"), factor2 = c("x5", "x6", "x7", "x8")) for specifying a measurement model with two latent factors labeled factor1 and factor2 each comprising four indicators. Note that the name of each list element is used to label factors, i.e., all list elements need to be named, otherwise factors are labeled with "f1", "f2", "f3" and so on.

rescov

a character vector or a list of character vectors for specifying residual covariances, e.g. rescov = c("x1", "x2") for specifying a residual covariance between items x1 and x2, or rescov = list(c("x1", "x2"), c("x3", "x4")) for specifying residual covariances between items x1 and x2, and items x3 and x4.

hierarch

logical: if TRUE, a second-order factor model is specified given at least three first-order factors were specified in model. Note that it is not possible to specify more than one second-order factor.

meanstructure

logical: if TRUE (default), intercept/means of observed variables means of latent variables will be added to the model. Note that meanstructure = FALSE is only applicable when the missing is listwise, pairwise, or doubly-robust.

ident

a character string indicating the method used for identifying and scaling latent variables, i.e., "marker" for the marker variable method fixing the first factor loading of each latent variable to 1, "var" for the fixed variance method fixing the variance of each latent variable to 1, or "effect" for the effects-coding method using equality constraints so that the average of the factor loading for each latent variable equals 1. By default, fixed variance method is used when hierarch = FALSE, whereas marker variable method is used when hierarch = TRUE.

parameterization

a character string indicating the method used for identifying and scaling latent variables when indicators are ordered, i.e., "delta" (default) for delta parameterization and "theta" for theta parameterization.

ordered

if FALSE (default), all indicators of the measurement model are treated as continuous. If TRUE, all indicators of the measurement model are treated as ordered (ordinal). Alternatively, a character vector indicating which variables to treat as ordered (ordinal) variables can be specified.

cluster

either a character string indicating the variable name of the cluster variable in data, or a vector representing the nested grouping structure (i.e., group or cluster variable) for computing cluster-robust standard errors. Note that cluster-robust standard errors are not available when treating indicators of the measurement model as ordered (ordinal).

estimator

a character string indicating the estimator to be used (see 'Details'). By default, "MLR" is used for CFA models with continuous indicators (i.e., ordered = FALSE) and "WLSMV" is used for CFA model with ordered-categorical indicators (i.e., ordered = TRUE).

test

a character string indicating the test statistics, i.e., "none" for no test statistic, "standard" for a conventional chi-square test, "satorra.bentler" for a Satorra-Bentler scaled test statistic, "scaled.shifted" for a mean and variance adjusted test statistic (scaled and shifted), "mean.var.adjusted" for a mean and variance adjusted test statistic (Satterthwaite style), "yuan.bentler" for a Yuan-Bentler scaled test statistic, "yuan.bentler.mplus" for a test statistic which is asymptotically equivalent to the Yuan-Bentler T2-star test statistic, "browne.residual.adf" for a Browne’s residual-based test statistic using ADF theory, "browne.residual.nt" for Browne’s residual-based test statistic using normal theory, "mean.var.adjusted.corrected" and "scaled.shifted.corrected" for a test statistic with the corrected (unbiased) estimator of the trace of the squared UGamma matrix (Hayakawa, 2019), which remains accurate when the number of observed variables is large relative to the sample size. Note that the default setting is depending on the argument estimator and the argument cluster (see 'Details').

se

a character string indicating the standard errors, i.e., "none" for no standard errors, "standard" for conventional standard error based on inverting the expected observed or first.order information matrix, "robust.sem" for conventional robust standard errors, and "robust.huber.white" for the 'MLR' (aka pseudo ML, Huber-White) approach. The argument "se" is set to "two.stage" or "robust.two.stage" when specifying missing = "two.stage" or missing = "robust.two.stage". Note that the default setting is depending on the argument estimator and the argument cluster (see 'Details').

missing

a character string indicating how to deal with missing data, i.e., "listwise" for listwise deletion, "pairwise" for pairwise deletion, "fiml" for full information maximum likelihood method, "two.stage" for two-stage maximum likelihood method, "robust.two.stage" for robust two-stage maximum likelihood method, and "doubly-robust" for doubly-robust method (see 'Details'). By default, "fiml" is used for CFA models with continuous indicators when using estimator = "MLR", and "pairwise" for CFA models with ordered-categorical indicators when using estimator = "pairwise".

print

a character string or character vector indicating which results to show on the console, i.e. "all" for all results, "summary" for a summary of the specification of the estimation method and missing data handling in lavaan, "coverage" for the variance-covariance coverage of the data, "descript" for descriptive statistics, "fit" for model fit, "est" for parameter estimates, "modind" for modification indices, "resid" for the residual correlation, and "opdyke" for the discrepancy between model-implied and observed correlation expressed in terms of the relative percentile of an Opdyke distribution (McNeish, 2025). By default, a summary of the specification, model fit, and parameter estimates are printed. Note that "fit" will be excluded when specifying the argument test = "none".

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 \alpha = .01.

resid.minval

numeric value indicating the minimum absolute residual correlation coefficients and standardized means to highlight. 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 or by setting the argument color to "default".

opdyke.prec

a numeric value indicating the precision of the probability density function calculations of the Opdyke distribution. The default is 1 which calculates the PDF for polar angles between (0, pi) in 0.01 increments. Specifying 10 calculates the PDF polar angles between (0, pi) in 0.001 increments, which takes considerably longer, especially if there are many correlation elements.

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.

color

a character string indicating the text color for highlighting absolute residual correlation coefficients and standardized means equal or higher resid.minval and predicted correlations outside the minimum and maximum percentile of the Opdyke distribution, i.e., i.e., "default" for the default text color without color coding and various text colors for highlighting "red", "b.red" (default), "green", "b.green", "blue", or "b.blue", see the help page of the chr.color function. Note that this option is not supported when using R Markdown and when writing the output into a text file (.txt).

style

a character vector indicating the font style for highlighting absolute residual correlation coefficients and standardized means equal or higher resid.minval, i.e., "regular" (default) for regular text, "bold" for bold text, and "italic" for italic text. Note that the font style "bold" and "italic" can be combined, i.e., style = c("bold", "italic") provides a bold and italic text. Note that the argument color needs to be specified to change the style of the text, e.g. color = "black" and style = "bold" to for bold text.

digits

an integer value indicating the number of decimal places to be used for displaying results.

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 NA before conducting the analysis. Note that as.na() function is only applied to data but not to cluster.

write

a character string naming a file for writing the output into either a text file with file extension ".txt" (e.g., "Output.txt") or Excel file with file extension ".xlsx" (e.g., "Output.xlsx"). If the file name does not contain any file extension, an Excel file will be written.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown.

Details

Estimator

The R package lavaan provides seven estimators that affect the estimation, namely "ML", "GLS", "WLS", "DWLS", "ULS", "DLS", and "PML". All other options for the argument estimator combine these estimators with various standard error and chi-square test statistic computation. Note that the estimators also differ in how missing values can be dealt with (e.g., listwise deletion, pairwise deletion, or full information maximum likelihood, FIML).

  • "ML": Maximum likelihood with conventional standard errors (se = "standard") and conventional test statistic (test = "standard"). For both complete and incomplete data using pairwise deletion or FIML.

  • "MLM": Maximum likelihood parameter estimates with conventional robust standard errors (se = "robust.sem") and a Satorra-Bentler scaled test statistic (test = "satorra.bentler") that are robust to non-normality. For complete data only.

  • "MLMV": Maximum likelihood parameter estimates with conventional robust standard errors (se = "robust.sem") and a mean and a variance adjusted test statistic (test = "scaled.shifted") using a scale-shifted approach that are robust to non-normality. For complete data only.

  • "MLMVS": Maximum likelihood parameter estimates with conventional robust standard errors (se = "robust.sem") and a mean and a variance adjusted test statistic (test = "mean.var.adjusted") using the Satterthwaite approach that are robust to non-normality. For complete data only.

  • "MLF": Maximum likelihood parameter estimates with standard errors approximated by first-order derivatives (se = "standard") and conventional test statistic (test = "standard"). For both complete and incomplete data using pairwise deletion or FIML.

  • "MLR": Maximum likelihood parameter estimates with Huber-White robust standard errors (se = "robust.huber.white") a test statistic which is asymptotically equivalent to the Yuan-Bentler T2* test statistic (test = "yuan.bentler.mplus") that are robust to non-normality and non-independence of observed when specifying a cluster variable using the argument cluster. For both complete and incomplete data using pairwise deletion or FIML.

  • "GLS": Generalized least squares parameter estimates with conventional standard errors (se = "standard") and conventional test statistic (test = "standard") that uses a normal-theory based weight matrix. For complete data only.

  • "WLS": Weighted least squares parameter estimates (sometimes called ADF estimation) with conventional standard errors (se = "standard") and conventional test statistic that uses a full weight matrix (test = "standard"). For both complete and incomplete data using pairwise deletion.

  • "DWLS": Diagonally weighted least squares parameter estimates which uses the diagonal of the weight matrix for estimation with conventional standard errors (se = "standard") and conventional test statistic (test = "standard"). For both complete and incomplete data using pairwise deletion.

  • "WLSM": Diagonally weighted least squares parameter estimates which uses the diagonal of the weight matrix for estimation, but uses the full weight matrix for computing the conventional robust standard errors (se = "robust.sem") and a Satorra-Bentler scaled test statistic (test = "satorra.bentler"). For both complete and incomplete data using pairwise deletion.

  • "WLSMV": Diagonally weighted least squares parameter estimates which uses the diagonal of the weight matrix for estimation, but uses the full weight matrix for computing the conventional robust standard errors (se = "robust.sem") and a mean and a variance adjusted test statistic (test = "scaled.shifted") using a scale-shifted approach. For both complete and incomplete data using pairwise deletion.

  • "WLSMVS": Diagonally weighted least squares parameter estimates which uses the diagonal of the weight matrix for estimation, but uses the full weight matrix for computing the conventional robust standard errors (se = "robust.sem") and a mean and a variance adjusted test statistic (test = "mean.var.adjusted") using the Satterthwaite approach. For both complete and incomplete data using pairwise deletion.

  • "ULS": Unweighted least squares parameter estimates with conventional standard errors (se = "standard") and conventional test statistic (test = "standard"). For both complete and incomplete data using pairwise deletion.

  • "ULSM": Unweighted least squares parameter estimates with conventional robust standard errors (se = "robust.sem") and a Satorra-Bentler scaled test statistic (test = "satorra.bentler"). For both complete and incomplete data using pairwise deletion.

  • "ULSMV": Unweighted least squares parameter estimates with conventional robust standard errors (se = "robust.sem") and a mean and a variance adjusted test statistic (test = "scaled.shifted") using a scale-shifted approach. For both complete and incomplete data using pairwise deletion.

  • "ULSMVS": Unweighted least squares parameter estimates with conventional robust standard errors (se = "robust.sem") and a mean and a variance adjusted test statistic (test = "mean.var.adjusted") using the Satterthwaite approach. For both complete and incomplete data using pairwise deletion.

  • "DLS": Distributionally-weighted least squares parameter estimates with conventional robust standard errors (se = "robust.sem") and a Satorra-Bentler scaled test statistic (test = "satorra.bentler"). For complete data only.

  • "PML": Pairwise maximum likelihood parameter estimates with Huber-White robust standard errors (se = "robust.huber.white") and a mean and a variance adjusted test statistic (test = "mean.var.adjusted") using the Satterthwaite approach. For both complete and incomplete data using pairwise deletion.

Missing Data

The R package lavaan provides six methods for dealing with missing data:

  • "listwise": Listwise deletion, i.e., all cases with missing values are removed from the data before conducting the analysis. This is only valid if the data are missing completely at random (MCAR).

  • "pairwise": Pairwise deletion, i.e., each element of a variance-covariance matrix is computed using cases that have data needed for estimating that element. This is only valid if the data are missing completely at random (MCAR).

  • "fiml": Full information maximum likelihood (FIML) method, i.e., likelihood is computed case by case using all available data from that case. FIML method is only applicable for following estimators: "ML", "MLF", and "MLR".

  • "two.stage": Two-stage maximum likelihood estimation, i.e., sample statistics is estimated using EM algorithm in the first step. Then, these estimated sample statistics are used as input for a regular analysis. Standard errors and test statistics are adjusted correctly to reflect the two-step procedure. Two-stage method is only applicable for following estimators: "ML", "MLF", and "MLR".

  • "robust.two.stage": Robust two-stage maximum likelihood estimation, i.e., two-stage maximum likelihood estimation with standard errors and a test statistic that are robust against non-normality. Robust two-stage method is only applicable for following estimators: "ML", "MLF", and "MLR".

  • "doubly.robust": Doubly-robust method only applicable for pairwise maximum likelihood estimation (i.e., estimator = "PML").

Convergence and Model Idenfitification Checks

In line with the R package lavaan, this functions provides several checks for model convergence and model identification:

  • Degrees of freedom: An error message is printed if the number of degrees of freedom is negative, i.e., the model is not identified.

  • Model convergence: An error message is printed if the optimizer has not converged, i.e., results are most likely unreliable.

  • Standard errors: An error message is printed if the standard errors could not be computed, i.e., the model might not be identified.

  • Variance-covariance matrix of the estimated parameters: A warning message is printed if the variance-covariance matrix of the estimated parameters is not positive definite, i.e., the smallest eigenvalue of the matrix is smaller than zero or very close to zero.

  • Negative variances of observed variables: A warning message is printed if the estimated variances of the observed variables are negative.

  • Variance-covariance matrix of observed variables: A warning message is printed if the estimated variance-covariance matrix of the observed variables is not positive definite, i.e., the smallest eigenvalue of the matrix is smaller than zero or very close to zero.

  • Negative variances of latent variables: A warning message is printed if the estimated variances of the latent variables are negative.

  • Variance-covariance matrix of latent variables: A warning message is printed if the estimated variance-covariance matrix of the latent variables is not positive definite, i.e., the smallest eigenvalue of the matrix is smaller than zero or very close to zero.

Note that unlike the R package lavaan, the item.cfa function does not provide any results when the degrees of freedom is negative, the model has not converged, or standard errors could not be computed.

Model Fit

The item.cfa function provides the chi-square test, incremental fit indices (i.e., CFI and TLI), and absolute fit indices (i.e., RMSEA, and SRMR) to evaluate overall model fit. However, different versions of the CFI, TLI, and RMSEA are provided depending on the estimator. Unlike the R package lavaan, the different versions are labeled with Standard, Scaled, and Robust in the output:

  • "Standard": CFI, TLI, and RMSEA without any non-normality corrections. These fit measures based on the normal theory maximum likelihood test statistic are sensitive to deviations from multivariate normality of endogenous variables. Simulation studies by Brosseau-Liard et al. (2012), and Brosseau-Liard and Savalei (2014) showed that the uncorrected fit indices are affected by non-normality, especially at small and medium sample sizes (e.g., n < 500).

  • "Scaled": Population-corrected robust CFI, TLI, and RMSEA with ad hoc non-normality corrections that simply replace the maximum likelihood test statistic with a robust test statistic (e.g., mean-adjusted chi-square). These fit indices change the population value being estimated depending on the degree of non-normality present in the data. Brosseau-Liard et al. (2012) demonstrated that the ad hoc corrected RMSEA increasingly accepts poorly fitting models as non-normality in the data increases, while the effect of the ad hoc correction on the CFI and TLI is less predictable with non-normality making fit appear worse, better, or nearly unchanged (Brosseau-Liard & Savalei, 2014).

  • "Robust": Sample-corrected robust CFI, TLI, and RMSEA with non-normality corrections based on formula provided by Li and Bentler (2006) and Brosseau-Liard and Savalei (2014). These fit indices do not change the population value being estimated and can be interpreted the same way as the uncorrected fit indices when the data would have been normal.

In conclusion, the use of sample-corrected fit indices (Robust) instead of population-corrected fit indices (Scaled) is recommended. Note that when sample size is very small (e.g., n < 200), non-normality correction does not appear to adjust fit indices sufficiently to counteract the effect of non-normality (Brosseau-Liard & Savalei, 2014).

Modification Indices

The item.cfa function provides modification indices when requested by using the print argument. Modification indices (aka score tests) are univariate Lagrange Multipliers (LM) representing a chi-square statistic with a single degree of freedom. LM approximates the amount by which the chi-square test statistic would decrease if a fixed or constrained parameter is freely estimated (Kline, 2023). However, (standardized) expected parameter change (EPC) values should also be inspected since modification indices are sensitive to sample size. EPC values are an estimate of how much the parameter would be expected to change if it were freely estimated (Brown, 2023).

Residual Correlation Matrix

The item.cfa function provides the residual correlation matrix when requested by using the print argument. The residual correlation matrix is computed by separately converting the sample covariance and model-implied covariance matrices to correlation matrices before calculation differences between observed and predicted covariances (i.e., type = "cor.bollen"). As a rule of thumb, absolute correlation residuals greater than .10 indicate possible evidence for poor local fit, whereas smaller correlation residuals than 0.05 indicate negligible degree of model misfit (Maydeu-Olivares, 2017). There is no reliable connection between the size of diagnostic statistics (i.e., modification indices and residuals) and the type or amount of model misspecification since (1) diagnostic statistics are themselves affected by misspecification, (2) misspecification in one part of the model distorts estimates in other parts of the model (i.e., error propagation), and (3) equivalent models have identical residuals but contradict the pattern of causal effects (Kline, 2023). Note that according to Kline (2023) "any report of the results without information about the residuals is deficient" (p. 172).

Relative Opdyke Distribution Percentile Matrix

The item.cfa function provides the relative Opdyke distribution percentile matrix (McNeish, 2025) when requested by using the print argument. Approximate local fit evaluation based on the relative Opdyke distribution percentile does not rely on a fixed interval, such as the common r \pm 0.10 rule of thumb for interpreting correlation residuals. Instead, it is based on the percentiles of the distribution of values that an observed correlation could take while still yielding a valid correlation matrix. The Opdyke distribution for the observed correlation can determine the percentile rank associated with the model-implied correlation. Accordingly, approximate local fit can be evaluated by whether the model-implied correlation falls within a certain percentile of the observed correlation's distribution, rather than using a heuristic fixed interval. The observed correlation corresponds to the median of the Opdyke distribution, i.e., approximate fit can be gauged by proximity to the 50th percentile of the distribution. In other words, correlation discrepancies are expressed in terms of relative percentiles of the Opdyke distribution. Note that the common r \pm 0.10 rule of thumb for interpreting correlation residuals roughly corresponds to a model-implied correlation between the 40th and 60th percentiles of the observed correlation's Opdyke distribution. However, this rule may not necessarily generalize to all observed correlations. Note that Opdyke percentiles are only applicable to correlation structure elements, but are not applicable to mean structure residuals.

Value

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 data

args

specification of function arguments

model

specified model

model.fit

fitted lavaan object (mod.fit)

check

results of the convergence and model identification check

result

list with result tables, i.e., summary for the summary of the specification of the estimation method and missing data handling in lavaan, coverage for the variance-covariance coverage of the data, descript for descriptive statistics, fit for model fit est for parameter estimates, modind for modification indices, resid for the residual correlation matrices and standardized residual means, and opdyke for the relative Opdyke distribution percentile matrix

Note

The function uses the functions cfa, lavInspect, lavTech, modindices, parameterEstimates, and standardizedsolution 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).

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Brosseau-Liard, P. E., Savalei, V., & Li. L. (2012). An investigation of the sample performance of two nonnormality corrections for RMSEA, Multivariate Behavioral Research, 47, 904-930. https://doi.org/10.1080/00273171.2014.933697

Brosseau-Liard, P. E., & Savalei, V. (2014) Adjusting incremental fit indices for nonnormality. Multivariate Behavioral Research, 49, 460-470. https://doi.org/10.1080/00273171.2014.933697

Brown, T. A. (2023). Confirmatory factor analysis. In R. H. Hoyle (Ed.), Handbook of structural equation modeling (2nd ed.) (pp. 361–379). The Guilford Press.

Hayakawa K. (2019). Corrected goodness-of-fit test in covariance structure analysis. Psychological Methods, 24(3), 371-389. https://doi.org/10.1037/met0000180

Kline, R. B. (2023). Principles and practice of structural equation modeling (5th ed.). Guilford Press.

Li, L., & Bentler, P. M. (2006). Robust statistical tests for evaluating the hypothesis of close fit of misspecified mean and covariance structural models. UCLA Statistics Preprint #506. University of California.

Maydeu-Olivares, A. (2017). Assessing the size of model misfit in structural equation models. Psychometrika, 82(3), 533–558. https://doi.org/10.1007/s11336-016-9552-7

McNeish, D. (2025). Less Heuristic Approximate Local Fit Evaluation in Structural Equation Models. Structural Equation Modeling: A Multidisciplinary Journal, 32(4), 590-605. https://doi.org/10.1080/10705511.2025.2473342

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

See Also

item.alpha, item.omega, item.scores

Examples

## Not run: 

# Load data set "HolzingerSwineford1939" in the lavaan package
data("HolzingerSwineford1939", package = "lavaan")

#————————————————————————————————————————————————————————————————————————————
# Measurement Model with One Factor

# Example 1a: Specification using the argument '...'
item.cfa(HolzingerSwineford1939, x1:x3)

# Example 1b: Alternative specification without using the '...' argument
item.cfa(HolzingerSwineford1939[, c("x1", "x2", "x3")])

# Example 1c: Alternative specification using the argument 'model'
item.cfa(HolzingerSwineford1939, model = c("x1", "x2", "x3"))

# Example 1e: Alternative specification using the argument 'model'
item.cfa(HolzingerSwineford1939, model = list(visual = c("x1", "x2", "x3")))

#————————————————————————————————————————————————————————————————————————————
# Measurement Model with Three Factors

# Example 2: Specification using the argument 'model'
item.cfa(HolzingerSwineford1939,
         model = list(visual = c("x1", "x2", "x3"),
                      textual = c("x4", "x5", "x6"),
                      speed = c("x7", "x8", "x9")))

#————————————————————————————————————————————————————————————————————————————
# Residual Covariances

# Example 3a: One residual covariance
item.cfa(HolzingerSwineford1939,
         model = list(visual = c("x1", "x2", "x3"),
                      textual = c("x4", "x5", "x6"),
                      speed = c("x7", "x8", "x9")),
         rescov = c("x1", "x2"))

# Example 3b: Two residual covariances
item.cfa(HolzingerSwineford1939,
         model = list(visual = c("x1", "x2", "x3"),
                      textual = c("x4", "x5", "x6"),
                      speed = c("x7", "x8", "x9")),
         rescov = list(c("x1", "x2"), c("x4", "x5")))

#————————————————————————————————————————————————————————————————————————————
# Second-Order Factor Model based on Three First-Order Factors

# Example 4
item.cfa(HolzingerSwineford1939,
         model = list(visual = c("x1", "x2", "x3"),
                      textual = c("x4", "x5", "x6"),
                      speed = c("x7", "x8", "x9")), hierarch = TRUE)

#————————————————————————————————————————————————————————————————————————————
# Measurement Model with Ordered-Categorical Indicators

# Example 5
item.cfa(data.items, pitem1, pitem2r, pitem3r, pitem4, ordered = TRUE)

#————————————————————————————————————————————————————————————————————————————
# Cluster-Robust Standard Errors

# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")

# Example 6a: Specification using the '...' argument
item.cfa(y4:y6, data = Demo.twolevel, cluster = "cluster")

# Example 6b: Alternative specification without using the '...' argument
item.cfa(Demo.twolevel[, c("y4", "y5", "y6")], cluster = Demo.twolevel$cluster)

# Example 6c: Alternative specification without using the '...' argument
item.cfa(Demo.twolevel[, c("y4", "y5", "y6", "cluster")], cluster = "cluster")

#————————————————————————————————————————————————————————————————————————————
# Argument 'print'

# Example 7a: Request all results
item.cfa(HolzingerSwineford1939, x1::x9, print = "all")

# Example 7b: Request modification indices with value equal or higher than 20
item.cfa(HolzingerSwineford1939, x1::x9, print = "modind", mod.minval = 20)

# Example 7c: Highlight absolute residual correlation equal or higher than 0.05
item.cfa(HolzingerSwineford1939, x1::x9, print = "resid", resid.minval = 0.05,
         color = "b.blue")

# Example 7d: Highlight Opdyke distribution percentiles outside 0.45 and 0.55
item.cfa(HolzingerSwineford1939, x1::x9, print = "opdyke", opdyke.minmax = c(0.45, 0.55),
         color = "black", style = "bold")

#————————————————————————————————————————————————————————————————————————————
# lavaan Summary of the Estimated Model

# Example 8
mod <- item.cfa(HolzingerSwineford1939, x1, x2, x3, output = FALSE)

lavaan::summary(mod$model.fit, standardized = TRUE, fit.measures = TRUE)

#————————————————————————————————————————————————————————————————————————————
# Write Results

# Example 9a: Write Results into a text file
item.cfa(HolzingerSwineford1939, x1, x2, x3, print = "all", write = "CFA.txt")

# Example 9b: Write Results into an Excel file
item.cfa(HolzingerSwineford1939, x1, x2, x3, print = "all", write = "CFA.xlsx")

## End(Not run)

misty documentation built on Aug. 2, 2026, 9:06 a.m.

Related to item.cfa in misty...