# Deming Linear Regression [wbburgin]

Updated
Deming regression is a type of linear regression used to model the relationship between two variables when there is variability in both variables. Deming regression provides a solution by simultaneously accounting for the variability in both the independent and dependent variables, resulting in a more accurate estimation of the underlying relationship. In the hard-science fields, where measurements are critically important to judging the conclusions drawn from data, Deming regression can be used to account for measurement error.

Tradingview's default linear regression indicator (the ta.linreg() function) uses least squares linear regression, which is similar but different than Deming regression. In least squares regression, the regression function minimizes the sum of the squared vertical distances between the data points and the fitted line. This method assumes that the errors or variability are only present in the y-values (dependent variable), and that the x-values (independent variable) are measured without error.

In time series data used in trading, Deming regression can be more accurate than least squares regression because the ratio of the variances of the x and y variables is large. X is the bar index, which is an incrementally-increasing function that has little variance, while Y is the price data, which has extremely high variance when compared to the bar index. In such situations, least squares regression can be heavily influenced by outliers or extreme points in the data, whereas Deming regression is more resistant to such influence.

Additionally, if your x-axis uses variable widths - such as renko blocks or other types of non-linear widths - Deming regression might be more effective than least-squares linear regression because it accounts for the variability in your x-values as well. Additionally, if you are creating a machine-learning model that uses linear regression to filter or extrapolate data, this regression method may be more accurate than least squares.

In contrast to least squares regression, Deming regression takes into account the variability or errors in both the x- and y-values. It minimizes the sum of the squared perpendicular distances between the data points and the fitted line, accounting for both the x- and y-variability. This makes Deming regression more robust in both variables than least squares regression.
Release Notes:

Premium strategies, indicators, and algorithms: www.patreon.com/wbburgin/membership

Use my strategies on CryptoRobotics: cryptorobotics.co/?trade=f23b09

Backtesting of certain algorithms (for fun): tinyurl.com/yc7jwj8h
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer