From 45ef4b916353c54a9990a88d949edffe50da85c9 Mon Sep 17 00:00:00 2001 From: jbytecode Date: Mon, 8 Jan 2024 14:03:09 +0300 Subject: [PATCH] replace ols(X,y) with X\y in other methods --- src/hs93.jl | 14 +++++--------- src/satman2013.jl | 7 +++---- src/theilsen.jl | 6 +++--- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/hs93.jl b/src/hs93.jl index 17660c2..1db9e13 100644 --- a/src/hs93.jl +++ b/src/hs93.jl @@ -6,7 +6,7 @@ export hs93 import ..Basis: RegressionSetting, @extractRegressionSetting, designMatrix, responseVector, applyColumns -import ..OrdinaryLeastSquares: ols, predict, residuals, coef + import ..Diagnostics: dffits import Distributions: TDist, quantile @@ -116,8 +116,7 @@ function hs93basicsubset( s = length(initialindices) indices = initialindices for i in range(s + 1, stop = h) - olsreg = ols(X[indices, :], y[indices]) - betas = coef(olsreg) + betas = X[indices, :] \ y[indices] d = zeros(Float64, n) XM = X[indices, :] for j = 1:n @@ -204,9 +203,8 @@ function hs93( betas = [] while s < n - olsreg = ols(X[indices, :], y[indices]) - betas = coef(olsreg) - resids = residuals(olsreg) + betas = X[indices, :] \ y[indices] + resids = y[indices] - X[indices,:] * betas sigma = sqrt(sum(resids .^ 2.0) / (length(resids) - p)) d = zeros(Float64, n) XM = X[indices, :] @@ -237,9 +235,7 @@ function hs93( outlierset = filter(x -> abs(d[x]) > abs(tcalc), 1:n) inlierset = setdiff(1:n, outlierset) - cleanols = ols(X[inlierset, :], y[inlierset]) - cleanbetas = coef(cleanols) - + cleanbetas = X[inlierset, :] \ y[inlierset] if abs(d[orderingd][s+1]) > abs(tcalc) result = Dict( "d" => d, diff --git a/src/satman2013.jl b/src/satman2013.jl index f1a16d8..7bd30fc 100644 --- a/src/satman2013.jl +++ b/src/satman2013.jl @@ -7,7 +7,7 @@ export satman2013 import ..Basis: RegressionSetting, @extractRegressionSetting, designMatrix, responseVector, applyColumns import ..LTS: iterateCSteps -import ..OrdinaryLeastSquares: ols, coef, wls, residuals +import ..OrdinaryLeastSquares: coef, wls, residuals import ..Diagnostics: mahalanobisSquaredMatrix import Distributions: median import LinearAlgebra: diag @@ -106,9 +106,8 @@ function satman2013(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}) _, bestset = iterateCSteps(X, y, best_h_indices, h) # Estimate the final regression parameters - olsreg = ols(X[bestset, :], y[bestset]) - betas = coef(olsreg) - resids = y .- (X * betas) + betas = X[bestset, :] \ y[bestset] + resids = y .- X * betas med_res = median(resids) standardized_resids = (resids .- med_res) / median(abs.(resids .- med_res)) diff --git a/src/theilsen.jl b/src/theilsen.jl index 8ac418b..b99ae4b 100644 --- a/src/theilsen.jl +++ b/src/theilsen.jl @@ -46,9 +46,9 @@ function theilsen(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}, m::Int for i in 1:nsamples luckyindices = sample(1:n, m, replace = false) - olsresult = ols(X[luckyindices, :], y[luckyindices]) - betas = coef(olsresult) - allbetas[i, :] = betas + #olsresult = ols(X[luckyindices, :], y[luckyindices]) + #betas = coef(olsresult) + allbetas[i, :] = X[luckyindices, :] \ y[luckyindices] end multimed = multivariatemedian(allbetas)