Skip to content

Commit bb96c2d

Browse files
authored
tolerances for issingular (#783)
* tolerances for issingular * version bump * NEWS
1 parent 41a948a commit bb96c2d

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
MixedModels v4.26.0 Release Notes
2+
==============================
3+
- `issingular` now accepts comparison tolerances through the keyword arguments `atol` and `rtol`. [#783]
4+
15
MixedModels v4.25.4 Release Notes
26
==============================
37
- Added additional precompilation for rePCA. [#749]
@@ -559,3 +563,4 @@ Package dependencies
559563
[#775]: https://github.com/JuliaStats/MixedModels.jl/issues/775
560564
[#776]: https://github.com/JuliaStats/MixedModels.jl/issues/776
561565
[#778]: https://github.com/JuliaStats/MixedModels.jl/issues/778
566+
[#783]: https://github.com/JuliaStats/MixedModels.jl/issues/783

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]>", "Jose Bayoan Santiago Calderon <[email protected]>"]
4-
version = "4.25.4"
4+
version = "4.26.0"
55

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

src/bootstrap.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,22 @@ function Base.getproperty(bsamp::MixedModelFitCollection, s::Symbol)
408408
end
409409

410410
"""
411-
issingular(bsamp::MixedModelFitCollection)
411+
issingular(bsamp::MixedModelFitCollection;
412+
atol::Real=0, rtol::Real=atol>0 ? 0 : √eps))
412413
413414
Test each bootstrap sample for singularity of the corresponding fit.
414415
415416
Equality comparisons are used b/c small non-negative θ values are replaced by 0 in `fit!`.
416417
417418
See also [`issingular(::MixedModel)`](@ref).
418419
"""
419-
issingular(bsamp::MixedModelFitCollection) = map-> any.== bsamp.lowerbd), bsamp.θ)
420+
function issingular(
421+
bsamp::MixedModelFitCollection; atol::Real=0, rtol::Real=atol > 0 ? 0 : eps()
422+
)
423+
return map(bsamp.θ) do θ
424+
return _issingular(bsamp.lowerbd, θ; atol, rtol)
425+
end
426+
end
420427

421428
Base.length(x::MixedModelFitCollection) = length(x.fits)
422429

src/mixedmodel.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function StatsAPI.dof_residual(m::MixedModel)
5858
end
5959

6060
"""
61-
issingular(m::MixedModel, θ=m.θ)
61+
issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps)
6262
6363
Test whether the model `m` is singular if the parameter vector is `θ`.
6464
@@ -68,8 +68,15 @@ Equality comparisons are used b/c small non-negative θ values are replaced by 0
6868
For `GeneralizedLinearMixedModel`, the entire parameter vector (including
6969
β in the case `fast=false`) must be specified if the default is not used.
7070
"""
71-
issingular(m::MixedModel, θ=m.θ) = any(lowerbd(m) .== θ)
72-
issingular(m::GeneralizedLinearMixedModel, θ=m.optsum.final) = any(lowerbd(m) .== θ)
71+
function issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol > 0 ? 0 : eps())
72+
return _issingular(m.lowerbd, θ; atol, rtol)
73+
end
74+
75+
function _issingular(v, w; atol, rtol)
76+
return any(zip(v, w)) do (x, y)
77+
return isapprox(x, y; atol, rtol)
78+
end
79+
end
7380

7481
# FIXME: better to base this on m.optsum.returnvalue
7582
StatsAPI.isfitted(m::MixedModel) = m.optsum.feval > 0

0 commit comments

Comments
 (0)