-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add deepest regression estimator (#13)
- Loading branch information
Showing
9 changed files
with
163 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "LinRegOutliers" | ||
uuid = "6d4de0fb-32d9-4c65-aac1-cc9ed8b94b1a" | ||
authors = ["Mehmet Hakan Satman <[email protected]>", "Shreesh Adiga <[email protected]>", "Guillermo Angeris <[email protected]>", "Emre Akadal <[email protected]>"] | ||
version = "0.10.2" | ||
version = "0.11.0" | ||
|
||
[deps] | ||
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5" | ||
|
@@ -14,6 +14,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | |
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" | ||
Requires = "ae029012-a4dd-5104-9daa-d747884805df" | ||
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d" | ||
mrfDepth_jll = "53656f53-9700-50e7-bf9c-d3aea1338d1b" | ||
|
||
[compat] | ||
Clustering = "0.12.2, 0.13, 0.14, 0.15" | ||
|
@@ -26,6 +27,7 @@ PrecompileTools = "1" | |
Requires = "1" | ||
StatsModels = "0.4, 0.5, 0.6, 0.7" | ||
julia = "1.4" | ||
mrfDepth_jll = "1.0.14" | ||
|
||
[extras] | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module DeepestRegression | ||
|
||
export deepestregression | ||
|
||
import ..Basis: | ||
RegressionSetting, @extractRegressionSetting, designMatrix, responseVector | ||
|
||
using mrfDepth_jll: mrfDepth_jll | ||
|
||
|
||
""" | ||
deepestregression(setting; maxit = 1000) | ||
Estimate Deepest Regression paramaters. | ||
# Arguments | ||
- `setting::RegressionSetting`: RegressionSetting object with a formula and dataset. | ||
- `maxit`: Maximum number of iterations | ||
# Description | ||
Estimates Deepest Regression Estimator coefficients. | ||
# References | ||
Van Aelst S., Rousseeuw P.J., Hubert M., Struyf A. (2002). The | ||
deepest regression method. Journal of Multivariate Analysis, | ||
81, 138-166. | ||
# Output | ||
- `betas`: Vector of regression coefficients estimated. | ||
""" | ||
function deepestregression(setting::RegressionSetting; maxit::Int = 10000) | ||
X = designMatrix(setting) | ||
y = responseVector(setting) | ||
if all(x -> isone(x), X[:, 1]) | ||
X = X[:, 2:end] | ||
end | ||
return deepestregression(X, y, maxit = maxit) | ||
end | ||
|
||
function deepestregression(X::Matrix{Float64}, y::Vector{Float64}; maxit::Int = 10000)::Vector{Float64} | ||
drdata = hcat(X, y) | ||
n, p = size(drdata) | ||
n = Int32(n) | ||
p = Int32(p) | ||
betas = zeros(Float64, p) | ||
maxit = Int32(maxit) | ||
iter = Int32(1) | ||
MDEPAPPR = Int32(p) | ||
ccall((:sweepmedres_, mrfDepth_jll.libmrfDepth), | ||
Cint, | ||
(Ref{Float64}, # X | ||
Ref{Int32}, # n | ||
Ref{Int32}, # np | ||
Ref{Float64}, # betas | ||
Ref{Cint}, # maxit | ||
Ref{Cint}, # iter | ||
Ref{Cint}, # MDEPAPPR | ||
), drdata, n, p, betas, maxit, iter, MDEPAPPR) | ||
|
||
return vcat(betas[end], betas[1:(end-1)]) | ||
end | ||
|
||
|
||
end # end of module DeepestRegression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import LinRegOutliers: DataSets | ||
|
||
@testset "Deepest Regression" begin | ||
|
||
@testset "Simple Data" begin | ||
eps = 0.1 | ||
|
||
n = 100000 | ||
x1 = rand(n) | ||
x2 = rand(n) | ||
o = ones(Float64, n) | ||
e = randn(n) | ||
y = 15 .+ 10 .* x1 + 5 .* x2 + e | ||
X = hcat(x1, x2) | ||
|
||
result = deepestregression(X, y) | ||
|
||
@test isapprox(result[1], 15, atol = eps) | ||
@test isapprox(result[2], 10, atol = eps) | ||
@test isapprox(result[3], 5, atol = eps) | ||
end | ||
|
||
@testset "Stackloss Data Example" begin | ||
|
||
eps = 0.001 | ||
|
||
setting = createRegressionSetting( | ||
@formula(stackloss ~ airflow + watertemp + acidcond), | ||
DataSets.stackloss) | ||
|
||
result = deepestregression(setting) | ||
|
||
@test isapprox(result[1], -35.37610619, atol = eps) | ||
@test isapprox(result[2], 0.82522124, atol = eps) | ||
@test isapprox(result[3], 0.44247788, atol = eps) | ||
@test isapprox(result[4], -0.07964602, atol = eps) | ||
|
||
end | ||
end |
313a007
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
313a007
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/90164
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: