Learn R Programming

matrixCorr (version 0.8.3)

bland_altman: Bland-Altman statistics with confidence intervals

Description

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.

Usage

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, ... )

Value

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

Arguments

group1, group2

Numeric vectors of equal length.

two

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.

mode

Integer; 1 uses group1 - group2, 2 uses group2 - group1.

conf_level

Confidence level for CIs (default 0.95).

verbose

Logical; if TRUE, prints how many OpenMP threads are used.

x

A "ba" object.

digits

Number of digits for estimates (default 3).

ci_digits

Number of digits for CI bounds (default 3).

...

Passed to ggplot2::theme() (ggplot path) or plot().

title

Plot title.

subtitle

Optional subtitle. If NULL, shows n and LoA summary.

point_alpha

Point transparency.

point_size

Point size.

line_size

Line width for mean/LoA.

shade_ci

Logical; if TRUE, draw shaded CI bands instead of 6 dashed lines.

shade_alpha

Transparency of CI bands.

smoother

One of "none", "loess", "lm" to visualize proportional bias.

symmetrize_y

Logical; if TRUE, y-axis centered at mean difference with symmetric limits.

Author

Thiago de Paula Oliveira

Details

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).

References

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.

See Also

print.ba, plot.ba, ccc,ccc_pairwise_u_stat, ccc_lmm_reml

Examples

Run this code
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