1- module RobustHatRegression
1+ module RobustHatRegression
22
33
44export robhatreg
@@ -7,31 +7,31 @@ import ..Basis: RegressionSetting, @extractRegressionSetting, designMatrix, resp
77import .. OrdinaryLeastSquares: ols, residuals, coef
88import .. LTS: iterateCSteps
99
10- import Distributions: quantile
10+ import Distributions: quantile
1111import LinearAlgebra: inv, diag
1212
1313
14- function trimean (u:: AbstractVector{T} ):: Float64 where T <: Real
14+ function trimean (u:: AbstractVector{T} ):: Float64 where {T <: Real }
1515 return (quantile (u, 0.25 ) + 2.0 * quantile (u, 0.50 ) + quantile (u, 0.75 )) / 4.0
1616end
1717
18- function m (v:: Vector , u:: Vector ):: Float64
18+ function m (v:: AbstractVector{T} , u:: AbstractVector{T} ):: Float64 where {T <: Real }
1919 return trimean (u .* v) * length (u)
2020end
2121
22- function m (mat:: AbstractMatrix , u:: AbstractVector ):: AbstractMatrix
22+ function m (mat:: AbstractMatrix{T} , u:: AbstractVector{T} ):: AbstractMatrix where {T <: Real }
2323 L = length (u)
2424 y = zeros (Float64, L, 1 )
2525 for i in 1 : L
2626 y[i, 1 ] = u[i]
2727 end
28- result = m (mat, y)
28+ result = m (mat, y)
2929 return result
3030end
3131
32- function m (m1:: AbstractMatrix , m2:: AbstractMatrix )
32+ function m (m1:: AbstractMatrix{T} , m2:: AbstractMatrix{T} ) :: AbstractMatrix where {T <: Real }
3333 n1, _ = size (m1)
34- _ , p2 = size (m2)
34+ _, p2 = size (m2)
3535 newmat = zeros (Float64, n1, p2)
3636 for i in 1 : n1
3737 for j in 1 : p2
@@ -41,7 +41,7 @@ function m(m1::AbstractMatrix, m2::AbstractMatrix)
4141 return newmat
4242end
4343
44- function hatrob (x:: AbstractMatrix )
44+ function hatrob (x:: AbstractMatrix{T} ) where {T <: Real }
4545 return x * inv (m (x' , x)) * x'
4646end
4747
@@ -64,7 +64,7 @@ Perform robust regression using the robust hat matrix method.
6464Satman, Mehmet Hakan, A robust initial basic subset selection
6565method for outlier detection algorithms in linear regression, In Press
6666"""
67- function robhatreg (setting:: RegressionSetting )
67+ function robhatreg (setting:: RegressionSetting ):: Dict
6868 X, y = @extractRegressionSetting setting
6969 return robhatreg (X, y)
7070end
@@ -90,9 +90,9 @@ Perform robust regression using the robust hat matrix method.
9090Satman, Mehmet Hakan, A robust initial basic subset selection
9191method for outlier detection algorithms in linear regression, In Press
9292"""
93- function robhatreg (X, y)
93+ function robhatreg (X:: AbstractMatrix{T} , y:: AbstractVector{T} ) :: Dict where {T <: Real }
9494 n, p = size (X)
95- h = Int (ceil ((n + p + 1 )/ 2 ))
95+ h = Int (ceil ((n + p + 1 ) / 2 ))
9696 myhat = hatrob (X)
9797 diagonals = diag (myhat)
9898 prms = sortperm (diagonals)
0 commit comments