20.15 单因素多重比较 oneway.test

单因素方差分析,各个组的方差不一定相同,检验两个及以上来自正态分布的样本是否有相同的均值?

usage(oneway.test)
oneway.test(formula, data, subset, na.action, var.equal = FALSE)
## 假定方差不等
oneway.test(extra ~ group, data = sleep)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  extra and group
## F = 3.4626, num df = 1.000, denom df = 17.776, p-value = 0.07939
## 假定方差相等
oneway.test(extra ~ group, data = sleep, var.equal = TRUE)
## 
##  One-way analysis of means
## 
## data:  extra and group
## F = 3.4626, num df = 1, denom df = 18, p-value = 0.07919
## 和线性回归结果一样
anova(lm(extra ~ group, data = sleep))
## Analysis of Variance Table
## 
## Response: extra
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## group      1 12.482 12.4820  3.4626 0.07919 .
## Residuals 18 64.886  3.6048                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

CO2 数据

# coplot(uptake ~ conc | Plant, data = CO2, show.given = FALSE, type = "b")
# levels(CO2$Plant) # Plant 是有序的
library(ggplot2)
library(patchwork)
p1 <- ggplot(data = CO2, aes(x = conc, y = uptake)) +
  geom_point(aes(color = Treatment)) +
  geom_line(aes(color = Treatment)) +
  facet_wrap(~Plant, ncol = 4, dir = "v")
p2 <- ggplot(data = CO2, aes(x = conc, y = uptake)) +
  geom_point(aes(color = Type)) +
  geom_line(aes(color = Type)) +
  facet_wrap(~Plant, ncol = 4, dir = "v")
p1 / p2
草类植物吸收 CO2

图 20.2: 草类植物吸收 CO2