使用R的非零假设的相关显着性

时间:2021-08-15 07:36:55

I'm testing the correlation between two variables:

我正在测试两个变量之间的相关性:

set.seed(123)
x <- rnorm(20)
y <- x + x * 1:20
cor.test(x, y, method = c("spearman"))

which gives:

Spearman's rank correlation rho

data:  x and y 
S = 54, p-value = 6.442e-06
alternative hypothesis: true rho is not equal to 0 
sample estimates:
   rho 
0.9594 

The p-value is testing the null hypothesis that the correlation is zero. Is there an R function that will allow me to test a different null hypothesis - say that the correlation is less than or equal to 0.3?

p值正在测试相关为零的零假设。是否有一个R函数可以让我测试一个不同的零假设 - 比如说相关性小于或等于0.3?

2 个解决方案

#1


0  

It doesn't say in the question, but if you can live with Pearson assumptions (bivariate normal), you can just look to the upper bound of the confidence interval. Any null hypothesis like yours that is greater than that would be rejected at p<0.05.

它没有在问题中说,但如果你可以忍受Pearson假设(双变量正态),你可以只看到置信区间的上限。像你这样的任何零假设都比p <0.05更高。

> cor.test(x, y, method = c("pearson"))$conf
[1] 0.7757901 0.9629837

#2


3  

You can use bootstrap to calculate the confidence interval for rho:

您可以使用bootstrap来计算rho的置信区间:

1) Make function to extract the estimate of the cor.test (remember to put indices so the boot can sample the data):

1)使函数提取cor.test的估计值(记得放置索引,以便引导可以对数据进行采样):

rho <- function(x, y, indices){
  rho <- cor.test(x[indices], y[indices],  method = c("spearman"))
  return(rho$estimate)
}

2) Use the boot package to bootstrap your estimate:

2)使用启动包来引导您的估计:

library(boot)    
boot.rho <- boot(x ,y=y, rho, R=1000)

3) Take the confidence interval:

3)采取置信区间:

boot.ci(boot.rho)

#1


0  

It doesn't say in the question, but if you can live with Pearson assumptions (bivariate normal), you can just look to the upper bound of the confidence interval. Any null hypothesis like yours that is greater than that would be rejected at p<0.05.

它没有在问题中说,但如果你可以忍受Pearson假设(双变量正态),你可以只看到置信区间的上限。像你这样的任何零假设都比p <0.05更高。

> cor.test(x, y, method = c("pearson"))$conf
[1] 0.7757901 0.9629837

#2


3  

You can use bootstrap to calculate the confidence interval for rho:

您可以使用bootstrap来计算rho的置信区间:

1) Make function to extract the estimate of the cor.test (remember to put indices so the boot can sample the data):

1)使函数提取cor.test的估计值(记得放置索引,以便引导可以对数据进行采样):

rho <- function(x, y, indices){
  rho <- cor.test(x[indices], y[indices],  method = c("spearman"))
  return(rho$estimate)
}

2) Use the boot package to bootstrap your estimate:

2)使用启动包来引导您的估计:

library(boot)    
boot.rho <- boot(x ,y=y, rho, R=1000)

3) Take the confidence interval:

3)采取置信区间:

boot.ci(boot.rho)