如何使用 Julia 计算 p 值的皮尔逊相关系数?

Pur*_*ney 7 julia

我正在寻求帮助,以使用 Julia 语言计算 Pearson 相关系数与 p 值。Python 中的类似函数是scipy.stats.pearson.

下面的 Julia 函数仅给出相关性。感谢您有关 p 值部分的帮助/提示。

using RDatasets, Statistics
iris = dataset("datasets", "iris");
Statistics.cor(iris.SepalLength, iris.SepalWidth)
Run Code Online (Sandbox Code Playgroud)

Bog*_*ski 2

我不知道现有的实现,但这是使用Fisher 变换进行 H0 等于 0 的双边测试:

using Distributions

cortest(x,y) =
    if length(x) == length(y)
        2 * ccdf(Normal(), atanh(abs(cor(x, y))) * sqrt(length(x) - 3))
    else
        error("x and y have different lengths")
    end
Run Code Online (Sandbox Code Playgroud)

或使用 HypothesisTests.jl 包,例如:

using HypothesisTests

OneSampleZTest(atanh(cor(iris.SepalLength, iris.SepalWidth)),
               1, nrow(iris)-3)
Run Code Online (Sandbox Code Playgroud)