Welcome to methcomp’s documentation!

methcomp.regression.deming(method1: numpy.ndarray, method2: numpy.ndarray, CI: float = 0.95, vr: Optional[float] = None, sdr: Optional[float] = None, bootstrap: int = 1000, x_label: str = 'Method 1', y_label: str = 'Method 2', title: Optional[str] = None, line_reference: bool = True, line_CI: bool = True, legend: bool = True, square: bool = False, ax: Optional[matplotlib.axes._axes.Axes] = None, point_kws: Optional[Dict] = None, color_regr: Optional[str] = None, alpha_regr: Optional[float] = None)[source]

Provide a method comparison using Deming regression.

This is an Axis-level function which will draw the Deming plot onto the current active Axis object unless ax is provided.

Parameters
  • method1 (np.ndarray) – Values for method 1

  • method2 (np.ndarray) – Values for method 2

  • CI (float, optional) – The confidence interval employed in regression line (default=0.95)

  • vr (float, optional) – The assumed known ratio of the (residual) variance of the ys relative to that of the xs. [default=1]

  • sdr (float, optional) – The assumed known standard deviations. Parameter vr takes precedence if both are given. [default=1]

  • bootstrap (int, optional) – Amount of bootstrap estimates that should be performed to acquire standard errors (and confidence intervals). If None, no bootstrap is performed. [default=1000]

  • x_label (str, optional) – The label which is added to the X-axis. (default: “Method 1”)

  • y_label (str, optional) – The label which is added to the Y-axis. (default: “Method 2”)

  • title (str, optional) – Title of the regression plot. If None is provided, no title will be plotted.

  • line_reference (bool, optional) – If True, a grey reference line at y=x will be plotted in the plot (default: True)

  • line_CI (bool, optional) – If True, dashed lines will be plotted at the boundaries of the confidence intervals. (default: False)

  • legend (bool, optional) – If True, will provide a legend containing the computed regression equation. (default: True)

  • square (bool, optional) – If True, set the Axes aspect to “equal” so each cell will be square-shaped. (default: True)

  • ax (matplotlib.axes.Axes, optional) – matplotlib axis object, if not passed, uses gca()

  • point_kws (Optional[Dict], optional) – Additional keywords to plt

  • color_regr (Optional[str], optional) – color for regression line and CI area

  • alpha_regr (Optional[float], optional) – alpha for regression CI area

Returns

axes object with the Deming regression plot

Return type

matplotlib.axes.Axes

See also

regressor.Deming

References

Koopmans_1937

Koopmans, T. C. (1937). “Linear regression analysis of economic time series.” DeErven F. Bohn, Haarlem, Netherlands.

Deming_1943

Deming, W. E. (1943). “Statistical adjustment of data.” Wiley, NY (Dover Publications edition, 1985).

methcomp.regression.linear(method1: numpy.ndarray, method2: numpy.ndarray, CI: float = 0.95, x_label: str = 'Method 1', y_label: str = 'Method 2', title: Optional[str] = None, line_reference: bool = True, line_CI: bool = True, legend: bool = True, square: bool = False, ax: Optional[matplotlib.axes._axes.Axes] = None, point_kws: Optional[Dict] = None, color_regr: Optional[str] = None, alpha_regr: Optional[float] = None)[source]

Provide a method comparison using simple, linear regression.

This is an Axis-level function which will draw the linear regression plot onto the current active Axis object unless ax is provided.

Parameters
  • method1 (np.ndarray) – Values for method 1

  • method2 (np.ndarray) – Values for method 2

  • CI (float, optional) – The confidence interval employed in regression line (default=0.95)

  • x_label (str, optional) – The label which is added to the X-axis. (default: “Method 1”)

  • y_label (str, optional) – The label which is added to the Y-axis. (default: “Method 2”)

  • title (str, optional) – Title of the regression plot. If None is provided, no title will be plotted.

  • line_reference (bool, optional) – If True, a grey reference line at y=x will be plotted in the plot (default: True)

  • line_CI (bool, optional) – If True, dashed lines will be plotted at the boundaries of the confidence intervals. (default: False)

  • legend (bool, optional) – If True, will provide a legend containing the computed regression equation. (default: True)

  • square (bool, optional) – If True, set the Axes aspect to “equal” so each cell will be square-shaped. (default: True)

  • ax (matplotlib.axes.Axes, optional) – matplotlib axis object, if not passed, uses gca()

  • point_kws (Optional[Dict], optional) – Additional keywords to plt

  • color_regr (Optional[str], optional) – color for regression line and CI area

  • alpha_regr (Optional[float], optional) – alpha for regression CI area

