class: center, middle, inverse, title-slide .title[ # Bland-Altman Plots - Method Comparison Studies using Julia ] .subtitle[ ## Statistical Modelling with Julia ] --- <style type="text/css"> body{ font-size: 20pt; } </style> ### Bland-Altman Plot The **Bland-Altman plot**, also known as the Tukey mean-difference plot. The Bland-Altman plot is a graphical method used to compare two measurement techniques or methods. It helps visualize the agreement between the two methods by plotting the difference between the measurements against the average of the measurements. --- Here's how it works: 1. **Calculate the difference:** For each pair of measurements obtained by the two methods, calculate the difference (Method 1 - Method 2). 2. **Calculate the average:** For each pair of measurements, calculate the average ((Method 1 + Method 2) / 2). 3. **Plot the data:** Plot the differences on the y-axis against the averages on the x-axis. 4. **Calculate and plot the bias:** Calculate the mean of the differences. This represents the bias between the two methods. Plot this as a horizontal line on the graph. 5. **Calculate and plot the limits of agreement:** Calculate the standard deviation of the differences and multiply it by 1.96. Add and subtract this value from the bias to get the upper and lower limits of agreement. Plot these as horizontal lines on the graph. --- The Bland-Altman plot helps assess: * **Bias:** Whether one method consistently measures higher or lower than the other. * **Limits of agreement:** The range within which 95% of the differences between the two methods are expected to fall. * **Outliers:** Any data points that fall outside the limits of agreement, suggesting potential issues with one or both methods. --- ```julia using Plots # Sample data (replace with your actual data) method1 = [10.1, 12.3, 15.5, 18.2, 20.7] method2 = [10.5, 12.1, 15.8, 18.0, 20.9] # Calculate differences and averages differences = method2 .- method1 averages = (method2 .+ method1) ./ 2 # Calculate mean and standard deviation of differences mean_diff = mean(differences) std_diff = std(differences) ``` --- ```julia # Calculate limits of agreement (95% confidence interval) upper_limit = mean_diff + 1.96 * std_diff lower_limit = mean_diff - 1.96 * std_diff # Create the Bland-Altman plot scatter(averages, differences, xlabel="Average of Measurements", ylabel="Difference (Method 2 - Method 1)", title="Bland-Altman Plot") # Plot the mean difference hline!(mean_diff, linestyle=:dash, color=:red) # Plot the limits of agreement hline!(upper_limit, linestyle=:dash, color=:green) hline!(lower_limit, linestyle=:dash, color=:green) # Add annotations (optional) annotate!(mean(averages), mean_diff, text("Mean Difference"), fontsize=8, offset=(0, 5)) # Display the plot savefig("bland_altman_plot.png") ``` --- **Explanation:** 1. **Import the `Plots` package:** This line imports the necessary package for creating plots in Julia. 2. **Define sample data:** Replace the example data with your actual data. 3. **Calculate differences and averages:** - `differences = method2 .- method1` calculates the difference between each pair of measurements. - `averages = (method2 .+ method1) ./ 2` calculates the average of each pair of measurements. 4. **Calculate mean and standard deviation of differences:** - `mean_diff = mean(differences)` calculates the mean of the differences. - `std_diff = std(differences)` calculates the standard deviation of the differences. 5. **Calculate limits of agreement:** - `upper_limit` and `lower_limit` calculate the upper and lower limits of agreement, which represent the 95% confidence interval for the mean difference. 6. **Create the Bland-Altman plot:** - `scatter()` creates a scatter plot of the differences against the averages. - `xlabel!()`, `ylabel!()`, and `title!()` add labels and a title to the plot. 7. **Plot the mean difference and limits of agreement:** - `hline!()` adds horizontal lines to the plot for the mean difference and the limits of agreement. 8. **Add annotations (optional):** - `annotate!()` adds a text annotation to the plot to indicate the mean difference. 9. **Display the plot:** - `savefig("bland_altman_plot.png")` saves the plot to a file named "bland_altman_plot.png". This comprehensive example demonstrates how to create a Bland-Altman plot in Julia to assess the agreement between two measurement methods. Remember to interpret the plot carefully, considering the mean difference and the limits of agreement, to determine the level of agreement between the two methods. ---