baplot <- function(m1, m2, ...) { # m1 and m2 are the measurements and the input arguments of the funtion 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 measurement values",pch=16, 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) title("Bland-Altman plot") }