| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/mlogit.R |
| 3 |
\name{augment.mlogit} |
| 4 |
\alias{augment.mlogit} |
| 5 |
\title{Augment data with information from a(n) mlogit object} |
| 6 |
\usage{ |
| 7 |
\method{augment}{mlogit}(x, data = x$model, ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{x}{an object returned from \code{\link[mlogit:mlogit]{mlogit::mlogit()}}.} |
| 11 |
|
| 12 |
\item{data}{Not currently used} |
| 13 |
|
| 14 |
\item{...}{Additional arguments. Not used. Needed to match generic |
| 15 |
signature only. \strong{Cautionary note:} Misspelled arguments will be |
| 16 |
absorbed in \code{...}, where they will be ignored. If the misspelled |
| 17 |
argument has a default value, the default value will be used. |
| 18 |
For example, if you pass \code{conf.lvel = 0.9}, all computation will |
| 19 |
proceed using \code{conf.level = 0.95}. Two exceptions here are: |
| 20 |
\itemize{ |
| 21 |
\item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if |
| 22 |
it will be ignored. |
| 23 |
\item \code{augment()} methods will warn when supplied a \code{newdata} argument if it |
| 24 |
will be ignored. |
| 25 |
}} |
| 26 |
} |
| 27 |
\description{ |
| 28 |
Augment accepts a model object and a dataset and adds |
| 29 |
information about each observation in the dataset. Most commonly, this |
| 30 |
includes predicted values in the \code{.fitted} column, residuals in the |
| 31 |
\code{.resid} column, and standard errors for the fitted values in a \code{.se.fit} |
| 32 |
column. New columns always begin with a \code{.} prefix to avoid overwriting |
| 33 |
columns in the original dataset. |
| 34 |
|
| 35 |
Users may pass data to augment via either the \code{data} argument or the |
| 36 |
\code{newdata} argument. If the user passes data to the \code{data} argument, |
| 37 |
it \strong{must} be exactly the data that was used to fit the model |
| 38 |
object. Pass datasets to \code{newdata} to augment data that was not used |
| 39 |
during model fitting. This still requires that at least all predictor |
| 40 |
variable columns used to fit the model are present. If the original outcome |
| 41 |
variable used to fit the model is not included in \code{newdata}, then no |
| 42 |
\code{.resid} column will be included in the output. |
| 43 |
|
| 44 |
Augment will often behave differently depending on whether \code{data} or |
| 45 |
\code{newdata} is given. This is because there is often information |
| 46 |
associated with training observations (such as influences or related) |
| 47 |
measures that is not meaningfully defined for new observations. |
| 48 |
|
| 49 |
For convenience, many augment methods provide default \code{data} arguments, |
| 50 |
so that \code{augment(fit)} will return the augmented training data. In these |
| 51 |
cases, augment tries to reconstruct the original data based on the model |
| 52 |
object with varying degrees of success. |
| 53 |
|
| 54 |
The augmented dataset is always returned as a \link[tibble:tibble]{tibble::tibble} with the |
| 55 |
\strong{same number of rows} as the passed dataset. This means that the passed |
| 56 |
data must be coercible to a tibble. If a predictor enters the model as part |
| 57 |
of a matrix of covariates, such as when the model formula uses |
| 58 |
\code{\link[splines:ns]{splines::ns()}}, \code{\link[stats:poly]{stats::poly()}}, or \code{\link[survival:Surv]{survival::Surv()}}, it is represented |
| 59 |
as a matrix column. |
| 60 |
|
| 61 |
We are in the process of defining behaviors for models fit with various |
| 62 |
\code{na.action} arguments, but make no guarantees about behavior when data is |
| 63 |
missing at this time. |
| 64 |
} |
| 65 |
\details{ |
| 66 |
At the moment this only works on the estimation dataset. Need to set |
| 67 |
it up to predict on another dataset. |
| 68 |
} |
| 69 |
\examples{ |
| 70 |
\dontshow{if (rlang::is_installed("mlogit")) withAutoprint(\{ # examplesIf} |
| 71 |
|
| 72 |
# load libraries for models and data |
| 73 |
library(mlogit) |
| 74 |
|
| 75 |
data("Fishing", package = "mlogit") |
| 76 |
Fish <- dfidx(Fishing, varying = 2:9, shape = "wide", choice = "mode") |
| 77 |
|
| 78 |
# fit model |
| 79 |
m <- mlogit(mode ~ price + catch | income, data = Fish) |
| 80 |
|
| 81 |
# summarize model fit with tidiers |
| 82 |
tidy(m) |
| 83 |
augment(m) |
| 84 |
glance(m) |
| 85 |
\dontshow{\}) # examplesIf} |
| 86 |
} |
| 87 |
\seealso{ |
| 88 |
\code{\link[=augment]{augment()}} |
| 89 |
|
| 90 |
Other mlogit tidiers: |
| 91 |
\code{\link{glance.mlogit}()}, |
| 92 |
\code{\link{tidy.mlogit}()} |
| 93 |
} |
| 94 |
\concept{mlogit tidiers} |
| 95 |
\value{ |
| 96 |
A \code{\link[tibble:tibble]{tibble::tibble()}} with columns: |
| 97 |
\item{.fitted}{Fitted or predicted value.} |
| 98 |
\item{.probability}{Class probability of modal class.} |
| 99 |
\item{.resid}{The difference between observed and fitted values.} |
| 100 |
|
| 101 |
} |