3.0

3.0 | 8 ratings Rate this file 8 Downloads (last 30 days) File Size: 1013 Bytes File ID: #6716

Orthogonal Linear Regression

by Per Sundqvist

 

11 Jan 2005 (Updated 13 Jan 2005)

Fits a line y=p0+p1*y to a dataset (xdata,ydata) in an orthogonal way.

| Watch this File

File Information
Description

% Orthogonal linear least square fit of xdata and ydata vectors
% p=linortfit(xdata,ydata) gives the the coefficient-vector p that
% corresponds to the linear expression: y=p(1)+p(2)*x, where p
% is minimized with respect to the objective function
% sum((p(1)+p(2)*xdata-ydata).^2/(1+p(2)^2)).
%
% Example:
%
% %prepare some data
% xdata=0:0.1:10;
% ydata=2+7*xdata+6*randn(size(xdata));
% %orthogonal linear fit
% p=linortfit(xdata,ydata)
% yy=p(1)+p(2)*xdata;
% %compare with normal linear regression
% p0=polyfit(xdata,ydata,1);
% yy0=polyval(p0,xdata);
% %plot to compare data with linear fits
% plot(xdata,ydata,'.',xdata,yy,xdata,yy0,':');

Acknowledgements
This submission has inspired the following:
Orthogonal Linear Regression
MATLAB release MATLAB 6.5.1 (R13SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (13)
14 Jan 2005 hla myint

excellent

14 Jan 2005 min naing

Excellent

14 Jan 2005 Jos jnvdg@arcor.de

Another approach, orthogonal linear fit using a SVD approximation:

M = [mean(xdata) mean(ydata)] ;
[U,S,V]=svd( [(xdata - mean(xdata), ydata - mean(ydata)] );
N=(-1/V(end,end)) * V(:,end); % scaling
P = [N(1) - M*N] ; % Slope and Intercept

15 Jan 2005 Per Sundqvist

Ok, what dou you mean by approximation?

23 Aug 2005 Rolf Schulte

Total least squares is a linear problem (see contribution with SVD solution). Using a non-linear optimiser (fminsearch) leads to unnecessary problems (getting stuck in local minima; inefficient; etc).

24 Aug 2005 Per Sundqvist

Derivatives of sum((p(1)+p(2)*xdata-ydata).^2/(1+p(2)^2)) w.r.t p gives NOT a linear system to solve! It is easy to proof. Therefore you MUST use fminsearch. I.e., there is difference between linear regression and orthogonal fitting of a line to data points

06 Jan 2006 John D'Errico

Clearly there is a difference between linear regression and orthogonal regression, but the ORTHOGONAL regression is indeed very solvable with either svd or eig. Fminsearch is not at all necessary, and is in fact a very inefficient way to solve this problem. Its not even that accurate.

19 Apr 2006 yin gang  
19 Apr 2006 yin gang  
14 Oct 2006 John Bennett

Saved me some thinking time!

08 Aug 2007 Ozgur Erdogan

So practical, thank you.

22 Feb 2008 D. G.

This function is numerically and mathematically VERY poor. Use #16800 instead.
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=16800

11 Oct 2010 Toan Cao

hi, everybody
I have a set of data points in 2D: (x,y)
I would like to fit them into a straight line that is described by formula: x.cosθ +y.sinθ= ρ, in stead of: y=ax+b
How can i find two parameters : θ, ρ
Looking forward to your reply!
Thank you very much !

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
approximation Per Sundqvist 22 Oct 2008 07:39:31
interpolation Per Sundqvist 22 Oct 2008 07:39:31
linear regression Per Sundqvist 22 Oct 2008 07:39:31
interpolation orthogonal Per Sundqvist 22 Oct 2008 07:39:31
least squares fit Per Sundqvist 22 Oct 2008 07:39:31

Contact us at files@mathworks.com