Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ MixedModels v5.0.0 Release Notes
- Internal code around optimization in profiling has been restructuring so that fitting done during calls to `profile` respect the `backend` and `optimizer` settings. [#853]
- The `prfit!` convenience function has been removed. [#853]
- The `dataset` and `datasets` functions have been removed. They are now housed in `MixedModelsDatasets`.[#854]
- One argument `predict(::GeneralizedLinearMixedModel)`, i.e. prediction on the original data, now supports the `type` keyword argument. [#856]

MixedModels v4.38.0 Release Notes
==============================
Expand Down
5 changes: 5 additions & 0 deletions src/predict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ function StatsAPI.predict(
return type == :linpred ? y : broadcast!(Base.Fix1(linkinv, Link(m)), y, y)
end

function StatsAPI.predict(m::GeneralizedLinearMixedModel; type=:response)
type in (:linpred, :response) || throw(ArgumentError("Invalid value for type: $(type)"))
return type == :response ? fitted(m) : m.resp.eta
end

# β is separated out here because m.β != m.LMM.β depending on how β is estimated for GLMM
# also β should already be pivoted but NOT truncated in the rank deficient case
function _predict(m::MixedModel{T}, newdata, β; new_re_levels) where {T}
Expand Down
5 changes: 2 additions & 3 deletions test/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ end
@testset "generalized" begin
gm1 = fit(MixedModel, @formula(use ~ 1 + urban + livch + age + abs2(age) + (1 | dist)),
MixedModels.dataset(:contra), Bernoulli(); progress=false)
@test deviance(gm1) ≈ 2372.7286 atol = 1.0e-3

gm2 = glmm(@formula(use ~ 1 + urban + livch + age + abs2(age) + (1 | dist)),
MixedModels.dataset(:contra), Bernoulli(); progress=false)
@test deviance(gm2) ≈ 2372.7286 atol = 1.0e-3

@test deviance(gm1) ≈ deviance(gm2)
end

@testset "Normal-IdentityLink" begin
Expand Down
2 changes: 2 additions & 0 deletions test/predict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ end
# we can skip a lot of testing if the broad strokes work because
# internally this is punted off to the same machinery as LMM
@test predict(gm0) ≈ fitted(gm0)
@test predict(gm0; type=:response) ≈ fitted(gm0)
@test predict(gm0; type=:linpred) ≈ GLM.linkfun.(Ref(Link(gm0)), fitted(gm0))
# XXX these tolerances aren't great but are required for fast=false fits
@test predict(gm0, contra; type=:linpred) ≈ gm0.resp.eta rtol = 0.1
@test predict(gm0, contra; type=:response) ≈ gm0.resp.mu rtol = 0.01
Expand Down
Loading