Predicted Values of a 'lm_from_lavaan'-Class Object
Source:R/lavaan2lm_list.R
predict.lm_from_lavaan.Rd
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, ...)
Value
A numeric vector of the predicted values, with length equal to the number of rows of user-supplied data.
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.
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)
#> [1] 0.8250255
predict(fit_list$y, newdata = tmp)
#> [1] 3.464241