predict.mid: Predict Method for fitted MID Models

View source: R/predict_mid.R

predict.midR Documentation

Predict Method for fitted MID Models

Description

predict.mid() is an S3 method for "mid" objects that obtains predictions from a fitted MID model. It can be used to predict on new data or to retrieve the fitted values from the original data.

Usage

## S3 method for class 'mid'
predict(
  object,
  newdata = NULL,
  na.action = "na.pass",
  type = c("response", "link", "terms"),
  terms = object$terms,
  ...
)

Arguments

object

a "mid" object to be used to make predictions.

newdata

a data frame of the new observations. If NULL, the original fitted values are extracted and returned.

na.action

a function or character string specifying what should happen when the data contain NA values.

type

the type of prediction required. One of "response", "link", or "terms".

terms

a character vector of term labels, specifying a subset of component functions to use for predictions.

...

arguments to be passed to other methods (not used in this method).

Details

The type argument allows you to specify the scale of the prediction. By default (type = "response"), the function returns predictions on the original scale of the response variable. Alternatively, you can obtain predictions on the scale of the linear predictor by setting type = "link". For a detailed breakdown, setting type = "terms" returns a matrix where each column represents the contribution of a specific model term on the linear predictor scale.

The terms argument allows for predictions based on a subset of the model's component functions, excluding others.

Value

predict.mid() returns a numeric vector of MID model predictions, or a matrix if type = "terms".

See Also

interpret, mid.effect, get.yhat

Examples

data(airquality, package = "datasets")
test <- 1:10
mid <- interpret(Ozone ~ .^2, airquality[-test, ], lambda = 1, link = "log")

# Predict on new data
predict(mid, airquality[test, ])

# Get predictions on the link scale
predict(mid, airquality[test, ], type = "link")

# Get the contributions of specific terms
predict(mid, airquality[test, ], terms = c("Temp", "Wind"), type = "terms")

midr documentation built on Sept. 11, 2025, 1:07 a.m.