qwraps2 (version 0.4.2)

qblandaltman: Bland Altman Plots

Description

Construct and plot a Bland Altman plot in ggplot2.

Usage

qblandaltman(x, alpha = getOption("qwraps2_alpha", 0.05), generate_data = TRUE)

qblandaltman_build_data_frame(x, alpha = getOption("qwraps2_alpha", 0.05))

Arguments

x

a data.frame with two columns. If a data.frame with more than two columns is used only the first two columns will be used.

alpha

(Defaults to 0.05) place (1 - alpha)*100 place on the plot.

generate_data

logical, defaults to TRUE. If TRUE, then the call to qblandaltman_build_data_frame is done automatically for you. If FALSE, then you should explicitly call qblandaltman_build_data_frame before calling qblandaltman.

Value

a ggplot. Minimal aesthetics have been used so that the user may modify the graphic as desired with ease.

Details

Providing a data.frame with two columns, the function returns a ggplot version of a Bland Altman plot with the specified confidence intervals.

Two ways to call the plotting function. If you submit a data.frame qblandaltman then the data needed to produce the Bland Altman plot is automatically generated by a call to qblandaltman_build_data_frame. Alternatively, you may call qblandaltman_build_data_frame directly and then call qblandaltman. This might be helpful if you are putting multiple Bland Altman plots together into one ggplot object. See Examples.

References

Altman, Douglas G., and J. Martin Bland. "Measurement in medicine: the analysis of method comparison studies." The statistician (1983): 307-317.

Bland, J. Martin, and DouglasG Altman. "Statistical methods for assessing agreement between two methods of clinical measurement." The lancet 327, no. 8476 (1986): 307-310.

Examples

Run this code
# NOT RUN {
# load ggplot2 and the diamonds data set
data(diamonds, package = "ggplot2")

# compare a simple regression to random noise
dat <- 
  data.frame(fitted(lm(price ~ poly(carat, 4), data = diamonds)),  # fitted values
             diamonds$price + rnorm(nrow(diamonds), sd = 0.2),     # observed with noise
             pi)                                                   # extra column
qblandaltman(dat)

# simple example
dat <- data.frame(eval1 = rpois(100, 3), eval2 = rpois(100, 3.4)) 
qblandaltman(dat)

ggplot2::last_plot() + ggplot2::theme_bw()

# Two plots in one ggplot object
set.seed(42)
dat1 <- data.frame(eval1 = rnorm(100), eval2 = rt(100, df = 1))
dat2 <- data.frame(eval1 = rpois(50, 3), eval2 = rpois(50, 4))

# individual plots
qblandaltman(dat1)
qblandaltman(dat2)

# combined plots
dat <- rbind(cbind(set = "rnorm", qblandaltman_build_data_frame(dat1)), 
             cbind(set = "rpois", qblandaltman_build_data_frame(dat2)))
qblandaltman(dat, generate_data = FALSE) + ggplot2::facet_wrap( ~ set)

# }

Run the code above in your browser using DataLab