File tree Expand file tree Collapse file tree 1 file changed +7
-20
lines changed Expand file tree Collapse file tree 1 file changed +7
-20
lines changed Original file line number Diff line number Diff line change 6464
6565# ### Parameters
6666
67- import StatsBase: params
68-
6967params (d:: ZeroInflatedPoisson ) = (d. λ, d. p,)
7068partype (:: ZeroInflatedPoisson{T} ) where {T} = T
7169
@@ -75,16 +73,12 @@ excessprob(d::ZeroInflatedPoisson) = d.p
7573# ### Evaluation
7674
7775function logpdf (d:: ZeroInflatedPoisson , y:: Real )
78- LL = 0.0
79- if y == 0
80- LLs = zeros (typeof (log (d. λ)), 2 )
81- LLs[1 ] = log (d. p)
82- LLs[2 ] = log1p (- d. p) - d. λ
83- LL = logsumexp (LLs)
84- else
85- LL = log1p (- d. p) + logpdf (Poisson (d. λ), y)
86- end
87- return LL
76+ lp = if iszero (y)
77+ logaddexp (log (d. p), log1p (- d. p) - d. λ)
78+ else
79+ log1p (- d. p) + logpdf (Poisson (d. λ), y)
80+ end
81+ return lp
8882end
8983
9084function cdf (d:: ZeroInflatedPoisson , x:: Real )
@@ -119,13 +113,6 @@ function quantile(d::ZeroInflatedPoisson, q::Real)
119113 return out
120114end
121115
122- # # Sampling
123-
124- function rand (rng:: AbstractRNG , d:: ZeroInflatedPoisson )
125- zo = rand (rng, Uniform (0 , 1 ))
126- return quantile (d, zo)
127- end
128-
129116# ### Fitting
130117
131118struct ZeroInflatedPoissonStats <: SufficientStats
136123
137124suffstats (:: Type{<:ZeroInflatedPoisson} , x:: AbstractArray{T} ) where {T<: Integer } = ZeroInflatedPoissonStats (
138125 sum (x),
139- sum (x .== 0 ) / length ( x),
126+ mean (iszero, x),
140127 length (x)
141128 )
142129
You can’t perform that action at this time.
0 commit comments