library(tidyverse)
data <- starwars %>%
filter(sex == "male" | sex == "female")
model <- lm(height ~ sex, data = data)
residuals <- data.frame(res = residuals(model))
problem <- residuals %>% filter(res > 2.5 | res < -2.5)
nrow(problem)/nrow(data) - 1
-
Filtering for male the female using the
filter()function - 2
- Running a linear regression (that is a t-test here) to get residuals
- 3
- Calculate residuals for the observations
- 4
- Find potentially problematic observations
[1] 0.8157895