Last active
July 12, 2020 21:57
-
-
Save apreshill/9d33891b5f9be4669ada20f76f101baa to your computer and use it in GitHub Desktop.
Shows us why visualizing residuals from a model is important
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(broom) | |
library(ggplot2) | |
# read in the data | |
# others available here: http://www4.stat.ncsu.edu/~stefanski/NSF_Supported/Hidden_Images/stat_res_plots.html | |
owl <- read.table("http://www4.stat.ncsu.edu/~stefanski/NSF_Supported/Hidden_Images/orly_owl_files/orly_owl_Lin_4p_5_flat.txt", | |
header = FALSE) | |
# fit the linear model | |
fit <- lm(V1 ~ . - 1, data = owl) | |
# save the residuals via broom | |
owl_vars <- augment(fit) | |
# plot fitted vs residuals | |
ggplot(owl_vars, aes(x = .fitted, y = .resid)) + | |
geom_point(size = 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment