Skip to content

Commit

Permalink
Returns smallest mode in mode(Binomial), fix modes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusps authored Dec 17, 2024
1 parent 790411a commit 194adf9
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/univariate/discrete/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,36 @@ params(d::Binomial) = (d.n, d.p)

mean(d::Binomial) = ntrials(d) * succprob(d)
var(d::Binomial) = ntrials(d) * succprob(d) * failprob(d)
function mode(d::Binomial{T}) where T<:Real

function mode(d::Binomial)
(n, p) = params(d)
v = (n + 1) * p
quasi_mode = floor(Int, v)
if quasi_mode == v
if p == 1
n
else
quasi_mode-1
end
else
quasi_mode
end
end

function modes(d::Binomial)
(n, p) = params(d)
n > 0 ? floor(Int, (n + 1) * d.p) : zero(T)
v = (n + 1) * p
quasi_mode = floor(Int, v)
if quasi_mode == v
if p == 1
Int[n]
else
Int[quasi_mode-1, quasi_mode]
end
else
Int[quasi_mode]
end
end
modes(d::Binomial) = Int[mode(d)]

function skewness(d::Binomial)
n, p1 = params(d)
Expand Down

0 comments on commit 194adf9

Please sign in to comment.