How to do one-way ANOVA in R with unequal sample sizes?

亡梦爱人 提交于 2019-12-03 02:57:50

Try this one

site1 <- c(34,25,27,31,26,34,21)
site2 <- c(33,35,31,31,42,33)
site3 <- c(17,30,30,26,32,28,26,29)
site4 <- c(28,33,31,27,32,33,40)

Data <- data.frame(
       Y=c(site1, site2, site3, site4),
       Site =factor(rep(c("site1", "site2", "site3", "site4"), times=c(length(site1), length(site2), length(site3), length(site4))))
       )

Data

  Y  Site
 34 site1
 25 site1
 27 site1
 31 site1
 26 site1
 34 site1
 21 site1
 33 site2
 35 site2
 31 site2
 31 site2
 42 site2
 33 site2
 17 site3
 30 site3
 30 site3
 26 site3
 32 site3
 28 site3
 26 site3
 29 site3
 28 site4
 33 site4
 31 site4
 27 site4
 32 site4
 33 site4
 40 site4

ANOVA

fm1 <- aov(Y~Site, data=Data)
anova(fm1)

Output

Analysis of Variance Table

Response: Y
          Df Sum Sq Mean Sq F value  Pr(>F)  
Site       3 212.35  70.782  3.4971 0.03098 *
Residuals 24 485.76  20.240                  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!