问题描述
方差分析返回重要结果的一种方法。因此,我想进行Dunnetts检验,以比较对照组和治疗组的控制方法(方法D)。我刚接触R时,有人会帮我做这个吗?这是我的数据:
mydata <- tibble(
score = c(14,12,10,9,6,5,17,15,7,14,11,8,4,2,2),method = as.factor(paste0("Method ",rep(c("A","B","C","D"),each=7)))
)
解决方法
首先,我读入数据:
mydata <- tibble(
score = c(14,12,10,9,6,5,17,15,7,14,11,8,4,2,2),method = as.factor(paste0("Method ",rep(c("A","B","C","D"),each=7))
))
接下来,如果要与Method D
进行比较,则应将因子设为第一级:
mydata$method <- relevel(mydata$method,"Method D")
接下来,估算方差分析:
a <- aov(score ~ method,data=mydata)
最后,使用multcomp
包,您可以生成为您提供适当检验的常规线性假设检验:
library(multcomp)
g <- glht(a,linfct = mcp(method = "Dunnett"))
summary(g)
#
# Simultaneous Tests for General Linear Hypotheses
# Multiple Comparisons of Means: Dunnett Contrasts
# Fit: aov(formula = score ~ method,data = mydata)
#
# Linear Hypotheses:
# Estimate Std. Error t value Pr(>|t|)
# Method A - Method D == 0 5.286 1.630 3.243 0.00940 **
# Method B - Method D == 0 6.714 1.630 4.120 0.00116 **
# Method C - Method D == 0 5.429 1.630 3.331 0.00761 **
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# (Adjusted p values reported -- single-step method)