Skip to content

Commit

Permalink
tolerances for issingular (#783)
Browse files Browse the repository at this point in the history
* tolerances for issingular

* version bump

* NEWS
  • Loading branch information
palday authored Sep 12, 2024
1 parent 41a948a commit bb96c2d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
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]
Expand Down Expand Up @@ -559,3 +563,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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MixedModels"
uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
author = ["Phillip Alday <[email protected]>", "Douglas Bates <[email protected]>", "Jose Bayoan Santiago Calderon <[email protected]>"]
version = "4.25.4"
version = "4.26.0"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand Down
11 changes: 9 additions & 2 deletions src/bootstrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,22 @@ 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.
Equality comparisons are used b/c small non-negative θ values are replaced by 0 in `fit!`.
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)

Expand Down
13 changes: 10 additions & 3 deletions src/mixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 `θ`.
Expand All @@ -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 _issingular(m.lowerbd, θ; 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
Expand Down

2 comments on commit bb96c2d

@palday
Copy link
Member Author

@palday palday commented on bb96c2d Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/115061

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v4.26.0 -m "<description of version>" bb96c2d1d112b65ea7625e44302af0d246bc85f5
git push origin v4.26.0

Please sign in to comment.