Search code examples
rlsmeans

Specific within group comparisons for lsmeans


I would like to limit the post-hoc contrasts calculated using the package 'lsmeans' in R.

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

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

This outputs comparisons of all the possible combinations of benchmark x gc x opt.

My question is: how can I specify in the lsmeans function to only calculate and output comparisons within each of the unique benchmark:gc combinations?

I only want to know if their is a sigifciant difference between "on and off" treatments within each combination of benchmark x gc. I have added the red lines to show this.

Raw data below:

enter image description here

example from 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))

Solution

  • Found answer thanks to inspiration here: 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
    

    Answer:

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