Skip to content

Commit a79d32b

Browse files
committed
fix loglik calc
1 parent 0858435 commit a79d32b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/generalizedlinearmixedmodel.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ is the squared length of the conditional modes, `u`, plus the determinant
6969
of `Λ'Z'WZΛ + I`, plus the sum of the squared deviance residuals.
7070
"""
7171
function StatsBase.deviance(m::GeneralizedLinearMixedModel{T}, nAGQ = 1) where {T}
72-
# TODO: fix dispersion's contribution for non Gaussians
72+
# TODO: fix dispersion's contribution for non Gaussians
7373
disp = dispersion_parameter(m) ? nobs(m) * (1 + log2π + log(varest(m))) : zero(T)
7474
nAGQ == 1 && return T(sum(m.resp.devresid) + logdet(m) +
7575
sum(u -> sum(abs2, u), m.u) + disp)
@@ -415,7 +415,6 @@ function StatsBase.loglikelihood(m::GeneralizedLinearMixedModel{T}) where {T}
415415
mu = r.mu
416416
d = r.d
417417
if length(wts) == length(y)
418-
# in GLM.jl, they use the deviance of the
419418
ϕ = deviance(r)/sum(wts)
420419
@inbounds for i in eachindex(y, mu, wts)
421420
accum += GLM.loglik_obs(d, y[i], mu[i], wts[i], ϕ)
@@ -426,7 +425,7 @@ function StatsBase.loglikelihood(m::GeneralizedLinearMixedModel{T}) where {T}
426425
accum += GLM.loglik_obs(d, y[i], mu[i], 1, ϕ)
427426
end
428427
end
429-
accum
428+
accum - (mapreduce(u -> sum(abs2, u), +, m.u) + logdet(m)) / 2
430429
end
431430

432431
StatsBase.nobs(m::GeneralizedLinearMixedModel) = length(m.η)
@@ -556,7 +555,7 @@ function Base.setproperty!(m::GeneralizedLinearMixedModel, s::Symbol, y)
556555
end
557556
end
558557

559-
sdest(m::GeneralizedLinearMixedModel{T}) where {T} = dispersion_parameter(m) ? varest(m) : convert(T, NaN)
558+
sdest(m::GeneralizedLinearMixedModel{T}) where {T} = dispersion_parameter(m) ? varest(m) : convert(T, NaN)
560559

561560
function Base.show(io::IO, m::GeneralizedLinearMixedModel)
562561
if m.optsum.feval < 0

0 commit comments

Comments
 (0)