View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Linear Regression with Errors in X and Y

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

5.0 | 3 ratings Rate this file 23 Downloads (last 30 days) File Size: 4.66 KB File ID: #26586 Version: 1.0
image thumbnail

Linear Regression with Errors in X and Y


Travis Wiens (view profile)


Calculates slope and intercept for linear regression of data with errors in X and Y.

| Watch this File

File Information

Calculates slope and intercept for linear regression of data with errors in X and Y. The errors can be specified as varying point to point, as can the correlation of the errors in X and Y.

The uncertainty in the slope and intercept are also estimated.

This follows the method in D. York, N. Evensen, M. Martinez, J. Delgado "Unified equations for the slope, intercept, and standard errors of the best straight line" Am. J. Phys. 72 (3) March 2004.

The package includes an example and a Monte Carlo simulation verifying the estimated uncertainties.

For more info, visit

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
23 Nov 2015 Maayan Yehudai

Hi Travis,
I was wondering if this code provides with an MSWD value for the isochron linear fit.


Comment only
11 Nov 2014 Juan

Juan (view profile)

Hi Travis,
It looks like code is supposed to do exactly what I am after, unfortunately I am having problems with your York_fit.m code:

at 40 ==> tmp=Y/[X; ones(1,N)]; shouldn't it be tmp=[Y/X; ones(1,N)]; ?

but even if I change this I am still encountering more errors:

??? Error using ==> times
Matrix dimensions must agree.

Error in ==> york_fit at 58

Comment only
08 Oct 2014 Felix

Felix (view profile)

I really like the code but is it possible to force the linear regression to go through the origin, i.e. a=0?

Comment only
22 Sep 2014 Travis Wiens

Travis Wiens (view profile)

Rainer Boegle: This method is only for a single input.

Comment only
20 Sep 2014 Rainer Boegle

Can I use multiple regression and
can I omit the offset in the model?
E.g. Y is explained by two betas corresponding with two different x (of same type of measurement, i.e. same error), but no offset is fitted?

Y = X*beta + error
where X = [x1; x2]

Comment only
07 Jun 2013 Antoni J. Canós  
20 Aug 2011 Stephan Koehler  
04 Feb 2010 Paul Behrens  

Contact us