# [R] Tukey HSD

jlpugh jlpugh at email.arizona.edu
Thu Feb 9 20:28:08 CET 2012

```Hey Folks:

New to R and learning as I go, but really, I know just enough to get myself
into trouble. I've waded through everything up till now, and don't see
anything in the search that is directly helpful for the POS that I've
created.

The GOAL: All I want in the world is a program that performs 1-way ANOVA's
on every column in a data set (taking the first column as the definition of
the groups) and then spits out ONLY those results that were significant (p
<= whatever I want), with their respective plots and TukeyHSD results.
Sounds simple, right?

Data:

http://r.789695.n4.nabble.com/file/n4374072/test_text.txt test_text.txt

CODE:  ( which occurs after TEST <- read.table("test_text.txt") )

i <- 2;
sink (file = "test_output.txt", append = FALSE)
mydf <- data.frame(TEST)
for (j in 1:ncol(mydf)-1) {
var1 <- mydf[,1]
var2 <- mydf[,i]
fm1 <- aov(var1 ~ var2)
tky <- TukeyHSD(fm1)
otpt <- capture.output(summary(fm1))
i <- i+1;
lines <- as.vector(unlist(strsplit(otpt[2]," ")),mode="list") # gets the
p-value
if (grepl("[1234567890]",lines[14],perl = TRUE)) { #make sure that slot for
p-value has a number
number <- as.numeric(lines[14]) # make it numeric for logic test
if (number <= 0.1) {
cat(otpt, sep = "\n\n")
cat(tky, sep = "\n\n")
quartz(boxplot(mydf[,i] ~ mydf[,1]))
}
}
}
sink()

The ERROR:

Error in TukeyHSD.aov(fm1) : no factors in the fitted model
In replications(paste("~", xx), data = mf) : non-factors ignored: var2

It works if I leave out " tky <- TukeyHSD(fm1) " and the subsequent cat.
I've tried doing the Tukey on the mydf[,1].. itself, changing their classes,
etc. Perhaps the whole approach is flawed.

THANKS!

--
View this message in context: http://r.789695.n4.nabble.com/Tukey-HSD-tp4374072p4374072.html
Sent from the R help mailing list archive at Nabble.com.

```