View source: R/predict_lm_list.R
predict.lm_list | R Documentation |
Compute the predicted values based on the models stored in an 'lm_list'-class object.
## S3 method for class 'lm_list'
predict(object, x = NULL, y = NULL, m = NULL, newdata, ...)
object |
An 'lm_list'-class object. |
x |
The variable name at the start of a path. |
y |
The variable name at the end of a path. |
m |
Optional. The mediator(s)
from |
newdata |
Required. A data frame of the new data. It must be a data frame. |
... |
Additional arguments. Ignored. |
An lm_list
-class object is
a list of lm
-class objects, this
function is similar to the
stats::predict()
method of lm()
but it works on a system defined by a
list of regression models.
This is an advanced helper used by some functions in this package. Exported for advanced users.
A numeric vector of the predicted values, with length equal to the number of rows of user-supplied data.
lm2list()
data(data_serial_parallel)
lm_m11 <- lm(m11 ~ x + c1 + c2, data_serial_parallel)
lm_m12 <- lm(m12 ~ m11 + x + c1 + c2, data_serial_parallel)
lm_m2 <- lm(m2 ~ x + c1 + c2, data_serial_parallel)
lm_y <- lm(y ~ m11 + m12 + m2 + x + c1 + c2, data_serial_parallel)
# Join them to form a lm_list-class object
lm_serial_parallel <- lm2list(lm_m11, lm_m12, lm_m2, lm_y)
lm_serial_parallel
summary(lm_serial_parallel)
newdat <- data_serial_parallel[3:5, ]
predict(lm_serial_parallel,
x = "x",
y = "y",
m = "m2",
newdata = newdat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.