Skip to content

Commit

Permalink
Fix problem with docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
gragusa committed Dec 11, 2024
1 parent 56d81ae commit a2357cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
19 changes: 9 additions & 10 deletions src/linpred.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ A `LinPred` type with a dense QR decomposition of `X`
- `qr`: either a `QRCompactWY` or `QRPivoted` object created from `X`, with optional row weights.
- `scratchm1`: scratch Matrix{T} of the same size as `X`
"""

mutable struct DensePredQR{T<:BlasReal, Q<:Union{QRCompactWY, QRPivoted}, W<:AbstractWeights} <: DensePred
X::Matrix{T} # model matrix
beta0::Vector{T} # base coefficient vector
Expand Down Expand Up @@ -454,18 +453,18 @@ function leverage(pp::DensePredChol{T, C, W}) where {T, C<:Cholesky, W}
end

function leverage(pp::DensePredQR{T, C, W}) where {T, C<:QRPivoted, W}
X = modelmatrix(pp; weighted=isweighted(pp))
_, k = size(X)
ch = pp.qr
rnk = length(ch.p)
p = ch.p
idx = invperm(p)[1:rnk]
sum(x -> x^2, view(X, :, 1:rnk)/ch.R[1:rnk, idx], dims=2)
X = modelmatrix(pp; weighted=isweighted(pp))
_, k = size(X)
ch = pp.qr
rnk = length(ch.p)
p = ch.p
idx = invperm(p)[1:rnk]
sum(x -> x^2, view(X, :, 1:rnk)/ch.R[1:rnk, idx], dims=2)
end

function leverage(pp::DensePredQR{T, C, W}) where {T, C<:Cholesky, W}
X = modelmatrix(pp; weighted=isweighted(pp))
sum(x -> x^2, X/pp.qr.R, dims=2)
X = modelmatrix(pp; weighted=isweighted(pp))
sum(x -> x^2, X/pp.qr.R, dims=2)

Check warning on line 467 in src/linpred.jl

View check run for this annotation

Codecov / codecov/patch

src/linpred.jl#L465-L467

Added lines #L465 - L467 were not covered by tests
end

response(obj::LinPredModel) = obj.rr.y
Expand Down
12 changes: 6 additions & 6 deletions src/lm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,6 @@ Compute [Cook's distance](https://en.wikipedia.org/wiki/Cook%27s_distance)
for each observation in linear model `obj`, giving an estimate of the influence
of each data point.
"""
## To remove when https://github.com/JuliaStats/StatsAPI.jl/pull/16 is merged
function crossmodelmatrix(model::RegressionModel; weighted::Bool=false)
x = weighted ? modelmatrix(model; weighted=weighted) : modelmatrix(model)
return Symmetric(x' * x)
end

function StatsBase.cooksdistance(obj::LinearModel)
u = residuals(obj; weighted=isweighted(obj))
mse = GLM.dispersion(obj,true)
Expand All @@ -418,3 +412,9 @@ function StatsBase.cooksdistance(obj::LinearModel)
D = @. u^2 * (hii / (1 - hii)^2) / (k*mse)
return D
end

## To remove when https://github.com/JuliaStats/StatsAPI.jl/pull/16 is merged
function crossmodelmatrix(model::RegressionModel; weighted::Bool=false)
x = weighted ? modelmatrix(model; weighted=weighted) : modelmatrix(model)
return Symmetric(x' * x)

Check warning on line 419 in src/lm.jl

View check run for this annotation

Codecov / codecov/patch

src/lm.jl#L417-L419

Added lines #L417 - L419 were not covered by tests
end

0 comments on commit a2357cf

Please sign in to comment.