On Tue, 11 Mar 2003 07:06:08 -0500
Jonathan Baron <baron at cattell.psych.upenn.edu> wrote:
> The Goodman/Kruskal gamma is a nice descriptive rank-order
> correlation statistic, often used in psychology. It is nice
> because it is easy to understand. It takes all pairs of values
> of each variable and asks whether they are congruent (S+ is the
> number in the same order for both variables) or discordant (S-,
> opposite ranking). The statistic is (S+ - S-)/(S+ + S-). It is
> like tau except for the denominator. (And the significance test
> is the same as the test for tau, in cor.test.)
>
> In trying to find the gamma statistic in R, I found one version
> as part of lrm in the Design library and another as part of
> rcorr.cens in the Hmisc library. The former won't compute if the
> model does not converge. The latter is not really gamma, because
> it discards ties in only one of the two variables.
>
> So here is a little function to compute gamma. I tried other
> ways of doing it, but this one seems as fast as any. I post it
> here to make sure I haven't made a major error. x and y are
> vectors of the same length.
>
> goodman <- function(x,y){
> Rx <- outer(x,x,function(u,v) sign(u-v))
> Ry <- outer(y,y,function(u,v) sign(u-v))
> S1 <- Rx*Ry
> return(sum(S1)/sum(abs(S1)))}
>
> --
> Jonathan Baron, Professor of Psychology, University of Pennsylvania
> R page: http://finzi.psych.upenn.edu/
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Hi Jonathan,
The "outer" method is elegant but uses too much memory for large
datasets. Use the outx=TRUE argument to rcorr.cens, which will give you gamma,
with standard error.
--
Frank E Harrell Jr Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat