If you want to compare the results of two methods to measure a continuous outcome, you will find that correlation/regression displays or models the relationship between the two sets of outcomes. But what you really want to know and analyze, is the difference between the two sets of outcomes. The method is best known by the names of the two authors who published on this topic in the Lancet: Bland and Altman.

Take a look at the dataset TwoTests1.

Set the working directory:

read the file into R using:

>  TwoTests1 <- read.csv(file="TwoTests1.csv",head=TRUE, sep=",")

look at the data using:

>  TwoTests1

The data shows you three columns: a case identifier, and two rows of test results of what could very well be a continuous variable.

In a few steps you can calculate the:

  1. difference between each pair of test results
  2. the mean of the paired test results

define the function (all these steps will be this function):

> bland_altman_plot <- function(x,y,xlab="Average testresult", ylab="Deviation of experimental test")

assign and compute the required data, R awaits the steps of the function. Copy-paste the entire function into R:

{
 x <- TwoTests1$Test1
 y <- TwoTests1$Test2
 d <- ((TwoTests1$Test1 + TwoTests1$Test2)/2)
 diff <- x - y         

 plot(diff ~ d,pch=16,ylim=c(-60,60),xlab=xlab,ylab=ylab)
 abline(h=mean(diff)-c(-2,0,2)*sd(diff),lty=2)
}

call the function:

> bland_altman_plot(d,diff,xlab="Test 1",ylab="Difference Test1 and Test2")

The last command will result in the plot shown:

Adapted from:

https://stat.ethz.ch/pipermail/r-help/2008-July/166921.html

and

http://rstats.tiddlyspot.com/#Bland-Altman

previous: T test in R

next: Pitman’s T in R

(Visited 2,315 times, 2 visits today)