Returns

axes object with the linear regression plot

Return type

matplotlib.axes.Axes

See also

regressor.Linear

methcomp.regression.passingbablok(method1: numpy.ndarray, method2: numpy.ndarray, CI: float = 0.95, x_label: str = 'Method 1', y_label: str = 'Method 2', title: Optional[str] = None, line_reference: bool = True, line_CI: bool = True, legend: bool = True, square: bool = False, ax: Optional[matplotlib.axes._axes.Axes] = None, point_kws: Optional[Dict] = None, color_regr: Optional[str] = None, alpha_regr: Optional[float] = None)[source]

Provide a method comparison using Passing-Bablok regression.

This is an Axis-level function which will draw the Passing-Bablok plot onto the current active Axis object unless ax is provided.

Parameters
  • method1 (np.ndarray) – Values for method 1

  • method2 (np.ndarray) – Values for method 2

  • CI (float, optional) – The confidence interval employed in regression line (default=0.95)

  • x_label (str, optional) – The label which is added to the X-axis. (default: “Method 1”)

  • y_label (str, optional) – The label which is added to the Y-axis. (default: “Method 2”)

  • title (str, optional) – Title of the regression plot. If None is provided, no title will be plotted.

  • line_reference (bool, optional) – If True, a grey reference line at y=x will be plotted in the plot (default: True)

  • line_CI (bool, optional) – If True, dashed lines will be plotted at the boundaries of the confidence intervals. (default: False)

  • legend (bool, optional) – If True, will provide a legend containing the computed regression equation. (default: True)

  • square (bool, optional) – If True, set the Axes aspect to “equal” so each cell will be square-shaped. (default: True)

  • ax (matplotlib.axes.Axes, optional) – matplotlib axis object, if not passed, uses gca()

  • point_kws (Optional[Dict], optional) – Additional keywords to plt

  • color_regr (Optional[str], optional) – color for regression line and CI area

  • alpha_regr (Optional[float], optional) – alpha for regression CI area

Returns

axes object with the Passing-Bablok regression plot

Return type

matplotlib.axes.Axes

See also

regressor.PassingBablok

References

passing_1983

Passing, H. and W. Bablok W. “A New Biometrical Procedure for Testing the Equality of Measurements from Two Different Analytical Methods.” J. Clin. Chem. Clin. Biochem 21 (1983): 709-720.

passing_1988

Bablok, W., et al. “A General Regression Procedure for Method Transformation. Application of Linear Regression Procedures for Method Comparison Studies in Clinical Chemistry, Part III.” Journal of clinical chemistry and clinical biochemistry. Zeitschrift fur klinische Chemie und klinische Biochemie 26.11 (1988): 783-790.

class methcomp.blandaltman.BlandAltman(method1: Union[List[float], numpy.ndarray], method2: Union[List[float], numpy.ndarray], diff: str = 'absolute', limit_of_agreement: float = 1.96, CI: float = 0.95)[source]

Class for drawing a Bland-Altman plot

plot(x_label: str = 'Mean of methods', y_label: str = 'Difference between methods', graph_title: Optional[str] = None, reference: bool = False, xlim: Optional[Tuple] = None, ylim: Optional[Tuple] = None, color_mean: str = '#008bff', color_loa: str = '#FF7000', color_points: str = '#000000', point_kws: Optional[Dict] = None, ci_alpha: float = 0.2, loa_linestyle: str = '--', ax: Optional[matplotlib.axes._axes.Axes] = None)[source]

