Skip to content

Instantly share code, notes, and snippets.

@decodebiology
Forked from jmmateoshggm/baplot.R
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decodebiology/ef0756c447150ccdd6a1 to your computer and use it in GitHub Desktop.
Save decodebiology/ef0756c447150ccdd6a1 to your computer and use it in GitHub Desktop.
# Bland-Altman plot R function.
# Author: jmmateos@mce.hggm.es
baplot <- function(m1, m2, ...) {
# m1 and m2 are the measurements
means <- (m1 + m2) / 2
diffs <- m1 - m2
mdiff <- mean(diffs)
sddiff <- sd(diffs)
# Compute the figure limits
ylimh <- mdiff + 3 * sddiff
yliml <- mdiff - 3 * sddiff
# Plot data
plot(diffs ~ means, xlab = "Average values",
ylab = "Differences", ylim = c(yliml, ylimh), ...)
abline(h = mdiff) # Center line
# Standard deviations lines
abline(h = mdiff + 1.96 * sddiff, lty = 2)
abline(h = mdiff - 1.96 * sddiff, lty = 2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment