如果您想引导相关性测试,只需从引导统计函数返回相关系数即可。在这种情况下,引导相关性测试的 p 值是不合适的,因为您忽略了相关性测试的方向性。
在 CrossValidated 上检查这个问题,以获得有关执行引导假设检验的一些不错的答案:https://stats.stackexchange.com/questions/20701/computing-p-value-using-bootstrap-with-r
library("boot")
data <- read.csv("~/Documents/stack/tmp.csv", header = FALSE)
colnames(data) <- c("x", "y")
data <- as.data.frame(data)
x <- data$Var1
y <- data$Var2
dat <- data.frame(x,y)
set.seed(1)
b3 <- boot(data,
statistic = function(data, i) {
cor(data[i, "x"], data[i, "y"], method='pearson')
},
R = 1000
)
b3
#>
#> ORDINARY NONPARAMETRIC BOOTSTRAP
#>
#>
#> Call:
#> boot(data = data, statistic = function(data, i) {
#> cor(data[i, "x"], data[i, "y"], method = "pearson")
#> }, R = 1000)
#>
#>
#> Bootstrap Statistics :
#> original bias std. error
#> t1* 0.1279691 -0.0004316781 0.314056
boot.ci(b3, type = c("norm", "basic", "perc", "bca")) #bootstrapped CI.
#> BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
#> Based on 1000 bootstrap replicates
#>
#> CALL :
#> boot.ci(boot.out = b3, type = c("norm", "basic", "perc", "bca"))
#>
#> Intervals :
#> Level Normal Basic
#> 95% (-0.4871, 0.7439 ) (-0.4216, 0.7784 )
#>
#> Level Percentile BCa
#> 95% (-0.5225, 0.6775 ) (-0.5559, 0.6484 )
#> Calculations and Intervals on Original Scale
plot(density(b3$t))
abline(v = 0, lty = "dashed", col = "grey60")
在这种情况下,如果没有 p 值,则可以非常肯定地说,抽样分布的大部分质量非常接近于零。