View source: R/deming_regression.R
| deming_regression | R Documentation |
Performs Deming regression to assess agreement between two measurement methods. Unlike ordinary least squares, Deming regression accounts for measurement error in both variables, making it appropriate for method comparison studies where neither method is a perfect reference.
deming_regression(
x,
y = NULL,
data = NULL,
error_ratio = 1,
conf_level = 0.95,
ci_method = c("jackknife", "bootstrap"),
boot_n = 1999,
weighted = FALSE,
na_action = c("omit", "fail")
)
x |
Numeric vector of measurements from method 1 (reference method),
or a formula of the form |
y |
Numeric vector of measurements from method 2 (test method).
Ignored if |
data |
Optional data frame containing the variables specified in
|
error_ratio |
Ratio of error variances (Var(error_y) / Var(error_x)). Default is 1 (orthogonal regression, assuming equal error variances). Can be estimated from replicate measurements or set based on prior knowledge of method precision. |
conf_level |
Confidence level for intervals (default: 0.95). |
ci_method |
Method for calculating confidence intervals:
|
boot_n |
Number of bootstrap resamples when |
weighted |
Logical; if |
na_action |
How to handle missing values: |
Deming regression (also known as errors-in-variables regression or Model II regression) is designed for situations where both X and Y are measured with error. This is the typical case in method comparison studies where both the reference and test methods have measurement uncertainty.
The error ratio (lambda, \lambda) represents the ratio of error variances:
\lambda = \frac{Var(\epsilon_y)}{Var(\epsilon_x)}
When \lambda = 1 (default), this is equivalent to orthogonal regression, which
minimizes perpendicular distances to the regression line. When \lambda != 1, the
regression minimizes a weighted combination of horizontal and vertical
distances.
Choosing the error ratio:
If both methods have similar precision: use \lambda = 1
If precision differs: estimate from replicate measurements as
\lambda = CV_y² / CV_x² (squared coefficient of variation ratio)
If one method is much more precise: consider ordinary least squares
An object of class c("deming_regression", "valytics_comparison", "valytics_result"),
which is a list containing:
List with original data and metadata:
x, y: Numeric vectors (after NA handling)
n: Number of paired observations
n_excluded: Number of pairs excluded due to NAs
var_names: Named character vector with variable names
List with statistical results:
intercept: Intercept point estimate
slope: Slope point estimate
intercept_ci: Named numeric vector with lower and upper CI
slope_ci: Named numeric vector with lower and upper CI
intercept_se: Standard error of intercept
slope_se: Standard error of slope
residuals: Perpendicular residuals
fitted_x: Fitted x values
fitted_y: Fitted y values
List with analysis settings:
error_ratio: Error variance ratio used
conf_level: Confidence level used
ci_method: CI method used
boot_n: Number of bootstrap samples (if applicable)
weighted: Whether weighted regression was used
The matched function call.
Slope = 1: No proportional difference between methods
Slope != 1: Proportional (multiplicative) difference exists
Intercept = 0: No constant difference between methods
Intercept != 0: Constant (additive) difference exists
Use the confidence intervals to test these hypotheses: if 1 is within the slope CI and 0 is within the intercept CI, the methods are considered equivalent.
Ordinary Least Squares (OLS): Assumes X is measured without error. Biases slope toward zero when both variables have error.
Passing-Bablok: Non-parametric, robust to outliers, but assumes linear relationship and no ties.
Deming: Parametric, accounts for error in both variables, allows specification of error ratio.
Linear relationship between X and Y
Measurement errors are normally distributed
Error variances are constant (homoscedastic) or known ratio
Errors in X and Y are independent
Deming WE (1943). Statistical Adjustment of Data. Wiley.
Linnet K (1990). Estimation of the linear relationship between the measurements of two methods with proportional errors. Statistics in Medicine, 9(12):1463-1473. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1002/sim.4780091210")}
Linnet K (1993). Evaluation of regression procedures for methods comparison studies. Clinical Chemistry, 39(3):424-432. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/clinchem/39.3.424")}
Cornbleet PJ, Gochman N (1979). Incorrect least-squares regression coefficients in method-comparison analysis. Clinical Chemistry, 25(3):432-438.
plot.deming_regression() for visualization,
summary.deming_regression() for detailed summary,
pb_regression() for non-parametric alternative,
ba_analysis() for Bland-Altman analysis
# Simulated method comparison data
set.seed(42)
true_values <- rnorm(50, mean = 100, sd = 20)
method_a <- true_values + rnorm(50, sd = 5)
method_b <- 1.05 * true_values + 3 + rnorm(50, sd = 5)
# Basic analysis (orthogonal regression, lambda = 1)
dm <- deming_regression(method_a, method_b)
dm
# Using formula interface with data frame
df <- data.frame(reference = method_a, test = method_b)
dm <- deming_regression(reference ~ test, data = df)
# With known error ratio (e.g., test method has 2x variance)
dm <- deming_regression(method_a, method_b, error_ratio = 2)
# With bootstrap confidence intervals
dm_boot <- deming_regression(method_a, method_b, ci_method = "bootstrap")
# Using package example data
data(glucose_methods)
dm <- deming_regression(reference ~ poc_meter, data = glucose_methods)
summary(dm)
plot(dm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.