如何获得R中单尾自举Pearson相关性的置信区间

如何获得R中单尾自举Pearson相关性的置信区间

本文介绍了如何获得R中单尾自举Pearson相关性的置信区间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为R中的单尾非参数自举Pearson相关检验计算95%的自举置信区间.但是,boot.ci仅给出两尾CI.如何计算单尾引导程序CI?

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?

这是使用cor.test进行单尾自举Pearson相关性测试的代码. (它的末尾包含boot.ci,它返回两尾CI,而不是所需的单尾CI.输出包含在注释中(#)以进行比较.)

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"))

Carpenter and Bithell(2000,第1149-1157页)概述了使用基本的,学生化的,百分位数,偏差校正,偏差校正的加速,测试反转和学生化的测试反转方法来计算单边95%引导程序置信范围的算法,但是我不知道如何将R中的任何一项应用于相关性测试.

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.

推荐答案

我意识到,通过在boot.ci(b, conf = 0.90)中指定两尾90%CI并注意所需的界限(对于正相关,下限;对于负相关,上限). (另一个界限对于负的单尾相关性将为-1或对于正的单尾相关性将为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.)

这篇关于如何获得R中单尾自举Pearson相关性的置信区间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:20