AndriSignorell / DescTools

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

MultinomCI one-sided error #153

Closed h-huss closed 2 months ago

h-huss commented 4 months ago

MultinomCI yields strange (0 / 1) estimates for one-sided intervals.

> MultinomCI(c(100,100,100,100,100,100), sides='right')
           est    lwr.ci    upr.ci
[1,] 0.1666667 0.1316667 0.2018585
[2,] 0.0000000 0.1316667 0.2018585
[3,] 0.1666667 0.1316667 0.2018585
[4,] 0.1666667 0.1316667 0.2018585
[5,] 0.1666667 0.1316667 0.2018585
[6,] 0.1666667 0.1316667 0.2018585

> MultinomCI(c(100,100,100,100,100,100), sides='left')
           est    lwr.ci    upr.ci
[1,] 0.1666667 0.1316667 0.2018585
[2,] 0.1666667 0.1316667 0.2018585
[3,] 1.0000000 0.1316667 0.2018585
[4,] 0.1666667 0.1316667 0.2018585
[5,] 0.1666667 0.1316667 0.2018585
[6,] 0.1666667 0.1316667 0.2018585

This is most likely caused by https://github.com/AndriSignorell/DescTools/blob/cc8369d3d8edb35563785d97ca962460c2de97d3/R/StatsAndCIs.r#L3574-L3577 which overrides the second/third row instead of column

AndriSignorell commented 4 months ago

Thanks. You're perfectly right, this is a bug. Will soon be fixed.

AndriSignorell commented 2 months ago

This is fixed with 0.99.55:

> library(DescTools)
> packageVersion("DescTools")
[1] '0.99.55'
> 
> MultinomCI(c(100,100,100,100,100,100), sides='right')
           est lwr.ci    upr.ci
[1,] 0.1666667      0 0.2018585
[2,] 0.1666667      0 0.2018585
[3,] 0.1666667      0 0.2018585
[4,] 0.1666667      0 0.2018585
[5,] 0.1666667      0 0.2018585
[6,] 0.1666667      0 0.2018585

> MultinomCI(c(100,100,100,100,100,100), sides='left')
           est    lwr.ci upr.ci
[1,] 0.1666667 0.1316667      1
[2,] 0.1666667 0.1316667      1
[3,] 0.1666667 0.1316667      1
[4,] 0.1666667 0.1316667      1
[5,] 0.1666667 0.1316667      1
[6,] 0.1666667 0.1316667      1