[R] Pairwise Tukey test with letter in descending order
    Jim Lemon 
    jim at bitwrit.com.au
       
    Wed Jun 18 02:22:45 CEST 2014
    
    
  
On Tue, 17 Jun 2014 08:58:12 PM Cleber Chaves wrote:
> Dear all,
> has a long time that I unsuccessfully try to obtain letters of each 
equal
> means in a Tukey test of a GLM object, in a descending order. Could
> someone, please, help me?
> 
> I try this:
> 
> m1 <- glm(comp~pop)
> anova(m1,test="F")
> lsmeans(m1, cld~pop, adjust='tukey')
> 
> But the letters I obtain are not in descendig order, and I dispend a 
lot of
> time to organize it when the outcome have many letters (e.c. A to F
> letters).
> 
Hi Cleber,
You may be able to do something like the following that is from the 
example for TukeyHSD:
summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks))
...
TukeyHSD(fm1, "tension", ordered = TRUE)
  Tukey multiple comparisons of means
    95% family-wise confidence level
    factor levels have been ordered
Fit: aov(formula = breaks ~ wool + tension, data = warpbreaks)
$tension
         diff        lwr      upr     p adj
M-H  4.722222 -4.6311985 14.07564 0.4474210
L-H 14.722222  5.3688015 24.07564 0.0011218
L-M 10.000000  0.6465793 19.35342 0.0336262
# assign this to an object
thsd<-TukeyHSD(fm1, "tension", ordered = TRUE)
# see if there is a way to reorder the comparisons
str(thsd)
List of 1
 $ tension: num [1:3, 1:4] 4.72 14.72 10 -4.63 5.37 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:3] "M-H" "L-H" "L-M"
  .. ..$ : chr [1:4] "diff" "lwr" "upr" "p adj"
 - attr(*, "class")= chr [1:2] "TukeyHSD" "multicomp"
 - attr(*, "orig.call")= language aov(formula = breaks ~ wool + 
tension, data = warpbreaks)
 - attr(*, "conf.level")= num 0.95
 - attr(*, "ordered")= logi TRUE
# reorder the matrix of comparisons
thsd$tension<-thsd$tension[order(rownames(thsd$tension)),]
thsd
  Tukey multiple comparisons of means
    95% family-wise confidence level
    factor levels have been ordered
Fit: aov(formula = breaks ~ wool + tension, data = warpbreaks)
$tension
         diff        lwr      upr     p adj
L-H 14.722222  5.3688015 24.07564 0.0011218
L-M 10.000000  0.6465793 19.35342 0.0336262
M-H  4.722222 -4.6311985 14.07564 0.4474210
Jim
    
    
More information about the R-help
mailing list