Debian Codegraph @

man/augment.rq.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/quantreg-rq.R
3 \name{augment.rq}
4 \alias{augment.rq}
5 \title{Augment data with information from a(n) rq object}
6 \usage{
7 \method{augment}{rq}(x, data = model.frame(x), newdata = NULL, ...)
8 }
9 \arguments{
10 \item{x}{An \code{rq} object returned from \code{\link[quantreg:rq]{quantreg::rq()}}.}
11
12 \item{data}{A \link[base:data.frame]{base::data.frame} or \code{\link[tibble:tibble]{tibble::tibble()}} containing the original
13 data that was used to produce the object \code{x}. Defaults to
14 \code{stats::model.frame(x)} so that \code{augment(my_fit)} returns the augmented
15 original data. \strong{Do not} pass new data to the \code{data} argument.
16 Augment will report information such as influence and cooks distance for
17 data passed to the \code{data} argument. These measures are only defined for
18 the original training data.}
19
20 \item{newdata}{A \code{\link[base:data.frame]{base::data.frame()}} or \code{\link[tibble:tibble]{tibble::tibble()}} containing all
21 the original predictors used to create \code{x}. Defaults to \code{NULL}, indicating
22 that nothing has been passed to \code{newdata}. If \code{newdata} is specified,
23 the \code{data} argument will be ignored.}
24
25 \item{...}{
26 Arguments passed on to \code{\link[quantreg:predict.rq]{quantreg::predict.rq}}
27 \describe{
28 \item{\code{object}}{ object of class rq or rqs or rq.process produced by \code{rq} }
29 \item{\code{interval}}{type of interval desired: default is 'none', when set to
30 'confidence' the function returns a matrix predictions with point predictions
31 for each of the 'newdata' points as well as lower and upper confidence limits.}
32 \item{\code{level}}{converage probability for the 'confidence' intervals.}
33 \item{\code{type}}{For \code{predict.rq}, the method for 'confidence' intervals, if desired.
34 If 'percentile' then one of the bootstrap methods is used to generate percentile
35 intervals for each prediction, if 'direct' then a version of the Portnoy and Zhou
36 (1998) method is used, and otherwise an estimated covariance matrix for the parameter
37 estimates is used. Further arguments to determine the choice of bootstrap
38 method or covariance matrix estimate can be passed via the \dots argument.
39 For \code{predict.rqs} and \code{predict.rq.process} when \code{stepfun = TRUE},
40 \code{type} is "Qhat", "Fhat" or "fhat" depending on whether the user would
41 like to have estimates of the conditional quantile, distribution or density functions
42 respectively. As noted below the two former estimates can be monotonized with the
43 function \code{rearrange}. When the "fhat" option is invoked, a list of conditional
44 density functions is returned based on Silverman's adaptive kernel method as
45 implemented in \code{akj} and \code{approxfun}.}
46 \item{\code{na.action}}{ function determining what should be done with missing values
47 in 'newdata'. The default is to predict 'NA'.}
48 }}
49 }
50 \description{
51 Augment accepts a model object and a dataset and adds
52 information about each observation in the dataset. Most commonly, this
53 includes predicted values in the \code{.fitted} column, residuals in the
54 \code{.resid} column, and standard errors for the fitted values in a \code{.se.fit}
55 column. New columns always begin with a \code{.} prefix to avoid overwriting
56 columns in the original dataset.
57
58 Users may pass data to augment via either the \code{data} argument or the
59 \code{newdata} argument. If the user passes data to the \code{data} argument,
60 it \strong{must} be exactly the data that was used to fit the model
61 object. Pass datasets to \code{newdata} to augment data that was not used
62 during model fitting. This still requires that at least all predictor
63 variable columns used to fit the model are present. If the original outcome
64 variable used to fit the model is not included in \code{newdata}, then no
65 \code{.resid} column will be included in the output.
66
67 Augment will often behave differently depending on whether \code{data} or
68 \code{newdata} is given. This is because there is often information
69 associated with training observations (such as influences or related)
70 measures that is not meaningfully defined for new observations.
71
72 For convenience, many augment methods provide default \code{data} arguments,
73 so that \code{augment(fit)} will return the augmented training data. In these
74 cases, augment tries to reconstruct the original data based on the model
75 object with varying degrees of success.
76
77 The augmented dataset is always returned as a \link[tibble:tibble]{tibble::tibble} with the
78 \strong{same number of rows} as the passed dataset. This means that the passed
79 data must be coercible to a tibble. If a predictor enters the model as part
80 of a matrix of covariates, such as when the model formula uses
81 \code{\link[splines:ns]{splines::ns()}}, \code{\link[stats:poly]{stats::poly()}}, or \code{\link[survival:Surv]{survival::Surv()}}, it is represented
82 as a matrix column.
83
84 We are in the process of defining behaviors for models fit with various
85 \code{na.action} arguments, but make no guarantees about behavior when data is
86 missing at this time.
87 }
88 \details{
89 Depending on the arguments passed on to \code{predict.rq} via \code{...},
90 a confidence interval is also calculated on the fitted values resulting in
91 columns \code{.lower} and \code{.upper}. Does not provide confidence
92 intervals when data is specified via the \code{newdata} argument.
93 }
94 \examples{
95 \dontshow{if (rlang::is_installed("quantreg")) withAutoprint(\{ # examplesIf}
96
97 # load modeling library and data
98 library(quantreg)
99
100 data(stackloss)
101
102 # median (l1) regression fit for the stackloss data.
103 mod1 <- rq(stack.loss ~ stack.x, .5)
104
105 # weighted sample median
106 mod2 <- rq(rnorm(50) ~ 1, weights = runif(50))
107
108 # summarize model fit with tidiers
109 tidy(mod1)
110 glance(mod1)
111 augment(mod1)
112
113 tidy(mod2)
114 glance(mod2)
115 augment(mod2)
116
117 # varying tau to generate an rqs object
118 mod3 <- rq(stack.loss ~ stack.x, tau = c(.25, .5))
119
120 tidy(mod3)
121 augment(mod3)
122
123 # glance cannot handle rqs objects like `mod3`--use a purrr
124 # `map`-based workflow instead
125 \dontshow{\}) # examplesIf}
126 }
127 \seealso{
128 \link{augment}, \code{\link[quantreg:rq]{quantreg::rq()}}, \code{\link[quantreg:predict.rq]{quantreg::predict.rq()}}
129
130 Other quantreg tidiers:
131 \code{\link{augment.nlrq}()},
132 \code{\link{augment.rqs}()},
133 \code{\link{glance.nlrq}()},
134 \code{\link{glance.rq}()},
135 \code{\link{tidy.nlrq}()},
136 \code{\link{tidy.rq}()},
137 \code{\link{tidy.rqs}()}
138 }
139 \concept{quantreg tidiers}
140 \value{
141 A \code{\link[tibble:tibble]{tibble::tibble()}} with columns:
142 \item{.fitted}{Fitted or predicted value.}
143 \item{.resid}{The difference between observed and fitted values.}
144 \item{.tau}{Quantile.}
145
146 }