From a2357cfeca83d531f51e21a87ef410beccae0d8f Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Wed, 11 Dec 2024 13:21:09 +0100 Subject: [PATCH] Fix problem with docstrings --- src/linpred.jl | 19 +++++++++---------- src/lm.jl | 12 ++++++------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/linpred.jl b/src/linpred.jl index 9a978626..cf4e856b 100644 --- a/src/linpred.jl +++ b/src/linpred.jl @@ -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 @@ -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) end response(obj::LinPredModel) = obj.rr.y diff --git a/src/lm.jl b/src/lm.jl index ec00b72f..f1d55572 100644 --- a/src/lm.jl +++ b/src/lm.jl @@ -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) @@ -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) +end