如何找到R中相关系数的p值?
t检验用于找到相关系数的p值,并在此基础上确定两个变量之间是否存在统计上显着的关系。在R中,我们可以使用cor.test函数执行此测试。例如,如果我们有一个向量x和y,那么我们可以使用cor.test(x,y)找到p值。
例1
set.seed(444) x1<−1:10 y1<−10:1 cor.test(x1,y1)
皮尔逊的乘积矩相关性
data: x1 and y1 t = −134217728, df = 8, p−value < 2.2e−16 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: −1 −1 sample estimates: cor −1
例2
x2<−rnorm(5000,12,1) y2<−rnorm(5000,12,3) cor.test(x2,y2)
皮尔逊的乘积矩相关性
data: x2 and y2 t = −1.0611, df = 4998, p−value = 0.2887 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: −0.04270876 0.01271735 sample estimates: cor −0.01500724
范例3
x3<−rpois(10000,10) y3<−rpois(10000,8) cor.test(x3,y3)
皮尔逊的乘积矩相关性
data: x3 and y3 t = 1.2085, df = 9998, p−value = 0.2269 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: −0.007516765 0.031677652 sample estimates: cor 0.01208509
例子4
x4<−runif(5557,10,20) y4<−runif(5557,12,25) cor.test(x4,y4)
皮尔逊的乘积矩相关性
data: x4 and y4 t = −0.84014, df = 5555, p−value = 0.4009 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: −0.03755372 0.01502620 sample estimates: cor −0.01127155
范例5
x5<−rexp(479,3.2) y5<−rexp(479,1.2) cor.test(x5,y5)
皮尔逊的乘积矩相关性
data: x5 and y5 t = −1.3626, df = 477, p−value = 0.1736 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: −0.15101987 0.02747874 sample estimates: cor −0.06226847
范例6
x6<−rlnorm(1000,2,1.5) y6<−rlnorm(1000,4,0.8) cor.test(x6,y6)
皮尔逊的乘积矩相关性
data: x6 and y6 t = −1.4907, df = 998, p−value = 0.1364 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: −0.10880908 0.01490269 sample estimates: cor −0.04713393
范例7
x7<−sample(0:9,5000,replace=TRUE) y7<−sample(1:10,5000,replace=TRUE) cor.test(x7,y7)
皮尔逊的乘积矩相关性
data: x7 and y7 t = −1.2418, df = 4998, p−value = 0.2144 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: −0.04526022 0.01016128 sample estimates: cor −0.01756296
范例8
x8<−sample(101:150,100000,replace=TRUE) y8<−sample(51:150,100000,replace=TRUE) cor.test(x8,y8)
皮尔逊的乘积矩相关性
data: x8 and y8 t = −0.7474, df = 99998, p−value = 0.4548 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: −0.008561341 0.003834517 sample estimates: cor −0.002363503