11using 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)
2031end
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