AndriSignorell / DescTools

Tools for Descriptive Statistics and Exploratory Data Analysis
http://andrisignorell.github.io/DescTools/
82 stars 18 forks source link

Additional bootstrap methods in MedianCI() #109

Open DrJerryTAO opened 1 year ago

DrJerryTAO commented 1 year ago

Hi @AndriSignorell, currently MedianCI(method = "boot") implements type = "basic" only. Is there a reason for not allowing other types such as "bca", "perc", "norm"? Would you also consider adding the random-number-generator seed control within the function and adding MedianDiffCI() using bootstrap methods?

GegznaV commented 1 year ago

You may use set.seed() so additional arguments related to random number control are not necessary.

2023 bal. 8, št 00:20, MrJerryTAO @.***> rašė:

Hi @AndriSignorell https://github.com/AndriSignorell, currently MedianCI(method = "boot") implements type = "basic" only. Is there a reason for not allowing other types such as "bca", "perc", "norm"? Would you also consider adding the random-number-generator seed control within the function and adding MedianDiffCI() using bootstrap methods?

— Reply to this email directly, view it on GitHub https://github.com/AndriSignorell/DescTools/issues/109, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADBC43COMK5UX7JVIZI7M7TXACAJNANCNFSM6AAAAAAWW57T6Y . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Generalized commented 5 months ago

@AndriSignorell I vote for allowing at least the percentile and bca options too. For skewed data, the basic approach can often lead to nonsensical, symmetrical CIs (similar to Wald's). CI for quantiles cannot be automatically assumed symmetrical, especially for smaller samples. The BCa gives much better results, reflecting the skewness, and often agrees with the exact CI based on the binomial distribution.

Example (here the binomial one doesn't account for ties, and being exact isn't the most efficient, so it covers 0 here) obraz

and

> MedianCI(x$Diff)
   median    lwr.ci    upr.ci 
 -5.31250 -27.14286   0.00000 
attr(,"conf.level")
[1] 0.9586105
> MedianCI(x$Diff, method = "boot")
   median    lwr.ci    upr.ci 
 -5.31250 -10.35714  16.33929 
AndriSignorell commented 4 months ago

The function has been rewritten (0.99.54.2) so that different types of boostrap confidence intervals can now be calculated. The default has been changed to "perc", which seems robust and suitable for the median.

set.seed(99)
x <- runif(100)

MedianCI(x)
MedianCI(x, method="boot", type="bca")
MedianCI(x, method="boot", type="perc")
MedianCI(x, method="boot", type="basic")

Any suggestions for implementing MedianDiffCI()?