From f864a3df1681baf92f74b254b00c28dca23a8df5 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 12 Sep 2024 12:41:40 +0000 Subject: [PATCH 1/8] tolerances for issingular --- src/bootstrap.jl | 9 +++++++-- src/mixedmodel.jl | 13 ++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/bootstrap.jl b/src/bootstrap.jl index c90dc33a7..80d0d2609 100644 --- a/src/bootstrap.jl +++ b/src/bootstrap.jl @@ -408,7 +408,8 @@ function Base.getproperty(bsamp::MixedModelFitCollection, s::Symbol) end """ - issingular(bsamp::MixedModelFitCollection) + issingular(bsamp::MixedModelFitCollection; + atol::Real=0, rtol::Real=atol>0 ? 0 : √eps)) Test each bootstrap sample for singularity of the corresponding fit. @@ -416,7 +417,11 @@ Equality comparisons are used b/c small non-negative θ values are replaced by 0 See also [`issingular(::MixedModel)`](@ref). """ -issingular(bsamp::MixedModelFitCollection) = map(θ -> any(θ .== bsamp.lowerbd), bsamp.θ) +function issingular(bsamp::MixedModelFitCollection; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps()) + return map(bsamp.θ) do θ + return _issingular(bsamp.lowerbd, θ; atol, rtol) + end +end Base.length(x::MixedModelFitCollection) = length(x.fits) diff --git a/src/mixedmodel.jl b/src/mixedmodel.jl index 3b145f959..db604d5ae 100644 --- a/src/mixedmodel.jl +++ b/src/mixedmodel.jl @@ -58,7 +58,7 @@ function StatsAPI.dof_residual(m::MixedModel) end """ - issingular(m::MixedModel, θ=m.θ) + issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps) Test whether the model `m` is singular if the parameter vector is `θ`. @@ -68,8 +68,15 @@ Equality comparisons are used b/c small non-negative θ values are replaced by 0 For `GeneralizedLinearMixedModel`, the entire parameter vector (including β in the case `fast=false`) must be specified if the default is not used. """ -issingular(m::MixedModel, θ=m.θ) = any(lowerbd(m) .== θ) -issingular(m::GeneralizedLinearMixedModel, θ=m.optsum.final) = any(lowerbd(m) .== θ) +function issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps()) + return _singular(m.lowerbound, θ; atol, rtol) +end + +function _issingular(v, w; atol, rtol) + return any(zip(v, w)) do (x, y) + return isapprox(x, y; atol, rtol) + end +end # FIXME: better to base this on m.optsum.returnvalue StatsAPI.isfitted(m::MixedModel) = m.optsum.feval > 0 From 3ed78a4693f2f99052fc2458ca818d8150612a43 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 12 Sep 2024 12:43:43 +0000 Subject: [PATCH 2/8] version bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index bc051ae95..a49022ce7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MixedModels" uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316" author = ["Phillip Alday ", "Douglas Bates ", "Jose Bayoan Santiago Calderon "] -version = "4.25.4" +version = "4.26.0" [deps] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" From 3d27728d81417e99aa070107efc5ecbfadc450b8 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 12 Sep 2024 12:44:04 +0000 Subject: [PATCH 3/8] NEWS --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4e2304383..e9e7b47d8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +MixedModels v4.26.0 Release Notes +============================== +- `issingular` now accepts comparison tolerances through the keyword arguments `atol` and `rtol`. [#783] + + MixedModels v4.25.4 Release Notes ============================== - Added additional precompilation for rePCA. [#749] @@ -559,3 +564,4 @@ Package dependencies [#775]: https://github.com/JuliaStats/MixedModels.jl/issues/775 [#776]: https://github.com/JuliaStats/MixedModels.jl/issues/776 [#778]: https://github.com/JuliaStats/MixedModels.jl/issues/778 +[#783]: https://github.com/JuliaStats/MixedModels.jl/issues/783 From d922191f19b6a88d6f5d46d5dd5de87f7992f66d Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 12 Sep 2024 12:44:29 +0000 Subject: [PATCH 4/8] thinko --- src/mixedmodel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixedmodel.jl b/src/mixedmodel.jl index db604d5ae..226d3e86f 100644 --- a/src/mixedmodel.jl +++ b/src/mixedmodel.jl @@ -69,7 +69,7 @@ Equality comparisons are used b/c small non-negative θ values are replaced by 0 β in the case `fast=false`) must be specified if the default is not used. """ function issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps()) - return _singular(m.lowerbound, θ; atol, rtol) + return _issingular(m.lowerbound, θ; atol, rtol) end function _issingular(v, w; atol, rtol) From 96d5d7eaf38ecad72741323eb30b82609681fc83 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 12 Sep 2024 12:45:03 +0000 Subject: [PATCH 5/8] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/bootstrap.jl | 4 +++- src/mixedmodel.jl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bootstrap.jl b/src/bootstrap.jl index 80d0d2609..e59809bab 100644 --- a/src/bootstrap.jl +++ b/src/bootstrap.jl @@ -417,7 +417,9 @@ Equality comparisons are used b/c small non-negative θ values are replaced by 0 See also [`issingular(::MixedModel)`](@ref). """ -function issingular(bsamp::MixedModelFitCollection; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps()) +function issingular( + bsamp::MixedModelFitCollection; atol::Real=0, rtol::Real=atol > 0 ? 0 : √eps() +) return map(bsamp.θ) do θ return _issingular(bsamp.lowerbd, θ; atol, rtol) end diff --git a/src/mixedmodel.jl b/src/mixedmodel.jl index 226d3e86f..2d404c7ef 100644 --- a/src/mixedmodel.jl +++ b/src/mixedmodel.jl @@ -75,7 +75,7 @@ end function _issingular(v, w; atol, rtol) return any(zip(v, w)) do (x, y) return isapprox(x, y; atol, rtol) - end + end end # FIXME: better to base this on m.optsum.returnvalue From d948d9a20cc6a912a67f92657cc84c38bee4b50a Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 12 Sep 2024 12:46:10 +0000 Subject: [PATCH 6/8] Blue style --- src/bootstrap.jl | 4 +++- src/mixedmodel.jl | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bootstrap.jl b/src/bootstrap.jl index 80d0d2609..e59809bab 100644 --- a/src/bootstrap.jl +++ b/src/bootstrap.jl @@ -417,7 +417,9 @@ Equality comparisons are used b/c small non-negative θ values are replaced by 0 See also [`issingular(::MixedModel)`](@ref). """ -function issingular(bsamp::MixedModelFitCollection; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps()) +function issingular( + bsamp::MixedModelFitCollection; atol::Real=0, rtol::Real=atol > 0 ? 0 : √eps() +) return map(bsamp.θ) do θ return _issingular(bsamp.lowerbd, θ; atol, rtol) end diff --git a/src/mixedmodel.jl b/src/mixedmodel.jl index 226d3e86f..e076d4166 100644 --- a/src/mixedmodel.jl +++ b/src/mixedmodel.jl @@ -68,14 +68,14 @@ Equality comparisons are used b/c small non-negative θ values are replaced by 0 For `GeneralizedLinearMixedModel`, the entire parameter vector (including β in the case `fast=false`) must be specified if the default is not used. """ -function issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps()) - return _issingular(m.lowerbound, θ; atol, rtol) +function issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol > 0 ? 0 : √eps()) + return _issingular(m.lowerbound, θ; atol, rtol) end function _issingular(v, w; atol, rtol) return any(zip(v, w)) do (x, y) return isapprox(x, y; atol, rtol) - end + end end # FIXME: better to base this on m.optsum.returnvalue From 6987db6f8e09e23c1553521f2b1fbcf50a6bac94 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 12 Sep 2024 12:47:54 +0000 Subject: [PATCH 7/8] stray newline --- NEWS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e9e7b47d8..8fc431a7d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,6 @@ MixedModels v4.26.0 Release Notes ============================== - `issingular` now accepts comparison tolerances through the keyword arguments `atol` and `rtol`. [#783] - MixedModels v4.25.4 Release Notes ============================== - Added additional precompilation for rePCA. [#749] From 48a526245fb290d95272bb4d19d9c912114bc56c Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 12 Sep 2024 12:48:38 +0000 Subject: [PATCH 8/8] thinko --- src/mixedmodel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixedmodel.jl b/src/mixedmodel.jl index e076d4166..36e11fc81 100644 --- a/src/mixedmodel.jl +++ b/src/mixedmodel.jl @@ -69,7 +69,7 @@ Equality comparisons are used b/c small non-negative θ values are replaced by 0 β in the case `fast=false`) must be specified if the default is not used. """ function issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol > 0 ? 0 : √eps()) - return _issingular(m.lowerbound, θ; atol, rtol) + return _issingular(m.lowerbd, θ; atol, rtol) end function _issingular(v, w; atol, rtol)