Skip to content

Commit 823e137

Browse files
authored
reset optsum.final in unfit! (#828)
* reset optsum.final in unfit! * NEWS, version bump * tweak test tolerance * fix somewhat misguided test * update CI
1 parent fe1e589 commit 823e137

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

.github/workflows/minimum.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ jobs:
2121
strategy:
2222
matrix:
2323
julia-version: [min]
24-
julia-arch: [x64]
25-
os: [ubuntu-22.04, macos-13, windows-2019]
24+
os: [ubuntu-22.04, macos-14, windows-2019]
2625
steps:
2726
- uses: actions/checkout@v4
2827
- uses: julia-actions/setup-julia@v2

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
MixedModels v4.35.1 Release Notes
2+
==============================
3+
- The final parameter vector `optsum.final` is now reset in calls to `unfit!`. This has the secondary effect of correctly starting the fit for `prfit!` at the initial parameter vector instead of the final parameter vector of any previous optimization. [#828]
4+
15
MixedModels v4.35.0 Release Notes
26
==============================
37
- `StatsAPI.cooksdistance(::LinearMixedModel)` is now defined and exported. [#825]
@@ -632,3 +636,4 @@ Package dependencies
632636
[#815]: https://github.com/JuliaStats/MixedModels.jl/issues/815
633637
[#823]: https://github.com/JuliaStats/MixedModels.jl/issues/823
634638
[#825]: https://github.com/JuliaStats/MixedModels.jl/issues/825
639+
[#828]: https://github.com/JuliaStats/MixedModels.jl/issues/828

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MixedModels"
22
uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
33
author = ["Phillip Alday <[email protected]>", "Douglas Bates <[email protected]>"]
4-
version = "4.35.0"
4+
version = "4.35.1"
55

66
[deps]
77
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ Typical distribution forms are _Bernoulli_ for binary data or _Poisson_ for coun
5050

5151
## Currently Tested Platforms
5252

53-
|OS | OS Version |Arch |Julia |
54-
|:------:|:-------------:|:---:|:--------------:|
55-
|Linux | Ubuntu 20.04 | x64 |v1.8 |
56-
|Linux | Ubuntu 20.04 | x64 |current release |
57-
|Linux | Ubuntu 20.04 | x64 |nightly |
58-
|macOS | Monterey 12 | x64 |v1.8 |
59-
|Windows | Server 2019 | x64 |v1.8 |
53+
|OS | OS Version |Arch |Julia |
54+
|:------:|:-------------:|:------:|:--------------:|
55+
|Linux | Ubuntu 22.04 | x64 |v1.10 |
56+
|Linux | Ubuntu 22.04 | x64 |current release |
57+
|Linux | Ubuntu 22.04 | x64 |nightly |
58+
|macOS | Sonoma 14 | aarm64 |v1.10 |
59+
|Windows | Server 2019 | x64 |v1.10 |
6060

6161
Note that previous releases still support older Julia versions.
6262

src/linearmixedmodel.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,13 @@ end
12531253
Mark a model as unfitted.
12541254
"""
12551255
function unfit!(model::LinearMixedModel{T}) where {T}
1256-
model.optsum.feval = -1
1257-
model.optsum.initial_step = T[]
1256+
optsum = model.optsum
1257+
optsum.feval = -1
1258+
optsum.initial_step = T[]
1259+
# for variances (bounded at zero), we have ones, while
1260+
# for everything else (bounded at -Inf), we have zeros
1261+
map!(T iszero, optsum.initial, optsum.lowerbd)
1262+
copyto!(optsum.final, optsum.initial)
12581263
reevaluateAend!(model)
12591264

12601265
return model

test/pirls.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ end
110110
cbpp = dataset(:cbpp)
111111
gm2 = fit(MixedModel, first(gfms[:cbpp]), cbpp, Binomial(); wts=float(cbpp.hsz), progress=false, init_from_lmm=[, ])
112112
@test weights(gm2) == cbpp.hsz
113-
@test deviance(gm2,true) 100.09585619892968 atol=0.0001
114-
@test sum(abs2, gm2.u[1]) 9.723054788538546 atol=0.0001
115-
@test logdet(gm2) 16.90105378801136 atol=0.001
113+
@test deviance(gm2, true) 100.09585619892968 rtol=0.0001
114+
@test sum(abs2, gm2.u[1]) 9.723054788538546 rtol=0.0001
115+
@test logdet(gm2) 16.90105378801136 rtol=0.0001
116116
@test isapprox(sum(gm2.resp.devresid), 73.47174762237978, atol=0.001)
117117
@test isapprox(loglikelihood(gm2), -92.02628186840045, atol=0.001)
118118
@test !dispersion_parameter(gm2)
@@ -281,7 +281,5 @@ end
281281
form = @formula(recalled ~ serialpos + zerocorr(serialpos | subject) + (1 | subject & session))
282282
glmm = @test_logs((:warn, r"Evaluation at default initial parameter vector failed"),
283283
GeneralizedLinearMixedModel(form, df, Bernoulli()));
284-
glmm.optsum.ftol_rel = 1e-7
285-
fit!(glmm; init_from_lmm=[, ], fast=true, progress=false)
286-
@test deviance(glmm) 996.0402 atol=0.01
284+
@test all(==(1e-8), glmm.optsum.initial)
287285
end

test/prima.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ prmodel = LinearMixedModel(formula(model), dataset(:sleepstudy))
1616
prmodel.optsum.backend = :prima
1717

1818
@testset "$optimizer" for optimizer in (:cobyla, :lincoa)
19-
MixedModels.unfit!(prmodel)
19+
unfit!(prmodel)
2020
prmodel.optsum.optimizer = optimizer
2121
fit!(prmodel; progress=false, fitlog=false)
2222
@test isapprox(loglikelihood(model), loglikelihood(prmodel))
2323
end
2424

25+
@testset "refit!" begin
26+
refit!(prmodel; progress=false, fitlog=true)
27+
@test prmodel.optsum.fitlog[1][1] == [1.0]
28+
end
29+
2530
@testset "failure" begin
26-
MixedModels.unfit!(prmodel)
31+
unfit!(prmodel)
2732
prmodel.optsum.optimizer = :bobyqa
2833
prmodel.optsum.maxfeval = 5
2934
@test_logs((:warn, r"PRIMA optimization failure"),

0 commit comments

Comments
 (0)