You are on page 1of 11

Checking and fixing

non normality
using R
Aim
Checking non normal
distributions of errors using R.

Creating and storing the residuals


Displaying the residuals
Testing the distribution
Repairing the problem
Packages
R Base: stats
tidyverse for the “pipes”

modelr for adding residuals (however …)


1. Creating and storing residuals
model_1 <- my_data %>%
lm(y ~ x1 + x2 + x3, .)
2. Displaying residuals (histogram)
2. Displaying residuals (QQ plot)
3. Testing the normality
shapiro.test(my_data$residuals_1)

Gives both W and the p-value

Null = normal distribution: so, if p is


low, it is very unlikely these data are
from a random sample from a normal
distribution.
4. Repairing the non-normality problem
1. Creating a better model

2. Transforming the y-variable.


4. Repairing the non-normality problem
Aim
Checking non normal
distributions of errors using R.

Creating and storing the residuals


Displaying the residuals
Testing the distribution
Repairing the problem
Checking and fixing
non normality
using R

You might also like