Skip to content

Commit

Permalink
unfit! now wipes more state
Browse files Browse the repository at this point in the history
  • Loading branch information
palday committed Nov 5, 2024
1 parent 3b565a2 commit 9622f36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/generalizedlinearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -767,19 +767,21 @@ function stderror!(v::AbstractVector{T}, m::GeneralizedLinearMixedModel{T}) wher
end

function unfit!(model::GeneralizedLinearMixedModel{T}) where {T}
deviance!(model, 1)
reevaluateAend!(model.LMM)

reterms = model.LMM.reterms
optsum = model.LMM.optsum
# we need to reset optsum so that it
# plays nice with the modifications fit!() does
optsum.lowerbd = mapfoldl(lowerbd, vcat, reterms)
optsum.initial = mapfoldl(getθ, vcat, reterms)
# for variances (bounded at zero), we have ones, while
# for everything else (bounded at -Inf), we have zeros
optsum.initial = map(T iszero, optsum.lowerbd)
optsum.final = copy(optsum.initial)
optsum.xtol_abs = fill!(copy(optsum.initial), 1.0e-10)
optsum.initial_step = T[]
optsum.feval = -1
deviance!(model, 1)

return model
end
Expand Down
3 changes: 3 additions & 0 deletions src/linearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,9 @@ Mark a model as unfitted.
function unfit!(model::LinearMixedModel{T}) where {T}
model.optsum.feval = -1
model.optsum.initial_step = T[]
# for variances (bounded at zero), we have ones, while
# for everything else (bounded at -Inf), we have zeros
model.optsum.initial .= map(T iszero, model.optsum.lowerbd)
reevaluateAend!(model)

return model
Expand Down

0 comments on commit 9622f36

Please sign in to comment.