m=c(1,2,5,4,6,8)
h=c(1,2,9,8,7,3)
cor(m,h)
#[1] 0.4093729
Run Code Online (Sandbox Code Playgroud)
如果你估计相关系数(R),那么你也可以估计95%
相关系数(R)的置信区间,导致例如像
R = 0.40 [0.33 0.56]
Run Code Online (Sandbox Code Playgroud)
对R的"最佳"估计是真正的R在和之间0.40
的95%
可能性.(请注意,这些数字是完全组成的.)0.3
0.56
我正在寻找一个函数,它将分别提供R的下限和上限.有类似的东西:
R = 0.40
upper [0.33]
lower [0.56]
Run Code Online (Sandbox Code Playgroud)
类似于此的东西MATLAB
:
[R,P,RLO,RUP]=corrcoef(...) also returns matrices RLO and RUP, of the same size as R,
containing lower and upper bounds for a 95% confidence interval for each coefficient.
Run Code Online (Sandbox Code Playgroud)
cor
它说,在帮助页面的"另见"部分
置信区间(和测试)的cor.test
> cor.test(m, h)
Pearson's product-moment correlation
data: m and h
t = 0.8974, df = 4, p-value = 0.4202
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.6022868 0.9164582
sample estimates:
cor
0.4093729
Run Code Online (Sandbox Code Playgroud)
或者更直接地获得间隔:
> x = cor.test(m, h)
> x$conf.int
[1] -0.6022868 0.9164582
attr(,"conf.level")
[1] 0.95
Run Code Online (Sandbox Code Playgroud)