如何在 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)

Pearson 积矩相关系数

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)

Pearson 积矩相关系数

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)

Pearson 积矩相关系数

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)

Pearson 积矩相关系数

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)

Pearson 积矩相关系数

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)

Pearson 积矩相关系数

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)

Pearson 积矩相关系数

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)

Pearson 积矩相关系数

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

更新于: 2020 年 10 月 17 日

11K+ 次查看

开启你的 职业生涯

通过完成课程获得认证

开始学习
广告