-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
504717e
commit 94aaf13
Showing
3 changed files
with
588 additions
and
0 deletions.
There are no files selected for viewing
562 changes: 562 additions & 0 deletions
562
docs/41_descriptive_statistics/bland_altman_on_folders_of_images.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# A function for drawing Bland-Altman plots | ||
# source: modified from https://stackoverflow.com/questions/16399279/bland-altman-plot-in-python | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
def bland_altman_plot(data1, data2, measure="", title="", *args, **kwargs): | ||
""" | ||
Draws a Bland-Altman plot from two lists of measurements. | ||
The physical measure should be given to put in axis labels. | ||
The given title will show on top of the plot. | ||
""" | ||
data1 = np.asarray(data1) | ||
data2 = np.asarray(data2) | ||
mean = np.mean([data1, data2], axis=0) | ||
diff = data1 - data2 # Difference between data1 and data2 | ||
md = np.mean(diff) # Mean of the difference | ||
sd = np.std(diff, axis=0) # Standard deviation of the difference | ||
|
||
plt.scatter(mean, diff, *args, **kwargs) | ||
plt.axhline(md, color='gray', linestyle='--') | ||
plt.axhline(md + 1.96*sd, color='gray', linestyle='--') | ||
plt.axhline(md - 1.96*sd, color='gray', linestyle='--') | ||
plt.xlabel("average " + measure) | ||
plt.ylabel("difference " + measure) | ||
plt.title(title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters