【问题标题】:Correlation significance for non-zero null hypothesis using R使用 R 的非零零假设的相关显着性
【发布时间】:2011-12-28 03:30:54
【问题描述】:

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

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

给出:

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 

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

【问题讨论】:

  • 在我看来,这对于排名相关程序来说会很困难。您可能想在堆栈交换上提出问题(没有特定于 R 的标签)...
  • 我认为@BenBolker 的意思是 stats.stackexchange.com,所以你知道。
  • 我现在缺少脑细胞,但你不会从实际计算两个数据集的相关系数开始,然后用空检验或贝叶斯估计您的计算质量?
  • 也许你在这里找到答案:stats.stackexchange.com/q/14220/3094

标签: r correlation


【解决方案1】:

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

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

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

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

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

3) 取置信区间:

boot.ci(boot.rho)

【讨论】:

    【解决方案2】:

    问题中没有说,但是如果您可以接受 Pearson 假设(二元正态),您可以只查看置信区间的上限。任何像您这样大于该值的零假设都会在 p

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

    【讨论】:

    • 是的,我曾为皮尔逊系数考虑过这一点,但不幸的是,我的真实数据中有几个异常值,因此我认为 rho 会更合适。我不知道是否有办法为 rho 生成置信区间。
    • 您可以使用 bootstrap 为 rho 生成置信区间,请参阅其他答案。
    猜你喜欢
    • 2021-03-18
    • 2018-06-10
    • 2015-06-28
    • 2014-01-21
    • 1970-01-01
    • 2021-07-13
    • 2020-06-01
    • 1970-01-01
    相关资源
    最近更新 更多