Skip to content

Commit

Permalink
multiple dispatch for (X, y) style call
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytecode committed Oct 7, 2020
1 parent dbdd387 commit 08cd5e1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
authors = ["Mehmet Hakan Satman <[email protected]>"]
name = "LinRegOutliers"
uuid = "6d4de0fb-32d9-4c65-aac1-cc9ed8b94b1a"
authors = ["Mehmet Hakan Satman <[email protected]>"]
version = "0.3.15"
version = "0.4.0"

[deps]
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
Expand Down
15 changes: 15 additions & 0 deletions src/.dev/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ include("outlier.jl")
@test applyColumns(mean, mat) == [1.0, 0.0]
end

@testset "Ordinary Least Squares" begin
tol = 0.0001
#  The model is exatly y = 5 + 5x
var1 = Float64[1, 2, 3, 4, 5]
X = hcat(ones(5), var1)
betas = [5.0, 5.0]
y = X * betas

# OLS
olsreg = ols(X, y)
@test isapprox(coef(olsreg), betas, atol=tol)
@test isapprox(residuals(olsreg), zeros(Float64, 5), atol=tol)
@test isapprox(predict(olsreg), y, atol=tol)
end

@testset "Basis - createRegressionSetting, designMatrix, responseVector" begin
dataset = DataFrame(
x=[1.0, 2, 3, 4, 5],
Expand Down
3 changes: 3 additions & 0 deletions src/LinRegOutliers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export jacknifedS
export cooks
export mahalabonisSquaredMatrix

# Ordinary least squares
export OLS, ols, wls, residuals, predict

# Algorithms
export hs93, hs93initialset, hs93basicsubset
export ks89
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ using LinRegOutliers
@test applyColumns(mean, mat) == [1.0, 0.0]
end

@testset "Ordinary Least Squares" begin
tol = 0.0001
#  The model is exatly y = 5 + 5x
var1 = Float64[1, 2, 3, 4, 5]
X = hcat(ones(5), var1)
betas = [5.0, 5.0]
y = X * betas

# OLS
olsreg = ols(X, y)
@test isapprox(coef(olsreg), betas, atol=tol)
@test isapprox(residuals(olsreg), zeros(Float64, 5), atol=tol)
@test isapprox(predict(olsreg), y, atol=tol)
end

@testset "Basis - createRegressionSetting, designMatrix, responseVector" begin
dataset = DataFrame(
x=[1.0, 2, 3, 4, 5],
Expand Down

0 comments on commit 08cd5e1

Please sign in to comment.