首页 > 解决方案 > 为什么 spearman 在 zscore 上产生不同的结果?

问题描述

嗨,无论是 zscore 还是 raw,spearman 相关似乎都应该产生相同的结果。这里有两个例子。

https://stats.stackexchange.com/questions/77562/why-does-correlation-come-out-the-same-on-raw-data-and-z-scored-standardized-d

https://stats.stackexchange.com/questions/13952/can-spearmans-correlation-be-run-on-z-scores

然而,对于这个例子,这两个相关性是不同的,我想知道发生了什么。

df = read.csv("https://www.dropbox.com/s/jdktw9jugzm97v3/test.csv?dl=1", head=F)

cor(df[, 1], df[,2], method="spearman")
cor(scale(df[, 1]), scale(df[,2]), method="spearman")

# 0.8462699 vs 0.8905341

有趣的是,皮尔逊给出了相同的结果。我想知道我在这里做什么或想错了?

编辑:所以另外我认为这可能是由于关系,所以我也使用了应该处理关系的肯德尔,但它也会给出不同的结果。

cor(as.matrix ( df[, 1] ) , as.matrix ( df[,2] ), method="kendall" )
cor(scale(as.matrix ( df[, 1] )), scale(as.matrix ( df[,2] )),  method="kendall")

谢谢。

标签: rcorrelationpearson

解决方案


嗨,正如上面在评论中提到的,这是由于舍入错误造成的。没有人回答,但我想添加这个,以防其他人偶然发现类似的问题。所以当我四舍五入到 15-16 位时,结果是一样的。

df = read.csv("https://www.dropbox.com/s/jdktw9jugzm97v3/test.csv?dl=1", head=F)

df = round(df, digits = 15)

cor(as.matrix ( df[, 1] ) , as.matrix ( df[,2] ), method="spearman" )
cor(scale(df[, 1] ), scale(df[,2] ),  method="spearman")

感谢大家对此的帮助。


推荐阅读