---
title: "Deming Regression: Do the Blood Pressure Machine and the Stethoscope Agree?"
description: "Deming (errors-in-variables) regression in R, by hand and with the deming package, on 4,212 US adults whose blood pressure was measured both by a physician with a stethoscope and by a machine (NHANES 2017-2018): attenuation, why two ordinary regressions contradict each other, the error variance ratio from repeated readings, jackknife standard errors, testing slope 1 and intercept 0, sensitivity to the ratio, Bland-Altman limits of agreement and APA reporting."
author: ""
---
```{r options, echo=FALSE, warning=FALSE, message=FALSE}
directory<-if (rstudioapi::isAvailable()) paste0(dirname(rstudioapi::getActiveDocumentContext()$path),"/") else ""
source(paste0(directory, "R/code_options.R"))
# no knitr cache: the page downloads its data from the CDC each time it runs (in a few seconds),
# and a cached chunk would quietly keep an old download
knitr::opts_chunk$set(fig.height = 4.5, cache = FALSE)
```
## The question: can the machine replace the physician?
For decades the US health survey NHANES measured blood pressure with a mercury column and a stethoscope. Mercury is poisonous, so the survey wanted to change to an automatic machine. But if the machine reads differently, every trend in the nation's blood pressure would jump on the day of the change. So in 2017–2018 the survey did both: **each person was measured by a physician with the stethoscope and by a technician with the machine**, in random order (Ostchega et al., 2021).
This page asks the question of every comparison of two instruments:
1. Does the machine read **higher or lower by a constant amount**? (constant bias)
2. Does it read higher or lower **in proportion**, for example more wrong for high blood pressures? (proportional bias)
The natural idea is a regression of the machine on the stethoscope, and a test of whether the slope is 1 and the intercept 0. It gives a **wrong answer**. Ordinary regression assumes that $x$ is measured without error, and here both instruments err. **Deming regression** is the regression for two variables that are both measured with error.
```{r packages}
library(foreign) # read.xport(): the SAS transport files of the CDC (comes with R)
library(ggplot2)
library(deming) # deming(): the packaged version
line_colours <- c("equal readings" = "grey40", "OLS: machine on stethoscope" = "#eb6834",
"OLS: stethoscope on machine" = "#eda100", "Deming" = "#2a78d6")
# number formats for the text
f1 <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2 <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
f3 <- function(x) formatC(x, format = "f", digits = 3, big.mark = ",")
# no leading zero
nz <- function(x, d = 2) sub("^(-?)0", "\\1", formatC(x, format = "f", digits = d))
pval <- function(p) if (p < .001) "< .001" else paste("=", nz(p, 3))
num <- function(x) trimws(format(x, big.mark = ","))
```
---
## 1. The data
The CDC publishes the files free and with no login (National Center for Health Statistics, 2021): `BPX_J` (physician, mercury, stethoscope), `BPXO_J` (technician, automatic "oscillometric" machine) and `DEMO_J` (age). Each instrument took **three readings**, one after the other, which will be important later.
```{r download}
nhanes <- function(file) {
path <- tempfile(fileext = ".xpt")
download.file(
paste0("https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2017/DataFiles/", file, ".xpt"),
path,
mode = "wb",
quiet = TRUE
)
read.xport(path)
}
steth_names <- paste0("BPXSY", 1:3) # systolic, stethoscope, readings 1 to 3 (mmHg)
machine_names <- paste0("BPXOSY", 1:3) # systolic, machine, readings 1 to 3
bp <- merge(nhanes("BPX_J")[, c("SEQN", steth_names)], nhanes("BPXO_J")[, c("SEQN", machine_names)])
bp <- merge(bp, nhanes("DEMO_J")[, c("SEQN", "RIDAGEYR")])
bp <- subset(bp, RIDAGEYR >= 18)
bp <- bp[complete.cases(bp), ] # all six readings
nrow(bp)
bp$steth <- rowMeans(bp[, steth_names]) # the mean of three readings
bp$machine <- rowMeans(bp[, machine_names])
summary(bp[, c("steth", "machine")])
```
We keep the adults with all six readings, `r num(nrow(bp))` people, and the **systolic** pressure (the upper number), in millimeters of mercury (mmHg). The machine reads `r f1(abs(mean(bp$machine - bp$steth)))` mmHg lower on average.
---
## 2. Look at the data, and get two answers that contradict each other
```{r ols_both}
x <- bp$steth
y <- bp$machine
n <- length(x)
ols <- lm(y ~ x) # machine predicted from stethoscope
reverse <- lm(x ~ y) # stethoscope predicted from machine
slopes <- c(machine_on_steth = coef(ols)[["x"]], steth_on_machine = coef(reverse)[["y"]])
slopes
# the second line, drawn in the same axes (machine as a function of stethoscope)
rev_line <- c(intercept = -coef(reverse)[[1]] / coef(reverse)[[2]], slope = 1 / coef(reverse)[[2]])
rev_line
```
```{r look, fig.height = 6.5}
dem_slope <- function(x, y, lambda) { # the formula is explained in section 3
sxx <- var(x); syy <- var(y); sxy <- cov(x, y)
b1 <- (syy - lambda * sxx + sqrt((syy - lambda * sxx)^2 + 4 * lambda * sxy^2)) / (2 * sxy)
c(b0 = mean(y) - b1 * mean(x), b1 = b1)
}
lines_ols <- data.frame(
line = factor(c("equal readings", "OLS: machine on stethoscope", "OLS: stethoscope on machine"),
levels = names(line_colours)),
intercept = c(0, coef(ols)[[1]], rev_line[["intercept"]]),
slope = c(1, coef(ols)[[2]], rev_line[["slope"]]))
ggplot(bp, aes(steth, machine)) +
geom_point(alpha = 0.12, size = 1, colour = "grey30") +
geom_abline(
data = lines_ols,
aes(intercept = intercept, slope = slope, colour = line),
linewidth = 1
) +
scale_colour_manual(values = line_colours, name = NULL) +
coord_fixed(xlim = c(75, 225), ylim = c(75, 225)) +
labs(
title = "Systolic blood pressure, two ways",
x = "stethoscope (mmHg)",
y = "machine (mmHg)"
) +
theme_bw() +
theme(legend.position = "bottom", legend.direction = "vertical")
```
- **Regress the machine on the stethoscope:** the slope is `r f2(slopes[[1]])`. A person at 180 mmHg would get only `r f1(coef(ols)[[1]] + coef(ols)[[2]] * 180)` from the machine. Conclusion: the machine **underestimates** high blood pressure.
- **Regress the stethoscope on the machine:** the slope is `r f2(slopes[[2]])`, also below 1. Turned around, one mmHg of the stethoscope is `r f2(rev_line[["slope"]])` mmHg of the machine. Conclusion: the machine **overestimates** high blood pressure.
The same people, the same numbers, and opposite conclusions. Neither is right. Both slopes are pulled below 1 by measurement error in the variable on the right-hand side.
---
## 3. The model step by step, with formulas
### Step 1: two noisy readings of two hidden values
Each person has a true value that nobody sees. The two instruments read it with errors:
$$x_i = \xi_i + \delta_i, \qquad y_i = \eta_i + \varepsilon_i, \qquad \eta_i = \beta_0 + \beta_1 \xi_i$$
$\xi_i$ (xi) is what the stethoscope would show without error, $\eta_i$ (eta) what the machine would. The errors $\delta_i$ and $\varepsilon_i$ are independent of everything, with variances $\sigma_\delta^2$ and $\sigma_\varepsilon^2$. The instruments agree perfectly, apart from the errors, if $\beta_0 = 0$ and $\beta_1 = 1$.
### Step 2: why ordinary regression gives a slope that is too small
Ordinary regression uses $x$, not $\xi$. The covariance of $x$ with $y$ is not affected by the errors, because they are independent, but the **variance of $x$** is larger than that of $\xi$. So the OLS slope tends to
$$b_{OLS} \longrightarrow \beta_1 \cdot \frac{\sigma_\xi^2}{\sigma_\xi^2 + \sigma_\delta^2}$$
The fraction is the **reliability** of $x$. It is below 1, so the slope is too small: **attenuation**. More data do not help, because it is not a problem of sampling. And it has the same form as the [regression to the mean](EXAMPLE_SIMPLE_LINEAR_REGRESSION.Rmd) of Galton's heights.
### Step 3: which distance should be small?
OLS assumes that all the error is in $y$, so it minimizes the vertical distances. If both are wrong, a point should be allowed to move in both directions to reach the line, and the more precise variable should move less. Deming regression minimizes
$$\sum_i \left[ \frac{(x_i - \hat\xi_i)^2}{\sigma_\delta^2} + \frac{(y_i - \beta_0 - \beta_1 \hat\xi_i)^2}{\sigma_\varepsilon^2} \right]$$
over the line **and** over the hidden $\hat\xi_i$. Only the ratio of the two variances matters for the line:
$$\lambda = \frac{\sigma_\varepsilon^2}{\sigma_\delta^2} = \frac{\text{error variance of } y}{\text{error variance of } x}$$
### Step 4: the formula
With the sample variances $s_{xx}$, $s_{yy}$ and the covariance $s_{xy}$, the minimum has a closed form:
$$b_1 = \frac{s_{yy} - \lambda s_{xx} + \sqrt{(s_{yy} - \lambda s_{xx})^2 + 4 \lambda s_{xy}^2}}{2 s_{xy}}, \qquad b_0 = \bar y - b_1 \bar x$$
Three special cases show what $\lambda$ does:
| $\lambda$ | Means | The line becomes |
|---|---|---|
| $\lambda \to \infty$ | no error in $x$ | OLS of $y$ on $x$ |
| $\lambda = 1$ | equally large errors | **orthogonal** regression, perpendicular distances |
| $\lambda \to 0$ | no error in $y$ | OLS of $x$ on $y$, turned around |
```{r special_cases}
rbind(`lambda = 10000` = dem_slope(x, y, 10000),
`lambda = 1` = dem_slope(x, y, 1),
`lambda = 0.0001` = dem_slope(x, y, 0.0001))
```
So the two contradicting answers of section 2 are the two extremes, and the truth lies **between** them. Where, depends on $\lambda$.
### Step 5: $\lambda$ must come from somewhere else
The cloud of points alone cannot say which instrument is noisier: a wide cloud can come from either. We need outside information. The best source are **repeated readings** with each instrument: they differ only by error. For person $i$ with readings $x_{i1}, x_{i2}, x_{i3}$, the variance of the three around their own mean estimates the error variance, and we average it over the people:
$$\hat\sigma_\delta^2 = \frac{1}{n}\sum_i \text{var}(x_{i1}, x_{i2}, x_{i3})$$
This is why NHANES took three readings with each.
### Step 6: the standard error
There is no simple formula that is exact, so we use the **jackknife**: leave out one person at a time, compute the slope again, and see how much it moves. With $b_{(-i)}$ the slope without person $i$, the pseudo-values are $b_i^* = n\,b - (n - 1)\,b_{(-i)}$, and the standard error is their standard deviation divided by $\sqrt n$.
---
## 4. Fitting the model
### The error variances, from the repeated readings
```{r error_variances}
X <- as.matrix(bp[, steth_names])
Y <- as.matrix(bp[, machine_names])
var_steth <- mean(apply(X, 1, var)) # error variance of one reading
var_machine <- mean(apply(Y, 1, var))
lambda <- var_machine / var_steth
c(sd_steth = sqrt(var_steth), sd_machine = sqrt(var_machine), lambda = lambda)
```
One reading of the stethoscope has an error of about $\pm$ `r f1(sqrt(var_steth))` mmHg (one SD), one reading of the machine $\pm$ `r f1(sqrt(var_machine))`. So the machine is a little noisier, and $\lambda$ = `r f2(lambda)`. The variables $x$ and $y$ are means of three readings, so both error variances are divided by 3, and the ratio stays the same. If $x$ were the mean of three readings and $y$ a single one, we would have to multiply.
### The line by hand
```{r deming_by_hand}
b <- dem_slope(x, y, lambda)
b
# jackknife: the slope and the intercept without person i, for every i
leave_out <- t(sapply(seq_len(n), function(i) dem_slope(x[-i], y[-i], lambda)))
pseudo <- sweep(-(n - 1) * leave_out, 2, n * b, "+")
se <- apply(pseudo, 2, sd) / sqrt(n)
ci <- cbind(lower = b - qt(0.975, n - 2) * se, upper = b + qt(0.975, n - 2) * se)
cbind(estimate = b, SE = se, ci)
```
### The line with the package
`deming()` takes the standard deviations of the errors of each row. Ours are means of three readings, so the error variance of one reading is divided by 3. For the line, only the ratio of the two matters:
```{r deming_package}
fit <- deming(machine ~ steth, data = bp,
xstd = rep(sqrt(var_steth / 3), n), ystd = rep(sqrt(var_machine / 3), n))
fit
```
### Reading the output
```{r tests}
z_slope <- (b[["b1"]] - 1) / se[["b1"]]
z_intercept <- b[["b0"]] / se[["b0"]]
p_slope <- 2 * pnorm(-abs(z_slope))
p_intercept <- 2 * pnorm(-abs(z_intercept))
at_mean <- mean(y) - mean(x)
```
- **`Slope`** = `r f3(b[["b1"]])`, 95% CI [`r f3(ci["b1", 1])`, `r f3(ci["b1", 2])`]. The interesting value is **1**, and the question is whether the interval contains it. It does (*z* = `r f2(z_slope)`, *p* `r pval(p_slope)`): there is no clear sign of a proportional bias.
- **`Intercept`** = `r f2(b[["b0"]])`, 95% CI [`r f2(ci["b0", 1])`, `r f2(ci["b0", 2])`]. It is the difference at a blood pressure of 0, where nobody is, so it is very uncertain, and its test is not very useful.
- **The bias in the middle of the data** is the useful number: at the average blood pressure (`r f1(mean(x))`), the machine reads `r f1(abs(at_mean))` mmHg lower. At 180 mmHg, the line says `r f1(b[["b0"]] + b[["b1"]] * 180)`, a difference of `r f1(b[["b0"]] + b[["b1"]] * 180 - 180)`, where the first OLS line claimed `r f1(coef(ols)[[1]] + coef(ols)[[2]] * 180 - 180)`.
- **`Scale`** measures how far the points are from the line, in units of the errors we gave. It should be about 1 if those errors were the whole story. It is `r f1(fit$sigma)`. This is a warning, which section 6 follows.
```{r lines, fig.height = 6.5}
lines_all <- rbind(lines_ols, data.frame(line = "Deming", intercept = b[["b0"]], slope = b[["b1"]]))
ggplot(bp, aes(steth, machine)) +
geom_point(alpha = 0.1, size = 1, colour = "grey30") +
geom_abline(
data = lines_all,
aes(intercept = intercept, slope = slope, colour = line),
linewidth = 1
) +
scale_colour_manual(values = line_colours, name = NULL) +
coord_fixed(xlim = c(75, 225), ylim = c(75, 225)) +
labs(
title = "The Deming line lies between the two OLS lines",
x = "stethoscope (mmHg)",
y = "machine (mmHg)"
) +
theme_bw() +
theme(legend.position = "bottom", legend.direction = "vertical")
```
---
## 5. Two proofs that OLS is the one that is wrong
### With the data: make $x$ noisier on purpose
We have three readings. A single reading is noisier than the mean of three, so if attenuation is real, the OLS slope must **fall** when we use one reading only, although the two instruments are still the same:
```{r one_reading}
one_x <- bp$BPXSY1
one_y <- bp$BPXOSY1
proof <- rbind(
`mean of 3 readings` = c(OLS = coef(lm(y ~ x))[[2]], Deming = dem_slope(x, y, lambda)[["b1"]]),
`first reading only` = c(
OLS = coef(lm(one_y ~ one_x))[[2]],
Deming = dem_slope(one_x, one_y, lambda)[["b1"]]
)
)
round(proof, 3)
```
OLS falls from `r f3(proof[1, "OLS"])` to `r f3(proof[2, "OLS"])`. Deming stays at `r f3(proof[1, "Deming"])` and `r f3(proof[2, "Deming"])`.
### With a simulation: a known truth
2,000 studies of 300 people. The two instruments agree **perfectly** apart from their errors ($\beta_0 = 0$, $\beta_1 = 1$), with an error SD of 7 mmHg each:
```{r simulation}
set.seed(11)
sim <- t(replicate(2000, {
xi <- rnorm(300, mean(x), sd(x)) # the true blood pressures
xs <- xi + rnorm(300, 0, 7)
ys <- xi + rnorm(300, 0, 7)
c(
OLS = cov(xs, ys) / var(xs),
reversed = var(ys) / cov(xs, ys),
Deming = dem_slope(xs, ys, 1)[["b1"]]
)
}))
reliability <- var(x) / (var(x) + 49)
c(colMeans(sim), expected_OLS = reliability)
```
```{r simulation_chart}
sim_long <- data.frame(
slope = as.vector(sim),
method = factor(
rep(c("OLS: machine on stethoscope", "OLS: stethoscope on machine", "Deming"), each = 2000),
levels = names(line_colours)
)
)
ggplot(sim_long, aes(slope, colour = method, fill = method)) +
geom_density(alpha = 0.25, linewidth = 0.8) +
geom_vline(xintercept = 1, linetype = "dashed", colour = "grey40") +
scale_colour_manual(values = line_colours, name = NULL) +
scale_fill_manual(values = line_colours, name = NULL) +
labs(title = "2,000 simulated studies of two instruments that agree perfectly",
subtitle = "Dashed line: the true slope", x = "estimated slope", y = "density") +
theme_bw() + theme(legend.position = "bottom", legend.direction = "vertical")
```
OLS averages `r f2(mean(sim[, "OLS"]))`, which is the reliability, as step 2 promised. Deming averages `r f2(mean(sim[, "Deming"]))`. The narrowness of the OLS curve is worth a thought: it is a **precise** estimate of the wrong number.
---
## 6. The weak point: is $\lambda$ right?
Everything depends on $\lambda$, and the `Scale` of `r f1(fit$sigma)` warned us. If the error variances of the repeated readings were the whole story, the difference between the two instruments would vary by their sum:
```{r difference_variance}
difference <- y - x
expected <- var_steth / 3 + var_machine / 3 # both are means of three readings
c(observed_variance = var(difference), expected_from_repeated_readings = expected,
ratio = var(difference) / expected)
```
The differences vary `r f1(var(difference) / expected)` times as much as the repeated readings say. The three readings of an instrument were taken **in a row, by the same examiner, with the same cuff**. They share everything that changes from one occasion to the next: the mood, the position, the cuff, how the physician hears. These errors are in each instrument's mean, and the repeats cannot show them. So the repeated readings underestimate the errors, and we cannot know whether they underestimate both **in the same proportion**. What we can do is to ask how much it matters:
```{r sensitivity}
ratios <- c(0.25, 0.5, 1, lambda, 2, 4)
sens <- t(sapply(ratios, function(l) dem_slope(x, y, l)))
data.frame(lambda = round(ratios, 2), intercept = round(sens[, 1], 2), slope = round(sens[, 2], 3))
```
```{r sensitivity_chart}
grid <- exp(seq(log(1/20), log(20), length.out = 200))
path <- data.frame(lambda = grid, slope = sapply(grid, function(l) dem_slope(x, y, l)[["b1"]]))
ggplot(path, aes(lambda, slope)) +
annotate("rect", xmin = 0.5, xmax = 2, ymin = -Inf, ymax = Inf, fill = "grey85", alpha = 0.6) +
geom_hline(yintercept = 1, linetype = "dashed", colour = "grey40") +
geom_hline(
yintercept = c(slopes[[1]], rev_line[["slope"]]),
colour = c("#eb6834", "#eda100"),
linewidth = 0.8
) +
geom_line(colour = "#2a78d6", linewidth = 1) +
geom_point(data = data.frame(lambda = lambda, slope = b[["b1"]]), size = 3, colour = "#2a78d6") +
scale_x_log10(breaks = c(0.1, 0.5, 1, 2, 10)) +
labs(
title = "The Deming slope for every possible λ",
subtitle = "Horizontal lines: the two OLS slopes. Grey band: one error variance up to twice the other",
x = "λ = error variance of the machine / error variance of the stethoscope (log scale)",
y = "slope"
) +
theme_bw()
```
As long as neither error variance is more than twice the other, the slope is between `r f2(dem_slope(x, y, 2)[["b1"]])` and `r f2(dem_slope(x, y, 0.5)[["b1"]])`, close to 1. The exact value, and whether it is "significantly" different from 1, does depend on $\lambda$: the confidence interval of section 4 takes it as known, and it is too narrow for that reason. The OLS slope of `r f2(slopes[[1]])` would be right only if the stethoscope made **no** errors at all, which nobody believes.
The lesson for the design of a comparison: repeat the measurement on **different occasions**, by different examiners, so that the repeats contain all the errors.
---
## 7. Agreement is more than a line
Deming regression compares the instruments **on average**. It says nothing about one person. For that, the usual tool is the plot of Bland and Altman (1986): the difference against the mean of the two.
```{r bland_altman}
middle <- (x + y) / 2
limits <- mean(difference) + c(-1.96, 1.96) * sd(difference)
trend <- lm(difference ~ middle)
c(bias = mean(difference), lower = limits[1], upper = limits[2])
round(coef(summary(trend)), 3)
```
```{r bland_altman_chart}
ggplot(data.frame(middle, difference), aes(middle, difference)) +
geom_point(alpha = 0.12, size = 1, colour = "grey30") +
geom_hline(yintercept = 0, colour = "grey60") +
geom_hline(yintercept = mean(difference), colour = "#2a78d6", linewidth = 1) +
geom_hline(yintercept = limits, colour = "#eb6834", linetype = "dashed", linewidth = 0.8) +
labs(
title = "Machine minus stethoscope, against the mean of the two",
subtitle = "Blue: mean difference. Orange: limits of agreement, which hold 95% of the differences",
x = "mean of the two (mmHg)",
y = "difference (mmHg)"
) +
theme_bw()
crosses <- mean((x >= 130) != (y >= 130))
```
- The mean difference is `r f1(mean(difference))` mmHg. The differences do not depend clearly on the level (slope `r f3(coef(trend)[[2]])`, *p* `r pval(coef(summary(trend))[2, 4])`), which agrees with a Deming slope near 1.
- The **limits of agreement** run from `r f1(limits[1])` to `r f1(limits[2])` mmHg. For one person the two methods can differ a lot: for `r f1(100 * crosses)`% of the adults, one method says 130 mmHg or more and the other says less. 130 is the line that current US guidelines use for high blood pressure.
So for averages of thousands of people the machine can replace the stethoscope, with a correction of about one mmHg. For one visit of one patient neither instrument is precise. Both statements are needed, and they answer different questions.
---
## 8. Things to keep in mind
- **Use Deming when neither variable is the outcome** and both measure the same thing with error. If you want to **predict** one reading from the other, OLS is right: the best prediction of $y$ from a noisy $x$ does regress towards the mean.
- **$\lambda$ is an assumption** unless it comes from repeats that contain all the sources of error. Report it, and show how the slope changes with it. A wrong $\lambda$ also makes the tests wrong (Linnet, 1998).
- **Errors that grow with the level.** Deming regression assumes the same error variance everywhere. Here the repeats of both instruments vary more at higher pressures. The **weighted** version lets the error SD of each instrument grow in proportion to the level, that is, it assumes a constant coefficient of variation (Linnet, 1990). The argument `stdpat` gives the pattern: a constant and a multiplier for $x$, then for $y$:
```{r weighted}
level_bands <- cut(middle, quantile(middle, 0:4 / 4), include.lowest = TRUE)
spread_by_level <- data.frame(stethoscope = tapply(apply(X, 1, var), level_bands, mean),
machine = tapply(apply(Y, 1, var), level_bands, mean))
round(sqrt(spread_by_level), 1) # error SD of one reading, by quarter of blood pressure
weighted_fit <- deming(
machine ~ steth,
data = bp,
stdpat = c(0, sqrt(var_steth / 3) / mean(x), 0, sqrt(var_machine / 3) / mean(y))
)
coef(weighted_fit)
```
- The weighted slope is `r f3(coef(weighted_fit)[[2]])`, against `r f3(b[["b1"]])`. The change, `r f3(abs(coef(weighted_fit)[[2]] - b[["b1"]]))`, is about `r f1(abs(coef(weighted_fit)[[2]] - b[["b1"]]) / se[["b1"]])` times the standard error: the choice of the error model is part of the uncertainty, and the confidence interval does not contain it.
- **Outliers** pull the Deming line as they pull OLS. `deming::pbreg()` (Passing–Bablok) and `deming::thielsen()` are versions based on ranks.
- **Test the pair** (intercept, slope) against (0, 1) together if you need one test, or better, report the expected difference at values that matter, as we did for 180 mmHg.
- **With several predictors** measured with error, use a structural equation model with latent variables, or multiple indicators (see the factor models of [measurement invariance](EXAMPLE_MEASUREMENT_INVARIANCE.rmd)).
- **Survey weights.** We compared instruments within persons, and did not estimate the blood pressure of the US population, for which NHANES needs its weights.
---
## 9. Reporting the results in APA style
A report (APA 7th edition) needs the two instruments, the number of readings, where $\lambda$ came from, the slope and intercept with their uncertainty, and the agreement for individuals. The numbers come from the R objects:
```{r apa_numbers}
apa_table <- data.frame(
Method = c(
"OLS, machine on stethoscope", "OLS, stethoscope on machine (turned around)",
"Deming, λ from the repeated readings", "Deming, λ = 1"
),
Intercept = f2(c(coef(ols)[[1]], rev_line[[1]], b[["b0"]], dem_slope(x, y, 1)[["b0"]])),
Slope = f3(c(coef(ols)[[2]], rev_line[[2]], b[["b1"]], dem_slope(x, y, 1)[["b1"]])),
At180 = f1(
c(
coef(ols)[[1]] + 180 * coef(ols)[[2]],
rev_line[[1]] + 180 * rev_line[[2]],
b[["b0"]] + 180 * b[["b1"]],
sum(dem_slope(x, y, 1) * c(1, 180))
) -
180
)
)
```
**Method** (data analysis):
> We compared systolic blood pressure measured by a physician with a mercury sphygmomanometer and a stethoscope and by a technician with an oscillometric device, in random order, in `r num(nrow(bp))` adults of NHANES 2017–2018 with three readings by each method (Ostchega et al., 2021). The means of the three readings were compared with Deming regression, because both methods have measurement error. The ratio of the error variances (λ = `r f2(lambda)`, device to stethoscope) was estimated from the repeated readings; standard errors were obtained with the jackknife. Because the repeated readings were taken on one occasion, we also report the slope for λ between 0.5 and 2. Agreement for individuals is described by the limits of agreement (Bland & Altman, 1986). Analyses were conducted in R (Version `r paste(R.version$major, R.version$minor, sep = ".")`; R Core Team, `r R.version$year`) with the package deming (Therneau, 2024).
**Results:**
> The device read lower than the stethoscope on average (*M* = `r f1(mean(y))` against `r f1(mean(x))` mmHg), mean difference = `r f1(mean(difference))` mmHg, 95% limits of agreement [`r f1(limits[1])`, `r f1(limits[2])`]. The Deming slope was `r f3(b[["b1"]])`, 95% CI [`r f3(ci["b1", 1])`, `r f3(ci["b1", 2])`], and the intercept `r f2(b[["b0"]])` mmHg, 95% CI [`r f2(ci["b0", 1])`, `r f2(ci["b0", 2])`], which shows no clear proportional bias. For λ between 0.5 and 2 the slope was between `r f3(dem_slope(x, y, 2)[["b1"]])` and `r f3(dem_slope(x, y, 0.5)[["b1"]])`. Ordinary least squares, which ignores the error of the stethoscope, gave a slope of `r f3(coef(ols)[[2]])` (Table 1).
**Table 1**
*Oscillometric Device Against Stethoscope: Systolic Blood Pressure*
```{r apa_table, echo=FALSE}
knitr::kable(apa_table, col.names = c("Method", "Intercept", "Slope", "Difference at 180 mmHg"),
align = "lrrr", format = "pipe", row.names = FALSE)
```
*Note.* *N* = `r num(nrow(bp))`. Difference at 180 mmHg: the reading of the device that the line expects when the stethoscope reads 180, minus 180.
**Points to remember:**
- Say how many readings each value rests on, and when they were taken.
- Report λ, where it came from, and how sensitive the slope is to it.
- Test the slope against 1, not against 0, and do not report the correlation as agreement: *r* = `r nz(cor(x, y))` here, and it would be the same if the machine read twice as high.
- Give the limits of agreement for individuals.
---
## 10. Summary
| | |
|---|---|
| **When** | Two measurements of the same thing, both with error: instruments, laboratories, raters, self-report against measurement |
| **Why not OLS** | Error in $x$ flattens the slope (attenuation), and more data do not help |
| **The model** | $x = \xi + \delta$, $y = \beta_0 + \beta_1 \xi + \varepsilon$, with $\lambda = \sigma^2_\varepsilon / \sigma^2_\delta$ known |
| **How (R)** | `deming::deming(y ~ x, xstd = , ystd = )`; errors that grow with the level: `stdpat = c(0, cv_x, 0, cv_y)` |
| **λ** | From repeated measurements; $\lambda = 1$ is orthogonal regression |
| **Reading it** | Slope 1 and intercept 0 mean agreement on average; look at the expected difference at values that matter |
| **Standard errors** | Jackknife or bootstrap |
| **Also report** | Bland–Altman limits of agreement, for individuals |
| **Related pages** | [Simple linear regression](EXAMPLE_SIMPLE_LINEAR_REGRESSION.Rmd), [weighted least squares](EXAMPLE_WEIGHTED_LEAST_SQUARES.Rmd) |
---
## References
Bland, J. M., & Altman, D. G. (1986). Statistical methods for assessing agreement between two methods of clinical measurement. *The Lancet*, *327*(8476), 307–310. https://doi.org/10.1016/S0140-6736(86)90837-8
Linnet, K. (1990). Estimation of the linear relationship between the measurements of two methods with proportional errors. *Statistics in Medicine*, *9*(12), 1463–1473. https://doi.org/10.1002/sim.4780091210
Linnet, K. (1998). Performance of Deming regression analysis in case of misspecified analytical error ratio in method comparison studies. *Clinical Chemistry*, *44*(5), 1024–1031. https://doi.org/10.1093/clinchem/44.5.1024
National Center for Health Statistics. (2021). *National Health and Nutrition Examination Survey 2017–2018: Blood pressure, oscillometric measurements (BPXO_J)* [Data set]. https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2017/DataFiles/BPXO_J.htm
Ostchega, Y., Nwankwo, T., Chiappa, M., Graber, J., & Nguyen, D. T. (2021). *Comparing blood pressure values obtained by two different protocols: National Health and Nutrition Examination Survey, 2017–2018* (Vital and Health Statistics, Series 2, No. 187). National Center for Health Statistics. https://doi.org/10.15620/cdc:104185
Therneau, T. (2024). *deming: Deming, Theil-Sen, Passing-Bablock and total least squares regression* [R package]. https://CRAN.R-project.org/package=deming