[R] cor(X) with P-Value
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Sat Jul 23 15:09:13 CEST 2005
Worik Turei stanton wrote:
> Friends
>
> I am new to R (and statistics) so am struggling a bit.
>
> Briefly...
>
> I am interested in getting the P-Value from cor(X) where X is a matrix.
>
> I have found cor.test.
>
> Verbosely...
>
> I have 4 vectors and can generate the corellation matrix...
>
>
>
>>cor(cbind(X1, X2, X3, X4))
>
> X1 X2 X3 X4
> X1 1.00000000 -0.06190365 -0.156972795 0.182547517
> X2 -0.06190365 1.00000000 0.264352860 0.146750844
> X3 -0.15697279 0.26435286 1.000000000 -0.006380052
> X4 0.18254752 0.14675084 -0.006380052 1.000000000
>
> But I want the P-Values (gives me the significance I belive).
>
>
>>cor.test(X2, X3)
>
>
> Pearson's product-moment correlation
>
> data: X2 and X3
> t = 3.3346, df = 148, p-value = 0.001080
> alternative hypothesis: true correlation is not equal to 0
> 95 percent confidence interval:
> 0.1086963 0.4073565
> sample estimates:
> cor
> 0.2643529
>
> is very cool. Just what I want. But there is too much information for
> too little data.
>
> What I would like to do is some thing like...
>
> cor_with_p_test(cbind(X1, X2, X3, X4))
> X1 X2 X3
> X1 1 -0.06190365 -0.1569728...
> P 0.4517 0.05507 ...
>
> X2 -0.06190365 1 0.2643529 ...
> P 0.4517 0.001080 ...
> :
> :
>
> I think I could write a function for it if such a function does not exist
> if I could do...
>
>
>>CT23 <- cor.test(X2, X3)
>>CT23$P
>
> 0.001080
>
>>CT23$V
>
> 0.2643529
>
> But I do not know how.
>
> cheers
> Worik
library(Hmisc)
rcorr(cbind(. . . .))
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list