Code covered by the BSD License

### Highlights from Linear Regression with Errors in X and Y

5.0
5.0 | 3 ratings Rate this file 78 Downloads (last 30 days) File Size: 4.66 KB File ID: #26586

# 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.

File Information
Description

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

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

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

### Rainer Boegle (view profile)

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

### Antoni J. Canós (view profile)

20 Aug 2011 Stephan Koehler

### Stephan Koehler (view profile)

04 Feb 2010 Paul Behrens

Contact us