Skip to content

Commit 125af4b

Browse files
committed
LMS returns betas rather than coefs
1 parent 976a489 commit 125af4b

3 files changed

Lines changed: 35 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# v0.9.6 (Upcoming Release)
1+
# v0.10.0 (Upcoming Release)
22

3+
- LMS returns betas rather than coefs
34

45

56
# v0.9.5

src/lms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function lms(X::Array{Float64,2}, y::Array{Float64,1}; iters = nothing, crit = 2
9494
s = 1.4826 * sqrt((1.0 + (5.0 / (n - p))) * bestobjective)
9595
standardizedres = bestres / s
9696
d = Dict()
97-
d["coef"] = bestparamaters
97+
d["betas"] = bestparamaters
9898
d["objective"] = bestobjective
9999
d["S"] = s
100100
d["stdres"] = standardizedres

test.jl

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
using LinRegOutliers
22

3-
3+
import LinRegOutliers.OrdinaryLeastSquares: ols, wls, coef, residuals
4+
import Distributions: median
45

56
#sett = createRegressionSetting(@formula(calls ~ year), phones)
67
#sett = createRegressionSetting(@formula(y ~ x1 + x2 + x3), hbk)
78

8-
n = 1000
9-
p = 25
10-
betas = [5.0 for i in 1:p]
11-
x = rand(n, p)
12-
e = randn(n)
13-
y = x * betas + e
14-
range = collect(701:1000)
15-
no = length(range)
16-
17-
y[range] .= rand(no)
18-
for i in 1:25
19-
x[range, i] .= rand(no)
9+
function generatedata(
10+
n::Int,
11+
p::Int,
12+
contamination::Float64,
13+
direction::Symbol,
14+
)::Tuple{Array{Float64,2},Array{Float64,1}}
15+
if !(direction in [:y, :x])
16+
error("- Direction must be :x or :y")
17+
end
18+
on = ones(Float64, n)
19+
pxvars = p - 1
20+
xvars = randn(n, pxvars)
21+
b = [5.0 for i = 1:pxvars]
22+
y = 5.0 .+ xvars * b + randn(n)
23+
totalcontamination = round(Int, contamination * n)
24+
if direction == :y
25+
y[1:totalcontamination] .= maximum(y) .+ abs.(rand(totalcontamination) * 5.0)
26+
elseif direction == :x
27+
xvars[1:totalcontamination, :] .=
28+
maximum(xvars) .+ abs.(rand(totalcontamination) * 5.0)
29+
end
30+
return (hcat(on, xvars), y)
2031
end
21-
result = lts(x, y)
32+
33+
34+
35+
sett = createRegressionSetting(@formula(calls ~ year), phones)
36+
x = designMatrix(sett)
37+
y = responseVector(sett)
38+
x, y = generatedata(1000, 25, 0.30, :x)
39+
result = gwcga(x, y)

0 commit comments

Comments
 (0)