Bland-Altman analysis is used to study the agreement between two measurements. Here is how it is created.
Step 1: Collect the two measurements
Sample_Data <- data.frame(A=c(6, 5, 3, 5, 6, 6, 5, 4, 7, 8, 9,
10, 11, 13, 10, 4, 15, 8, 22, 5), B=c(5, 4, 3, 5, 5, 6, 8, 6, 4, 7, 7, 11, 13, 5, 10, 11, 14, 8, 9, 4))
Step 2: Calculate the means of the measurement 1 and measurement 2
Sample_Data$average <- rowMeans(Sample_Data)
Step 3: Calculate the difference between measurement 1 and measurement 2
Sample_Data$difference <- Sample_Data$A - Sample_Data$B
Step 4: Calculate the limits of the agreement based on the chosen confidence interval
mean_difference <- mean(Sample_Data$difference)
lower_limit <- mean_difference - 1.96*sd( Sample_Data$difference )
upper_limit <- mean_difference + 1.96*sd( Sample_Data$difference )
Step 5: Create a scatter plot with the mean on the X-axis and the difference on the Y-axis. Mark the limits and the mean of difference.
ggplot(Sample_Data, aes(x = average, y = difference)) +
geom_point(size=3) +
geom_hline(yintercept = mean_difference, color= "red", lwd=1.5) +
geom_hline(yintercept = lower_limit, color = "green", lwd=1.5) +
geom_hline(yintercept = upper_limit, color = "green", lwd=1.5) +
ggtitle("")+
ylab("Difference")+
xlab("Average")
