add_residuals | R Documentation |
Add residuals to a data frame
add_residuals(data, model, var = "resid")
spread_residuals(data, ...)
gather_residuals(data, ..., .resid = "resid", .model = "model")
data |
A data frame used to generate the residuals |
model, var |
|
... |
|
.resid, .model |
The variable names used by |
A data frame. add_residuals
adds a single new column,
.resid
, to the input data
. spread_residuals
adds
one column for each model. gather_predictions
adds two columns
.model
and .resid
, and repeats the input rows for
each model.
df <- tibble::tibble(
x = sort(runif(100)),
y = 5 * x + 0.5 * x ^ 2 + 3 + rnorm(length(x))
)
plot(df)
m1 <- lm(y ~ x, data = df)
df %>% add_residuals(m1)
m2 <- lm(y ~ poly(x, 2), data = df)
df %>% spread_residuals(m1, m2)
df %>% gather_residuals(m1, m2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.