# Matlab shell-scripts for linear regression analysis

## Model I regressions

- lsqfity –
**Standard**Model I linear regression- [Y-on-X regression]
- Sometimes referred to as ordinary least squares (OLS).
- Fit line by minimizing y-residuals only
- All data points are given equal weight
- Use whenever X is controlled and Y is measured

- lsqfitx –
**Alternate**or**Reversed**Model I regression- [X-on-Y regression]
- Fit line by minimizing x-residuals only
- All data points are given equal weight

- lsqfityw –
**Weighted**Model I regression- [wY-on-X regression]
- Fit line by minimizing y-residuals only
- Data points are given varying weight
- Use whenever X is controlled and Y is measured with varying uncertainty
- Please note that:
- This m-file gives the correct results for all parameters (See table 6.2 in Bevington and Robinson, 2003); but,
- the uncertainties in the slope and intercept are much smaller than the same uncertainties calculated by lsqfity.m or lsqfitx.m (see the results table).
- Also note that if the values for the uncertainties in the y-data (sY) are constant, then the slope and intercept will be the same as that calculated with lsqfity.m, but the uncertainties in these parameters (sm & sb) will be different.

- lsqfityz –
**Weighted**Model I regression –Jan 2000*revised*- [zY-on-X regression]
- This is the same regression as lsqfityw.m,
**except that:**- York’s (1966) equations for the uncertainties in weighted slope and intercept are used.
- The revised uncertainties are more in line with those from lsqfity.m.

Model II regressions

- lsqfitma –
**Pearson’s Major Axis**- aka: first principal component
- [Correlation of X & Y]
- Line is fit by minimizing BOTH x- and y-residuals simultaneously
- All data are given equal weight
- Use when units and range of X and Y are the same or very similar

- lsqfitgm –
**Geometric Mean regression**- aka:
*reduced*major axis or*standard*major axis - [Correlation of X & Y]
- Slope of line is the geometric mean of the two slopes determined by regressing Y-on-X and X-on-Y
- All data are given equal weight
- Use when units or range of X and Y are different
- Please note that:
- This algorithm uses
*both*lsqfity.m and lsqfitx.m for determining the slope. - The uncertainties in the slope and intercept are estimated by analogy with the symmetrical uncertainty limits for a model I regression following the treatment by Ricker (1973).

- This algorithm uses

- aka:
- lsqbisec –
**Least Squares Bisector**- [Regression/correlation of X & Y]
- Slope of line is determined by bisecting the minor angle between the two model I regressions:

Y-on-X and X-on-Y - All data are given equal weight
- Use when units or range of X and Y are different
- Please note that:
- This algorithm uses
*both*lsqfity.m and lsqfitx.m for determining the slope. - The uncertainties in the slope and intercept are estimated by analogy with the symmetrical uncertainty limits for a model I regression following the treatment by Ricker (1973).

- This algorithm uses

- lsqcubic –
**Least-Squares-Cubic**- [Regression/correlation of wX & wY.]
- Line is fit by minimizing both x- and y-residuals simultaneously for WEIGHTED data points.
- Each data point can be given its own weight either as the inverse-square of the actual measurement precision or as the inverse-square of the product of the relative measurement precision for the method times concentration.
- Use when the measurement error of X and/or Y varies.
- Please note that:
- This algorithm uses lsqfitma.m for the first estimate of the slope.
- Iteration proceeds until the change in the slope is less than the user defined limit.

**Download a text version of this page.**