Skip to content

Commit 7dbd4c2

Browse files
committed
warning for GLMM with dispersion parameter (#373)* warning for GLMM with dispersion parameter(cherry picked from commit 66b8863)
1 parent e7bef62 commit 7dbd4c2

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/generalizedlinearmixedmodel.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ GeneralizedLinearMixedModel(f::FormulaTerm, tbl,
233233
GeneralizedLinearMixedModel(f::FormulaTerm, tbl::Tables.ColumnTable,
234234
d::Normal,
235235
l::IdentityLink;
236-
wts = [],
237-
offset = [],
238-
contrasts = Dict{Symbol,Any}()) =
236+
wts = wts,
237+
offset = offset,
238+
contrasts = contrasts) =
239239
throw(ArgumentError("use LinearMixedModel for Normal distribution with IdentityLink"))
240240
function GeneralizedLinearMixedModel(f::FormulaTerm, tbl::Tables.ColumnTable,
241241
d::Distribution,
@@ -247,7 +247,14 @@ function GeneralizedLinearMixedModel(f::FormulaTerm, tbl::Tables.ColumnTable,
247247
d = Bernoulli()
248248
end
249249
(isa(d, Normal) && isa(l, IdentityLink)) &&
250-
throw(ArgumentError("use LinearMixedModel for Normal distribution with IdentityLink"))
250+
throw(ArgumentError("use LinearMixedModel for Normal distribution with IdentityLink"))
251+
252+
if !any(isa(d, dist) for dist in (Bernoulli, Binomial, Poisson))
253+
@warn """Results for families with a dispersion parameter are not reliable.
254+
It is best to avoid trying to fit such models in MixedModels until
255+
the authors get a better understanding of those cases."""
256+
end
257+
251258
LMM = LinearMixedModel(f, tbl, contrasts = contrasts; wts = wts)
252259
y = copy(LMM.y)
253260
# the sqrtwts field must be the correct length and type but we don't know those

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
33
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
4+
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
45
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
56
NamedArrays = "86f7a689-2022-50b4-a561-43c23ac3c673"
67
RData = "df47a6cb-8c03-5eed-afd8-b6050d6c41da"

test/pirls.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using DataFrames, LinearAlgebra, MixedModels, RData, Test
22

3+
using GLM: SqrtLink
4+
35
if !@isdefined(dat) || !isa(dat, Dict{Symbol, DataFrame})
46
const dat = Dict(Symbol(k) => v for (k, v) in
57
load(joinpath(dirname(pathof(MixedModels)), "..", "test", "dat.rda")))
@@ -76,3 +78,13 @@ end
7678
#@test isapprox(sum(x -> sum(abs2, x), gm4.u), 196.8695297987013, atol=0.1)
7779
#@test isapprox(sum(gm4.resp.devresid), 220.92685781326136, atol=0.1)
7880
end
81+
82+
@testset "dispersion" begin
83+
84+
form = @formula(Y ~ 1 + U + (1 + U | G))
85+
86+
@test_logs (:warn, r"dispersion parameter") GeneralizedLinearMixedModel(form, dat[:sleepstudy], Gamma())
87+
@test_logs (:warn, r"dispersion parameter") GeneralizedLinearMixedModel(form, dat[:sleepstudy], InverseGaussian())
88+
@test_logs (:warn, r"dispersion parameter") GeneralizedLinearMixedModel(form, dat[:sleepstudy], Normal(), SqrtLink())
89+
90+
end

0 commit comments

Comments
 (0)