如何通过R's cor()的相关分析计算P值和标准误差 [英] How to compute P-value and standard error from correlation analysis of R's cor()

查看:41
本文介绍了如何通过R's cor()的相关分析计算P值和标准误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据,其中包含针对每个条件(x和y)的54个样本.我已经通过以下方式计算了相关性:

I have data that contain 54 samples for each condition (x and y). I have computed the correlation the following way:

> dat <- read.table("http://dpaste.com/1064360/plain/",header=TRUE)
> cor(dat$x,dat$y)
[1] 0.2870823

在上面的R的cor()函数中是否存在一种本机生成相关SE的方法和T检验的p值?

Is there a native way to produce SE of correlation in R's cor() functions above and p-value from T-test?

如该网络(第14.6页)

推荐答案

我认为您正在寻找的只是 cor.test()函数,它将返回您所需要的一切寻找相关的标准误差除外.但是,如您所见,其公式非常简单,如果使用 cor.test ,则具有计算所需的所有输入.

I think that what you're looking for is simply the cor.test() function, which will return everything you're looking for except for the standard error of correlation. However, as you can see, the formula for that is very straightforward, and if you use cor.test, you have all the inputs required to calculate it.

使用示例中的数据(以便您可以将其与14.6页的结果进行比较):

Using the data from the example (so you can compare it yourself with the results on page 14.6):

> cor.test(mydf$X, mydf$Y)

    Pearson's product-moment correlation

data:  mydf$X and mydf$Y
t = -5.0867, df = 10, p-value = 0.0004731
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.9568189 -0.5371871
sample estimates:
       cor 
-0.8492663 

如果愿意,还可以创建如下所示的函数,以包含相关系数的标准误差.

If you wanted to, you could also create a function like the following to include the standard error of the correlation coefficient.

为方便起见,这是等式:

For convenience, here's the equation:

r =相关估计, n -2 =自由度,这两个参数在上面的输出中都可以轻松获得.因此,一个简单的函数可能是:

r = the correlation estimate and n - 2 = degrees of freedom, both of which are readily available in the output above. Thus, a simple function could be:

cor.test.plus <- function(x) {
  list(x, 
       Standard.Error = unname(sqrt((1 - x$estimate^2)/x$parameter)))
}

并按如下所示使用它:

cor.test.plus(cor.test(mydf$X, mydf$Y))

在这里,"mydf"定义为:

Here, "mydf" is defined as:

mydf <- structure(list(Neighborhood = c("Fair Oaks", "Strandwood", "Walnut Acres",
  "Discov. Bay", "Belshaw", "Kennedy", "Cassell", "Miner", "Sedgewick", 
  "Sakamoto", "Toyon", "Lietz"), X = c(50L, 11L, 2L, 19L, 26L, 
  73L, 81L, 51L, 11L, 2L, 19L, 25L), Y = c(22.1, 35.9, 57.9, 22.2, 
  42.4, 5.8, 3.6, 21.4, 55.2, 33.3, 32.4, 38.4)), .Names = c("Neighborhood", 
  "X", "Y"), class = "data.frame", row.names = c(NA, -12L))

这篇关于如何通过R's cor()的相关分析计算P值和标准误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