Bland–Altman Plot in ggplot2

Peter Dalgaard 著 “Introductory Statistics with R” の Ch. 5.6 “Paired t test” を読んでいたところ「対応のある2群の差を可視化して確認するには、対応同士の平均と差の分散図を描くとヨイ」といったようなことが書かれていた。このプロットを Bland–Altman Plot と呼ぶらしい。

せっかくなので ggplot2 で描いてみた。

bland_altman_plot <- function(dat){
  dat$diff <- dat$pre - dat$post
  ggplot(dat, aes(pre, diff)) +
  geom_hline(yintercept = mean(dat$diff) + c(-2, 0, 2) * sd(dat$diff), linetype=2, color='brown') +
  geom_point() +  theme_bw() +
  xlab('mean of pre and post') + ylab('pre - post') + opts(title = 'Bland-Altman Plot')
}

データを突っ込んでみる

x <- c(1.83,  0.50,  1.62,  2.48, 1.68, 1.88, 1.55, 3.06, 1.30)
y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29)
dat <- data.frame(pre=x, post=y)
bland_altman_plot(dat)

> library(ISwR) # sample library for "Introductory Statistics with R"
> intake
    pre post
1  5260 3910
2  5470 4220
3  5640 3885
4  6180 5160
5  6390 5645
6  6515 4680
7  6805 5265
8  7515 5975
9  7515 6790
10 8230 6900
11 8770 7335
bland_altman_plot(intake)

Advertisements
Tagged with: , ,
Posted in R
One comment on “Bland–Altman Plot in ggplot2
  1. Faisal says:

    excellent! thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
%d bloggers like this: