predict.lm_list function

Predicted Values of an 'lm_list'-Class Object

Predicted Values of an 'lm_list'-Class Object

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, ...)

Arguments

  • 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 x to y. A numeric vector of the names of the mediators. The path goes from the first element to the last element. For example, if m = c("m1", "m2"), then the path is x -> m1 -> m2 -> y.
  • newdata: Required. A data frame of the new data. It must be a data frame.
  • ...: Additional arguments. Ignored.

Returns

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

Details

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.

Examples

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)

See Also

lm2list()

  • Maintainer: Shu Fai Cheung
  • License: GPL (>= 3)
  • Last published: 2025-01-25