假设有reader1 和reader2,分别对一定数量病人的某一影像指标进行评分,现在想看一下这两位研究者评分的一致性,绘制Bland-Altman图是一种较为直观、简单的方式。代码实现方法如下:
- 显示分组信息的B-A plot
library(BlandAltmanLeh)
library(ggplot2)
reader1 <- ap_reader1$Elongation # numeric
reader2 <- ap_reader2$Elongation
# bland.altman.plot(reader1, reader2) #普通B-A plot
MVI <- rep(c(1,2), 63, length.out = 125) # new knowledge; "each = 63"
ba.stats <- bland.altman.stats(reader1, reader2)
plot(ba.stats$means, ba.stats$diffs, col= MVI,
sub=paste("critical difference is", round(ba.stats$critical.diff,4)),
main="Bland-Altman Plot", ylim=c(-0.6,0.6), pch=18-MVI)
abline(h = ba.stats$lines, lty=c(2,3,2), col=c("lightblue","blue","lightblue"),
lwd=c(3,2,3))
legend(x = "topright", legend = c("MVI-","MVI+"), fill = 1:2) # 这里的fill和MVI里的值对应
# Notes: MVI里赋值时不要赋0和1,因为他们代表黑和白,图片上显示不出来
- 带直方图的B-A plot:
library(ggExtra)
print(ggMarginal(bland.altman.plot(reader1, reader2, graph.sys = "ggplot2"),
type = "histogram", size=4))
临床上还会有一种情况,比如一个量表只有1-10分,2个评价者对100个患者评分的话,必然很多人的评分是相同的。如果用普通的B-A图展示的话,有些点就会被覆盖住,无法展现评分差异的全貌。以下代码就是解决这种情况的:
- B-A图里的重复值
A <- c(7, 8, 4, 6, 4, 5, 9, 7, 5, 8, 1, 4, 5, 7, 3, 4, 4, 9, 3, 3,
1, 4, 5, 6, 4, 7, 4, 7, 7, 5, 4, 6, 3, 4, 6, 4, 7, 4, 6, 5, 1, 1, 1, 1, 1, 1)
B <- c(8, 7, 4, 6, 3, 6, 9, 8, 4, 9, 0, 5, 5, 9, 3, 5, 5, 8, 3, 3,
1, 4, 4, 7, 4, 8, 3, 7, 7, 5, 6, 7, 3, 3, 7, 3, 6, 5, 9, 5, 1, 1, 1, 1, 1, 1)
bland.altman.plot(A, B)
bland.altman.plot(A, B, sunflower=TRUE) # 不同形状代表不同的重复值
- ggplot2 给出的解决方案:
print( bland.altman.plot(A, B, graph.sys = "ggplot2", geom_count = TRUE) )
参考资料:
BlandAltmanLeh Intro