Bug 16437 - TukeyHSD fails for models without intercept
Summary: TukeyHSD fails for models without intercept
Alias: None
Product: R
Classification: Unclassified
Component: Analyses (show other bugs)
Version: R 3.2.0
Hardware: Other Linux
: P5 minor
Assignee: R-core
Depends on:
Reported: 2015-06-22 12:33 UTC by Arnaud LE ROUZIC
Modified: 2015-12-14 13:48 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Arnaud LE ROUZIC 2015-06-22 12:33:26 UTC

Comment 1 Arnaud LE ROUZIC 2015-06-22 12:44:51 UTC
TukeyHSD.aov ends up with an error 

Error in prjs[, "(Intercept)"] : subscript out of bounds

when the lm model has no intercept (for instance, if one sets the contrasts to FALSE). 

The bug comes from the fact that TukeyHSD calls model.tables.aov(x, "means"), which calculates factor means from the intercept. 

Steps to reproduce: 

dd <- data.frame(F=factor(rep(c("A","B","C"),each=3)), num=1:9)
lin <- lm(num~0+F, data=dd, contrasts=list(F=contr.sum(3, contrasts=FALSE)))
anov <- aov(lin)

The obvious workaround is to run a specific model (with intercept) for aov, as the results of the Tukey test should not depend on the contrasts chosen.
Comment 2 Brian Ripley 2015-08-11 12:01:27 UTC
In the original design there were no aov fits without intercepts.

model.tables and TukeyHSD have been modified to accommodate them from 3.2.2 patched.