Skip to content

Commit

Permalink
replace ols(X,y) with X\y in other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytecode committed Jan 8, 2024
1 parent 64a3823 commit 45ef4b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
14 changes: 5 additions & 9 deletions src/hs93.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, :]
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions src/satman2013.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions src/theilsen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 45ef4b9

Please sign in to comment.