It is mentioned in broom
website that it can be used for TukeyHSD
and multcomp
(See here). However, I could not figure it out how to use broom
for TukeyHSD
and multcomp
.
See MWE given below.
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)
What about this solution ?
The result is: