【问题标题】:Equal cor values in mtcars dataset? [closed]mtcars数据集中的cor值相等? [关闭]
【发布时间】:2018-10-27 10:55:59
【问题描述】:

当我在 R 中运行以下代码时:

print(cor(mtcars[,c(1,5)]),method="kendall") 

我总是得到相同的结果:

       mpg      drat
mpg  1.0000000 0.6811719
drat 0.6811719 1.0000000

不管我是否设置:

method="kendall" or "spearman" or "pearson"

所有三个相关测试都为 R 中的 mtcars 数据集给出相同的相关系数是巧合还是我做错了什么?

【问题讨论】:

    标签: r correlation


    【解决方案1】:

    那是因为您使用 method 参数来表示 print,而不是 cor(即错字):

    cor(mtcars[, c(1, 5)], method = "pearson")[1, 2]
    # [1] 0.6811719
    cor(mtcars[, c(1, 5)], method = "kendall")[1, 2]
    # [1] 0.4645488
    cor(mtcars[, c(1, 5)], method = "spearman")[1, 2]
    # [1] 0.6514555
    

    print(cor(mtcars[, c(1, 5)], method = "kendall"))
    #            mpg      drat
    # mpg  1.0000000 0.4645488
    # drat 0.4645488 1.0000000
    

    【讨论】:

    • 有错字的问题应该被关闭,而不是回答,正是出于这个原因。如果有的话,您应该将此作为评论,而不是答案。
    猜你喜欢
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 2016-12-23
    • 2011-04-04
    • 1970-01-01
    • 2019-01-17
    • 2019-04-06
    • 1970-01-01
    相关资源
    最近更新 更多