##### Code for running an ANOVA in R ###Import data datum=read.csv(file.choose()) ### creates a data frame named datum from imported ### csv file head(datum) ### check data was imported properly ### Tell R that Protein is a categorical variable ### Same as 'Class' statement in SAS datum$Protein=as.factor(datum$Protein) ### Plot relationship plot(Mass~Protein,data=datum) ### Generate a box and whiskers plot ### run an ANOVA using aov command resultsAOV=aov(Mass~Protein,data=datum) ### run an ANOVA for effect of protein on mass, ### call the object 'results' summary(resultsAOV) ### give summary of ANOVA ### returns anova table with SSE, MSE, F statistic and p-value ### Significant p-value indicates at least 2 groups are significantly different ### run an ANOVA using the lm command results=lm(Mass~Protein,data=datum) ### run a regression with mass as dependent ### and sex as independent variables summary(results) ### Give results ### note F statistic from lm and aov give same results ### F statistics and p-values are at bottom of summary output ### Get confidence intervals on differrence between groups confint(results) ### How to change the reference category help(relevel) ###use the relevel command to change reference categories results2=lm(Mass~relevel(Protein,ref="0.35"),data=datum) #Changes the reference group ### to "0.35" summary(results2) ### How to run a post-hoc analysis TukeyHSD(results) ##### Additional post-hoc tests - beyond scope of our class ### run a scheffe's comparison library(agricolae) ### Scheffe's test is in the library (agricolae) help(scheffe.test) scheffe.test(resultsAOV,"Sex") ### run a scheffe's test