当然有。在模型中排除交互项。
> my.data <- data.frame(y = rnorm(100), region = rep(c("a", "b"), each = 50), gender = sample(c("M", "F"), 100, replace = TRUE))
> head(my.data)
y region gender
1 0.3333316 a M
2 1.6364059 a F
3 0.6679500 a F
4 -0.7460313 a M
5 0.7327712 a F
6 -0.8305134 a M
> tail(my.data)
y region gender
95 -1.387498267 b F
96 0.124378046 b M
97 -0.568782743 b M
98 -0.004699849 b M
99 -1.449213423 b F
100 -1.146313313 b F
>
> mdl1 <- aov(y ~ region * gender, data = my.data)
> TukeyHSD(mdl1)
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = y ~ region * gender, data = my.data)
$region
diff lwr upr p adj
b-a -0.0140727 -0.4041448 0.3759994 0.9430592
$gender
diff lwr upr p adj
M-F -0.13387 -0.5267813 0.2590414 0.5004702
$`region:gender`
diff lwr upr p adj
b:F-a:F -0.57419765 -1.3487805 0.20038521 0.2191452
a:M-a:F -0.63398152 -1.3658935 0.09793048 0.1136445
b:M-a:F -0.20795605 -0.9398681 0.52395596 0.8794703
a:M-b:F -0.05978387 -0.7916959 0.67212813 0.9965356
b:M-b:F 0.36624160 -0.3656704 1.09815361 0.5599334
b:M-a:M 0.42602548 -0.2605688 1.11261980 0.3710470
>
> mdl2 <- update(mdl1, . ~ region + gender)
> TukeyHSD(mdl2)
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = y ~ region + gender, data = my.data)
$region
diff lwr upr p adj
b-a -0.0140727 -0.4147704 0.3866251 0.9445724
$gender
diff lwr upr p adj
M-F -0.13387 -0.5374843 0.2697444 0.5119119
如果您想删除/保留特定条款,您可以这样做。
> tk <- TukeyHSD(mdl1)
> str(tk)
List of 3
$ region : num [1, 1:4] -0.0141 -0.4041 0.376 0.9431
..- attr(*, "dimnames")=List of 2
.. ..$ : chr "b-a"
.. ..$ : chr [1:4] "diff" "lwr" "upr" "p adj"
$ gender : num [1, 1:4] -0.134 -0.527 0.259 0.5
..- attr(*, "dimnames")=List of 2
.. ..$ : chr "M-F"
.. ..$ : chr [1:4] "diff" "lwr" "upr" "p adj"
$ region:gender: num [1:6, 1:4] -0.5742 -0.634 -0.208 -0.0598 0.3662 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:6] "b:F-a:F" "a:M-a:F" "b:M-a:F" "a:M-b:F" ...
.. ..$ : chr [1:4] "diff" "lwr" "upr" "p adj"
- attr(*, "class")= chr [1:2] "TukeyHSD" "multicomp"
- attr(*, "orig.call")= language aov(formula = y ~ region * gender, data = my.data)
- attr(*, "conf.level")= num 0.95
- attr(*, "ordered")= logi FALSE
> rntk <- rownames(tk[["region:gender"]])
> tk[["region:gender"]] <- tk[["region:gender"]][grepl("b:F-a:F|a:M-a:F", rntk), ]
> tk
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = y ~ region * gender, data = my.data)
$region
diff lwr upr p adj
b-a -0.0140727 -0.4041448 0.3759994 0.9430592
$gender
diff lwr upr p adj
M-F -0.13387 -0.5267813 0.2590414 0.5004702
$`region:gender`
diff lwr upr p adj
b:F-a:F -0.5741976 -1.348781 0.20038521 0.2191452
a:M-a:F -0.6339815 -1.365894 0.09793048 0.1136445