##### Code for ANCOVA in R ### Importing data datum=read.csv(file.choose()) ### creates a data frame named datum from csv file head(datum) ### column headers of data file plus first 6 rows of data ###Plot Data plot(Mass~Protein,data=datum) ### scatterplot of data used in example ### Run ANCOVA - treat Protein as continuous (linear) variable results=lm(Mass~Protein+Supplement,data=datum) ### linear regression of example data summary(results) ### prints a summary of 'results' confint(results) ### Extract confidence intervals ### Run multi-factor ANOVA - treat Protein as categorical results2=lm(Mass~as.factor(Protein)+Supplement,data=datum) summary(results2) TukeyHSD(results2) anova(results2) ### generate an anova table of regression ### BE VERY CAREFUL WITH THESE RESULTS - THEY ARE TYPE I SUM OF SQUARES summary(aov(results2)) ### Also generates a type I sum of squares anova table ### Get type III sum of squares table library(car) Anova(results2,type=3) ### Note that there is no difference between type I and type III ### Sum of squares if model is fully factorial (no collinearity among variables)