Be the first to rate this file! 161 downloads (last 30 days) File Size: 76.83 KB File ID: #22027

Analytical solution for Orthogonal Linear Least Squares in two dimensions

by Francesco Pozzi

 

08 Nov 2008

No BSD License  

The function returns the Orthogonal Linear Least Squares estimate for parameters of line ax+by+c=0

Download Now | Watch this File

File Information
Description

ORTHLLS2D returns the Orthogonal Linear Least Squares estimate for parameters of line a x + b y + c = 0

function f = OrthLLS2D(x, y)

Inputs x and y must be real vectors of equal size.
Output f is the real vector [a b c] where a, b and c are the estimated parameters of the linear equation.

Since a more general function called LINORTFITN has already been submitted to File Exchange (ID number: 16800) in October 2007 by Mr. F. Carr, my file is supposed to be used as a brief introduction to the analytical problem in an extremely simple case.

Orthogonal Least Squares Estimate on a plane, in the simple case of a linear equation, is in fact a problem that can be easily solved analytically with no approximation (see pdf file for detailed explanation). Notice that in the general multidimensional case, an analytical solution may not exist (although Mr. Carr's function is an efficient approximation of the solution).

% ====================================================
% EXAMPLE: HOW TO USE THE FUNCTION
% ====================================================
Build two series, given the linear relation y = mx + q + error
T = 1000; % number of points
m = -1; % slope
q = 1; % intercept
x = randn(T, 1); % random x values
u = randn(T, 1); % random error
y = m * x + q + u; % y = mx + q + error
f = OrthLLS2D(x, y); % estimate [a, b, c] for equation ax + by + c = 0
plot(x, y, '.') % scatter plot for empirical points
hold on
plot(x, [ones(T,1) x] * [-f(3); -f(1)], '*r');% plot orthogonal linear least squares
b1 = regress(y, [ones(T,1) x]); % parameters of the ordinary least squares (y as a function of x)
b2 = regress(x, [ones(T,1) y]); % parameters of the ordinary least squares (x as a function of y)
plot(x, [ones(T,1) x] * b1, '.g'); % plot ordinary least squares (y as a function of x)
plot([ones(T,1) y] * b2, y, '.c'); % plot ordinary least squares (x as a function of y)

% ====================================================

See also LINORTFIT2, LINORTFITN.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Orthogonal Linear Regression

MATLAB release MATLAB 7 (R14)
Zip File Content  
Other Files OrthLLS2D.m,
Orthogonal Linear Least Squares on a two-dimensional plane.pdf,
Read Me.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
least squares Francesco Pozzi 09 Nov 2008 19:25:13
orthogonal least squares Francesco Pozzi 09 Nov 2008 19:25:13
orthogonal linear least squares Francesco Pozzi 09 Nov 2008 19:25:13
econometrics Francesco Pozzi 09 Nov 2008 19:25:13
statistics Francesco Pozzi 09 Nov 2008 19:25:13
statistics Cristina McIntire 10 Nov 2008 10:36:54
probability Cristina McIntire 10 Nov 2008 10:37:03
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com