首先,我建议您将两个对比放在一个列表中,例如,
contr = list(`2+2|0` = c(0, 0, 1, 0, 1, 0),
`2+3|1` = c(0, 0, 0, 1, 0, 1))
您必须决定何时要进行反向转换。请参阅有关转换的小插图,并注意有关“时间就是一切”的讨论。两个基本选项是:
一种选择:获取日志计数的边际均值,然后进行反向变换:
mod_con = update(contrast(mod_emm, contr), tran = "log")
summary(mod_con, type = "response")
[update
之所以需要调用,是因为contrast
除特殊情况外,它会去除转换,因为它并不总是知道分配给任意线性函数的比例。例如,两个平方根的差异不在平方根尺度上。]
第二种选择:对预测进行反向转换,然后对它们求和:
mod_emmr = regrid(mod_emm)
contrast(mod_emmr, contr)
这些结果之间的区别与几何平均值(选项 1)和算术平均值(选项 2)之间的区别相同。我怀疑它们中的任何一个都会产生与原始边际平均数相同的结果,因为它们是基于您的模型的预测。就个人而言,我认为第一个选项是更好的选择,因为 sum 是线性运算,并且模型在对数尺度上是线性的。
附录
其实还有第三种选择,就是创建一个分组变量。我将用pigs
数据集进行说明。
> pigs.lm <- lm(log(conc) ~ source + factor(percent), data = pigs)
以下是 EMM percent
:
> emmeans(pigs.lm, "percent")
percent emmean SE df lower.CL upper.CL
9 3.445307 0.04088810 23 3.360723 3.529890
12 3.624861 0.03837600 23 3.545475 3.704248
15 3.662706 0.04372996 23 3.572244 3.753168
18 3.745156 0.05296030 23 3.635599 3.854713
Results are averaged over the levels of: source
Results are given on the log (not the response) scale.
Confidence level used: 0.95
现在让我们创建一个分组因子group
:
> pigs.emm = add_grouping(ref_grid(pigs.lm), "group", "percent", c("1&2","1&2","3&4","3&4"))
> str(pigs.emm)
'emmGrid' object with variables:
source = fish, soy, skim
percent = 9, 12, 15, 18
group = 1&2, 3&4
Nesting structure: percent %in% group
Transformation: “log”
现在获取 EMMgroup
并注意它们只是各个级别的平均值:
> emmeans(pigs.emm, "group")
group emmean SE df lower.CL upper.CL
1&2 3.535084 0.02803816 23 3.477083 3.593085
3&4 3.703931 0.03414907 23 3.633288 3.774574
Results are averaged over the levels of: source, percent
Results are given on the log (not the response) scale.
Confidence level used: 0.95
以下是响应量表的摘要:
> summary(.Last.value, type = "response")
group response SE df lower.CL upper.CL
1&2 34.29790 0.961650 23 32.36517 36.34605
3&4 40.60662 1.386678 23 37.83703 43.57893
Results are averaged over the levels of: source, percent
Confidence level used: 0.95
Intervals are back-transformed from the log scale
这些是平均值而不是总和,但除此之外它有效,并且转换不会像在contrast()