Hi. I am currently trying to run some Spearman correlations, and have
encountered two issues.
1) When using cor.test() with a variable that includes ties, I get the
"Cannot compute exact p-values with ties" error. I have read that this
function now uses an asymptotic formula that allows for ties, so do not
understand why I am getting this error. (I am running version 2.4.0.)
I read the following data in from a CSV file:
species,ecoldom,ecolrank,abundance,persistence,behavdom,behavrank,aggrlevel
Fv,0.108333333,6,2.5,0,0.351351351,5,0.12195122
Mq,0.114583333,5,2,0,0.167539267,5,0.287878788
N,0.125,3,0.5,0,0.285714286,5,0.333333333
S,0.116792929,4,11,0.125,0.684027778,2,0.723214286
Th,0.164737654,1,22.5,0.875,0.717948718,2,1.614285714
Ts,0.131944444,2,3,0,0.712328767,2,1.068965517
I then use:
cor.test(ecoldom, persistence, method="spearman")
2) I have tried using spearman.test() as an alternative to cor.test() and
get different p-values (although the rho values are the same). Here is an
example:
spearman(ecoldom, abundance)
rho
0.4857143
spearman.test(ecoldom, abundance)
Rsquare F df1 df2 pvalue n
0.2359184 1.2350427 1.0000000 4.0000000 0.3287230 6.0000000
cor.test(ecoldom, abundance, method="spearman")
Spearman's rank correlation rho
data: ecoldom and abundance
S = 18, p-value = 0.3556
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.4857143
Is this difference due to the two functions using different algorithms?
Thanks
Elinor Lichtenberg
Hi. I am currently trying to run some Spearman correlations, and have
encountered two issues.
1) When using cor.test() with a variable that includes ties, I get the
"Cannot compute exact p-values with ties" error. I have read that this
function now uses an asymptotic formula that allows for ties, so do not
understand why I am getting this error. (I am running version 2.4.0.)
Because asymptotic formulas are not exact!
I read the following data in from a CSV file:
species,ecoldom,ecolrank,abundance,persistence,behavdom,behavrank,aggrlevel
Fv,0.108333333,6,2.5,0,0.351351351,5,0.12195122
Mq,0.114583333,5,2,0,0.167539267,5,0.287878788
N,0.125,3,0.5,0,0.285714286,5,0.333333333
S,0.116792929,4,11,0.125,0.684027778,2,0.723214286
Th,0.164737654,1,22.5,0.875,0.717948718,2,1.614285714
Ts,0.131944444,2,3,0,0.712328767,2,1.068965517
I then use:
cor.test(ecoldom, persistence, method="spearman")
2) I have tried using spearman.test() as an alternative to cor.test() and
get different p-values (although the rho values are the same). Here is an
example:
spearman(ecoldom, abundance)
rho
0.4857143
spearman.test(ecoldom, abundance)
Rsquare F df1 df2 pvalue n
0.2359184 1.2350427 1.0000000 4.0000000 0.3287230 6.0000000
cor.test(ecoldom, abundance, method="spearman")
Spearman's rank correlation rho
data: ecoldom and abundance
S = 18, p-value = 0.3556
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.4857143
Is this difference due to the two functions using different algorithms?
What spearman.test? It is not standard, and you're not telling us which
package it came from. Offhand I would guess that cor.test is using the
exact formula and spearman.test an asymptotic one. You can force
cor.test to use the asymptotic formula by setting exact=FALSE (oops,
there's a documentation buglet there).