r - 为什么 spearman 在 zscore 上产生不同的结果?
问题描述
嗨,无论是 zscore 还是 raw,spearman 相关似乎都应该产生相同的结果。这里有两个例子。
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")
谢谢。
解决方案
嗨,正如上面在评论中提到的,这是由于舍入错误造成的。没有人回答,但我想添加这个,以防其他人偶然发现类似的问题。所以当我四舍五入到 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")
感谢大家对此的帮助。
推荐阅读
- file - 从特定路径 Xamarin.Forms 读取文件
- foreach - 将嵌套 foreach 循环的结果存储在 FBM 类中
- c# - SQL:.NET 与 SSMS
- bash - bash - zip multiple files, take argument from variable, one of them has space in name
- javascript - 必应地图上的图钉
- material-ui - 如何设置 FormControlLabel 字体大小的样式
- javascript - 如何查看 HTML、CSS 和 ECMAScript 的历史版本
- c++ - while循环c ++中的非法指令
- tableau-api - 如何仅提取 Tableau 集的 IN 计数
- javascript - 表格和滚动条不刷新