Skip to content

Commit

Permalink
Incorporate suggestions from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusps authored Dec 15, 2024
1 parent d91cd7d commit b4647c2
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/univariate/discrete/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,19 @@ end
modes(d::Binomial) = Int[mode(d)]

function median(dist::Binomial)
bound = min(rv.p, 1-rv.p)
rv_mean = mean(rv)
floor_mean = floor(Int, rv_mean)
ceil_mean = ceil(Int, rv_mean)
if rv_mean - floor_mean <= bound
bound = min(dist.p, 1-dist.p) # from http://dx.doi.org/10.1111/j.1467-9574.1980.tb00681.x
dist_mean = mean(dist)

floor_mean = floor(Int, dist_mean)

if dist_mean - floor_mean < bound
floor_mean
elseif ceil_mean - rv_mean <= bound
ceil_mean
elseif cdf(rv, floor_mean) >= 0.5
elseif floor_mean + 1 - dist_mean < bound
floor_mean + 1
elseif cdf(dist, floor_mean) >= 0.5
floor_mean
else
ceil_mean
floor_mean + 1
end
end

Expand Down

0 comments on commit b4647c2

Please sign in to comment.