@@ -402,17 +402,27 @@ end
402
402
403
403
function StatsBase. loglikelihood (m:: GeneralizedLinearMixedModel{T} ) where {T}
404
404
accum = zero (T)
405
- D = Distribution (m. resp)
406
- if D <: Binomial
407
- for (μ, y, n) in zip (m. resp. mu, m. resp. y, m. wt)
408
- accum += logpdf (D (round (Int, n), μ), round (Int, y * n))
405
+ # adapted from GLM.jl
406
+ # note the use of loglik_obs to handle the different parameterizations
407
+ # of various response distributions which may not just be location+scale
408
+ r = m. resp
409
+ wts = r. wts
410
+ y = r. y
411
+ mu = r. mu
412
+ d = r. d
413
+ if length (wts) == length (y)
414
+ # in GLM.jl, they use the deviance of the
415
+ ϕ = deviance (r)/ sum (wts)
416
+ @inbounds for i in eachindex (y, mu, wts)
417
+ accum += GLM. loglik_obs (d, y[i], mu[i], wts[i], ϕ)
409
418
end
410
419
else
411
- for (μ, y) in zip (m. resp. mu, m. resp. y)
412
- accum += logpdf (D (μ), y)
420
+ ϕ = deviance (r)/ length (y)
421
+ @inbounds for i in eachindex (y, mu)
422
+ accum += GLM. loglik_obs (d, y[i], mu[i], 1 , ϕ)
413
423
end
414
424
end
415
- accum - ( mapreduce (u -> sum (abs2, u), + , m . u) + logdet (m)) / 2
425
+ accum
416
426
end
417
427
418
428
StatsBase. nobs (m:: GeneralizedLinearMixedModel ) = length (m. η)
0 commit comments