##### 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 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 ### run a Mixed-effects ANOVA using the lme command library(nlme) results=lme(Mass~Protein,data=datum,random=~1|Tank) ### ~1|Tank means that 'Tank' has it's own random effect ### if you want Tank to interact with another x variable ### relace the '1' with the variable you want to interact with Tank ### e.g., ~Protein|Tank