问题
m=c(1,2,5,4,6,8)
h=c(1,2,9,8,7,3)
cor(m,h)
#[1] 0.4093729
If you estimate the correlation coefficient (R), then you can also estimate a 95%
confidence interval for correlation coefficient (R), resulting in, for example something like
R = 0.40 [0.33 0.56]
where the "best" estimate for R is 0.40
and there's a 95%
chance that the true R is between 0.3
and 0.56
. (Note that these numbers are completely made up.)
I am looking for a function, which will provide the lower and upper bounds of R separately . To have something like:
R = 0.40
upper [0.33]
lower [0.56]
something simiilar to this in 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.
回答1:
In the "see also" section of cor
's help page, it says
cor.test for confidence intervals (and tests)
> 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
Or to get at the interval more directly:
> x = cor.test(m, h)
> x$conf.int
[1] -0.6022868 0.9164582
attr(,"conf.level")
[1] 0.95
来源:https://stackoverflow.com/questions/17808560/what-is-the-function-that-will-provide-you-the-lower-and-upper-bounds-of-correla