Debian Codegraph @

man/augment.survreg.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/survival-survreg.R
3 \name{augment.survreg}
4 \alias{augment.survreg}
5 \title{Augment data with information from a(n) survreg object}
6 \usage{
7 \method{augment}{survreg}(
8 x,
9 data = model.frame(x),
10 newdata = NULL,
11 type.predict = "response",
12 type.residuals = "response",
13 ...
14 )
15 }
16 \arguments{
17 \item{x}{An \code{survreg} object returned from \code{\link[survival:survreg]{survival::survreg()}}.}
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 \examples{
94 \dontshow{if (rlang::is_installed(c("survival", "ggplot2"))) withAutoprint(\{ # examplesIf}
95
96 # load libraries for models and data
97 library(survival)
98
99 # fit model
100 sr <- survreg(
101 Surv(futime, fustat) ~ ecog.ps + rx,
102 ovarian,
103 dist = "exponential"
104 )
105
106 # summarize model fit with tidiers + visualization
107 tidy(sr)
108 augment(sr, ovarian)
109 glance(sr)
110
111 # coefficient plot
112 td <- tidy(sr, conf.int = TRUE)
113
114 library(ggplot2)
115
116 ggplot(td, aes(estimate, term)) +
117 geom_point() +
118 geom_errorbarh(aes(xmin = conf.low, xmax = conf.high), height = 0) +
119 geom_vline(xintercept = 0)
120 \dontshow{\}) # examplesIf}
121 }
122 \seealso{
123 \code{\link[=augment]{augment()}}, \code{\link[survival:survreg]{survival::survreg()}}
124
125 Other survreg tidiers:
126 \code{\link{glance.survreg}()},
127 \code{\link{tidy.survreg}()}
128
129 Other survival tidiers:
130 \code{\link{augment.coxph}()},
131 \code{\link{glance.aareg}()},
132 \code{\link{glance.cch}()},
133 \code{\link{glance.coxph}()},
134 \code{\link{glance.pyears}()},
135 \code{\link{glance.survdiff}()},
136 \code{\link{glance.survexp}()},
137 \code{\link{glance.survfit}()},
138 \code{\link{glance.survreg}()},
139 \code{\link{tidy.aareg}()},
140 \code{\link{tidy.cch}()},
141 \code{\link{tidy.coxph}()},
142 \code{\link{tidy.pyears}()},
143 \code{\link{tidy.survdiff}()},
144 \code{\link{tidy.survexp}()},
145 \code{\link{tidy.survfit}()},
146 \code{\link{tidy.survreg}()}
147 }
148 \concept{survival tidiers}
149 \concept{survreg tidiers}
150 \value{
151 A \code{\link[tibble:tibble]{tibble::tibble()}} with columns:
152 \item{.fitted}{Fitted or predicted value.}
153 \item{.resid}{The difference between observed and fitted values.}
154 \item{.se.fit}{Standard errors of fitted values.}
155
156 }