library(ggplot2)
library(broom)
library(dplyr)
# Identify outliers
ggplot(mariokart, aes(x = total_pr, y = cond)) +
geom_boxplot()
# Replot without the outliers
mariokart %>%
filter(total_pr < 80) %>%
ggplot(aes(x = total_pr, y = cond)) +
geom_boxplot()
# Fit a multiple regression models
mariokart_no <- mariokart %>% filter(total_pr < 80)
m1 <- lm(total_pr ~ cond + stock_photo + duration + wheels, data = mariokart_no)
tidy(m1)
m2 <- lm(total_pr ~ cond + stock_photo + wheels, data = mariokart_no)
tidy(m2)
m3 <- lm(total_pr ~ cond + wheels, data = mariokart_no)
tidy(m3)
# Fit diagnostics
aug_m3 <- augment(m3)
ggplot(aug_m3, aes(x = .fitted, y = .resid)) +
geom_point() +
geom_hline(yintercept = 0, linetype = "dashed") +
labs(x = "Fitted values", y = "Residuals")
ggplot(aug_m3, aes(x = .fitted, y = abs(.resid))) +
geom_point() +
geom_hline(yintercept = 0, linetype = "dashed") +
labs(x = "Fitted values", y = "Absolute value of residuals")
ggplot(aug_m3, aes(x = 1:nrow(aug_m3), y = .resid)) +
geom_point() +
geom_hline(yintercept = 0, linetype = "dashed") +
labs(x = "Order of data collection", y = "Residuals")
ggplot(aug_m3, aes(x = cond, y = .resid)) +
geom_boxplot() +
labs(x = "Condition", y = "Residuals")
ggplot(aug_m3, aes(x = wheels, y = .resid)) +
geom_point() +
labs(
x = "Number of wheels", y = "Residuals",
title = "Notice curvature"
)
Run the code above in your browser using DataLab