library(NHANES) nh_adult <- subset(NHANES, Age >= 18) library(stats) library(ggplot2) #One factor multiple levels x<-nh_adult$Race1 y<-nh_adult$Height lmod<-lm(y~x) # Normality and mean zero of residuals qqnorm(residuals(lmod)) qqline(residuals(lmod)) plot(jitter(fitted(lmod)),residuals(lmod)) tapply(y,x,mean, na.rm = TRUE) abline(h=0) par(mfrow=c(3,2)) out<-tapply(y,x,qqnorm) # Each subset seems to deviate from normality at the tails. #Equality of variances: Levene's test with deviation from median library(car) leveneTest(lmod,center=median) #Pairwise testing and confidence interval options(contrasts=c("contr.treatment", "contr.treatment")) summary(lm(y~x)) # This is when Black (the first level) is one of the levels being compared. #The following will give all the pairwise differences install.packages("emmeans") library(emmeans) pairs(emmeans(lmod,~x))