Provide a method comparison using Bland-Altman plotting. This is an Axis-level function which will draw the Bland-Altman plot onto the current active Axis object unless ax is provided. :param x_label: The label which is added to the X-axis. If None is provided, a standard

label will be added.

Parameters
  • y_label (str, optional) – The label which is added to the Y-axis. If None is provided, a standard label will be added.

  • graph_title (str, optional) – Title of the Bland-Altman plot. If None is provided, no title will be plotted.

  • reference (bool, optional) – If True, a grey reference line at y=0 will be plotted in the Bland-Altman.

  • xlim (list, optional) – Minimum and maximum limits for X-axis. Should be provided as list or tuple. If not set, matplotlib will decide its own bounds.

  • ylim (list, optional) – Minimum and maximum limits for Y-axis. Should be provided as list or tuple. If not set, matplotlib will decide its own bounds.

  • color_mean (str, optional) – Color of the mean difference line that will be plotted.

  • color_loa (str, optional) – Color of the limit of agreement lines that will be plotted.

  • color_points (str, optional) – Color of the individual differences that will be plotted.

  • point_kws (dict of key, value mappings, optional) – Additional keyword arguments for plt.scatter.

  • ci_alpha (float, optional) – Alpha value of the confidence interval.

  • loa_linestyle (str, optional) – Linestyle of the limit of agreement lines.

  • ax (matplotlib Axes, optional) – Axes in which to draw the plot, otherwise use the currently-active Axes.

Returns

ax – Axes object with the Bland-Altman plot.

Return type

matplotlib Axes

methcomp.blandaltman.blandaltman(method1, method2, diff='absolute', limit_of_agreement=1.96, CI=0.95, x_label: str = 'Mean of methods', y_label: str = 'Difference between methods', graph_title: Optional[str] = None, reference: bool = False, xlim: Optional[Tuple] = None, ylim: Optional[Tuple] = None, color_mean: str = '#008bff', color_loa: str = '#FF7000', color_points: str = '#000000', point_kws: Optional[Dict] = None, ci_alpha: float = 0.2, loa_linestyle: str = '--', ax: Optional[matplotlib.axes._axes.Axes] = None)methcomp.blandaltman.BlandAltman[source]

Provide a method comparison using Bland-Altman.

This functions creates a BlandAltman class which can be used to access the statistics (using .statistics()) or to generate a plot with additional arguments (using .plots()).

Parameters
  • method1 (array, or list) – Values obtained from both methods, preferably provided in a np.array.

  • method2 (array, or list) – Values obtained from both methods, preferably provided in a np.array.

  • diff ("absolute" or "percentage") – The difference to display, whether it is an absolute one or a percentual one. If None is provided, it defaults to absolute.

  • limit_of_agreement (float, optional) – Multiples of the standard deviation to plot the limit of afgreement bounds at. This defaults to 1.96.

  • CI (float, optional) – The confidence interval employed in the mean difference and limit of agreement lines. Defaults to 0.95.

Returns

BlandAltman

Return type

class object containing the statistics and plot functionality

See also

pyCompare package on github [altman_1983] Altman, D. G., and Bland, J. M.

Series D (The Statistician), vol. 32, no. 3, 1983, pp. 307–317.

[altman_1999] Altman, D. G., and Bland, J. M.

Statistical Methods in Medical Research, vol. 8, no. 2, 1999, pp. 135–160.

methcomp.glucose.clarke(reference, test, units, x_label=None, y_label=None, title=None, xlim=None, ylim=None, color_grid='#000000', color_gridlabels='auto', color_points='auto', grid=True, percentage=False, point_kws=None, grid_kws=None, square=False, ax=None)[source]

Provide a glucose error grid analyses as designed by Clarke.

This is an Axis-level function which will draw the Clarke-error grid plot. onto the current active Axis object unless ax is provided.

