簡體   English   中英

在引導 cor.test kendall 后如何找到分位數/p 值

[英]How to find quantiles / p-value after bootstrapping a cor.test kendall

我正在使用 R 進行數據分析。 我想找到兩個數字向量的自舉相關的分位數/p 值。 在計算了兩個向量的相關性(方法 = kendall)后,我引導了該函數。 不知何故,查找分位數的功能不起作用

我正在使用 #mosaic 包並嘗試了下面的分位數函數。 兩個向量的相關性測試和 bootstrapping 運行良好,但我嘗試的兩個分位數函數都不起作用。 請看我下面的代碼:

#Score and Population are the vectors (both numeric), Index 2019 is the dataset I am analysing

##Correlation Kendall
cor.test(Index2019$Score, Index2019$Population,  method="kendall")

##Bootstraping
set.seed(1896)
H1_Bootstrapping <- do(1000) * cor.test(Score~Population, data= resample(Index2019), method="kendall")

#QUANTILE FUNCTIONS I tried
quantile( ~ cor.test, data = H1_Bootstrapping, probs = c(0.025, 0.975))

qdata(~cor.test,probs=c(.05,.95),data = H1_Bootstrapping)

quantile(H1_Bootstrapping, probs=c(0.05,0.95))

quantile(H1_Bootstrapping, probs=c(0.05,0.95),na.rm=TRUE)

我期望 0.05 和 0.95 置信區間的值,但在嘗試上述函數時實際上會出現以下錯誤:

quantile( ~ cor.test, data = H1_Bootstrapping, probs = c(0.025, 0.975))
ERROR MESSAGE:
Error in quantile.default(eval(formula[[2]], data, .envir), ...) : 
  anyNA() applied to non-(list or vector) of type 'closure'


qdata(~cor.test,probs=c(.05,.95),data = H1_Bootstrapping)
ERROR MESSAGE:
Error in quantile.default(x, ..., na.rm = na.rm) : 
  formal argument "probs" matched by multiple actual arguments


quantile(H1_Bootstrapping, probs=c(0.05,0.95))
ERROR MESSAGE:
Error in quantile.default(x, ..., na.rm = na.rm) : 
  missing values and NaN's not allowed if 'na.rm' is FALSE


quantile(H1_Bootstrapping, probs=c(0.05,0.95),na.rm=TRUE)
ERROR MESSAGE:
Error in (1 - h) * qs[i] : non-numeric argument to binary operator

你能幫我完成任何功能嗎? 非常感謝您的幫助!

H1_Bootstrapping$z您可以找到 Kendall 相關性的引導值。

library(mosaic)
## Generate data
set.seed(12345)
n <- 100
Index2019 <- data.frame(Score=rnorm(n), Population=rnorm(n))

## Correlation Kendall
cor.test(Index2019$Score, Index2019$Population,  method="kendall")

## Bootstraping
set.seed(1896)
H1_Bootstrapping <- do(1000) * cor.test(Score~Population, data= resample(Index2019), 
                                        method="kendall")

## QUANTILE FUNCTIONS
quantile( ~ z, data = H1_Bootstrapping, probs = c(0.05, 0.95))
#         5%        95% 
# -0.6468391  2.4376336

qdata(~z, p=c(.05,.95), data = H1_Bootstrapping)
#       quantile    p
# 5%  -0.6468391 0.05
# 95%  2.4376336 0.95

quantile(H1_Bootstrapping$z, probs=c(0.05,0.95))
#         5%        95% 
# -0.6468391  2.4376336

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM