如何获得 R 中单尾自举 Pearson 相关的置信区间?
How can I get confidence intervals for a one-tailed, bootstrapped Pearson correlation in R?
我想为 R
中的单尾非参数 bootstrapped Pearson 相关检验计算 95% bootstrap 置信区间。然而,boot.ci
只给出了双尾的 CIs。如何计算单尾 bootstrap CIs?
这是我使用 cor.test
进行单尾 bootstrapped Pearson 相关测试的代码。 (它在末尾包括 boot.ci
,其中 returns 双尾 CI,不需要单尾 CI。输出包含在注释中(#
) 进行比较。)
# Load boot package
library(boot)
# Make the results reproducible
set.seed(7612)
# Define bootstrapped Pearson correlation function and combine output into vector
bootCorTest <- function(data, i){
d <- data[i, ]
results <- cor.test(d$x, d$y, method = "pearson", alternative = "greater")
c(est = results$estimate, stat = results$statistic, param = results$parameter, p.value = results$p.value, CI = results$conf.int)
}
# Define data frame (from first dataset in help("cor.test"))
x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6, 3.1, 2.5, 5.0, 3.6, 4.0, 5.2, 2.8, 3.8)
dat <- data.frame(x, y)
# Perform bootstrapped correlation, 1000 bootstrap replicates
b <- boot(dat, bootCorTest, R = 1000)
#Bootstrap Statistics
# original bias std. error
# t1* 0.57118156 0.05237613 0.21511138
# t2* 1.84108264 1.04457361 3.14416940
# t3* 7.00000000 0.00000000 0.00000000
# t4* 0.05408653 0.01322028 0.09289083
# t5* -0.02223023 0.15123095 0.36338698
# t6* 1.00000000 0.00000000 0.00000000
b
# Original (non-bootstrap) statistics with labels
# est.cor stat.t param.df p.value CI1 CI2
# 0.57118156 1.84108264 7.00000000 0.05408653 -0.02223023 1.00000000
b$t0
# Two-tailed 95% Confidence intervals
# Level Normal Basic
# 95% ( 0.0972, 0.9404 ) ( 0.1867, 0.9321 )
# Level Percentile BCa
# 95% ( 0.2103, 0.9557 ) (-0.1535, 0.9209 )
boot.ci(b, type = c("norm", "basic", "perc", "bca"))
编辑:
Carpenter and Bithell (2000, pp. 1149-1157) 概述了使用基本、学生化、百分位数、偏差校正、偏差校正加速、测试反演和学生化测试反演方法计算单边 95% bootstrap 置信区间的算法,但我不知道如何应用 R
中的任何一个进行相关性测试。
我意识到可以通过在 boot.ci(b, conf = 0.90)
中指定双尾 90% CI 并注明所需的界限来获得单尾 95% bootstrap 下限或上限置信界限(较低的正相关或较高的负相关)。 (对于负单尾相关,另一个界限为 -1,对于正单尾相关,则为 1。)
我想为 R
中的单尾非参数 bootstrapped Pearson 相关检验计算 95% bootstrap 置信区间。然而,boot.ci
只给出了双尾的 CIs。如何计算单尾 bootstrap CIs?
这是我使用 cor.test
进行单尾 bootstrapped Pearson 相关测试的代码。 (它在末尾包括 boot.ci
,其中 returns 双尾 CI,不需要单尾 CI。输出包含在注释中(#
) 进行比较。)
# Load boot package
library(boot)
# Make the results reproducible
set.seed(7612)
# Define bootstrapped Pearson correlation function and combine output into vector
bootCorTest <- function(data, i){
d <- data[i, ]
results <- cor.test(d$x, d$y, method = "pearson", alternative = "greater")
c(est = results$estimate, stat = results$statistic, param = results$parameter, p.value = results$p.value, CI = results$conf.int)
}
# Define data frame (from first dataset in help("cor.test"))
x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6, 3.1, 2.5, 5.0, 3.6, 4.0, 5.2, 2.8, 3.8)
dat <- data.frame(x, y)
# Perform bootstrapped correlation, 1000 bootstrap replicates
b <- boot(dat, bootCorTest, R = 1000)
#Bootstrap Statistics
# original bias std. error
# t1* 0.57118156 0.05237613 0.21511138
# t2* 1.84108264 1.04457361 3.14416940
# t3* 7.00000000 0.00000000 0.00000000
# t4* 0.05408653 0.01322028 0.09289083
# t5* -0.02223023 0.15123095 0.36338698
# t6* 1.00000000 0.00000000 0.00000000
b
# Original (non-bootstrap) statistics with labels
# est.cor stat.t param.df p.value CI1 CI2
# 0.57118156 1.84108264 7.00000000 0.05408653 -0.02223023 1.00000000
b$t0
# Two-tailed 95% Confidence intervals
# Level Normal Basic
# 95% ( 0.0972, 0.9404 ) ( 0.1867, 0.9321 )
# Level Percentile BCa
# 95% ( 0.2103, 0.9557 ) (-0.1535, 0.9209 )
boot.ci(b, type = c("norm", "basic", "perc", "bca"))
编辑:
Carpenter and Bithell (2000, pp. 1149-1157) 概述了使用基本、学生化、百分位数、偏差校正、偏差校正加速、测试反演和学生化测试反演方法计算单边 95% bootstrap 置信区间的算法,但我不知道如何应用 R
中的任何一个进行相关性测试。
我意识到可以通过在 boot.ci(b, conf = 0.90)
中指定双尾 90% CI 并注明所需的界限来获得单尾 95% bootstrap 下限或上限置信界限(较低的正相关或较高的负相关)。 (对于负单尾相关,另一个界限为 -1,对于正单尾相关,则为 1。)