Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcdc3dd

Browse files
committedDec 15, 2017
Add allowrankdeficient to linear models.
1 parent 01ec607 commit fcdc3dd

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
 

‎src/GLM.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module GLM
44
using Distributions, Reexport
55
using Base.LinAlg.LAPACK: potrf!, potrs!
66
using Base.LinAlg.BLAS: gemm!, gemv!
7-
using Base.LinAlg: QRCompactWY, Cholesky, CholeskyPivoted, BlasReal
7+
using Base.LinAlg: copytri!, QRCompactWY, Cholesky, CholeskyPivoted, BlasReal
88
using StatsBase: StatsBase, CoefTable, StatisticalModel, RegressionModel
99
using StatsFuns: logit, logistic
1010
@reexport using StatsModels

‎src/linpred.jl

+14
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ Base.cholfact(p::SparsePredChol{T}) where {T} = copy(p.chol)
201201
Base.cholfact!(p::SparsePredChol{T}) where {T} = p.chol
202202

203203
invchol(x::DensePred) = inv(cholfact!(x))
204+
function invchol(x::DensePredChol{T,<: CholeskyPivoted}) where T
205+
ch = x.chol
206+
rnk = rank(ch)
207+
p = length(x.delbeta)
208+
rnk == p && return inv(ch)
209+
fac = ch.factors
210+
res = fill(convert(T, NaN), size(fac))
211+
for j in 1:rnk, i in 1:rnk
212+
res[i, j] = fac[i, j]
213+
end
214+
copytri!(LAPACK.potri!(ch.uplo, view(res, 1:rnk, 1:rnk)), ch.uplo, true)
215+
ipiv = invperm(ch.piv)
216+
res[ipiv, ipiv]
217+
end
204218
invchol(x::SparsePredChol) = cholfact!(x) \ eye(size(x.X, 2))
205219
vcov(x::LinPredModel) = scale!(invchol(x.pp), dispersion(x, true))
206220

‎test/runtests.jl

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CategoricalArrays, Compat, CSV, DataFrames, StatsBase
22
using Compat.Test
3-
using Revise # for debugging
43
using GLM
54

65
test_show(x) = show(IOBuffer(), x)

0 commit comments

Comments
 (0)
Please sign in to comment.