特定于 lsmeans 的组内比较

Specific within group comparisons for lsmeans

我想限制使用 R 中的包 'lsmeans' 计算的 post-hoc 对比。

library(nlme) #for gls
model<-gls(time~ benchmark*gc*opt, method="REML",data=d)

lsmeans.d<-lsmeans(model, ~benchmark:gc:opt)
pairs(lsmeans.d)

这会输出基准 x gc x opt 所有可能组合的比较结果。

我的问题是:如何在 lsmeans 函数中指定仅计算和输出每个唯一 benchmark:gc 组合中的比较?

我只想知道在基准 x gc 的每个组合中,它们是否是“开启和关闭”处理之间的显着差异。我添加了红线来显示这一点。

原始数据如下:

示例来自 2

d=expand.grid(obs=0:10, benchmark=c('antlr', 'bloat', 'chart', 'eclipse', 'fop', 'hsqldb', 'jython', 'luindex', 'lusearch', 'pmd', 'xalan'), gc=c('CopyMS', 'GenCopy', 'GenImmix', 'GenMS', 'Immix'), opt=c('on', 'off'), heapSize=seq(from=1.5, to=4, by=0.5))
d$time = rexp(nrow(d), 0.01)+1000
d$time = d$time + abs(d$heapSize-3)*100
d$time[d$opt=='on'] = d$time[d$opt=='on']-200
 
d$time[d$opt=='on' & d$benchmark=='bloat'] = d$time[d$opt=='on' & d$benchmark=='bloat'] + 190
d$time[d$opt=='on' & d$benchmark=='pmd' & d$gc=='Immix'] = d$time[d$opt=='on' & d$benchmark=='pmd' & d$gc=='Immix'] + 600

ggplot() +
facet_grid(gc~benchmark) +
geom_boxplot(data=d, mapping=aes(x=opt, y=time, color=opt))

感谢这里的灵感找到答案: first answer by rvs

Using the FIRST version of your 'fit' model, do lsm = lsmeans(fit, ~A*B|C) and then contrast(lsm, list(c = c(1,0,0,-1)) – rvl Nov 24 '16 at 21:33

答案:

lsm = lsmeans(model, ~benchmark*opt|gc)
pairs(lsm)