Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force return type on pwrss and logdet to provide stable type inference on objective #771

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/linalg/logdet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ 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))
@inbounds s = sum(j -> LD(L[kp1choose2(j)]), axes(m.reterms, 1))::T
if m.optsum.REML
lastL = last(L)
s += LD(lastL) # this includes the log of sqrtpwrss
s -= log(last(lastL)) # so we need to subtract it from the sum
end
return s + s # multiply by 2 b/c the desired det is of the symmetric mat, not the factor
return (s + s)::T # multiply by 2 b/c the desired det is of the symmetric mat, not the factor
end
10 changes: 5 additions & 5 deletions src/linearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function LinearMixedModel(
end

const _MISSING_RE_ERROR = ArgumentError(
"Formula contains no random effects; this isn't a mixed model. Perhaps you want to use GLM.jl?",
"Formula contains no random effects; this isn't a mixed model. Perhaps you want to use GLM.jl?"
)

function LinearMixedModel(
Expand All @@ -62,7 +62,7 @@ function LinearMixedModel(
fvars ⊆ tvars ||
throw(
ArgumentError(
"The following formula variables are not present in the table: $(setdiff(fvars, tvars))",
"The following formula variables are not present in the table: $(setdiff(fvars, tvars))"
),
)

Expand Down Expand Up @@ -226,7 +226,7 @@ end
function _offseterr()
return throw(
ArgumentError(
"Offsets are not supported in linear models. You can simply shift the response by the offset.",
"Offsets are not supported in linear models. You can simply shift the response by the offset."
),
)
end
Expand Down Expand Up @@ -372,7 +372,7 @@ function StatsBase.confint(m::MixedModel{T}; level=0.95) where {T}
return DictTable(;
coef=coefnames(m),
lower=β .- cutoff .* std,
upper=β .+ cutoff .* std
upper=β .+ cutoff .* std,
)
end

Expand Down Expand Up @@ -895,7 +895,7 @@ end

The penalized, weighted residual sum-of-squares.
"""
pwrss(m::LinearMixedModel) = abs2(last(last(m.L)))
pwrss(m::LinearMixedModel{T}) where {T} = abs2(last(last(m.L)))::T

"""
ranef!(v::Vector{Matrix{T}}, m::MixedModel{T}, β, uscale::Bool) where {T}
Expand Down
Loading