英文:
confidence interval result not computing with DescTools::MedianCI
问题
我运行了这段代码来获取我的数据集中4个不同组的置信区间。然而,对于第一组,似乎上限和下限的置信区间没有被计算。
阀门尺寸 阀门中位数 下限置信区间 上限置信区间
1 1 5760 -Inf Inf
2 2 7150 6100 8090
3 3 9210 8320 10400
4 4 10450 9520 13700
这是我之前用来得到结果的代码 - 对于其他组有效,但对于第一组无效:
library(DescTools)
barplot2 <- barplot %>%
dplyr::group_by(Valve.size) %>%
dplyr::summarise(valvemedian = MedianCI(DAP, na.rm = TRUE)[1],
lowerci = MedianCI(DAP, na.rm = TRUE)[2],
upperci = MedianCI(DAP, na.rm = TRUE)[3])
英文:
I ran this code to get the confidence intervals for the 4 different groups in my dataset. However for group 1, it seems that the upper and lower confidence intervals are not being computed.
Valve.size valvemedian lowerci upperci
<fct> <dbl> <dbl> <dbl>
1 1 5760 -Inf Inf
2 2 7150 6100 8090
3 3 9210 8320 10400
4 4 10450 9520 13700
This is the code that I used to get to the result before - it worked for the other groups except the first one:
library(DescTools)
barplot2 <- barplot %>%
dplyr::group_by(Valve.size) %>%
dplyr::summarise(valvemedian = MedianCI(DAP, na.rm = TRUE)[1],
lowerci = MedianCI(DAP, na.rm = TRUE)[2],
upperci = MedianCI(DAP, na.rm = TRUE)[3])
答案1
得分: 0
根据一些快速实验,看起来DescTools::MedianCI
的默认方法("exact")在向量中观测值为5或更少时,置信区间返回(-Inf, Inf)。相比之下,method = "boot"
似乎会一直返回非无限的置信区间,即使n=2
(n=1
会导致错误)。
如果您切换到使用method = "boot"
,您应该调用set.seed(...)
(使用您选择的整数值)以确保结果可重现。
可以进一步深入代码并弄清楚为什么(该过程从计算概率为0.5的二项式检验的临界值开始(95%置信区间),即qbinom(0.025, size = n, prob = 0.5, lower.tail = TRUE)
,对于n=5
,这个值为0,对于n=6
,这个值为1,这可能是问题的根源...)。关于精确方法背后原理的描述(可能比您想要的更技术性)在这个CrossValidated问题的答案中。
英文:
Based on some quick experiments, it looks like the default method for DescTools::MedianCI
("exact") returns (-Inf, Inf) as the confidence intervals whenever there are 5 or fewer observations in the vector. In contrast, method = "boot"
appears to return non-infinite confidence intervals down to n=2
(n=1
gives an error).
If you do switch to using method = "boot"
you should call set.seed(...)
(with the integer value of your choice) to make sure the results are reproducible.
It would be possible to dig further into the code and figure out why (the procedure starts (for 95% confidence intervals) by computing the critical value for a binomial test with probability = 0.5: qbinom(0.025, size = n, prob = 0.5, lower.tail = TRUE)
&mdash which comes out to 0 for n=5
and 1 for n=6
, that's probably where the trouble starts ...) What looks like a description of the rationale for the exact method (which may be more technical than you want) is in an answer to this CrossValidated question.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论