Debian Codegraph @

man/augment.glm.Rd

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