Learn R Programming

semhelpinghands (version 0.1.14)

compare_estimators: Refit a 'lavaan'-Model by Several Estimators

Description

Refit a model in 'lavaan' by several lavaan-supported estimators

Usage

compare_estimators(object, estimators = NULL)

se_ratios(fit_list, reference = NULL)

Value

A list of lavaan outputs, each of them is an update of the original output using one of the estimators.

Arguments

object

A 'lavaan'-class object.

estimators

A character vector of the estimator supported by the estimator argument of lavaan::lavaan() and its wrappers, such as lavaan::sem() and lavaan::cfa().

fit_list

The output of compare_estimators().

reference

The name of the reference method (ratios will be equal to one). Must be one of the estimator used on compare_estimators(). If NULL, the first estimator will be used.

Functions

  • compare_estimators(): Refit the model with different estimators.

  • se_ratios(): A wrapper of group_by_models() that computes the ratios of standard errors of different methods to those of one method.

Details

The function simply uses lapply() and update() to rerun the analysis once for each of the estimator using update(object, estimator = "x", x being the estimator.

The results can then be compared using group_by_models().

See Also

group_by_models()

Examples

Run this code

library(lavaan)
set.seed(5478374)
n <- 50
x <- runif(n) - .5
m <- .40 * x + rnorm(n, 0, sqrt(1 - .40))
y <- .30 * m + rnorm(n, 0, sqrt(1 - .30))
dat <- data.frame(x = x, y = y, m = m)
model <-
'
m ~ a*x
y ~ b*m
ab := a*b
'

fit <- sem(model, data = dat, fixed.x = FALSE)

# Refit the model by three different estimators
fit_more <- compare_estimators(fit, estimator = c("GLS", "MLR", "ML"))

# Use group_by_models to compare the estimates
group_by_models(fit_more, col_names = c("est", "pvalue"))

# Use se_ratios to compare standard errors
se_ratios(fit_more, reference = "ML")

Run the code above in your browser using DataLab