confidence interval result not computing with DescTools::MedianCI

huangapple go评论71阅读模式
英文:

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
  &lt;fct&gt;            &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;
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 &lt;- barplot %&gt;% 
  dplyr::group_by(Valve.size) %&gt;% 
  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=2n=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 = &quot;boot&quot; appears to return non-infinite confidence intervals down to n=2 (n=1 gives an error).

If you do switch to using method = &quot;boot&quot; 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.

huangapple
  • 本文由 发表于 2023年7月3日 03:14:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定