data <- read.csv("~/glucinsul.csv") head(data) data <- data.frame(Time=c(data$Time,data$Time), cond=c(rep(0,50),rep(1,50)),gluc=c(data$basegluc,data$ofgluc)) # compute mean for each time and conditon combination sum.tab <- tapply(data$gluc,list(data$Time,data$cond),mean) # # If you want to be an R pro, learn to use "plyr" library! # # make a plot plot(data$Time,data$gluc,xlab="Minutes",ylab="Glucose", sub="red = Control, blue = Treatment") points(c(0,30,60,90,120),sum.tab[,1],pch=16,col="red",cex=2) points(c(0,30,60,90,120),sum.tab[,2],pch=16,col="blue",cex=2) # make time a categorical variable data$Time <- as.factor(data$Time) # fit reduced model fit.reduced <- lm(gluc~Time,data=data) summary(fit.reduced) # fit full model fit.full <- lm(gluc~Time*cond,data=data) summary(fit.full) #compare the two anova(fit.reduced,fit.full) # to see where F came from: ((81.830 - 78.912)/5) / (78.912/90) # NOTE: R calls sum of squared errors "RSS" (residual sum of squares)!!!