Description Usage Arguments Additional Options Model Fitting Author(s) Examples
Least Absolute Deviation (LAD) is similar to an OLS regression model, but it minimizes the absolute deviation ||y - X * β||_1 instead of the sum of squares ||y - X * β||_2^2. LAD is equivalent to the median regression, a special case of the quantile regression models. LAD is a robust regression technique in the sense that the estimated coefficients are insensitive to outliers.
This function will not directly conduct the computation,
but rather returns an object of class "ADMM_LAD
" that contains
several memeber functions to actually constructs and fits the model.
Member functions that are callable from this object are listed below:
$opts() | Setting additional options. See section Additional Options for details. |
$fit() | Fit the model and do the actual computation. See section Model Fitting for details. |
1 |
x |
The data matrix. |
y |
The response vector. |
intercept |
Whether to include an intercept term. Default is |
Additional options related to ADMM algorithm can be set through the
$opts()
member function of an "ADMM_LAD
" object. The usage of
this method is
1 2 | model$opts(maxit = 10000, eps_abs = 1e-4, eps_rel = 1e-4,
rho = NULL)
|
Here model
is the object returned by admm_lad()
.
Explanation of the arguments is given below:
maxit
Maximum number of iterations.
eps_abs
Absolute tolerance parameter.
eps_rel
Relative tolerance parameter.
rho
ADMM step size parameter. If set to NULL
, the program
will compute a default one.
This member function will implicitly return the "ADMM_LAD
" object itself.
Model will be fit after calling the $fit()
member function. This is no
argument that needs to be set. The function will return an object of class
"ADMM_LAD_fit
", which contains the following fields:
x
The data matrix.
y
The response vector.
beta
The estimated regression coefficients, including the intercept.
niter
Number of ADMM iterations.
Class "ADMM_LAD_fit
" also contains a $plot()
member function,
which plots the fitted values with observed values. See the examples below.
Yixuan Qiu <http://statr.me>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ## Robust regression with LAD ##
## Generate data with an outlier
set.seed(123)
x = sort(rnorm(100))
y = x + rnorm(100, sd = 0.3)
y[1] = y[1] + 5
## Build an LAD model (median regression)
model = admm_lad(x, y)
## Lower down the precision for faster computation
model$opts(eps_rel = 1e-3)
## Fit the model
res = model$fit()
## Plot for the fitted values and observed values
res$plot()
## The steps above can be accomplished using a chainable call
admm_lad(x, y)$opts(eps_rel = 1e-3)$fit()$plot()
## Compare LAD with OLS
library(ggplot2)
ols = lm(y ~ x)$coefficients
d = data.frame(intercept = c(ols[1], res$beta[1], 0),
slope = c(ols[2], res$beta[2], 1),
method = c("OLS", "LAD", "Truth"))
ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) +
geom_point() +
geom_abline(aes(intercept = intercept, slope = slope, color = method),
data = d, show_guide = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.