From 15ab0b4b6863fd15e9ca2faec4baee63e56bf237 Mon Sep 17 00:00:00 2001 From: Douglas Bates Date: Fri, 21 Jun 2024 10:29:56 -0500 Subject: [PATCH 1/3] use ::Matrix{T} instead of ::T --- src/linalg/logdet.jl | 4 ++-- src/linearmixedmodel.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/linalg/logdet.jl b/src/linalg/logdet.jl index 97d637cb5..5f2c5a564 100644 --- a/src/linalg/logdet.jl +++ b/src/linalg/logdet.jl @@ -25,9 +25,9 @@ lower Cholesky factor. """ function LinearAlgebra.logdet(m::LinearMixedModel{T}) where {T} L = m.L - @inbounds s = sum(j -> LD(L[kp1choose2(j)]), axes(m.reterms, 1))::T + @inbounds s = sum(j -> LD(L[kp1choose2(j)])::T, axes(m.reterms, 1)) if m.optsum.REML - lastL = last(L) + lastL = last(L)::Matrix{T} s += LD(lastL) # this includes the log of sqrtpwrss s -= log(last(lastL)) # so we need to subtract it from the sum end diff --git a/src/linearmixedmodel.jl b/src/linearmixedmodel.jl index 8ec16f171..875b54c92 100644 --- a/src/linearmixedmodel.jl +++ b/src/linearmixedmodel.jl @@ -895,7 +895,7 @@ end The penalized, weighted residual sum-of-squares. """ -pwrss(m::LinearMixedModel{T}) where {T} = abs2(last(last(m.L)))::T +pwrss(m::LinearMixedModel{T}) where {T} = abs2(last(last(m.L)::Matrix{T})) """ ranef!(v::Vector{Matrix{T}}, m::MixedModel{T}, β, uscale::Bool) where {T} From c6131c11021edc84e0a087e39baecb223d5b5feb Mon Sep 17 00:00:00 2001 From: Douglas Bates Date: Fri, 21 Jun 2024 11:35:42 -0500 Subject: [PATCH 2/3] update NEWS.md --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index acf1b91cc..ece040c1a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +MixedModels v4.24.1 Release Notes +============================== +Add type notations in `pwrss(::LinearMixedModel)` and `logdet(::LinearMixedModel)` to enhance type inference. [#773] + MixedModels v4.24.0 Release Notes ============================== * Properties for `GeneralizedLinearMixedModel` now default to delegation to the internal weighted `LinearMixedModel` when that property is not explicitly handled by `GeneralizedLinearMixedModel`. Previously, properties were delegated on an explicit basis, which meant that they had to be added manually as use cases were discovered. The downside to the new approach is that it is now possible to access properties whose definition in the LMM case doesn't match the GLMM definition when the GLMM definition hasn't been explicitly been implemented. [#767] @@ -521,3 +525,4 @@ Package dependencies [#755]: https://github.com/JuliaStats/MixedModels.jl/issues/755 [#756]: https://github.com/JuliaStats/MixedModels.jl/issues/756 [#767]: https://github.com/JuliaStats/MixedModels.jl/issues/767 +[#773]: https://github.com/JuliaStats/MixedModels.jl/issues/773 From 598e77df158b1705e780bac064cc2bb6a8a6877d Mon Sep 17 00:00:00 2001 From: Douglas Bates Date: Sat, 22 Jun 2024 10:26:24 -0500 Subject: [PATCH 3/3] JuliaFormatter run (mostly adding trailing commas). --- src/generalizedlinearmixedmodel.jl | 4 ++-- src/likelihoodratiotest.jl | 2 +- src/linalg/rankUpdate.jl | 2 +- src/mixedmodel.jl | 4 ++-- src/predict.jl | 2 +- src/profile/thetapr.jl | 2 +- src/randomeffectsterm.jl | 2 +- src/remat.jl | 4 ++-- src/simulate.jl | 2 +- src/utilities.jl | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/generalizedlinearmixedmodel.jl b/src/generalizedlinearmixedmodel.jl index f9f6ad5dc..3e2125499 100644 --- a/src/generalizedlinearmixedmodel.jl +++ b/src/generalizedlinearmixedmodel.jl @@ -351,7 +351,7 @@ function GeneralizedLinearMixedModel( tbl, d::Distribution, l::Type; - kwargs... + kwargs..., ) throw(ArgumentError("Expected a Link instance (`$l()`), got a type (`$l`).")) end @@ -376,7 +376,7 @@ function GeneralizedLinearMixedModel( tbl::Tables.ColumnTable, d::Normal, l::IdentityLink; - kwargs... + kwargs..., ) return throw( ArgumentError("use LinearMixedModel for Normal distribution with IdentityLink") diff --git a/src/likelihoodratiotest.jl b/src/likelihoodratiotest.jl index 335cbaa3f..4e2bf7287 100644 --- a/src/likelihoodratiotest.jl +++ b/src/likelihoodratiotest.jl @@ -219,7 +219,7 @@ function _iscomparable(m::LinearMixedModel...) if any(getproperty.(getproperty.(m, :optsum), :REML)) isconstant(coefnames.(m)) || throw( ArgumentError( - "Likelihood-ratio tests for REML-fitted models are only valid when the fixed-effects specifications are identical", + "Likelihood-ratio tests for REML-fitted models are only valid when the fixed-effects specifications are identical" ), ) end diff --git a/src/linalg/rankUpdate.jl b/src/linalg/rankUpdate.jl index e6f1aacd6..705f87d53 100644 --- a/src/linalg/rankUpdate.jl +++ b/src/linalg/rankUpdate.jl @@ -12,7 +12,7 @@ function rankUpdate! end function rankUpdate!(C::AbstractMatrix, a::AbstractArray, α, β) return error( - "We haven't implemented a method for $(typeof(C)), $(typeof(a)). Please file an issue on GitHub.", + "We haven't implemented a method for $(typeof(C)), $(typeof(a)). Please file an issue on GitHub." ) end diff --git a/src/mixedmodel.jl b/src/mixedmodel.jl index f57b4c669..3b145f959 100644 --- a/src/mixedmodel.jl +++ b/src/mixedmodel.jl @@ -80,7 +80,7 @@ function StatsAPI.fit( tbl, d::Type, args...; - kwargs... + kwargs..., ) throw(ArgumentError("Expected a Distribution instance (`$d()`), got a type (`$d`).")) end @@ -91,7 +91,7 @@ function StatsAPI.fit( tbl, d::Distribution, l::Type; - kwargs... + kwargs..., ) throw(ArgumentError("Expected a Link instance (`$l()`), got a type (`$l`).")) end diff --git a/src/predict.jl b/src/predict.jl index 5a2246ac6..1cf1c144f 100644 --- a/src/predict.jl +++ b/src/predict.jl @@ -115,7 +115,7 @@ function _predict(m::MixedModel{T}, newdata, β; new_re_levels) where {T} any(any(ismissing, Tables.getcolumn(newdata, col)) for col in respvars) throw( ArgumentError( - "Response column must be initialized to a non-missing numeric value.", + "Response column must be initialized to a non-missing numeric value." ), ) end diff --git a/src/profile/thetapr.jl b/src/profile/thetapr.jl index 62f9473b2..aeb6ebf15 100644 --- a/src/profile/thetapr.jl +++ b/src/profile/thetapr.jl @@ -10,7 +10,7 @@ function optsumj(os::OptSummary, j::Integer) return OptSummary( deleteat!(copy(os.final), j), deleteat!(copy(os.lowerbd), j), - os.optimizer + os.optimizer, ) end diff --git a/src/randomeffectsterm.jl b/src/randomeffectsterm.jl index 432f9af9a..95beee5e7 100644 --- a/src/randomeffectsterm.jl +++ b/src/randomeffectsterm.jl @@ -174,7 +174,7 @@ function StatsModels.apply_schema( if !(typeof(first) <: CategoricalTerm) throw( ArgumentError( - "nesting terms requires categorical grouping term, got $first. Manually specify $first as `CategoricalTerm` in hints/contrasts", + "nesting terms requires categorical grouping term, got $first. Manually specify $first as `CategoricalTerm` in hints/contrasts" ), ) end diff --git a/src/remat.jl b/src/remat.jl index 74d92ff88..ee40c53e6 100644 --- a/src/remat.jl +++ b/src/remat.jl @@ -586,7 +586,7 @@ end function copyscaleinflate!( Ljj::UniformBlockDiagonal{T}, Ajj::UniformBlockDiagonal{T}, - Λj::ReMat{T,S} + Λj::ReMat{T,S}, ) where {T,S} λ = Λj.λ dind = diagind(S, S) @@ -604,7 +604,7 @@ end function copyscaleinflate!( Ljj::Matrix{T}, Ajj::UniformBlockDiagonal{T}, - Λj::ReMat{T,S} + Λj::ReMat{T,S}, ) where {T,S} copyto!(Ljj, Ajj) n = LinearAlgebra.checksquare(Ljj) diff --git a/src/simulate.jl b/src/simulate.jl index 1b4159e1e..9fbeb4ec9 100644 --- a/src/simulate.jl +++ b/src/simulate.jl @@ -236,7 +236,7 @@ function _simulate!( ismissing(σ) || throw( ArgumentError( - "You must not specify a dispersion parameter for model families without a dispersion parameter", + "You must not specify a dispersion parameter for model families without a dispersion parameter" ), ) diff --git a/src/utilities.jl b/src/utilities.jl index 5394a1fe3..413413b7c 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -136,7 +136,7 @@ function replicate( ) use_threads && Base.depwarn( "use_threads is deprecated and will be removed in a future release", - :replicate + :replicate, ) if !isnothing(hide_progress) Base.depwarn(