ba_plot: Bland-Altman plot

Description Usage Arguments References Examples

View source: R/plots.R

Description

Creates a scatter plot using the method of Bland and Altman where the x- and y-axes are the means of and differences between x and y, respectively. Lines for the mean and +/-1.96 times the standard deviation of the difference between x and y are shown.

Usage

1
2
3
4
ba_plot(x, y, trend = c("loess", "gam", "none"), span = 0.5,
  trend.n = 1000L, alpha = 0.05, xlab = "", ylab = "",
  xlim = NULL, ylim = NULL, panel.first = NULL, panel.last = NULL,
  ..., line_pars = list(col = 1:2, lty = c(2, 1, 2)))

Arguments

x, y

measurements

trend

character string giving the type of trend line, one of "loess" (default), "gam" (requires the mgcv package), or "none" where no curve is drawn

span

if trend = "loess", a numeric value that controls the degree of smoothing (see loess)

trend.n

integer value for the number of data points to be used by predict.loess

alpha

confidence level affecting the critical values and trend confidence bands

xlab, ylab

x- and y-axis labels

xlim, ylim

x- and y-axis limits

panel.first

an expression to be evaluated after the plot axes are set up but before any plotting takes place (default is just a grid); see plot.default

panel.last

an expression to be evaluated after plotting has taken place but before the axes, title, and box are added; see comments about panel.first

...

additional parameters passed to plot

line_pars

additional graphical parameters passed to text or abline; all parameters will be passed as-is except col which should be a vector of length one, two, or three to color the lines and text accordingly; see examples

References

Altman DG, Bland JM (1983). Measurement in medicine: the analysis of method comparison studies. The Statistician 32: 307-317.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
set.seed(1)
x <- rnorm(100)
y <- rnorm(100, 0.5)

## basic usage
ba_plot(x, y)
ba_plot(x, y, trend = 'gam')
ba_plot(x, y, trend = 'none', alpha = 0.1)


## use line_pars to set graphical parameters of individual lines
ba_plot(x, y, col = c('black', 'green')[(abs(x - y) > 2) + 1L],
        pch = '.', cex = 5, line_pars = list(col = c('yellow', 'red')))
        
## panel.first/panel.last is used as in plot.default
ba_plot(x, y, cex = 2, las = 1,
        col = as.numeric(cut(x - y, c(-Inf, -2, 2, Inf))) + 2,
        panel.first = {
          p <- par('usr')
          rect(p[1L], p[3L], p[2L], p[4L], col = 'cornsilk')
          grid(col = 'grey90', lty = 1)
        },
        line_pars = list(col = 3:5, family = 'HersheySerif'))

raredd/ragree documentation built on March 25, 2021, 1:42 p.m.