Learn R Programming

margins (version 0.2.0)

prediction: Extract Predictions from a Model Object

Description

Extract predicted values via predict from a model object, conditional on data

Usage

prediction(model, data, type = c("response", "link"))

Arguments

model

A model object, perhaps returned by lm or glm.

data

A data.frame over which to calculate marginal effects.

type

A character string indicating the type of marginal effects to estimate. Mostly relevant for non-linear models, where the reasonable options are “response” (the default) or “link” (i.e., on the scale of the linear predictor in a GLM).

Value

An data.frame with number of rows equal to number of rows in data, where each row is an observation and the two columns represent fitted/predicted values and the standard errors thereof. require("datasets") x <- lm(mpg ~ cyl * hp + wt, data = mtcars) prediction(x)

Details

This function is simply a wrapper around predict that returns a data.frame containing predicted values with respect to all variables specified in data. It is used internally by build_margins.

See Also

marginal_effects, build_margins