[R] How Rcmdr or na.exclude blocks TukeyHSD

John Fox jfox at mcmaster.ca
Tue Oct 23 22:46:42 CEST 2012

Dear Bob,

I'll just add very briefly that I think that this isn't an Rcmdr problem, but more generally a problem with -- or limitation of --TukeyHSD(), which doesn't work properly when na.action=na.exclude. 

The Rcmdr sets na.action=na.exclude so that it can correctly add observation statistics, such as residuals, to a data set in the presence of missing data. The Rcmdr restores the previous value of this option when it exits. I'm aware that you know all this, and just wanted to provide context.


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada

On Tue, 23 Oct 2012 20:13:38 +0000
 "Muenchen, Robert A (Bob)" <muenchen at utk.edu> wrote:
> Dear R-Helpers,
> I was calling the TukeyHSD function and not getting confidence intervals or p-values. It turns out this was caused by missing data and the fact that I had previously turned on R Commander (Rcmdr). John Fox knew that Rcmdr sets na.action to na.exclude, which causes the problem. If you have this problem, you can either exit Rcmdr before calling TukeyHSD or you can set na.action to na.omit. The code below demonstrates the situation.
> Cheers,
> Bob
> data(warpbreaks)
> head(warpbreaks)
> # Introduce a missing value:
> warpbreaks$breaks[1] <- NA
> head(warpbreaks)
> # Do a model:
> fm1 <- aov(breaks ~ tension, data = warpbreaks)
> TukeyHSD(fm1, "tension", ordered = TRUE)
> # Setting na.exclude or starting Rcmdr will kill the confidence intervals:
> options(na.action = na.exclude)
> fm1 <- aov(breaks ~ tension, data = warpbreaks)
> TukeyHSD(fm1, "tension", ordered = TRUE)
> # Setting na.omit or exiting Rcmdr will get it working again:
> options(na.action=na.omit)
> fm1 <- aov(breaks ~ tension, data = warpbreaks)
> TukeyHSD(fm1, "tension", ordered = TRUE)
> =========================================================
>   Bob Muenchen (pronounced Min'-chen), Manager  
>   Research Computing Support
>   Voice: (865) 974-5230  
>   Email: muenchen at utk.edu
>   Web:   http://oit.utk.edu/research, 
>   News:  http://itc2.utk.edu/newsletter_monthly/
> ========================================================
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list