Parameters
  • reference (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • test (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • units (str) – The SI units which the glucose values are provided in. Options: ‘mmol’, ‘mgdl’ or ‘mg/dl’.

  • x_label (str, optional) – The label which is added to the X-axis. If None is provided, a standard label will be added.

  • y_label (str, optional) – The label which is added to the Y-axis. If None is provided, a standard label will be added.

  • title (str, optional) – Title of the Clarke error grid plot. If None is provided, no title will be plotted.

  • xlim (list, optional) – Minimum and maximum limits for X-axis. Should be provided as list or tuple. If not set, matplotlib will decide its own bounds.

  • ylim (list, optional) – Minimum and maximum limits for Y-axis. Should be provided as list or tuple. If not set, matplotlib will decide its own bounds.

  • color_grid (str, optional) – Color of the Clarke error grid lines.

  • color_gridlabels (str, optional) – Color of the gridlabels (A, B, C, ..) that will be plotted. If set to ‘auto’, it will plot the points according to their zones.

  • color_points (str, optional) – Color of the individual differences that will be plotted. If set to ‘auto’, it will plot the points according to their zones.

  • grid (bool, optional) – Enable the grid lines of the Parkes error. Defaults to True.

  • percentage (bool, optional) – If True, percentage of the zones will be depicted in the plot.

  • point_kws (dict of key, value mappings, optional) – Additional keyword arguments for plt.scatter.

  • grid_kws (dict of key, value mappings, optional) – Additional keyword arguments for the grid with plt.plot.

  • square (bool, optional) – If True, set the Axes aspect to “equal” so each cell will be square-shaped.

  • ax (matplotlib Axes, optional) – Axes in which to draw the plot, otherwise use the currently-active Axes.

Returns

ax – Axes object with the Clarke-error grid plot.

Return type

matplotlib Axes

See also

Clarke, W., Cox, D., et, vol., no., 1987, pp.

methcomp.glucose.clarkezones(reference, test, units, numeric=False)[source]

Provides the error zones as depicted by the Clarke error grid analysis for each point in the reference and test datasets.

Parameters
  • reference (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • test (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • units (str) – The SI units which the glucose values are provided in. Options: ‘mmol’, ‘mgdl’ or ‘mg/dl’.

  • numeric (bool, optional) – If this is set to true, returns integers (0 to 4) instead of characters for each of the zones.

Returns

clarkezones – Returns a list depecting the zones for each of the reference and test values.

Return type

list

methcomp.glucose.parkes(type, reference, test, units, x_label=None, y_label=None, title=None, xlim=None, ylim=None, color_grid='#000000', color_gridlabels='auto', color_points='auto', grid=True, percentage=False, point_kws=None, grid_kws=None, square=False, ax=None)[source]

Provide a glucose error grid analyses as designed by Parkes.

This is an Axis-level function which will draw the Parke-error grid plot. onto the current active Axis object unless ax is provided.

Parameters
  • type (int) – Parkes error grid differ for each type of diabetes. This should be either 1 or 2 corresponding to the type of diabetes.

  • reference (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • test (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • units (str) – The SI units which the glucose values are provided in. Options: ‘mmol’, ‘mgdl’ or ‘mg/dl’.

  • x_label (str, optional) – The label which is added to the X-axis. If None is provided, a standard label will be added.

  • y_label (str, optional) – The label which is added to the Y-axis. If None is provided, a standard label will be added.

  • title (str, optional) – Title of the Parkes-error grid plot. If None is provided, no title will be plotted.

  • xlim (list, optional) – Minimum and maximum limits for X-axis. Should be provided as list or tuple. If not set, matplotlib will decide its own bounds.

  • ylim (list, optional) – Minimum and maximum limits for Y-axis. Should be provided as list or tuple. If not set, matplotlib will decide its own bounds.

  • color_grid (str, optional) – Color of the Clarke error grid lines. Defaults to #000000 which represents the black color.

  • color_gridlabels (str, optional) – Color of the grid labels (A, B, C, ..) that will be plotted. Defaults to ‘auto’ which colors the points according to their relative zones.

  • color_points (str, optional) – Color of the individual differences that will be plotted. Defaults to ‘auto’ which colors the points according to their relative zones.

  • grid (bool, optional) – Enable the grid lines of the Parkes error. Defaults to True.

  • percentage (bool, optional) – If True, percentage of the zones will be depicted in the plot.

  • square (bool, optional) – If True, set the Axes aspect to “equal” so each cell will be square-shaped.

  • point_kws (dict of key, value mappings, optional) – Additional keyword arguments for plt.scatter.

  • grid_kws (dict of key, value mappings, optional) – Additional keyword arguments for the grid with plt.plot.

  • ax (matplotlib Axes, optional) – Axes in which to draw the plot, otherwise use the currently-active Axes.

Returns

ax – Axes object with the Parkes error grid plot.

Return type

matplotlib Axes

References

[parkes_2000] Parkes, J. L., Slatin S. L. et al.

Diabetes Care, vol. 23, no. 8, 2000, pp. 1143-1148.

[pfutzner_2013] Pfutzner, A., Klonoff D. C., et al.

J Diabetes Sci Technol, vol. 7, no. 5, 2013, pp. 1275-1281.

methcomp.glucose.parkeszones(type, reference, test, units, numeric=False)[source]

Provides the error zones as depicted by the Parkes error grid analysis for each point in the reference and test datasets.

Parameters
  • type (int) – Parkes error grid differ for each type of diabetes. This should be either 1 or 2 corresponding to the type of diabetes.

  • reference (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • test (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • units (str) – The SI units which the glucose values are provided in. Options: ‘mmol’, ‘mgdl’ or ‘mg/dl’.

  • numeric (bool, optional) – If this is set to true, returns integers (0 to 4) instead of characters for each of the zones.

Returns

parkeszones – Returns a list depicting the zones for each of the reference and test values.

Return type

list

methcomp.glucose.seg(reference, test, units, x_label=None, y_label=None, title=None, xlim=None, ylim=None, percentage=False, point_kws=None, square=False, ax=None)[source]

Provide a glucose error grid analyses as designed by the surveillance error grid.

This is an Axis-level function which will draw the surveillance error grid plot. onto the current active Axis object unless ax is provided.

Parameters
  • reference (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • test (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • units (str) – The SI units which the glucose values are provided in. Options: ‘mmol’, ‘mgdl’ or ‘mg/dl’.

  • x_label (str, optional) – The label which is added to the X-axis. If None is provided, a standard label will be added.

  • y_label (str, optional) – The label which is added to the Y-axis. If None is provided, a standard label will be added.

  • title (str, optional) – Title of the plot. If None is provided, no title will be plotted.

  • xlim (list, optional) – Minimum and maximum limits for X-axis. Should be provided as list or tuple. If not set, matplotlib will decide its own bounds.

  • ylim (list, optional) – Minimum and maximum limits for Y-axis. Should be provided as list or tuple. If not set, matplotlib will decide its own bounds.

  • percentage (bool, optional) – If True, percentage of the zones will be depicted in the plot.

  • point_kws (dict of key, value mappings, optional) – Additional keyword arguments for plt.scatter.

  • square (bool, optional) – If True, set the Axes aspect to “equal” so each cell will be square-shaped.

  • ax (matplotlib Axes, optional) – Axes in which to draw the plot, otherwise use the currently-active Axes.

Returns

ax – Axes object with the Surveillance error grid plot.

Return type

matplotlib Axes

References

[klonoff_2014] Klonoff, D. C., Lias, C., et al.

J Diabetes Sci Technol, vol. 8, no. 4, 2014, pp 658-672.

[kovatchev_2014] Kovatchev, B. P., Wakeman, C. A., et al.

J Diabetes Sci Technol, vol 8, no. 4, 2014, pp. 673-684.

methcomp.glucose.segscores(reference, test, units)[source]

Provides the raw error values as depicted by the surveillance error grid analysis for each point in the reference and test datasets.

Parameters
  • reference (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • test (array, or list) – Glucose values obtained from the reference and predicted methods, preferably provided in a np.array.

  • units (str) – The SI units which the glucose values are provided in. Options: ‘mmol’, ‘mgdl’ or ‘mg/dl’.

Returns

segscores – Returns a list with a SEG score for each test, reference pair.

Return type

list

Indices and tables