问题
I want to calculate 95% bootstrap confidence intervals for a one-tailed, nonparametric bootstrapped Pearson correlation test in R
. However, boot.ci
only gives two-tailed CIs. How can I calculate one-tailed bootstrap CIs?
Here's my code for a one-tailed, bootstrapped Pearson correlation test using cor.test
. (It includes boot.ci
at the end, which returns two-tailed CI, not desired one-tailed CI. The output is included as comments (#
) for comparison.)
# 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"))
EDIT:
Carpenter and Bithell (2000, pp. 1149-1157) outline the algorithms for calculating one-sided 95% bootstrap confidence bounds using the basic, studentized, percentile, bias corrected, bias corrected accelerated, test-inversion, and studentized test-inversion methods, but I don't know how to apply any of these in R
for a correlation test.
回答1:
I realized that the one-tailed 95% bootstrap lower or upper confidence bound can be obtained by specifying two-tailed 90% CI in boot.ci(b, conf = 0.90)
and noting the desired bound (lower for positive correlations or upper for negative correlations). (The other bound will be either -1 for a negative one-tailed correlation or 1 for a positive one-tailed correlation.)
来源:https://stackoverflow.com/questions/57902348/how-can-i-get-confidence-intervals-for-a-one-tailed-bootstrapped-pearson-correl