Skip to content

Commit 45ef4b9

Browse files
committed
replace ols(X,y) with X\y in other methods
1 parent 64a3823 commit 45ef4b9

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/hs93.jl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export hs93
66

77
import ..Basis:
88
RegressionSetting, @extractRegressionSetting, designMatrix, responseVector, applyColumns
9-
import ..OrdinaryLeastSquares: ols, predict, residuals, coef
9+
1010
import ..Diagnostics: dffits
1111

1212
import Distributions: TDist, quantile
@@ -116,8 +116,7 @@ function hs93basicsubset(
116116
s = length(initialindices)
117117
indices = initialindices
118118
for i in range(s + 1, stop = h)
119-
olsreg = ols(X[indices, :], y[indices])
120-
betas = coef(olsreg)
119+
betas = X[indices, :] \ y[indices]
121120
d = zeros(Float64, n)
122121
XM = X[indices, :]
123122
for j = 1:n
@@ -204,9 +203,8 @@ function hs93(
204203
betas = []
205204

206205
while s < n
207-
olsreg = ols(X[indices, :], y[indices])
208-
betas = coef(olsreg)
209-
resids = residuals(olsreg)
206+
betas = X[indices, :] \ y[indices]
207+
resids = y[indices] - X[indices,:] * betas
210208
sigma = sqrt(sum(resids .^ 2.0) / (length(resids) - p))
211209
d = zeros(Float64, n)
212210
XM = X[indices, :]
@@ -237,9 +235,7 @@ function hs93(
237235

238236
outlierset = filter(x -> abs(d[x]) > abs(tcalc), 1:n)
239237
inlierset = setdiff(1:n, outlierset)
240-
cleanols = ols(X[inlierset, :], y[inlierset])
241-
cleanbetas = coef(cleanols)
242-
238+
cleanbetas = X[inlierset, :] \ y[inlierset]
243239
if abs(d[orderingd][s+1]) > abs(tcalc)
244240
result = Dict(
245241
"d" => d,

src/satman2013.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export satman2013
77
import ..Basis:
88
RegressionSetting, @extractRegressionSetting, designMatrix, responseVector, applyColumns
99
import ..LTS: iterateCSteps
10-
import ..OrdinaryLeastSquares: ols, coef, wls, residuals
10+
import ..OrdinaryLeastSquares: coef, wls, residuals
1111
import ..Diagnostics: mahalanobisSquaredMatrix
1212
import Distributions: median
1313
import LinearAlgebra: diag
@@ -106,9 +106,8 @@ function satman2013(X::AbstractMatrix{Float64}, y::AbstractVector{Float64})
106106
_, bestset = iterateCSteps(X, y, best_h_indices, h)
107107

108108
# Estimate the final regression parameters
109-
olsreg = ols(X[bestset, :], y[bestset])
110-
betas = coef(olsreg)
111-
resids = y .- (X * betas)
109+
betas = X[bestset, :] \ y[bestset]
110+
resids = y .- X * betas
112111
med_res = median(resids)
113112
standardized_resids = (resids .- med_res) / median(abs.(resids .- med_res))
114113

src/theilsen.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ function theilsen(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}, m::Int
4646

4747
for i in 1:nsamples
4848
luckyindices = sample(1:n, m, replace = false)
49-
olsresult = ols(X[luckyindices, :], y[luckyindices])
50-
betas = coef(olsresult)
51-
allbetas[i, :] = betas
49+
#olsresult = ols(X[luckyindices, :], y[luckyindices])
50+
#betas = coef(olsresult)
51+
allbetas[i, :] = X[luckyindices, :] \ y[luckyindices]
5252
end
5353

5454
multimed = multivariatemedian(allbetas)

0 commit comments

Comments
 (0)