Skip to content

Commit b4c3359

Browse files
committed
all specifying type argument n GLMMi predict on original data
1 parent 6408a34 commit b4c3359

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/predict.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ function StatsAPI.predict(
8686
return type == :linpred ? y : broadcast!(Base.Fix1(linkinv, Link(m)), y, y)
8787
end
8888

89+
function StatsAPI.predict(m::GeneralizedLinearMixedModel; type=:response)
90+
type in (:linpred, :response) || throw(ArgumentError("Invalid value for type: $(type)"))
91+
y = fitted(m)
92+
type == :response ? y : broadcast!(Base.Fix1(linkfun, Link(m)), y, y)
93+
return y
94+
end
95+
8996
# β is separated out here because m.β != m.LMM.β depending on how β is estimated for GLMM
9097
# also β should already be pivoted but NOT truncated in the rank deficient case
9198
function _predict(m::MixedModel{T}, newdata, β; new_re_levels) where {T}

test/predict.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ end
197197
# we can skip a lot of testing if the broad strokes work because
198198
# internally this is punted off to the same machinery as LMM
199199
@test predict(gm0) fitted(gm0)
200+
@test predict(gm0; type=:linpred) predict(gm0, contra; type=:linpred)
201+
@test predict(gm0; type=:response) predict(gm0, contra; type=:response)
200202
# XXX these tolerances aren't great but are required for fast=false fits
201203
@test predict(gm0, contra; type=:linpred) gm0.resp.eta rtol = 0.1
202204
@test predict(gm0, contra; type=:response) gm0.resp.mu rtol = 0.01

0 commit comments

Comments
 (0)