2

I am trying to calculate if my residuals are normally distributed for my two way ANOVA with repeated measures on Rstudio.

However, all the tutorials I find seem to specific to one way within ANOVAs or two way between ANOVAs.

If anyone knows the R script to determine the residuals and graph them It would be very much appreciated!

Thank you

2 Answers2

6

The residuals from an ANOVA can be handled like any linear regression in R, in that once you run a saved object from an ANOVA or regression, you can typically obtain the residuals fairly easy and thus run a QQ Plot. Here is a quick way I borrowed from this site, though I skipped a lot of the other stuff since it wasn't relevant:

#### Save Data as Object ####
my_data <- ToothGrowth

Create Second Factor

my_data$dose <- factor(my_data$dose, levels = c(0.5, 1, 2), labels = c("D0.5", "D1", "D2"))

Run Two-Way ANOVA

res.aov <- aov(len ~ supp + dose, data = my_data) summary(res.aov)

Plot Residuals

plot(res.aov, 2)

Which should give you this QQ plot:

enter image description here

As someone else noted here, you can also plot a histogram of the residuals and see if they are normal as well.

0

If you want to check the histogram of residuals:

hist(your_model$residuals)

If in top of that you want to explicitly test for normality:

shapiro.test(your_model$residuals)

But I would more carefully check the plot of standardized residuals vs Fitted values with:

plot(your_model)
OTStats
  • 213
glagla
  • 64