@EdM 提出了有效的观点——首先阅读这些观点。仅供参考,您可以使用emmeans包获得感兴趣的效果及其置信区间。例如:
library(emmeans)
# Toy data: add a dummy categorical variable to the Iris dataset
iris$Style <- rep(LETTERS[1:3], 50)
iris
Sepal.Length Sepal.Width Petal.Length Petal.Width Species Style
1 5.1 3.5 1.4 0.2 setosa A
2 4.9 3.0 1.4 0.2 setosa B
3 4.7 3.2 1.3 0.2 setosa C
4 4.6 3.1 1.5 0.2 setosa A
5 5.0 3.6 1.4 0.2 setosa B
...
拟合模型:
fit <- glm(data= iris, Sepal.Length ~ Species * Style)
summary(fit)
...
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.05294 0.12486 40.470 < 2e-16 ***
Speciesversicolor 0.71765 0.17657 4.064 7.97e-05 ***
Speciesvirginica 1.70331 0.17931 9.499 < 2e-16 ***
StyleB -0.04118 0.17657 -0.233 0.816
StyleC -0.10294 0.17931 -0.574 0.567
Speciesversicolor:StyleB 0.28934 0.25166 1.150 0.252
Speciesvirginica:StyleB -0.26801 0.25166 -1.065 0.289
Speciesversicolor:StyleC 0.35588 0.25166 1.414 0.160
Speciesvirginica:StyleC -0.08272 0.25359 -0.326 0.745
...
获得边际意味着:
emmeans(fit, spec= ~Style|Species)
Species = setosa:
Style emmean SE df lower.CL upper.CL
A 5.05 0.125 141 4.81 5.30
B 5.01 0.125 141 4.76 5.26
C 4.95 0.129 141 4.70 5.20
Species = versicolor:
Style emmean SE df lower.CL upper.CL
A 5.77 0.125 141 5.52 6.02
B 6.02 0.129 141 5.76 6.27
C 6.02 0.125 141 5.78 6.27
Species = virginica:
Style emmean SE df lower.CL upper.CL
A 6.76 0.129 141 6.50 7.01
B 6.45 0.125 141 6.20 6.69
C 6.57 0.125 141 6.32 6.82
例如,这表明这A是物种 setosa 中最高的风格,尽管 A、B 和 C 彼此之间并没有令人信服的不同。