user_change_raw: Case Influence on User-Defined Statistics

View source: R/est_change_raw_user.R

user_change_rawR Documentation

Case Influence on User-Defined Statistics

Description

Gets a lavaan_rerun() output and computes the changes in user-defined statistics for each case if included.

Usage

user_change_raw(rerun_out, user_function = NULL, ..., fit_name = NULL)

Arguments

rerun_out

The output from lavaan_rerun().

user_function

A function that accepts a lavaan-class object. This function is for computing user-defined statistics.

...

Optional arguments to be passed to user_function.

fit_name

If the function does not accept the lavaan-class object as its first argument, this should be the name of the argument of user_function for the lavaan-class object. For example, if the function is of the form foo(x = "x1", y = "y2", my_fit = fit), where fit should be the lavaan-class object, set fit_name to "my_fit" for passing teh lavaan-class object to the function.

Details

For each case, user_change_raw() computes the differences in user-defined statistics with and without this case:

(User statistics with all case) - (User statistics without this case).

The change is the raw change. The change is not divided by standard error. This is a measure of the influence of a case on the use-defined statistics if it is included.

If the value of a case is positive, including the case increases a statistic.

If the value of a case is negative, including the case decreases a statistic.

The user-defined statistics are computed by a user-supplied function, user_function. It must return a vector-like object (which can have only one value). If the vector is not named, names will be created as user_1, user_2, and so on.

Value

An est_change-class object, which is a matrix with the number of columns equals to the number of values returned by user_function when computed in one lavaan-class object, and the number of rows equals to the number of cases. The row names are the case identification values used in lavaan_rerun(). The elements are the raw differences. A print method is available for user-friendly output.

Author(s)

Shu Fai Cheung https://orcid.org/0000-0002-9871-9448.

References

Pek, J., & MacCallum, R. (2011). Sensitivity analysis in structural equation models: Cases and their influence. Multivariate Behavioral Research, 46(2), 202-228. doi:10.1080/00273171.2011.561068

Examples


# A path model

library(lavaan)
dat <- pa_dat
mod <-
"
m1 ~ a1 * iv1 + a2 * iv2
dv ~ b * m1
a1b := a1 * b
a2b := a2 * b
"
# Fit the model
fit <- sem(mod, dat)
summary(fit)
# Fit the model several times. Each time with one case removed.
# For illustration, do this only for four selected cases
fit_rerun <- lavaan_rerun(fit, parallel = FALSE,
                          to_rerun = c(2, 4, 7, 9))
# Get the R-squares
lavInspect(fit, what = "rsquare")
out <- user_change_raw(fit_rerun,
                       user_function = lavInspect,
                       what = "rsquare")
out

# Index plot
p <- index_plot(out,
                column = "dv",
                plot_title = "R-square: dv")
p



semfindr documentation built on April 3, 2025, 5:58 p.m.