| prediction-package {prediction} | R Documentation |
Extract predicted values via predict from a model object, conditional on data, and return a data frame.
prediction(model, ...)
## Default S3 method:
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = "response", ...)
## S3 method for class 'Arima'
prediction(model, ...)
## S3 method for class 'ar'
prediction(model, data, at = NULL, ...)
## S3 method for class 'arima0'
prediction(model, data, at = NULL, ...)
## S3 method for class 'betareg'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "link", "precision", "variance",
"quantile"), ...)
## S3 method for class 'clm'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = NULL, category, ...)
## S3 method for class 'coxph'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("risk", "expected", "lp"), ...)
## S3 method for class 'crch'
prediction(model, data = find_data(model), at = NULL,
type = c("response", "location", "scale", "quantile"), ...)
## S3 method for class 'gam'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "link", "terms"), ...)
## S3 method for class 'gee'
prediction(model, ...)
## S3 method for class 'glm'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "link"), ...)
## S3 method for class 'glmx'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "link"), ...)
## S3 method for class 'gls'
prediction(model, data = find_data(model), at = NULL, ...)
## S3 method for class 'hetglm'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "link", "scale"), ...)
## S3 method for class 'hurdle'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "count", "prob", "zero"), ...)
## S3 method for class 'hxlr'
prediction(model, data = find_data(model), at = NULL,
type = c("class", "probability", "cumprob", "location", "scale"), ...)
## S3 method for class 'ivreg'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, ...)
## S3 method for class 'lm'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = "response", ...)
## S3 method for class 'lme'
prediction(model, data = find_data(model), at = NULL, ...)
## S3 method for class 'loess'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = "response", ...)
## S3 method for class 'lqs'
prediction(model, data = find_data(model), at = NULL, ...)
## S3 method for class 'mca'
prediction(model, data = find_data(model), at = NULL, ...)
## S3 method for class 'mclogit'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "link"), ...)
## S3 method for class 'merMod'
prediction(model, data = find_data(model), at = NULL,
type = c("response", "link"), ...)
## S3 method for class 'mnlogit'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, category, ...)
## S3 method for class 'mnp'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = NULL, category, ...)
## S3 method for class 'multinom'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = NULL, category, ...)
## S3 method for class 'nls'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, ...)
## S3 method for class 'nnet'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = NULL, category, ...)
## S3 method for class 'plm'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, ...)
## S3 method for class 'polr'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = NULL, category, ...)
## S3 method for class 'ppr'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, ...)
## S3 method for class 'princomp'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, ...)
## S3 method for class 'rlm'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = "response", ...)
## S3 method for class 'rq'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, ...)
## S3 method for class 'selection'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = "response", ...)
## S3 method for class 'survreg'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "lp", "quantile", "uquantile"), ...)
## S3 method for class 'svm'
prediction(model, data = NULL, at = NULL, category, ...)
## S3 method for class 'svyglm'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "link"), ...)
## S3 method for class 'zeroinfl'
prediction(model, data = find_data(model, parent.frame()),
at = NULL, type = c("response", "count", "prob", "zero"), ...)
model |
|
... |
Additional arguments passed to |
data |
A data.frame over which to calculate marginal effects. If missing, |
at |
A list of one or more named vectors, specifically values at which to calculate the predictions. These are used to modify the value of |
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). For models of class “polr” (from |
category |
For multi-level or multi-category outcome models (e.g., ordered probit, multinomial logit, etc.), a value specifying which of the outcome levels should be used for the |
This function is simply a wrapper around predict that returns a data frame containing the value of data and the predicted values with respect to all variables specified in data.
Methods are currently implemented for the following object classes:
“lm”, see lm
“ar”, see ar
“Arima”, see arima
“arima0”, see arima0
“betareg”, see betareg
“clm”, see clm
“coxph”, see coxph
“crch”, see crch
“gam”, see gam
“gee”, see gee
“gls”, see gls
“hurdle”, see hurdle
“hxlr”, see hxlr
“ivreg”, see ivreg
“lda”, see lda
“lme”, see lme
“loess”, see loess
“lqs”, see lqs
“mca”, see mca
“mclogit”, see mclogit
“mnlogit”, see mnlogit
“mnp”, see mnp
“naiveBayes”, see naiveBayes
“nlme”, see nlme
“nls”, see nls
“nnet”, see nnet
“plm”, see plm
“polr”, see polr
“ppr”, see ppr
“princomp”, see princomp
“qda”, see qda
“rlm”, see rlm
“rq”, see rq
“selection”, see selection
“survreg”, see survreg
“svm”, see svm
“svyglm”, see svyglm
“zeroinfl”, see zeroinfl
A data frame with class “prediction” that has a number of rows equal to number of rows in data, or a multiple thereof, if !is.null(at). The return value contains data (possibly modified by at using build_datalist), plus a column containing fitted/predicted values ("fitted") and a column containing the standard errors thereof ("se.fitted"). Additional columns may be reported depending on the object class.
find_data, build_datalist, mean_or_mode, seq_range
require("datasets")
x <- lm(Petal.Width ~ Sepal.Length * Sepal.Width * Species, data = iris)
# prediction for every case
prediction(x)
# prediction for first case
prediction(x, iris[1,])
# basic use of 'at' argument
prediction(x, at = list(Species = c("setosa", "virginica")))
# prediction at means/modes of input variables
prediction(x, at = lapply(iris, mean_or_mode))
# prediction with multi-category outcome
## Not run:
library("mlogit")
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
mod <- mlogit(mode ~ price + catch, data = Fish)
prediction(mod)
prediction(mod, category = 3)
## End(Not run)