Skip to content

Commit

Permalink
Add allowrankdeficient to linear models.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbates committed Dec 15, 2017
1 parent 01ec607 commit fcdc3dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/GLM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module GLM
using Distributions, Reexport
using Base.LinAlg.LAPACK: potrf!, potrs!
using Base.LinAlg.BLAS: gemm!, gemv!
using Base.LinAlg: QRCompactWY, Cholesky, CholeskyPivoted, BlasReal
using Base.LinAlg: copytri!, QRCompactWY, Cholesky, CholeskyPivoted, BlasReal
using StatsBase: StatsBase, CoefTable, StatisticalModel, RegressionModel
using StatsFuns: logit, logistic
@reexport using StatsModels
Expand Down
14 changes: 14 additions & 0 deletions src/linpred.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ Base.cholfact(p::SparsePredChol{T}) where {T} = copy(p.chol)
Base.cholfact!(p::SparsePredChol{T}) where {T} = p.chol

invchol(x::DensePred) = inv(cholfact!(x))
function invchol(x::DensePredChol{T,<: CholeskyPivoted}) where T
ch = x.chol
rnk = rank(ch)
p = length(x.delbeta)
rnk == p && return inv(ch)
fac = ch.factors
res = fill(convert(T, NaN), size(fac))
for j in 1:rnk, i in 1:rnk
res[i, j] = fac[i, j]
end
copytri!(LAPACK.potri!(ch.uplo, view(res, 1:rnk, 1:rnk)), ch.uplo, true)
ipiv = invperm(ch.piv)
res[ipiv, ipiv]
end
invchol(x::SparsePredChol) = cholfact!(x) \ eye(size(x.X, 2))
vcov(x::LinPredModel) = scale!(invchol(x.pp), dispersion(x, true))

Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CategoricalArrays, Compat, CSV, DataFrames, StatsBase
using Compat.Test
using Revise # for debugging
using GLM

test_show(x) = show(IOBuffer(), x)
Expand Down

0 comments on commit fcdc3dd

Please sign in to comment.