File Exchange

image thumbnail

Linear Regression with Errors in X and Y

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

29 Downloads

Updated 03 Feb 2010

View License

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 http://blog.nutaksas.com

Comments and Ratings (14)

Roman Ackley

Jeff Lapierre

Chenlu Liu

Shea

Shea (view profile)

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

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

Thanks

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

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?

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]

Paul Behrens

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

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor