Least Absolute Value based regression

18 views (last 30 days)
abc
abc on 9 Nov 2013
Commented: Amin Nassaj on 26 Jan 2023
Hi ,
I want to use linear regression based on least absolute value deviation to find the coefficients of my model with the help of measured data and 3 independent variables. The number of measurements I have are much greater than 3( number of cofficients). I have been trying to implement LAV method for this, but with no success. I need urgent help. Can someone please guide me in this. If someone already has the code for LAV, I would be grateful if you could share it with me.
Thank you!

Accepted Answer

Matt J
Matt J on 10 Nov 2013
With only 3 unknowns, fminsearch should work fairly well
fminsearch(@(x) norm(A*x-b,1), x0 )
  14 Comments
NA
NA on 29 Oct 2021
Edited: NA on 29 Oct 2021
Hello Matt,
I have a regression model like:
zi = Ai1*x1+Ai2*x2+ei i=1,2,3,4,5
The observation are given as table below:
i = [1;2;3;4;5];
zi = [-3.01;3.52;-5.49;4.03;5.01];
Ai1 = [1;0.5;-1.5;0;1];
Ai2 = [1.5;-0.5;0.25;-1;-0.5];
AA = [i,zi,Ai1,Ai2];
T = array2table(AA);
T.Properties.VariableNames(1:4) = {'i','z_i','A_i1','A_i2'};
I used this code for LAV estimation
A = Ai1+Ai2;
b = zi;
len_x = size(A,2);
c = [zeros(len_x,1);ones(size(b))];
F = [A -eye(size(b,1)); -A -eye(size(b,1))];
g = [b; -b];
z = linprog(c,F,g);
xlav = z(1:2);
The result is not correct as xlav and residual should be
xlav = [3.005;-4.010]
residual = [0; 0.0125; 0.2; 0.02; 1]
Amin Nassaj
Amin Nassaj on 26 Jan 2023
The problem is the way you have defined matrix A. It must be:
A=[Ai1 Ai2];
Then it works!

Sign in to comment.

More Answers (1)

Matt J
Matt J on 29 Oct 2021
@NA In the years after this thread, I implemented minL1lin, which you can download from
A quick test shows that it gives your expected answer:
zi = [-3.01;3.52;-5.49;4.03;5.01];
Ai1 = [1;0.5;-1.5;0;1];
Ai2 = [1.5;-0.5;0.25;-1;-0.5];
[xlav,~,res]=minL1lin([Ai1,Ai2],zi)
Optimal solution found.
xlav = 2×1
3.0050 -4.0100
res = 5×1
0.0000 -0.0125 -0.0200 -0.0200 0.0000
  12 Comments
NA
NA on 10 Nov 2021
Thank you. If we change one of the entry of matrix A, such that
A_d = [A11 A12 A13 A14; A21 4*A22 A23 A24; A31 A32 A33 A34]
When we calculate residuals, how minL1lin removes the entry to find the regression. I mean, what is the threshold level that minL1lin use for regression?
Matt J
Matt J on 10 Nov 2021
Edited: Matt J on 10 Nov 2021
I'm not really following you. What leads you to believe that elements of A are being removed?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!