EVOLUTION-MANAGER
Edit File: add_residuals.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Add residuals to a data frame</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for add_residuals {modelr}"><tr><td>add_residuals {modelr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Add residuals to a data frame</h2> <h3>Description</h3> <p>Add residuals to a data frame </p> <h3>Usage</h3> <pre> add_residuals(data, model, var = "resid") spread_residuals(data, ...) gather_residuals(data, ..., .resid = "resid", .model = "model") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>data</code></td> <td> <p>A data frame used to generate the residuals</p> </td></tr> <tr valign="top"><td><code>model, var</code></td> <td> <p><code>add_residuals</code> takes a single <code>model</code>; the output column will be called <code>resid</code></p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p><code>gather_residuals</code> and <code>spread_residuals</code> take multiple models. The name will be taken from either the argument name of the name of the model.</p> </td></tr> <tr valign="top"><td><code>.resid, .model</code></td> <td> <p>The variable names used by <code>gather_residuals</code>.</p> </td></tr> </table> <h3>Value</h3> <p>A data frame. <code>add_residuals</code> adds a single new column, <code>.resid</code>, to the input <code>data</code>. <code>spread_residuals</code> adds one column for each model. <code>gather_predictions</code> adds two columns <code>.model</code> and <code>.resid</code>, and repeats the input rows for each model. </p> <h3>Examples</h3> <pre> 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) </pre> <hr /><div style="text-align: center;">[Package <em>modelr</em> version 0.1.8 <a href="00Index.html">Index</a>]</div> </body></html>