File Exchange

## Linear Deming Regression

version 1.2.0.0 (7.6 KB) by
deming perfoms a linear Deming regression. Useful when errors are present in both x and y variables.

Updated 29 Sep 2014

[ b sigma2_x x_est y_est stats] = deming(x,y,lambda,alpha)
deming() performs a linear Deming regression to find the linear coefficients:
y = b(1) + b(2)*x
under the assumptions that x and y *both* contain measurement error with measurement error variance related as lambda = sigma2_y/sigma2_x (sigma2_x and sigma2_y is the measurement error variance of the x and y variables, respectively).
Computations are performed as described by Anders Christian Jenson in a May 2007 description of the Deming regression function for MethComp (web: http://staff.pubhealth.ku.dk/~bxc/MethComp/Deming.pdf), which includes a nice derivation of the slope, intercept, variance, and (x,y) estimates.

Inputs:
x - [Nx1] Measured data w/ error
y - [Nx1] Measured data w/ error
lambda - [1x1] [OPTIONAL] Relationship between measurement error expressed as ratio: sigma2_y / sigma2_x (default = 1)
alpha - [1x1] [OPTIONAL] Confidence level (default = 0.05)

Outputs:
b - [2x1] Intercept (1) and slope (2)
sigma2_x - [1x1] Error variance. Note: sigma2_y = lambda*sigma2_x
x_est - [Nx1] Estimated x values
y_est - [Nx1] Estimated y values
stats - [STR] Additional statistical information
.s_e - Standard error of regression estimate
.s_b - Jacknife estimate of the standard error of the slope and intercept
.t_c - *Critical t-value used for confidence intervals
.b_ci - *Confidence interval for slope and intercept

*stats.b_ci and stats.t_c are only available if the statistics package is installed and/or the tinv function is available.

Example is available by typing "help deming" at the command line.

### Cite As

James Hall (2021). Linear Deming Regression (https://www.mathworks.com/matlabcentral/fileexchange/33484-linear-deming-regression), MATLAB Central File Exchange. Retrieved .

Ram

Hello!

Do you have any insights or resources for calculating prediction interval (not confidence intervals) for estimated future y values in deming regression? If you do, please let me know. I am trying to build a predictive model with prediction bound and any assistance would be extremely helpful.

Thank you

Ram Siwakoti

Geo T

I suggest replacing from line 135:

s_xx = cov(x);
s_xy = cov(x,y);
s_yy = cov(y);

Geo T

Hi. I have called the Deming function with the following code:

function DemingTest

# data0: {8,5}, {16,14}, {15,10}
# data1: {{1,7.5}, {2,11}, {2000, 1000}, {-1, 2}, {100,900}};
X = [1; 2; 2000; -1; 100];
Y = [7.5; 11; 1000; 2; 900];

[ b sigma2_x x_est y_est stats] = deming(X, Y);

intercept = b(1);
slope = b(2);

disp("intercept="), disp(intercept), disp(", slope="), disp(slope);

endfunction

The error I get is: error:
deming: A(I): index out of bounds; value 2 out of bound 1
error: called from
deming at line 135 column 14
DemingTest at line 32 column 33

Thanks,
Georgiana

Nice script.
In my case, the data is nonlinear, can we extend the solution to find Orthogonal nonlinear regression ?

vira bondar

the code is nice, but how to proceed if the errors for each point of the data set are different, so that we have to enter lambda not as scalar, but as vector

arnold

can this be used with any model or just with lines?

Jack

I have a quick question. The structure of b is b(1)=intercept, and b(2)=slope. However, it is not clear to me the structure of .s_b. Is it .s_b(1)=standard error of intercept, .s_b(2)=standard error of slope or is it the the other way around. you have a comment next to it and it is written the other way around. Thanks for the help, the code is very nice!

Hilda Huang

very nice! I have a quick question: is it possible to add in some functions to provide the option of forcing the intercept to zero?

Ian

... (meant to say "off by a factor of approximately sqrt(n).")

Ian

This is a nice script, but there appear to be a couple bugs regarding the calculation of confidence intervals.

First, a minor typo: on line 122,
if nargin < 5
should be
if nargin < 4

More significantly, on line 167,
stats.s_b = std(b_sub,[],2);
should be
stats.s_b = std(b_sub,[],2)*(n-1)/sqrt(n);

Without the latter bug fix, the confidence intervals that deming.m computes are off by a factor of sqrt(n).

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