Bland altman
daspi.plotlib.plotter.BlandAltman(source, target, feature, identity, reverse=False, agreement=3.92, confidence=0.95, feature_axis='mean', lines_same_color=False, target_on_y=True, color=None, marker=None, ax=None, visible_spines=None, hide_axis=None, **kwds)
¶
Bases: Plotter
Generate a Bland-Altman plot to compare two sets of measurements.
Bland-Altman plots [1]_ are extensively used to evaluate the agreement among two different instruments or two measurements techniques. They allow identification of any systematic difference between the measurements (i.e., fixed bias) or possible outliers.
The mean difference (= second - first) is the estimated bias, and the SD of the differences measures the random fluctuations around this mean. If the mean value of the difference differs significantly from 0 on the basis of a 1-sample t-test, this indicates the presence of fixed bias. If there is a consistent bias, it can be adjusted for by subtracting the mean difference from the new method.
It is common to compute 95% limits of agreement for each comparison (average difference ± 1.96 standard deviation of the difference), which tells us how far apart measurements by 2 methods were more likely to be for most individuals. If the differences within mean ± 1.96 SD are not clinically important, the two methods may be used interchangeably. The 95% limits of agreement can be unreliable estimates of the population parameters especially for small sample sizes so, when comparing methods or assessing repeatability, it is important to calculate confidence intervals for the 95% limits of agreement.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Pandas long format DataFrame containing the data source for the plot.
TYPE:
|
target
|
Column name of the target variable.
TYPE:
|
feature
|
Column name indicating which is the first (reference measurement) and which is the second measurement (the measurement to be compared).
TYPE:
|
identity
|
Column name containing identities of each sample, must occur once for each measurement.
TYPE:
|
reverse
|
Flag indicating if the order of the measurements should be reversed, by default False
TYPE:
|
agreement
|
Multiple of the standard deviation to plot agreement limits (in both direction). The defaults is 3.92 (± 1.96), which corresponds to 95 % confidence interval if the differences are normally distributed.
TYPE:
|
confidence
|
If not None, plot the specified percentage confidence interval of the mean and limits of agreement. The CIs of the mean difference and agreement limits describe a possible error in the estimate due to a sampling error. The greater the sample size, the narrower the CIs will be, by default 0.95
TYPE:
|
feature_axis
|
Definition of data used as feature axis (reference axis). - If 'mean' the mean for each measurement is calculated as (first + second)/2. - If 'data' the feature values are used for feature axis.
TYPE:
|
target_on_y
|
Flag indicating whether the target variable is plotted on the y-axis, by default True.
TYPE:
|
color
|
Color to be used to draw the artists. If None, the first color is taken from the color cycle, by default None.
TYPE:
|
marker
|
The marker style for the scatter plot. Available markers see: https://matplotlib.org/stable/api/markers_api.html, by default None
TYPE:
|
ax
|
The axes object for the plot. If None, an attempt is made to get
the current one using
TYPE:
|
**kwds
|
Those arguments have no effect. Only serves to catch further arguments that have no use here (occurs when this class is used within chart objects).
DEFAULT:
|
Examples:
Apply using the plot method of a DaSPi Chart object:
import daspi as dsp
chart = dsp.SingleChart(
source=dsp.load_dataset('shoe-sole'),
target='wear',
feature='status',
).plot(
dsp.BlandAltman,
identity='tester',
feature_axis='mean',
reverse=True)
Notes
The code is an adaptation of the Pingouin package. https://pingouin-stats.org/generated/pingouin.plot_blandaltman.html
The pingouin implementation is also a simplified version of the PyCombare package: https://github.com/jaketmp/pyCompare
References
.. [1] Bland, J. M., & Altman, D. (1986). Statistical methods for assessing agreement between two methods of clinical measurement. The lancet, 327(8476), 307-310.
identity = identity
instance-attribute
¶
Column name containing identities of each sample.
stripes = {}
instance-attribute
¶
Dictionary of Stripe objects used for drawing lines and their confidence intervals.
lines_same_color = lines_same_color
instance-attribute
¶
Whether to use same color for lines and their confidence intervals as for the points.
confidence = confidence
instance-attribute
¶
Confidence level of the confidence interval for mean and agreements.
estimation = LocationDispersionEstimator(samples=(df[_target]), strategy='norm', agreement=agreement)
instance-attribute
¶
Estimator instance to estimate the mean and limits of agreement.
kw_default
property
¶
Default keyword arguments for plotting (read-only)