Skip to content

Commit

Permalink
Adding the arcsine binomial proportion confidence interval (#86)
Browse files Browse the repository at this point in the history
* Added arcsine transformation CI calculation

* Fixed typo & replaced alpha by unicode equivalent

* Keep typofix, revert Unicode replacement

* Change sigma to z for semantic purposes

* Fix brackets, add information link

* Added tests for arcsine transformation CI

* Fixing arcsine test

Entered wrong values

* Left != right
  • Loading branch information
DCLukas authored and ararslan committed Mar 7, 2017
1 parent e58291e commit 10e6623
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function StatsBase.confint(x::BinomialTest, alpha::Float64=0.05; tail=:both, met
ci_jeffrey(x, alpha)
elseif method == :agresti_coull
ci_agresti_coull(x, alpha)
elseif method == :arcsine
ci_arcsine(x, alpha)
else
throw(ArgumentError("method=$(method) is not implemented yet"))
end
Expand Down Expand Up @@ -131,6 +133,13 @@ function ci_wilson(x::BinomialTest, alpha::Float64=0.05)
-q*σ, μ+q*σ)
end

# Arcsine transformation interval as based on Cohen's H: https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Arcsine_transformation
function ci_arcsine(x::BinomialTest, alpha::Float64=0.05)
q = quantile(Normal(), 1-alpha/2)
p = x.x / x.n
z = q/(2*sqrt(x.n))
(sin(asin(sqrt(p))-z)^2, sin(asin(sqrt(p))+z)^2)
end

## SIGN TEST

Expand Down
7 changes: 7 additions & 0 deletions test/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ t = BinomialTest(26, 78)
@test_ci_approx confint(t, method=:agresti_coull) (0.2384423809121706, 0.44387022232522744)
@test_ci_approx confint(t, tail=:left, method=:agresti_coull) (0.0, 0.42558712894362222)
@test_ci_approx confint(t, tail=:right, method=:agresti_coull) (0.25225408385003706, 1.0)
@test_ci_approx confint(t, method=:arcsine) (0.23366209634204066,0.44117918327686334)
@test_ci_approx confint(t, tail=:left, method=:arcsine) (0.0,0.4235046425920888)
@test_ci_approx confint(t, tail=:right, method=:arcsine) (0.2489264087216164,1.0)

show(IOBuffer(), t)

t = BinomialTest([trues(6); falses(3)])
Expand All @@ -40,6 +44,9 @@ t = BinomialTest([trues(6); falses(3)])
@test_ci_approx confint(t, method=:agresti_coull) (0.350905767251112,0.88271254994237336)
@test_ci_approx confint(t, tail=:left, method=:agresti_coull) (0.0,0.86049746046629294)
@test_ci_approx confint(t, tail=:right, method=:agresti_coull) (0.39579136642712159,1.0)
@test_ci_approx confint(t, method=:arcsine) (0.345812446615087,0.9188773496172281)
@test_ci_approx confint(t, tail=:left, method=:arcsine) (0.0,0.8879439981269358)
@test_ci_approx confint(t, tail=:right, method=:arcsine) (0.3965293068864491,1.0)
show(IOBuffer(), t)

x = [55, 58, 61, 61, 62, 62, 62, 63, 63, 64, 66, 68, 68, 69, 69, 69, 70, 71, 72, 72]
Expand Down

0 comments on commit 10e6623

Please sign in to comment.