###Lecture 28 - Code for running an ANOVA and Post-hoc tests (Tukey's HSD) in R ### import data datum=read.csv(file.choose()) head(datum) ### Run the Analysis results=lm(Y~X,data=datum) ### Run an ANOVA using the general linear model ### Note: replace 'Y' in above statement with Y variable ### Replace 'X' in above statement with X variable ### NOTE THAT LM DOES NOT MAINTAIN THE EXPERIMENT-WISE ERROR RATE! ### Run the Post-Hoc Tests ### NOTE THAT TUKEY'S CODE WILL NOT WORK ON AN LM, ONLY AOV results2=aov(results) ### convert results 2 (lm) to an true ANOVA TukeyHSD(results2) ### Run a TukeyHSD PostHoc test on results ###diff is difference between specified groups ###lwr is lower confidence limit on difference ###upr is upper confidence limit on difference ###subtract diff from upr to get confidence interval ###p adj is p-value for null hypothesis of no difference between the two specified groups ###Note that 'diff' from results2 are same as beta from results. ###Tukey's only adjusts p-values and confindence intervals, not betas. ### Plot results plot(datum$X,datum$Y) ### Note: replace 'Y' in above statement with Y variable ### Replace 'X' in above statement with X variable