File Exchange

## Linear Regression with Errors in X and Y

version 1.0.0.0 (4.66 KB) by
Calculates slope and intercept for linear regression of data with errors in X and Y.

Updated 03 Feb 2010

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.

### Cite As

Travis Wiens (2020). Linear Regression with Errors in X and Y (https://www.mathworks.com/matlabcentral/fileexchange/26586-linear-regression-with-errors-in-x-and-y), MATLAB Central File Exchange. Retrieved .

Marie-Noelle Amiot

Hi Travis,
Finally it was a simple problem of converting matrix data to vector data. It works fine ;-) ! Thanks for the code !

Marie-Noelle Amiot

I've got the same problem as Juan. Do you have a corrected version ?

Qing He

Hi Travis, thanks for this really awesome code, but I wonder how can I the correlation coefficient from the function?

Michael Darmanis

Roman Ackley

Anwar Mohiuddin

Jeff Lapierre

Chenlu Liu

Shea

Hi, similarly to Felix, I think the code is great and I'm wondering if it is possible to force the linear regression to go through the origin, i.e. a=0? Thank you

Maayan Yehudai

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

Thanks

Juan

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
Y_bar=sum(W.*Y)/sum(W);

Felix

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

Travis Wiens

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

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]

Antoni J. Canós

Stephan Koehler

Paul Behrens

##### MATLAB Release Compatibility
Created with R2007a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux