Computes Bland-Altman mean difference and limits of agreement (LoA) between two numeric measurement vectors, including t-based confidence intervals for the mean difference and for each LoA using 'C++' backend.
Note: Lin's concordance correlation coefficient (CCC) is a complementary, single-number summary of agreement (precision + accuracy). It is useful for quick screening or reporting an overall CI, but may miss systematic or magnitude-dependent bias; consider reporting CCC alongside Bland-Altman.
bland_altman(
group1,
group2,
two = 1.96,
mode = 1L,
conf_level = 0.95,
verbose = FALSE
)# S3 method for ba
print(x, digits = 3, ci_digits = 3, ...)
# S3 method for ba
plot(
x,
title = "Bland-Altman Plot",
subtitle = NULL,
point_alpha = 0.7,
point_size = 2.2,
line_size = 0.8,
shade_ci = TRUE,
shade_alpha = 0.08,
smoother = c("none", "loess", "lm"),
symmetrize_y = TRUE,
...
)
An object of class "ba" (list) with elements:
means, diffs: numeric vectors
groups: data.frame used after NA removal
based.on: integer, number of pairs used
lower.limit, mean.diffs, upper.limit
lines: named numeric vector (lower, mean, upper)
CI.lines: named numeric vector for CIs of those lines
two, critical.diff
Numeric vectors of equal length.
Positive scalar; the multiple of the standard deviation used to define the LoA (default 1.96 for nominal 95\ intervals always use \(t_{n-1,\,1-\alpha/2}\) regardless of this choice.
Integer; 1 uses group1 - group2, 2 uses group2 - group1.
Confidence level for CIs (default 0.95).
Logical; if TRUE, prints how many OpenMP threads are used.
A "ba" object.
Number of digits for estimates (default 3).
Number of digits for CI bounds (default 3).
Passed to ggplot2::theme() (ggplot path) or plot().
Plot title.
Optional subtitle. If NULL, shows n and LoA summary.
Point transparency.
Point size.
Line width for mean/LoA.
Logical; if TRUE, draw shaded CI bands instead of 6 dashed lines.
Transparency of CI bands.
One of "none", "loess", "lm" to visualize proportional bias.
Logical; if TRUE, y-axis centered at mean difference with symmetric limits.
Thiago de Paula Oliveira
Given paired measurements \((x_i, y_i)\), Bland-Altman analysis uses
\(d_i = x_i - y_i\) (or \(y_i - x_i\) if mode = 2) and
\(m_i = (x_i + y_i)/2\). The mean difference \(\bar d\) estimates bias.
The limits of agreement (LoA) are \(\bar d \pm z \cdot s_d\), where
\(s_d\) is the sample standard deviation of \(d_i\) and \(z\)
(argument two) is typically 1.96 for nominal 95% LoA.
Confidence intervals use Student's \(t\) distribution with \(n-1\) degrees of freedom, with
Mean-difference CI given by \(\bar d \pm t_{n-1,\,1-\alpha/2}\, s_d/\sqrt{n}\); and
LoA CI given by \((\bar d \pm z\, s_d) \;\pm\; t_{n-1,\,1-\alpha/2}\, s_d\,\sqrt{3/n}\).
Assumptions include approximately normal differences and roughly constant
variability across the measurement range; if differences increase with
magnitude, consider a transformation before analysis. Missing values are
removed pairwise (rows with an NA in either input are dropped before
calling the C++ backend).
Bland JM, Altman DG (1986). Statistical methods for assessing agreement between two methods of clinical measurement. The Lancet, 307-310.
Bland JM, Altman DG (1999). Measuring agreement in method comparison studies. Statistical Methods in Medical Research, 8(2), 135-160.
print.ba, plot.ba,
ccc,ccc_pairwise_u_stat,
ccc_lmm_reml
set.seed(1)
x <- rnorm(100, 100, 10)
y <- x + rnorm(100, 0, 8)
ba <- bland_altman(x, y)
print(ba)
plot(ba)
Run the code above in your browser using DataLab