Debian Codegraph @

man/augment.polr.Rd

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