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

backport of QR to 1.x #537

Open
wants to merge 9 commits into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/glmfit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ function dispersion(m::AbstractGLM, sqr::Bool=false)
end
end

dispersion(m::StatsModels.TableRegressionModel{<:AbstractGLM}, args...; kwargs...) = dispersion(m.model, args...; kwargs...)

"""
predict(mm::AbstractGLM, newX::AbstractMatrix; offset::FPVector=eltype(newX)[],
interval::Union{Symbol,Nothing}=nothing, level::Real = 0.95,
Expand Down
1 change: 1 addition & 0 deletions src/linpred.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ coef(obj::LinPredModel) = coef(obj.pp)
dof_residual(obj::LinPredModel) = nobs(obj) - dof(obj) + 1

hasintercept(m::LinPredModel) = any(i -> all(==(1), view(m.pp.X , :, i)), 1:size(m.pp.X, 2))
hasintercept(m::StatsModels.TableRegressionModel{<:LinPredModel}) = hasintercept(m.mf.f)

linpred_rank(x::LinPred) = length(x.beta0)
linpred_rank(x::DensePredChol{<:Any, <:CholeskyPivoted}) = rank(x.chol)
Expand Down
6 changes: 5 additions & 1 deletion src/negbinfit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function mle_for_θ(y::AbstractVector, μ::AbstractVector, wts::AbstractVector;
θ
end

_rr(m::StatsModels.TableRegressionModel{<:GeneralizedLinearModel}) = m.model.rr
_rr(m::GeneralizedLinearModel) = m.rr

"""
negbin(formula, data, [link::Link];
<keyword arguments>)
Expand Down Expand Up @@ -139,7 +142,8 @@ function negbin(F,
regmodel = glm(F, D, NegativeBinomial(θ), args...;
dropcollinear=dropcollinear, method=method, maxiter=maxiter,
atol=atol, rtol=rtol, verbose=verbose, kwargs...)
μ = regmodel.rr.mu

μ = _rr(regmodel).mu
Copy link
Member

Choose a reason for hiding this comment

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

Above the code seems to assume that regmodel is a TableRegressionModel, so you could just do regmodel.model.rr.mu and remove _rr.

prevθ = θ
θ = mle_for_θ(y, μ, wts; maxiter=maxiter, tol=rtol)
δ = prevθ - θ
Expand Down