Are there any R packages for the calculation of Kendall's tau-b and tau-c, and their associated standard errors? My searches on Google and Rseek have turned up nothing, but surely someone has implemented these in R.
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
There's a routine for Kendall's coefficient in
psych
package withcorr.test(x, method = "kendall")
. This function can be applied on data.frame, and also displays p-values for each pair of variables. I guess it displays tau-a coefficient. Only downside is that it's actually a wrapper forcor()
function.Wikipedia has good reference on Kendall's coefficient, and check this link out. Try
sos
package andfindFn()
function. I got bunch of stuff when querying"tau a"
andtau b
, but both ended with no luck. And search results seem to merge toKendall
package, as @Ian suggested.Stumbled across this page today, as I was looking for an implementation of kendall tau-b in R
For anyone else looking for the same thing:
tau-b is in fact part of the stats package.
See this link for more details: https://stat.ethz.ch/pipermail/r-help//2012-August/333656.html
I tried it and it works: library(stats)
this is the output:
Just ignore the warning messege. The tau is in fact tau b !!!
There are three Kendall tau statistics (tau-a, tau-b, and tau-c).
They are not interchangeable, and none of the answers posted so far deal with the last two, which is the subject of the OP's question.
I was unable to find functions to calculate tau-b or tau-c, either in the R Standard Library (stat et al.) or in any of the Packages available on CRAN or other repositories. I used the excellent R Package sos to search, so i believe results returned were reasonably thorough.
So that's the short answer to the OP's Question: no built-in or Package function for tau-b or tau-c.
But it's easy to roll your own.
Writing R functions for the Kendall statistics is just a matter of translating these equations into code:
tau-a: equal to concordant minus discordant pairs, divided by a factor to account for total number of pairs (sample size).
tau-b: explicit accounting for ties--i.e., both members of the data pair have the same value; this value is equal to concordant minus discordant pairs divided by a term representing the geometric mean between the number of pairs not tied on x (X0) and the number not tied on y (Y0).
tau-c: larger-table variant also optimized for non-square tables; equal to concordant minus discordant pairs multiplied by a factor that adjusts for table size).
So these four parameters are all you need to calculate tau-a, tau-b, and tau-c:
P
Q
m
n
(plus XO & Y0 for tau-b)
For instance, the code for tau-c is:
So how are Kendall's tau statistics related to the other statistical tests used in categorical data analysis?
All three Kendall tau statistics, along with Goodman's and Kruskal's gamma are for correlation of ordinal and binary data. (The Kendall tau statistics are more sophisticated alternatives to the gamma statistic (just P-Q).)
And so Kendalls's tau and the gamma are counterparts to the simple chi-square and Fisher's exact tests, both of which are (as far as I know) suitable only for nominal data.
example:
Quite a while, but the 3 functions are implemented in DescTools.
I have been doing a bit research on Kendall's tau. Directly using cor(x, y, method="kendall") will give you Kendall's tau-b, which is a little different from the original definition, i.e., Kendall's tau-a. Kendall's tau-b is more commonly used as it takes into account ties, hence, most available software packages (e.g. cor(), Kendall()) all calculate Kendall's tau-b.
The difference between Kendall's tau-a and tau-b is essentially the denominator. Specifically, for Kendall's tau-a, the denominator D=n*(n-1)/2, which is fixed, while for Kendall's tau-b, the denominator D=sqrt(No. pairs of Var1 excluding tied pairs)*sqrt(No. pairs of Var2 excluding tied pairs). The value of tua-b is usually larger than tau-a.
As a simple example, consider X=(1,2,3,4,4), Y=(2,3,4,4,4). Kendall's tau-b=0.88, while tau-a=0.7.
For Kendall's tau-c, I didn't see too much on it, so no comments.
Have you tried the function
cor
? There is a method you can set to"kendall"
(also options for"pearson"
and"spearman"
if needed), not sure if that covers all the standard errors you are looking for but it should get you started.