@@ -53,10 +53,19 @@ struct GeneralizedLinearMixedModel{T<:AbstractFloat} <: MixedModel{T}
53
53
mult:: Vector{T}
54
54
end
55
55
56
- StatsBase. coefnames (m:: GeneralizedLinearMixedModel ) = coefnames (m. LMM)
57
-
58
- StatsBase. coeftable (m:: GeneralizedLinearMixedModel ) = coeftable (m. LMM)
59
-
56
+ function StatsBase. coeftable (m:: GeneralizedLinearMixedModel )
57
+ co = fixef (m)
58
+ se = stderror (m)
59
+ z = co ./ se
60
+ pvalue = ccdf .(Chisq (1 ), abs2 .(z))
61
+ CoefTable (
62
+ hcat (co, se, z, pvalue),
63
+ [" Estimate" , " Std.Error" , " z value" , " P(>|z|)" ],
64
+ coefnames (m),
65
+ 4 , # pvalcol
66
+ 3 , # teststatcol
67
+ )
68
+ end
60
69
61
70
"""
62
71
deviance(m::GeneralizedLinearMixedModel{T}, nAGQ=1)::T where {T}
@@ -73,7 +82,7 @@ function StatsBase.deviance(m::GeneralizedLinearMixedModel{T}, nAGQ = 1) where {
73
82
u = vec (first (m. u))
74
83
u₀ = vec (first (m. u₀))
75
84
copyto! (u₀, u)
76
- ra = RaggedArray (m. resp. devresid, first (m. LMM. reterms ). refs)
85
+ ra = RaggedArray (m. resp. devresid, first (m. LMM. allterms ). refs)
77
86
devc0 = sum! (map! (abs2, m. devc0, u), ra) # the deviance components at z = 0
78
87
sd = map! (inv, m. sd, m. LMM. L[Block (1 , 1 )]. diag)
79
88
mult = fill! (m. mult, 0 )
@@ -112,16 +121,15 @@ function deviance!(m::GeneralizedLinearMixedModel, nAGQ = 1)
112
121
deviance (m, nAGQ)
113
122
end
114
123
115
- function GLM. dispersion (m:: GeneralizedLinearMixedModel , sqr:: Bool = false )
124
+ function GLM. dispersion (m:: GeneralizedLinearMixedModel{T} , sqr:: Bool = false ) where {T}
116
125
# adapted from GLM.dispersion(::AbstractGLM, ::Bool)
117
126
# TODO : PR for a GLM.dispersion(resp::GLM.GlmResp, dof_residual::Int, sqr::Bool)
118
127
r = m. resp
119
128
if dispersion_parameter (r. d)
120
- wrkwt, wrkresid = r. wrkwt, r. wrkresid
121
- s = sum (i -> wrkwt[i] * abs2 (wrkresid[i]), eachindex (wrkwt, wrkresid)) / dof_residual (m)
129
+ s = sum (wt * abs2 (re) for (wt, re) in zip (r. wrkwt, r. wrkresid)) / dof_residual (m)
122
130
sqr ? s : sqrt (s)
123
131
else
124
- one (eltype (r . mu) )
132
+ one (T )
125
133
end
126
134
end
127
135
@@ -391,7 +399,11 @@ function Base.getproperty(m::GeneralizedLinearMixedModel, s::Symbol)
391
399
m. β
392
400
elseif s ∈ (:σ , :sigma )
393
401
sdest (m)
394
- elseif s ∈ (:A , :L , :λ , :lowerbd , :corr , :vcov , :PCA , :rePCA , :optsum , :X , :reterms , :feterms , :formula , :σs , :σρs )
402
+ elseif s == :σs
403
+ σs (m)
404
+ elseif s == :σρs
405
+ σρs (m)
406
+ elseif s ∈ (:A , :L , :λ , :lowerbd , :corr , :PCA , :rePCA , :optsum , :X , :reterms , :feterms , :formula )
395
407
getproperty (m. LMM, s)
396
408
elseif s == :y
397
409
m. resp. y
@@ -401,18 +413,17 @@ function Base.getproperty(m::GeneralizedLinearMixedModel, s::Symbol)
401
413
end
402
414
403
415
function StatsBase. loglikelihood (m:: GeneralizedLinearMixedModel{T} ) where {T}
404
- accum = zero (T)
416
+ r = m . resp
405
417
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))
418
+ accum = (
419
+ if D <: Binomial
420
+ sum (logpdf (D (round (Int, n), μ), round (Int, y * n))
421
+ for (μ, y, n) in zip (r. mu, r. y, m. wt))
422
+ else
423
+ sum (logpdf (D (μ), y) for (μ, y) in zip (r. mu, r. y))
409
424
end
410
- else
411
- for (μ, y) in zip (m. resp. mu, m. resp. y)
412
- accum += logpdf (D (μ), y)
413
- end
414
- end
415
- accum - (mapreduce (u -> sum (abs2, u), + , m. u) + logdet (m)) / 2
425
+ )
426
+ accum - (sum (sum (abs2, u) for u in m. u) + logdet (m)) / 2
416
427
end
417
428
418
429
StatsBase. nobs (m:: GeneralizedLinearMixedModel ) = length (m. η)
@@ -589,16 +600,14 @@ varest(m::GeneralizedLinearMixedModel{T}) where {T} = one(T)
589
600
590
601
# delegate GLMM method to LMM field
591
602
for f in (
592
- :describeblocks ,
593
603
:feL ,
604
+ :fetrm ,
594
605
:(LinearAlgebra. logdet),
595
606
:lowerbd ,
596
607
:PCA ,
597
608
:rePCA ,
609
+ :(StatsBase. coefnames),
598
610
:(StatsModels. modelmatrix),
599
- :(StatsBase. vcov),
600
- :σs ,
601
- :σρs ,
602
611
)
603
612
@eval begin
604
613
$ f (m:: GeneralizedLinearMixedModel ) = $ f (m. LMM)
0 commit comments