![](/img/trans.png)
[英]What package in R is used to calculate non-zero null hypothesis p-values on linear models?
[英]Correlation significance for non-zero null hypothesis using R
我正在測試兩個變量之間的相關性:
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?
您可以使用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)
它沒有在問題中說,但如果你可以忍受Pearson假設(雙變量正常),你可以只查看置信區間的上限。 像你這樣的任何零假設都會在p <0.05時被拒絕。
> cor.test(x, y, method = c("pearson"))$conf
[1] 0.7757901 0.9629837
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.