# ANOVA & Sums of Squares in Excel and R

In this simple dataset, I have bird populations from three watersheds. I am completing an ANOVA by hand and in R and comparing the outputs.

Watershed <- c(rep(times=3, "FOX"), rep (times=3,"Manitowoc"), rep (times=3, "Milwaukee"))
Count <-  c(6,5,3,2,1,1,3,3,3)

Eagles <- as.data.frame(cbind (Watershed, Count)); Eagles$$Count <- as.numeric(Eagles$$Count)
Eagle.aov <- aov (Count ~ Watershed, data=Eagles)
summary (Eagle.aov)


When doing it by hand (Excel) I am getting a very different answer for my sum of squares compared to the R output.

Can anyone explain why these two are so different? Thanks! vs.

The difference is because of how you created your data frame. You did not need to cbind the 2 vectors. By doing so, the resultant matrix is of factors. That is why you had to convert back to numbers with as.numeric. But as.numeric converts the lowest level factor to 1, the next to 2, etc. So, in your case the factor '5' gets converted to the number 4 and the factor '6' gets converted to the number 5. Look at your data frame and how the 'FOX' counts have changed.

The R code should look like

Watershed<- c(rep(times=3, "FOX"), rep (times=3,"Manitowoc"), rep (times=3, "Milwaukee"))
Count<-  c(6,5,3,2,1,1,3,3,3)

Eagles<- data.frame(Watershed, Count);
Eagle.aov<- aov (Count ~ Watershed, data=Eagles)
summary (Eagle.aov)


The result matches the one done 'by hand' in Excel