post hoc in Kruskal Wallis
If the design is balanced this function will work
npcompare <- function (var,class)
{
k <- length(table(class))
n <- length(var)/k
se <- sqrt((n*(n*k)*(n*k+1))/12)
rvar <- rank(var)
for (i in 1:(k-1)) {
left <- sum(rvar[as.numeric(class)==i])
for (j in (i+1):k) {
right <- sum(rvar[as.numeric(class)==j])
diff = abs(left-right)
cat(paste(i,j,left,right,diff,round(1-pt(diff/se,k),4),'\n'))
}
}
cat('\n')
}
It's not formatted very elegantly, but it works.
Dave R.
On 11/24/2011 08:01 AM, Richard L. Boyce wrote:
Zar, in Biostatistical Analysis, has a Tukey-like test that is highly recommended. You may need to do it by hand, but it is quite easy.
Message: 5 Date: Wed, 23 Nov 2011 18:21:54 +0100 From: "Jakub Szymkowiak"<qbaszym at tlen.pl> To:<r-sig-ecology at r-project.org> Subject: [R-sig-eco] post hoc in Kruskal Wallis Message-ID:<C8041F4B78EB487C8707E72114C3F4CF at komp> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Hi, does anyone know, how can I perform post-hoc tests (especially Least Significant Difference and Sheffe Test) for results from Kruskal-Wallis test? In KruskaI-Wallis test I found some significant differences between tested groups, but I want to know between which groups this difference is really signifficant. Cheers, Jakub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ David W. Roberts office 406-994-4548 Professor and Head FAX 406-994-3190 Department of Ecology email droberts at montana.edu Montana State University Bozeman, MT 59717-3460