Skip to content

Commit c76ce2c

Browse files
committed
more constrained type definitions for the robust hat matrix based robust regression estimator
1 parent a08e0ad commit c76ce2c

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/robhatreg.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module RobustHatRegression
1+
module RobustHatRegression
22

33

44
export robhatreg
@@ -7,31 +7,31 @@ import ..Basis: RegressionSetting, @extractRegressionSetting, designMatrix, resp
77
import ..OrdinaryLeastSquares: ols, residuals, coef
88
import ..LTS: iterateCSteps
99

10-
import Distributions: quantile
10+
import Distributions: quantile
1111
import 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
1616
end
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)
2020
end
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
3030
end
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
4242
end
4343

44-
function hatrob(x::AbstractMatrix)
44+
function hatrob(x::AbstractMatrix{T}) where {T<:Real}
4545
return x * inv(m(x', x)) * x'
4646
end
4747

@@ -64,7 +64,7 @@ Perform robust regression using the robust hat matrix method.
6464
Satman, Mehmet Hakan, A robust initial basic subset selection
6565
method 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)
7070
end
@@ -90,9 +90,9 @@ Perform robust regression using the robust hat matrix method.
9090
Satman, Mehmet Hakan, A robust initial basic subset selection
9191
method 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

Comments
 (0)