| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/mgcv.R |
| 3 |
\name{augment.gam} |
| 4 |
\alias{augment.gam} |
| 5 |
\title{Augment data with information from a(n) gam object} |
| 6 |
\usage{ |
| 7 |
\method{augment}{gam}( |
| 8 |
x, |
| 9 |
data = model.frame(x), |
| 10 |
newdata = NULL, |
| 11 |
type.predict, |
| 12 |
type.residuals, |
| 13 |
... |
| 14 |
) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{x}{A \code{gam} object returned from a call to \code{\link[mgcv:gam]{mgcv::gam()}}.} |
| 18 |
|
| 19 |
\item{data}{A \link[base:data.frame]{base::data.frame} or \code{\link[tibble:tibble]{tibble::tibble()}} containing the original |
| 20 |
data that was used to produce the object \code{x}. Defaults to |
| 21 |
\code{stats::model.frame(x)} so that \code{augment(my_fit)} returns the augmented |
| 22 |
original data. \strong{Do not} pass new data to the \code{data} argument. |
| 23 |
Augment will report information such as influence and cooks distance for |
| 24 |
data passed to the \code{data} argument. These measures are only defined for |
| 25 |
the original training data.} |
| 26 |
|
| 27 |
\item{newdata}{A \code{\link[base:data.frame]{base::data.frame()}} or \code{\link[tibble:tibble]{tibble::tibble()}} containing all |
| 28 |
the original predictors used to create \code{x}. Defaults to \code{NULL}, indicating |
| 29 |
that nothing has been passed to \code{newdata}. If \code{newdata} is specified, |
| 30 |
the \code{data} argument will be ignored.} |
| 31 |
|
| 32 |
\item{type.predict}{Character indicating type of prediction to use. Passed |
| 33 |
to the \code{type} argument of the \code{\link[stats:predict]{stats::predict()}} generic. Allowed arguments |
| 34 |
vary with model class, so be sure to read the \code{predict.my_class} |
| 35 |
documentation.} |
| 36 |
|
| 37 |
\item{type.residuals}{Character indicating type of residuals to use. Passed |
| 38 |
to the \code{type} argument of \code{\link[stats:residuals]{stats::residuals()}} generic. Allowed arguments |
| 39 |
vary with model class, so be sure to read the \code{residuals.my_class} |
| 40 |
documentation.} |
| 41 |
|
| 42 |
\item{...}{Additional arguments. Not used. Needed to match generic |
| 43 |
signature only. \strong{Cautionary note:} Misspelled arguments will be |
| 44 |
absorbed in \code{...}, where they will be ignored. If the misspelled |
| 45 |
argument has a default value, the default value will be used. |
| 46 |
For example, if you pass \code{conf.lvel = 0.9}, all computation will |
| 47 |
proceed using \code{conf.level = 0.95}. Two exceptions here are: |
| 48 |
\itemize{ |
| 49 |
\item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if |
| 50 |
it will be ignored. |
| 51 |
\item \code{augment()} methods will warn when supplied a \code{newdata} argument if it |
| 52 |
will be ignored. |
| 53 |
}} |
| 54 |
} |
| 55 |
\description{ |
| 56 |
Augment accepts a model object and a dataset and adds |
| 57 |
information about each observation in the dataset. Most commonly, this |
| 58 |
includes predicted values in the \code{.fitted} column, residuals in the |
| 59 |
\code{.resid} column, and standard errors for the fitted values in a \code{.se.fit} |
| 60 |
column. New columns always begin with a \code{.} prefix to avoid overwriting |
| 61 |
columns in the original dataset. |
| 62 |
|
| 63 |
Users may pass data to augment via either the \code{data} argument or the |
| 64 |
\code{newdata} argument. If the user passes data to the \code{data} argument, |
| 65 |
it \strong{must} be exactly the data that was used to fit the model |
| 66 |
object. Pass datasets to \code{newdata} to augment data that was not used |
| 67 |
during model fitting. This still requires that at least all predictor |
| 68 |
variable columns used to fit the model are present. If the original outcome |
| 69 |
variable used to fit the model is not included in \code{newdata}, then no |
| 70 |
\code{.resid} column will be included in the output. |
| 71 |
|
| 72 |
Augment will often behave differently depending on whether \code{data} or |
| 73 |
\code{newdata} is given. This is because there is often information |
| 74 |
associated with training observations (such as influences or related) |
| 75 |
measures that is not meaningfully defined for new observations. |
| 76 |
|
| 77 |
For convenience, many augment methods provide default \code{data} arguments, |
| 78 |
so that \code{augment(fit)} will return the augmented training data. In these |
| 79 |
cases, augment tries to reconstruct the original data based on the model |
| 80 |
object with varying degrees of success. |
| 81 |
|
| 82 |
The augmented dataset is always returned as a \link[tibble:tibble]{tibble::tibble} with the |
| 83 |
\strong{same number of rows} as the passed dataset. This means that the passed |
| 84 |
data must be coercible to a tibble. If a predictor enters the model as part |
| 85 |
of a matrix of covariates, such as when the model formula uses |
| 86 |
\code{\link[splines:ns]{splines::ns()}}, \code{\link[stats:poly]{stats::poly()}}, or \code{\link[survival:Surv]{survival::Surv()}}, it is represented |
| 87 |
as a matrix column. |
| 88 |
|
| 89 |
We are in the process of defining behaviors for models fit with various |
| 90 |
\code{na.action} arguments, but make no guarantees about behavior when data is |
| 91 |
missing at this time. |
| 92 |
} |
| 93 |
\details{ |
| 94 |
For additional details on Cook's distance, see |
| 95 |
\code{\link[stats:influence.measures]{stats::cooks.distance()}}. |
| 96 |
} |
| 97 |
\examples{ |
| 98 |
\dontshow{if (rlang::is_installed("mgcv")) withAutoprint(\{ # examplesIf} |
| 99 |
|
| 100 |
# load libraries for models and data |
| 101 |
library(mgcv) |
| 102 |
|
| 103 |
# fit model |
| 104 |
g <- gam(mpg ~ s(hp) + am + qsec, data = mtcars) |
| 105 |
|
| 106 |
# summarize model fit with tidiers |
| 107 |
tidy(g) |
| 108 |
tidy(g, parametric = TRUE) |
| 109 |
glance(g) |
| 110 |
augment(g) |
| 111 |
\dontshow{\}) # examplesIf} |
| 112 |
} |
| 113 |
\seealso{ |
| 114 |
\code{\link[=augment]{augment()}}, \code{\link[mgcv:gam]{mgcv::gam()}} |
| 115 |
} |
| 116 |
\value{ |
| 117 |
A \code{\link[tibble:tibble]{tibble::tibble()}} with columns: |
| 118 |
\item{.cooksd}{Cooks distance.} |
| 119 |
\item{.fitted}{Fitted or predicted value.} |
| 120 |
\item{.hat}{Diagonal of the hat matrix.} |
| 121 |
\item{.resid}{The difference between observed and fitted values.} |
| 122 |
\item{.se.fit}{Standard errors of fitted values.} |
| 123 |
\item{.sigma}{Estimated residual standard deviation when corresponding observation is dropped from model.} |
| 124 |
|
| 125 |
} |