网站上提到broom
它可以用于TukeyHSD
和multcomp
(见这里)。但是,我无法弄清楚如何使用broom
forTukeyHSD
和multcomp
.
请参阅下面给出的 MWE。
df1 <- data.frame(
Rep = factor(rep(1:3, each = 4, times = 2)),
Trt = rep(paste0("T", 1:4), times = 6),
Loc = rep(paste0("Loc", 1:2), each = 12),
Y = rnorm(24)
)
library(dplyr)
df2 <- filter(df1, Loc=="Loc1")
fm1 <- aov(Y ~ Rep + Trt , data = df2)
anova(fm1)
library(multcompView)
fm1Tukey1 <-
data.frame(Letter = multcompLetters(TukeyHSD(fm1)$Trt[, "p adj"])$Letters)
fm1Tukey <- data.frame(Trt = row.names(fm1Tukey1), fm1Tukey1)
fm1Means1 <-
data.frame(
Mean = as.matrix(model.tables(x = fm1, type = "means")[[1]]$Trt)
, SE = model.tables(x = fm1, type = "means", se = TRUE)$se$Trt
)
names(fm1Means1) <- c("Mean", "SE")
fm1Means2 <- data.frame(Trt = row.names(fm1Means1), fm1Means1)
fm1Means <- left_join(fm1Means2, fm1Tukey)
library(dplyr)
fm3 <-
df1 %>%
group_by(Loc) %>%
do(model = aov(Y ~ Rep + Trt , data = .))
fm3$model
library(broom)
fm3 %>% tidy(model)