Skip to main content

Bland-Altman plots for Python

Project description

pyCompare

Build Status codecov PyPI - Python Version DOI PyPI Binder

A Python module for generating Bland-Altman plots to compare two sets of measurements.

You can try out the code using Binder.

Installation

To install via pip, run:

pip install pyCompare

Installation with pip allows the usage of the uninstall command:

pip uninstall pyCompare

Documentation

Usage

blandAltman(data1, data2,
            limitOfAgreement=1.96,
            confidenceInterval=95,
            confidenceIntervalMethod='approximate',
            detrend=None,
            percentage=False,
            **kwargs)

Generate a Bland-Altman plot to compare two sets of measurements of the same value.

Paired measurmentes from each set should be passed in data1 and data2 with each containing a list of values from one of the methods.

The range of the limits of agreement is 1.96 by default, and can be customised with the limitOfAgreement= argument.

By default confidance intervals are plotted over the 95% range, this can be customised to the x% range by passing the argument confidenceInterval=x or removed with confidenceInterval=None.

There are two options for plotting confidence intervals on the mean difference and limit of agreement:

  • [default] 'approximate' uses the approximate method described by Bland & Altman
  • 'exact paired' uses the exact paired method described by Carkeet

The 'exact paired' method will give more accurate confidence intervals on the limits of agreement when the number of paired measurements is low (approx < 100), at the expense of a much slower plotting time.

A multiplicative offset between the two measures can be modeled with the detrend= argument, which supports the following options:

  • [default] None do not attempt to detrend data - plots the raw values
  • 'Linear' attempt to model and remove a multiplicative offset between each assay by linear regression
  • 'ODR' attempt to model and remove a multiplicative offset between each assay by orthogonal distance regression

'ODR' is the recommended method if you do not use None.

If passed as True, the percentage= argument plots the percentage difference between measures, instead of the units the methods were measured in.

Plots are displayed using the current matplotlib backend by default, or may be saved with the savePath= argument.

When saving, png format graphics are saved by default:

blandAltman(data1, data2,
            savePath='SavedFigure.png')

The save format type can be chosen from those known by matplotlib with the figureFormat= argument:

blandAltman(data1, data2,
            savePath='SavedFigure.svg',
            figureFormat='svg)

Full list of arguments

blandAltman(data1, data2)

  • data1 (list like) – List of values from the first method
  • data2 (list like) – List of paired values from the second method
  • limitOfAgreement (float) – Multiple of the standard deviation to plot limit of agreement bounds at (defaults to 1.96)
  • confidenceInterval (None* or *float) – If not None, plot the specified percentage confidence interval on the mean and limits of agreement
  • confidenceIntervalMethod (str) – Method used to calculated confidence interval on the limits of agreement
  • detrend (None* or *str) – If not None attempt to detrend by the method specified
  • percentage (bool) – If True, plot differences as percentages (instead of in the units the data sources are in)
  • title (str) – Title text for the figure
  • ax (matplotlib.axes._subplots.AxesSubplot) – Matplotlib axis handle - if not None draw into this axis rather than creating a new figure
  • figureSize ((float, float)) – Figure size as a tuple of (width, height) in inches
  • dpi (int) – Figure resolution
  • savePath (str) – If not None, save figure at this path
  • figureFormat (str) – When saving figure use this format
  • meanColour (str) – Colour to use for plotting the mean difference
  • loaColour (str) – Colour to use for plotting the limits of agreement
  • pointColour (str) – Colour for plotting data points

References

To cite pyCompare, use the Zendo DOI: 10.5281/zenodo.1238915.

  • Altman, D. G., and Bland, J. M. “Measurement in Medicine: The Analysis of Method Comparison Studies” Journal of the Royal Statistical Society. Series D (The Statistician), vol. 32, no. 3, 1983, pp. 307–317. JSTOR.
  • Altman, D. G., and Bland, J. M. “Measuring agreement in method comparison studies” Statistical Methods in Medical Research, vol. 8, no. 2, 1999, pp. 135–160. DOI.
  • Carkeet, A. "Exact Parametric Confidence Intervals for Bland-Altman Limits of Agreement" Optometry and Vision Science, vol. 92, no 3, 2015, pp. e71–e80 DOI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyCompare-1.5.3.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

pyCompare-1.5.3-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file pyCompare-1.5.3.tar.gz.

File metadata

  • Download URL: pyCompare-1.5.3.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for pyCompare-1.5.3.tar.gz
Algorithm Hash digest
SHA256 df69b06c95294a7476d321a2076fb0b5b7cf930ef433ae86119d5067116ecb5e
MD5 0d11847296bac4a0417b9c8f8248cd00
BLAKE2b-256 2b9d2ae0260a28d8f5ef520c64263469593eb75350500214428b561c0da96d98

See more details on using hashes here.

File details

Details for the file pyCompare-1.5.3-py3-none-any.whl.

File metadata

  • Download URL: pyCompare-1.5.3-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for pyCompare-1.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ecf343e5c186fb62371e8a803c2baaedb1c3c736bada0a0bc5d70f10bbcd6888
MD5 8f410b466d2d8f8c2e30cc2d2b76d534
BLAKE2b-256 d2a2b2040016a2f7587a8ae11a933903fd87060277e397b7055ce6540765fba9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page