Skip to content

Take the dispersion into account for GLMM familes with a dispersion param #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d6c038b
return the dispersion for varest of GLMMs with a dispersion param
palday Feb 26, 2020
2760775
export additional links
palday Feb 26, 2020
c8261be
new computation of loglikelihood for GLMM that works with all families
palday Feb 26, 2020
cb90435
sdest for GLMM
palday Feb 26, 2020
43d09ca
initial work on including dispersion in GLMM deviance
palday Feb 26, 2020
0858435
fix sdest
palday Feb 26, 2020
a79d32b
fix loglik calc
palday Apr 13, 2020
ebe7906
start preparing tests for GLMMs with dispersion parameter
palday Apr 13, 2020
7300ef3
change GLMM objective to use NLopt's tracking of function calls (like…
palday Apr 13, 2020
0e591fe
rework tests for optimizer failure
palday Apr 14, 2020
8bc5254
remove explicit dispersion parameter from deviance
palday Apr 14, 2020
72e4ffc
simulate data for InverseGaussian and Gamma
palday May 16, 2020
12538df
separate construct and fit for simulated data
palday May 19, 2020
6c6aaa0
new gamma dataset
palday May 20, 2020
a6d518f
formulae for new gamma dataset
palday May 20, 2020
2577e13
merge master
palday May 23, 2020
fed8b01
Merge branch 'master' of github.com:JuliaStats/MixedModels.jl into gl…
palday Oct 6, 2020
c4d3fa4
Merge branch 'master' of github.com:JuliaStats/MixedModels.jl into gl…
palday Oct 29, 2020
d6db3b0
Merge branch 'master' of github.com:JuliaStats/MixedModels.jl into gl…
palday Dec 4, 2020
de610d7
Merge branch 'main' of github.com:JuliaStats/MixedModels.jl into glmm…
palday Mar 25, 2021
61dc4d4
Merge branch 'main' of github.com:JuliaStats/MixedModels.jl into glmm…
palday Jan 4, 2022
3fbaaf8
ditch MersenneTwister
palday Jan 4, 2022
4fc5b0d
Merge branch 'main' of github.com:JuliaStats/MixedModels.jl into glmm…
palday May 3, 2022
0af4eeb
Merge branch 'main' of github.com:JuliaStats/MixedModels.jl into glmm…
palday Aug 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions test/pirls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,53 @@ end
@test only(m11.θ) ≈ 1.838245201739852 atol=1.e-5
end

@testset "dispersion" begin
@testset "dispersion parameter" begin
@testset "gaussian with non identity link" begin
dyestuff = MixedModels.dataset(:dyestuff)

form = @formula(reaction ~ 1 + days + (1+days|subj))
dat = dataset(:sleepstudy)
gauss = fit(MixedModel, only(fms[:dyestuff]), dyestuff, Normal(), SqrtLink(), fast=true)
@test only(gauss.θ) ≈ 0.5528913 atol=0.001 # value from lme4
# this corresponds to the deviance(gauss) from lme4
# NB: "deviance" is complicated in lme4
# this is the way deviance(glmm) is computed in lme4
# but there are several "deviances" defined:
# https://github.com/lme4/lme4/issues/375#issuecomment-214494445
@test sum(gauss.resp.devresid) ≈ 58830. atol=0.001 # value from lme4

@test_logs (:warn, r"dispersion parameter") GeneralizedLinearMixedModel(form, dat, Gamma())
@test_logs (:warn, r"dispersion parameter") GeneralizedLinearMixedModel(form, dat, InverseGaussian())
@test_logs (:warn, r"dispersion parameter") GeneralizedLinearMixedModel(form, dat, Normal(), SqrtLink())
# bobyqa fails here
neldermead = GeneralizedLinearMixedModel(only(fms[:dyestuff]), dyestuff, Normal(), SqrtLink());
neldermead.optsum.optimizer = :LN_NELDERMEAD;
fit!(neldermead)
@test only(neldermead.θ) ≈ 0.5528913 atol=0.001 # value from lme4
@test sum(neldermead.resp.devresid) ≈ 58830. atol=0.001 # value from lme4
end

## simulate some data ##
rng = StableRNG(42);
ng = 25
ns = 500
# random effect
u = repeat(randn(rng, ns) .* 0.1, ng);
id = PooledArray(string.(repeat(1:ns, ng)));
# fixed effect
x = rand(rng, ns*ng);

@testset "inverse gaussian" begin
rng = StableRNG(42);
l = GLM.canonicallink(InverseGaussian())
invgauss = GeneralizedLinearMixedModel(@formula(y ~ 1 + x + (1|id)), dat, InverseGaussian());
#invgauss.optsum.optimizer = :LN_NELDERMEAD;
# fit!(invgauss)
end

@testset "gamma" begin
rng = StableRNG(42);
y = map(d -> rand(rng, d), Gamma.(1. ./ (1. .+ u + x)));
dat = (u=u, id=id, x=x, y=y)
gamma = GeneralizedLinearMixedModel(@formula(y ~ 1 + x + (1|id)), dat, Gamma());
#gamma.optsum.optimizer = :LN_NELDERMEAD;
# fit!(gamma)
end
# notes for future tests when GLMM with dispersion works
# @test dispersion_parameter(gm)
# @test dispersion(gm, false) == val
Expand Down