predict_across: Predict a Subset of Responses

View source: R/predict.R

predict_acrossR Documentation

Predict a Subset of Responses

Description

Predict across selected responses in a mediation model object. This is a lower-level version of the predict method that applies to objets of class mediation_model. Rather than giving predictions across all outcomes, it supports predictions across a subset specified as a vector. This can be convenient when we want to analyze how a specific subset of outcomes changes and do not need to run predictions across all possible.

Usage

predict_across(object, newdata, name)

Arguments

object

An object of class model containing an estimated model.

newdata

A data.frame containing new inputs from which to sample responses. If NULL, defaults to the data used to estimate fit.

name

A string or index specifying which of the dimensions of a multiresponse prediction to extract.

Value

A vector of predicted values for the outcome of interest.

Examples

exper <- demo_spline(tau = c(2, 1)) |>
    mediation_data(starts_with("outcome"), "treatment", "mediator")
fit <- multimedia(exper) |>
    estimate(exper)
predict_across(outcome_model(fit), NULL, "outcome_1")

# predict at newdata
newdata <- bind_mediation(exper)
predict_across(
    outcome_model(fit),
    newdata[seq_len(5), ],
    c("outcome_1", "outcome_2")
)

multimedia documentation built on Sept. 30, 2024, 9:28 a.m.