An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111121/c944d7a0/attachment.pl>
count ties after rank?
6 messages · Peter Langfelder, Hao, Zhaozhe, David Winsemius
On Mon, Nov 21, 2011 at 11:36 AM, Hao, Zhaozhe <haozhaozhe at ou.edu> wrote:
Hello! ? ?I need to use Kruskal-Wallis test and post-hoc test (Dunn's test) for my data. But when I searched around, I only found this function: kruskal.test. But nothing for Dunn's test. ? ?So I started to write one myself. ?But ?I do not know how to count ties in the data frame. I can use for loops but it seems long and unnecessary since the rank function actually knows the ties. So can anyone give me a hint on how I can "count" the number of ties?
If you just need the overall number of ties in a vector (say x), you can get it by nTies = length(x) - length(unique(x)) This will not work if missing data are present, so you will have to remove those first. HTH, Peter
On Nov 21, 2011, at 2:50 PM, Peter Langfelder wrote:
On Mon, Nov 21, 2011 at 11:36 AM, Hao, Zhaozhe <haozhaozhe at ou.edu> wrote:
Hello! I need to use Kruskal-Wallis test and post-hoc test (Dunn's test) for my data. But when I searched around, I only found this function: kruskal.test. But nothing for Dunn's test. So I started to write one myself. But I do not know how to count ties in the data frame. I can use for loops but it seems long and unnecessary since the rank function actually knows the ties. So can anyone give me a hint on how I can "count" the number of ties?
If you just need the overall number of ties in a vector (say x), you can get it by nTies = length(x) - length(unique(x))
And if you wnat to know which ties are which you can do: table(x)[table(x) > 1]
This will not work if missing data are present, so you will have to remove those first.
table() would ignore missing data (assuming it were properly NA not- valued). > x <- sample(c(1:10,NA,NA), 20, replace=TRUE) > table(x)[table(x) >1] x 1 4 7 9 10 2 3 2 2 2 > x [1] 7 10 3 9 NA NA 2 4 10 NA NA 4 5 9 6 4 1 1 7 8
David Winsemius, MD West Hartford, CT
On Nov 21, 2011, at 2:36 PM, Hao, Zhaozhe wrote:
Hello! I need to use Kruskal-Wallis test and post-hoc test (Dunn's test) for my data. But when I searched around,
"Searching around" is a bit vague as a search strategy: Try :kruskal dunn" at the location that RSiteSearch gets you to: http://search.r-project.org/cgi-bin/namazu.cgi?query=kruskal+Dunn&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08&idxname=Rhelp10&idxname=Rhelp02 Or in its default settings: http://search.r-project.org/cgi-bin/namazu.cgi?query=kruskal+Dunn&max=100&result=normal&sort=score&idxname=functions&idxname=vignettes&idxname=views
I only found this function: kruskal.test. But nothing for Dunn's test. So I started to write one myself.
You are perhaps referring to what others are callng the Nemenyi-
Damico-Wolfe-Dunn test. See the last example in the entry that ?
kruskal_test would have gotten you... had you known where it was.
install.packages("coin")
require(coin)
help("LocationTests")
But I do not know how to count ties in the data frame. I can use for loops but it seems long and unnecessary since the rank function actually knows the ties. So can anyone give me a hint on how I can "count" the number of ties? Many thanks.
David Winsemius, MD West Hartford, CT
Hi,
Thank you all for the the quick response. But there still some questions.
1) nTies = length(x) - length(unique(x)) cannot distinguish vector (1,2,2,2,3), and (1,2,2,3,3)....
2) table(x)[table(x) >1] tells me the right number, but how can I call the numbers from the result of table function? I.e., I want to get the tie number, t and use it in another equation.
From: David Winsemius [dwinsemius at comcast.net]
Sent: Monday, November 21, 2011 14:05
To: Peter Langfelder
Cc: Hao, Zhaozhe; r-help at r-project.org
Subject: Re: [R] count ties after rank?
Sent: Monday, November 21, 2011 14:05
To: Peter Langfelder
Cc: Hao, Zhaozhe; r-help at r-project.org
Subject: Re: [R] count ties after rank?
On Nov 21, 2011, at 2:50 PM, Peter Langfelder wrote: > On Mon, Nov 21, 2011 at 11:36 AM, Hao, Zhaozhe <haozhaozhe at ou.edu> > wrote: >> Hello! >> >> I need to use Kruskal-Wallis test and post-hoc test (Dunn's >> test) for my data. But when I searched around, I only found this >> function: kruskal.test. But nothing for Dunn's test. >> >> So I started to write one myself. But I do not know how to >> count ties in the data frame. I can use for loops but it seems long >> and unnecessary since the rank function actually knows the ties. So >> can anyone give me a hint on how I can "count" the number of ties? >> > > If you just need the overall number of ties in a vector (say x), you > can get it by > > nTies = length(x) - length(unique(x)) And if you wnat to know which ties are which you can do: table(x)[table(x) > 1] > > This will not work if missing data are present, so you will have to > remove those first. > table() would ignore missing data (assuming it were properly NA not- valued). > x <- sample(c(1:10,NA,NA), 20, replace=TRUE) > table(x)[table(x) >1] x 1 4 7 9 10 2 3 2 2 2 > x [1] 7 10 3 9 NA NA 2 4 10 NA NA 4 5 9 6 4 1 1 7 8 -- David Winsemius, MD West Hartford, CT
On Nov 21, 2011, at 3:20 PM, Hao, Zhaozhe wrote:
Hi,
Thank you all for the the quick response. But there still some
questions.
1) nTies = length(x) - length(unique(x)) cannot distinguish
vector (1,2,2,2,3), and (1,2,2,3,3)....
2) table(x)[table(x) >1] tells me the right number, but how can
I call the numbers from the result of table function? I.e., I want
to get the tie number, t and use it in another equation.
This will give you a named one ros matrix, Can e address by location or name. > x <- sample(c(1:10,NA,NA), 20, replace=TRUE) > ties <- table(x)[table(x) >1] > > ties x 1 2 3 4 5 8 2 3 2 2 2 3 > ties[1] 1 2 > ties["8"] # note that this is really 3 and that the 8 is a name 8 3 > names(ties) [1] "1" "2" "3" "4" "5" "8" > unname(ties) [1] 2 3 2 2 2 3
________________________________________ From: David Winsemius [dwinsemius at comcast.net] Sent: Monday, November 21, 2011 14:05 To: Peter Langfelder Cc: Hao, Zhaozhe; r-help at r-project.org Subject: Re: [R] count ties after rank? On Nov 21, 2011, at 2:50 PM, Peter Langfelder wrote: On Mon, Nov 21, 2011 at 11:36 AM, Hao, Zhaozhe <haozhaozhe at ou.edu> wrote: Hello! I need to use Kruskal-Wallis test and post-hoc test (Dunn's test) for my data. But when I searched around, I only found this function: kruskal.test. But nothing for Dunn's test. So I started to write one myself. But I do not know how to count ties in the data frame. I can use for loops but it seems long and unnecessary since the rank function actually knows the ties. So can anyone give me a hint on how I can "count" the number of ties? If you just need the overall number of ties in a vector (say x), you can get it by nTies = length(x) - length(unique(x)) And if you wnat to know which ties are which you can do: table(x)[table(x) > 1] This will not work if missing data are present, so you will have to remove those first. table() would ignore missing data (assuming it were properly NA not- valued). x <- sample(c(1:10,NA,NA), 20, replace=TRUE) table(x)[table(x) >1] x 1 4 7 9 10 2 3 2 2 2 x [1] 7 10 3 9 NA NA 2 4 10 NA NA 4 5 9 6 4 1 1 7 8 -- David Winsemius, MD West Hartford, CT
David Winsemius, MD West Hartford, CT