## 从任何统计测试中获取单个值(例如Spearman Rho值从cor.test)内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (29)

R中的统计测试输出了许多描述。虽然它们是有用的，但我们如何才能输出或提取单个值呢？

```> cor.test(x,y,method="spearman", exact=F)

Spearman's rank correlation rho

data:  x and y
S = 12767993, p-value = 0.0001517
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
-0.188074 ```

### 2 个回答

```> tst<-cor.test(1:10,rnorm(10),method="spearman")
> tst

Spearman's rank correlation rho

data:  1:10 and rnorm(10)
S = 140, p-value = 0.6818
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.1515152 ```

...

```> tst\$p.value
[1] 0.6818076
> tst\$estimate
rho
0.1515152 ```

`test.res <- cor.test(x,y,method="spearman", exact=F)`

```> str(test.res)
List of 8
\$ statistic  : Named num 182
..- attr(*, "names")= chr "S"
\$ parameter  : NULL
\$ p.value    : num 0.785
\$ estimate   : Named num -0.103
..- attr(*, "names")= chr "rho"
\$ null.value : Named num 0
..- attr(*, "names")= chr "rho"
\$ alternative: chr "two.sided"
\$ method     : chr "Spearman's rank correlation rho"
\$ data.name  : chr "1:10 and rnorm(10)"
- attr(*, "class")= chr "htest"```

`test.res\$p.value`