EVOLUTION-MANAGER
Edit File: fortify.lm.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: Supplement the data fitted to a linear model with model fit...</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 fortify.lm {ggplot2}"><tr><td>fortify.lm {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Supplement the data fitted to a linear model with model fit statistics.</h2> <h3>Description</h3> <p>If you have missing values in your model data, you may need to refit the model with <code>na.action = na.exclude</code>. </p> <h3>Usage</h3> <pre> ## S3 method for class 'lm' fortify(model, data = model$model, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>model</code></td> <td> <p>linear model</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>data set, defaults to data used to fit model</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>not used by this method</p> </td></tr> </table> <h3>Value</h3> <p>The original data with extra columns: </p> <table summary="R valueblock"> <tr valign="top"><td><code>.hat</code></td> <td> <p>Diagonal of the hat matrix</p> </td></tr> <tr valign="top"><td><code>.sigma</code></td> <td> <p>Estimate of residual standard deviation when corresponding observation is dropped from model</p> </td></tr> <tr valign="top"><td><code>.cooksd</code></td> <td> <p>Cooks distance, <code><a href="../../stats/html/influence.measures.html">cooks.distance()</a></code></p> </td></tr> <tr valign="top"><td><code>.fitted</code></td> <td> <p>Fitted values of model</p> </td></tr> <tr valign="top"><td><code>.resid</code></td> <td> <p>Residuals</p> </td></tr> <tr valign="top"><td><code>.stdresid</code></td> <td> <p>Standardised residuals</p> </td></tr> </table> <h3>Examples</h3> <pre> mod <- lm(mpg ~ wt, data = mtcars) head(fortify(mod)) head(fortify(mod, mtcars)) plot(mod, which = 1) ggplot(mod, aes(.fitted, .resid)) + geom_point() + geom_hline(yintercept = 0) + geom_smooth(se = FALSE) ggplot(mod, aes(.fitted, .stdresid)) + geom_point() + geom_hline(yintercept = 0) + geom_smooth(se = FALSE) ggplot(fortify(mod, mtcars), aes(.fitted, .stdresid)) + geom_point(aes(colour = factor(cyl))) ggplot(fortify(mod, mtcars), aes(mpg, .stdresid)) + geom_point(aes(colour = factor(cyl))) plot(mod, which = 2) ggplot(mod) + stat_qq(aes(sample = .stdresid)) + geom_abline() plot(mod, which = 3) ggplot(mod, aes(.fitted, sqrt(abs(.stdresid)))) + geom_point() + geom_smooth(se = FALSE) plot(mod, which = 4) ggplot(mod, aes(seq_along(.cooksd), .cooksd)) + geom_col() plot(mod, which = 5) ggplot(mod, aes(.hat, .stdresid)) + geom_vline(size = 2, colour = "white", xintercept = 0) + geom_hline(size = 2, colour = "white", yintercept = 0) + geom_point() + geom_smooth(se = FALSE) ggplot(mod, aes(.hat, .stdresid)) + geom_point(aes(size = .cooksd)) + geom_smooth(se = FALSE, size = 0.5) plot(mod, which = 6) ggplot(mod, aes(.hat, .cooksd)) + geom_vline(xintercept = 0, colour = NA) + geom_abline(slope = seq(0, 3, by = 0.5), colour = "white") + geom_smooth(se = FALSE) + geom_point() ggplot(mod, aes(.hat, .cooksd)) + geom_point(aes(size = .cooksd / .hat)) + scale_size_area() </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>