Skip to content

Commit

Permalink
Merge pull request #2 from marcusps/marcusps/fix-binomial-median
Browse files Browse the repository at this point in the history
Add test, remove `median` definition for `Binomial`
  • Loading branch information
marcusps authored Dec 14, 2024
2 parents 515c5e2 + f0275a3 commit e9aa32e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/univariate/discrete/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,8 @@ function mode(d::Binomial{T}) where T<:Real
end
modes(d::Binomial) = Int[mode(d)]

function median(d::Binomial)
round_down_mean = floor(Int,mean(d))
if cdf(d,round_down) < 0.5
round_down_mean+1
else
round_down_mean
end
end

# `median` falls back to quantile-based definition

function skewness(d::Binomial)
n, p1 = params(d)
p0 = 1 - p1
Expand Down
7 changes: 7 additions & 0 deletions test/univariate/discrete/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ end
@test Distributions.expectation(identity, Binomial(6)) 3.0
@test Distributions.expectation(x -> -x, Binomial(10, 0.2)) -2.0

# Test median
@test Distributions.median(Binomial(5,3//10)) == 1
@test Distributions.median(Binomial(25,3//10)) == 7
@test Distributions.median(Binomial(45,3//10)) == 13
@test Distributions.median(Binomial(65,3//10)) == 19
@test Distributions.median(Binomial(85,3//10)) == 25

# Test mode
@test Distributions.mode(Binomial(100, 0.4)) == 40
@test Distributions.mode(Binomial(1, 0.51)) == 1
Expand Down

0 comments on commit e9aa32e

Please sign in to comment.