predict.lm_from_lavaan: Predicted Values of a 'lm_from_lavaan'-Class Object

View source: R/lavaan2lm_list.R

predict.lm_from_lavaanR Documentation

Predicted Values of a 'lm_from_lavaan'-Class Object

Description

Compute the predicted values based on the model stored in a 'lm_from_lavaan'-class object.

Usage

## S3 method for class 'lm_from_lavaan'
predict(object, newdata, ...)

Arguments

object

A 'lm_from_lavaan'-class object.

newdata

Required. A data frame of the new data. It must be a data frame.

...

Additional arguments. Ignored.

Details

An lm_from_lavaan-class method that converts a regression model for a variable in a lavaan model to a formula object. This function uses the stored model to compute predicted values using user-supplied data.

This is an advanced helper used by plot.cond_indirect_effects(). Exported for advanced users and developers.

Value

A numeric vector of the predicted values, with length equal to the number of rows of user-supplied data.

See Also

lm_from_lavaan_list()

Examples

library(lavaan)
data(data_med)
mod <-
"
m ~ a * x + c1 + c2
y ~ b * m + x + c1 + c2
"
fit <- sem(mod, data_med, fixed.x = FALSE)
fit_list <- lm_from_lavaan_list(fit)
tmp <- data.frame(x = 1, c1 = 2, c2 = 3, m = 4)
predict(fit_list$m, newdata = tmp)
predict(fit_list$y, newdata = tmp)


manymome documentation built on Oct. 4, 2024, 5:10 p.m.