You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by John Gant <jo...@gmail.com> on 2005/08/25 02:39:11 UTC
[math]: spearman rank cross correlation
> Copied from the mailing list:
> ----- Original Message -----
> From: "John Gant" <jo...@gmail.com>
> >
> > Specifically testTwo() in
> > http://issues.apache.org/bugzilla/attachment.cgi?id=3D16172 takes care
> > of data with equal value (ie equal rank), is this the type of
> > situation to which you are referring? Yes I agree, we should implement
> > routines to sort in more diverse ways, but for right now I depend upon
> > Arrays.sort() to perform the sorting.
>=20
> Yes, and in this case the implementation is incorrectly computing the spe=
arman
> correlation as -0.1. But, according to R, the correlation is drastically
> different:
>=20
> > x <- c(2.0, 1.0, 3.0, 3.0, 5.0)
> > y <- c(4.0, 4.0, 1.0, 2.0, 3.0)
> > cor(x, y, method=3D"spearman")
> [1] -0.631579
>=20
> Thus, I hold the implementation needs to change to correctly rank data wi=
- Hide quoted text -
th
> ties.
Please take a look at http://www.louisville.edu/~jdgant01/SRCC.xls ,
this should agree with the unit tests for
SpearmanRankCrossCorrelation.java (please tell me if you see a
discrepancy). The TiesRankEquivalent.java class is a very generic/simple
implementation, and can be discarded if necessary. From what I have
read, tie ranking is the biggest and most complicated issue with
Spearman Rank Correlation. I will try, along with development on
K-means, to implement each of the ranking algorithms that R uses in
its corr() function.
Thanks,
John
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [math]: spearman rank cross correlation
Posted by Phil Steitz <ph...@gmail.com>.
On 9/6/05, John Gant <jo...@gmail.com> wrote:
>
> On 8/30/05, Phil Steitz <ph...@gmail.com> wrote:
> >
> > On 8/29/05, John Gant <jo...@gmail.com> wrote:
> > >
> > > Wondering if my next step is to implement the ranking algorithms in R?
> >
> >
> > Don't know exactly what you mean here. If you mean implement R's ranking
> > algorithms in java, that would be nice.
> >
> > Please review the results of the unit tests when compared to the excel
> > > workbook. The spearman cross correlation can be checked against R once
> > > ranking algorithms are finished, otherwise it must be checked by hand.
> >
> >
> > Where is the excel workbook?
>
>
> http://louisville.edu/~jdgant01/SRCC.xls
>
> Sorry about attaching so many files with no obvious explanation. My
> > > thought process for ranking algorithms is as follows:
> > >
> > > Interface -> RankingAlgorithm, includes the rank(double [] data)
> method.
> >
> >
> > Yes, sounds good.
> >
> > Concrete Class -> TiesEquivalentRank.java. This class implements the
> > > rank() method by assigning equivalent raw values the same rank without
> > > incrementing the rank per duplicate raw value.
> >
> >
> > Also good.
> >
> > Future Classes: all of R's ranking algorithms.
> >
> >
> > Also good, that is essentially what Brent was suggesting and I agree
> these
> > will be useful. The only question is package placement (see below).
> >
> > The SpearmanRankCrossCorrelation takes an instance of RankingAlgorithm
> > > as a constructor parameter. This allows for a more "pluggable"
> > > algorithm. If this seems incorrect please reply so that I do not
> > > implement K-means, or other clustering algorithms who use a distance
> > > measurement, in the same manner.
> >
> >
> > That also sounds fine. I have a couple of suggestions, however, about
> > package placement and organization of the code. Just as Pearson's R is
> > essentially an operation on vectors, so is Spearman's, so it would seem
> > more
> > natural to me to define a class that just provides a pairwise
> correlation
> > of
> > two vectors, as SimpleRegression does. Then the matrix-filling version
> can
> > be provided similarly to what you did for Pearson's. The ranking
> algorithm
> > implementations should probably go into something like
> > o.a.c.m.stat.ranksand I would put the Spearman's implementation, along
> > with a wrapper for the
> > Pearson's impl inside SimpleRegression into o.a.c.m.stat.correlation. I
> am
> > interested in others' views on this.
>
>
>
> An idea...would it be proper java to reconstruct the SimpleRegression.getR
> ()
> method to something like SimpleRegression.getR(SimpleRegression.TYPE)
> where
> TYPE is a static field defining the type of correlation? Or maybe
> something
> similar to getR("spearman") or getR("pearson")? The string idea sounds
> very
> ugly, and I think a static field is more conventional. Do you think this
> is
> the way to go, if so I can work on getting this implemented.
We made a decision early on in the history of [math] to avoid using "flag
parameters" in APIs, favoring differently named methods or classes instead.
Similarly, we try to avoid "return codes" favoring objects and exceptions.
To some extent, this is "the Java way." In any case, for consistency with
the rest of [math], I would not recommend that we use actual parameters to
select correlation algorithms. I would implement a separate class to do
Spearman's corr and, as indicated above, also a wrapper for Pearson's inside
a correlation package, possibly both implementing a simple Correlation
interface.
Phil
Thanks,
> John
>
>
Re: [math]: spearman rank cross correlation
Posted by John Gant <jo...@gmail.com>.
On 8/30/05, Phil Steitz <ph...@gmail.com> wrote:
>
> On 8/29/05, John Gant <jo...@gmail.com> wrote:
> >
> > Wondering if my next step is to implement the ranking algorithms in R?
>
>
> Don't know exactly what you mean here. If you mean implement R's ranking
> algorithms in java, that would be nice.
>
> Please review the results of the unit tests when compared to the excel
> > workbook. The spearman cross correlation can be checked against R once
> > ranking algorithms are finished, otherwise it must be checked by hand.
>
>
> Where is the excel workbook?
http://louisville.edu/~jdgant01/SRCC.xls
Sorry about attaching so many files with no obvious explanation. My
> > thought process for ranking algorithms is as follows:
> >
> > Interface -> RankingAlgorithm, includes the rank(double [] data) method.
>
>
> Yes, sounds good.
>
> Concrete Class -> TiesEquivalentRank.java. This class implements the
> > rank() method by assigning equivalent raw values the same rank without
> > incrementing the rank per duplicate raw value.
>
>
> Also good.
>
> Future Classes: all of R's ranking algorithms.
>
>
> Also good, that is essentially what Brent was suggesting and I agree these
> will be useful. The only question is package placement (see below).
>
> The SpearmanRankCrossCorrelation takes an instance of RankingAlgorithm
> > as a constructor parameter. This allows for a more "pluggable"
> > algorithm. If this seems incorrect please reply so that I do not
> > implement K-means, or other clustering algorithms who use a distance
> > measurement, in the same manner.
>
>
> That also sounds fine. I have a couple of suggestions, however, about
> package placement and organization of the code. Just as Pearson's R is
> essentially an operation on vectors, so is Spearman's, so it would seem
> more
> natural to me to define a class that just provides a pairwise correlation
> of
> two vectors, as SimpleRegression does. Then the matrix-filling version can
> be provided similarly to what you did for Pearson's. The ranking algorithm
> implementations should probably go into something like
> o.a.c.m.stat.ranksand I would put the Spearman's implementation, along
> with a wrapper for the
> Pearson's impl inside SimpleRegression into o.a.c.m.stat.correlation. I am
> interested in others' views on this.
An idea...would it be proper java to reconstruct the SimpleRegression.getR()
method to something like SimpleRegression.getR(SimpleRegression.TYPE) where
TYPE is a static field defining the type of correlation? Or maybe something
similar to getR("spearman") or getR("pearson")? The string idea sounds very
ugly, and I think a static field is more conventional. Do you think this is
the way to go, if so I can work on getting this implemented.
Thanks,
John
Re: [math]: spearman rank cross correlation
Posted by Phil Steitz <ph...@gmail.com>.
On 8/29/05, John Gant <jo...@gmail.com> wrote:
>
> Wondering if my next step is to implement the ranking algorithms in R?
Don't know exactly what you mean here. If you mean implement R's ranking
algorithms in java, that would be nice.
Please review the results of the unit tests when compared to the excel
> workbook. The spearman cross correlation can be checked against R once
> ranking algorithms are finished, otherwise it must be checked by hand.
Where is the excel workbook?
Sorry about attaching so many files with no obvious explanation. My
> thought process for ranking algorithms is as follows:
>
> Interface -> RankingAlgorithm, includes the rank(double [] data) method.
Yes, sounds good.
Concrete Class -> TiesEquivalentRank.java. This class implements the
> rank() method by assigning equivalent raw values the same rank without
> incrementing the rank per duplicate raw value.
Also good.
Future Classes: all of R's ranking algorithms.
Also good, that is essentially what Brent was suggesting and I agree these
will be useful. The only question is package placement (see below).
The SpearmanRankCrossCorrelation takes an instance of RankingAlgorithm
> as a constructor parameter. This allows for a more "pluggable"
> algorithm. If this seems incorrect please reply so that I do not
> implement K-means, or other clustering algorithms who use a distance
> measurement, in the same manner.
That also sounds fine. I have a couple of suggestions, however, about
package placement and organization of the code. Just as Pearson's R is
essentially an operation on vectors, so is Spearman's, so it would seem more
natural to me to define a class that just provides a pairwise correlation of
two vectors, as SimpleRegression does. Then the matrix-filling version can
be provided similarly to what you did for Pearson's. The ranking algorithm
implementations should probably go into something like
o.a.c.m.stat.ranksand I would put the Spearman's implementation, along
with a wrapper for the
Pearson's impl inside SimpleRegression into o.a.c.m.stat.correlation. I am
interested in others' views on this.
Thanks and sorry for the response latency. I will get the Pearson's stuff
committed shortly.
Phil
Thanks,
> John
>
>
Re: [math]: spearman rank cross correlation
Posted by John Gant <jo...@gmail.com>.
Wondering if my next step is to implement the ranking algorithms in R?
Please review the results of the unit tests when compared to the excel
workbook. The spearman cross correlation can be checked against R once
ranking algorithms are finished, otherwise it must be checked by hand.
Sorry about attaching so many files with no obvious explanation. My
thought process for ranking algorithms is as follows:
Interface -> RankingAlgorithm, includes the rank(double [] data) method.
Concrete Class -> TiesEquivalentRank.java. This class implements the
rank() method by assigning equivalent raw values the same rank without
incrementing the rank per duplicate raw value.
Future Classes: all of R's ranking algorithms.
The SpearmanRankCrossCorrelation takes an instance of RankingAlgorithm
as a constructor parameter. This allows for a more "pluggable"
algorithm. If this seems incorrect please reply so that I do not
implement K-means, or other clustering algorithms who use a distance
measurement, in the same manner.
Thanks,
John
On 8/24/05, John Gant <jo...@gmail.com> wrote:
> > Copied from the mailing list:
> > ----- Original Message -----
> > From: "John Gant" <jo...@gmail.com>
> > >
> > > Specifically testTwo() in
> > > http://issues.apache.org/bugzilla/attachment.cgi?id=3D16172 takes care
> > > of data with equal value (ie equal rank), is this the type of
> > > situation to which you are referring? Yes I agree, we should implement
> > > routines to sort in more diverse ways, but for right now I depend upon
> > > Arrays.sort() to perform the sorting.
> >=20
> > Yes, and in this case the implementation is incorrectly computing the spe=
> arman
> > correlation as -0.1. But, according to R, the correlation is drastically
> > different:
> >=20
> > > x <- c(2.0, 1.0, 3.0, 3.0, 5.0)
> > > y <- c(4.0, 4.0, 1.0, 2.0, 3.0)
> > > cor(x, y, method=3D"spearman")
> > [1] -0.631579
> >=20
> > Thus, I hold the implementation needs to change to correctly rank data wi=
> - Hide quoted text -
> th
> > ties.
>
> Please take a look at http://www.louisville.edu/~jdgant01/SRCC.xls ,
> this should agree with the unit tests for
> SpearmanRankCrossCorrelation.java (please tell me if you see a
> discrepancy). The TiesRankEquivalent.java class is a very generic/simple
> implementation, and can be discarded if necessary. From what I have
> read, tie ranking is the biggest and most complicated issue with
> Spearman Rank Correlation. I will try, along with development on
> K-means, to implement each of the ranking algorithms that R uses in
> its corr() function.
>
> Thanks,
> John
>
--
John Gant
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org