[1] 0.1834940
However, when I tried to reproduce the two correlation coefficients by
following their "defination", I got different results than from "cor".
For Spearman, I got:
od1 = order(mat[,1], decreasing=T)
od2= order(mat[,2], decreasing=T)
1-6*sum((od1-od2)^2)/(length(od1)^3-length(od1))
[1] -0.2909091
This is different with from "cor", which is 0.255.
For Kendal, I got:
accord=0
disaccord=0
experi=mat[,1]
target=mat[,2]
N= length(experi)
for(i in 1:(N-1)) {
for(j in (i+1):N) {
if((target[i] < target[j]) && (experi[i] < experi[j])) {
accord=accord+1
} else if ((target[i] > target[j]) && (experi[i] > experi[j])) {
disaccord=disaccord+1
}
}
}
(accord-disaccord)/(N*(N-1)/2)
[1] -0.2181818
This is also different with from "cor", which is 0.183.
Anybody could help me out explaining the right answer? Thanks in
advance!
Baoqiang