rd_plot | R Documentation |
rd_plot()
provides a visual diagnostic of the normality
assumption of the linear model. Provided an OLS model fit by lm()
in
base R, the function extracts the residuals of the model and creates
a density plot of those residuals (solid black line) against a standard
normal distribution with a mean of 0 and a standard deviation matching the
standard deviation of the residuals from the model. The function may be used
for diagnostic purposes.
rd_plot(mod)
mod |
a fitted linear model |
The user can always add ggplot2 elements on top of this for
greater legibility/clarity. For example, density plots can be finicky about
making observations appear where they don't. Perhaps adjusting the scale
of x
ad hoc, after the fact, may be warranted.
The goal of this function is to emphasize that in many real world applications, the normality assumption of the residuals is never held but can often be reasonably approximated upon visual inspection.
rd_plot()
returns a density plot a ggplot2 object. A
density plot of the actual residuals is a solid black line. A stylized normal
distribution matching the description of the residuals is the blue dashed
line.
Steven V. Miller
M1 <- lm(mpg ~ ., data=mtcars)
rd_plot(M1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.