Skip to content

Commit

Permalink
Change dof_residual definition to not depend on dispersion parameter (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack authored Aug 27, 2024
1 parent 0f8418b commit 5c33d9e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
CSV = "0.7, 0.8"
CSV = "0.7, 0.8, 0.9, 0.10"
CategoricalArrays = "0.8, 0.9, 0.10"
DataFrames = "0.22, 1"
Distributions = "0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25"
Expand Down
5 changes: 1 addition & 4 deletions src/glmfit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,7 @@ function nullloglikelihood(m::GeneralizedLinearModel)
return ll
end

function dof(x::GeneralizedLinearModel)
modelrank = linpred_rank(x.pp)
dispersion_parameter(x.rr.d) ? modelrank + 1 : modelrank
end
dof(obj::GeneralizedLinearModel) = linpred_rank(obj) + dispersion_parameter(obj.rr.d)

function _fit!(m::AbstractGLM, verbose::Bool, maxiter::Integer, minstepfac::Real,
atol::Real, rtol::Real, start)
Expand Down
3 changes: 2 additions & 1 deletion src/linpred.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,11 @@ coef(obj::LinPredModel) = coef(obj.pp)
coefnames(x::LinPredModel) =
x.formula === nothing ? ["x$i" for i in 1:length(coef(x))] : coefnames(formula(x).rhs)

dof_residual(obj::LinPredModel) = nobs(obj) - dof(obj) + 1
dof_residual(obj::LinPredModel) = nobs(obj) - linpred_rank(obj)

hasintercept(m::LinPredModel) = any(i -> all(==(1), view(m.pp.X , :, i)), 1:size(m.pp.X, 2))

linpred_rank(x::LinPredModel) = linpred_rank(x.pp)
linpred_rank(x::LinPred) = length(x.beta0)
linpred_rank(x::DensePredChol{<:Any, <:CholeskyPivoted}) = rank(x.chol)
linpred_rank(x::DensePredChol{<:Any, <:Cholesky}) = rank(x.chol.U)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ end
@test deviance(mdl) 135.68506068159
@test loglikelihood(mdl) -67.8425303407948
@test dof(mdl) == 3
@test dof_residual(mdl) == 98
@test dof_residual(mdl) == 97
@test aic(mdl) 141.68506068159
@test GLM.dispersion(mdl, true) 1
@test predict(mdl)[1:3] [0.4241893070433117, 0.3754516361306202, 0.6327877688720133] atol = 1.0E-6
Expand Down

0 comments on commit 5c33d9e

Please sign in to comment.