0

I'm doing a simple ANOVA in R, shown below.

x1 <- c(180,45,45,200,65,150,380,250,0,0,320,100,80,0,280,20,60,300,210,0,20,0,0,260,220)
x2 <- c(0,100,120,0,40,200,20,240,80,420,0,0,0,220,160,40,180,0,0,40,0,20,100,0,120)
dat = data.frame(cbind(x1,x2))
colnames(dat) <- c("Column1","Column2")
dat$Column2<-as.factor(dat$Column2)
anova(lm(Column1~Column2,data=dat))

This is the output I get.

Analysis of Variance Table

Response: Column1
          Df Sum Sq Mean Sq F value Pr(>F)
Column2   11 181842   16531  1.2339 0.3548
Residuals 13 174164   13397               

However, when I perform the same ANOVA in Excel using "ANOVA: Single Factor" I get the following results.

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
  • You haven't done the same analysis. In the R analysis, you have 25 observations in 12 groups. In your Excel analysis, you have 50 observations in two groups. Which of these analyses did you intend? – Benjamin Dec 15 '16 at 22:55
  • You're not comparing like with like - to get the same result in R you need to do something like: `test <- data.frame(value=c(x1,x2), group=rep(1:2, c(length(x1),length(x2)))); anova(lm(value ~ group, data=test))` – thelatemail Dec 15 '16 at 23:01

1 Answers1

2

You need to have a dataset where the two columns are values and groups:

> dat <- stack( data.frame(x1,x2) )
> colnames(dat) <- c("Column1","Column2")
> dat$Column2<-as.factor(dat$Column2)
> anova(lm(Column1~Column2,data=dat))
Analysis of Variance Table

Response: Column1
          Df Sum Sq Mean Sq F value Pr(>F)
Column2    1  23545   23544  1.8204 0.1836
Residuals 48 620806   12934          
IRTFM
  • 258,963
  • 21
  • 364
  • 487