| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/stats-nls.R |
| 3 |
\name{augment.nls} |
| 4 |
\alias{augment.nls} |
| 5 |
\title{Augment data with information from a(n) nls object} |
| 6 |
\usage{ |
| 7 |
\method{augment}{nls}(x, data = NULL, newdata = NULL, ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{x}{An \code{nls} object returned from \code{\link[stats:nls]{stats::nls()}}.} |
| 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{...}{Additional arguments. Not used. Needed to match generic |
| 26 |
signature only. \strong{Cautionary note:} Misspelled arguments will be |
| 27 |
absorbed in \code{...}, where they will be ignored. If the misspelled |
| 28 |
argument has a default value, the default value will be used. |
| 29 |
For example, if you pass \code{conf.lvel = 0.9}, all computation will |
| 30 |
proceed using \code{conf.level = 0.95}. Two exceptions here are: |
| 31 |
\itemize{ |
| 32 |
\item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if |
| 33 |
it will be ignored. |
| 34 |
\item \code{augment()} methods will warn when supplied a \code{newdata} argument if it |
| 35 |
will be ignored. |
| 36 |
}} |
| 37 |
} |
| 38 |
\description{ |
| 39 |
Augment accepts a model object and a dataset and adds |
| 40 |
information about each observation in the dataset. Most commonly, this |
| 41 |
includes predicted values in the \code{.fitted} column, residuals in the |
| 42 |
\code{.resid} column, and standard errors for the fitted values in a \code{.se.fit} |
| 43 |
column. New columns always begin with a \code{.} prefix to avoid overwriting |
| 44 |
columns in the original dataset. |
| 45 |
|
| 46 |
Users may pass data to augment via either the \code{data} argument or the |
| 47 |
\code{newdata} argument. If the user passes data to the \code{data} argument, |
| 48 |
it \strong{must} be exactly the data that was used to fit the model |
| 49 |
object. Pass datasets to \code{newdata} to augment data that was not used |
| 50 |
during model fitting. This still requires that at least all predictor |
| 51 |
variable columns used to fit the model are present. If the original outcome |
| 52 |
variable used to fit the model is not included in \code{newdata}, then no |
| 53 |
\code{.resid} column will be included in the output. |
| 54 |
|
| 55 |
Augment will often behave differently depending on whether \code{data} or |
| 56 |
\code{newdata} is given. This is because there is often information |
| 57 |
associated with training observations (such as influences or related) |
| 58 |
measures that is not meaningfully defined for new observations. |
| 59 |
|
| 60 |
For convenience, many augment methods provide default \code{data} arguments, |
| 61 |
so that \code{augment(fit)} will return the augmented training data. In these |
| 62 |
cases, augment tries to reconstruct the original data based on the model |
| 63 |
object with varying degrees of success. |
| 64 |
|
| 65 |
The augmented dataset is always returned as a \link[tibble:tibble]{tibble::tibble} with the |
| 66 |
\strong{same number of rows} as the passed dataset. This means that the passed |
| 67 |
data must be coercible to a tibble. If a predictor enters the model as part |
| 68 |
of a matrix of covariates, such as when the model formula uses |
| 69 |
\code{\link[splines:ns]{splines::ns()}}, \code{\link[stats:poly]{stats::poly()}}, or \code{\link[survival:Surv]{survival::Surv()}}, it is represented |
| 70 |
as a matrix column. |
| 71 |
|
| 72 |
We are in the process of defining behaviors for models fit with various |
| 73 |
\code{na.action} arguments, but make no guarantees about behavior when data is |
| 74 |
missing at this time. |
| 75 |
} |
| 76 |
\details{ |
| 77 |
augment.nls does not currently support confidence intervals due to |
| 78 |
a lack of support in stats::predict.nls(). |
| 79 |
} |
| 80 |
\examples{ |
| 81 |
\dontshow{if (rlang::is_installed("ggplot2")) withAutoprint(\{ # examplesIf} |
| 82 |
|
| 83 |
# fit model |
| 84 |
n <- nls(mpg ~ k * e^wt, data = mtcars, start = list(k = 1, e = 2)) |
| 85 |
|
| 86 |
# summarize model fit with tidiers + visualization |
| 87 |
tidy(n) |
| 88 |
augment(n) |
| 89 |
glance(n) |
| 90 |
|
| 91 |
library(ggplot2) |
| 92 |
|
| 93 |
ggplot(augment(n), aes(wt, mpg)) + |
| 94 |
geom_point() + |
| 95 |
geom_line(aes(y = .fitted)) |
| 96 |
|
| 97 |
newdata <- head(mtcars) |
| 98 |
newdata$wt <- newdata$wt + 1 |
| 99 |
|
| 100 |
augment(n, newdata = newdata) |
| 101 |
\dontshow{\}) # examplesIf} |
| 102 |
} |
| 103 |
\seealso{ |
| 104 |
\link{tidy}, \code{\link[stats:nls]{stats::nls()}}, \code{\link[stats:predict.nls]{stats::predict.nls()}} |
| 105 |
|
| 106 |
Other nls tidiers: |
| 107 |
\code{\link{glance.nls}()}, |
| 108 |
\code{\link{tidy.nls}()} |
| 109 |
} |
| 110 |
\concept{nls tidiers} |
| 111 |
\value{ |
| 112 |
A \code{\link[tibble:tibble]{tibble::tibble()}} with columns: |
| 113 |
\item{.fitted}{Fitted or predicted value.} |
| 114 |
\item{.resid}{The difference between observed and fitted values.} |
| 115 |
|
| 116 |
} |