Skip to main content

Implementation of indexes used in statistical agreement

Project description

Statistical Agreement

How to assert agreement using statistical indices ?

Overview

This repo implements some indices used in statistical agreement such as total deviation index (TDI) and coverage probability (CP).

Statistical Agreement is an ensemble of processes to declare (or not) if two (or more) measurement methods lead to the same results.

Currently, only implementations for basic continuous or categorical models are planned.

Installation

pip install statisticalagreement

Usage

You can find examples in the example folder.

Here is an example of CCC usage with Gaussian simulated data:

from scipy. stats import multivariate_normal
import numpy as np
import statisticalagreement as sa

import seaborn as sns    
import matplotlib.pyplot as plt

mean=np.array([-np.sqrt(0.1)/2, np.sqrt(0.1)/2])
cov=np.array([[1.1**2, 0.95*1.1*0.9], [0.95*1.1*0.9, 0.9**2]])
xy = multivariate_normal.rvs(mean=mean, cov=cov, size=100)

x = xy[:, 0]
y = xy[:, 1]

ax = sns.histplot(x - y)
ax.set(xlabel="Difference of methods")
plt.show()

# Return approximate estimate of CCC 
# with a alpha risk of 5% 
# and an allowance of whithin sample deviation of 10%.
ccc = sa.ccc(x, y, method="approx", alpha=0.05, allowance=0.10)
print(f"Approximate estimate of CCC: {ccc.estimate:.4f}\n\
Lower confident interval of the estimate with confident level of 95%: {ccc.limit:.4f}\n")
Approximate estimate of CCC: 0.8943
Lower confident interval of the estimate with confident level of 95%: 0.8625

Since allowance > limit, then there is no allowance by criterion defined by the user.

The distribution of the difference of methods can be displayed for visual analysis. Distribution of difference of methods

Running the main.py with the argument -e will display the examples.

Current Implementations

For each index listed in the following table:

  • naive designes an implemetation using a parametric hypothesis (like a normal hypothesis), and thus only accurate if the hypothesis is true.
  • robust designes an implemetation not depending of any kind of hypothesis.
  • tested indicates if the implementation of the said index is tested with a monte-carlo test and results are correct in regards of the scientific literature.
  • bootstrap indicates if an alternative way to compute confident interval using a resample method is implemented.
  • unified model indicates if there is an implementation for models using continuous and categorical data (for instance with multiple raters and/or readings) - not planned currently
Index Naive Tested Robust Tested Bootstrap Unified model
MSD :heavy_check_mark: :heavy_check_mark: :x: :x: :x: :x:
TDI :heavy_check_mark: :heavy_check_mark: :x: :x: :x: :x:
CP :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :x: :x:
Accuracy :heavy_check_mark: :heavy_check_mark: :x: :x: :x: :x:
Precision :heavy_check_mark: :heavy_check_mark: :x: :x: :x: :x:
CCC :heavy_check_mark: :heavy_check_mark: WIP :x: :x: :x:
Kappa :heavy_check_mark: :heavy_check_mark: :x: :x: :x: :x:
Weighted Kappa :heavy_check_mark:[^2] :heavy_check_mark: :x: :x: :x: :x:

[^2]: Absolute and Squared Weighted Kappa

Tests

Unit tests for all indeces are written. Estimate tests can be launched using the "not stochastic" marker:

pytest -v -m "not stochastic"

Variance tests rely on MonteCarlo simulation and are quite slow. Tehy can be launched using the "stochastic" marker:

pytest -v -m "stochastic"

Tests that match results from the scientific literature and also implemented. Currently tests of MonteCarlo simulations can be display running main.py with the -s i argument where i is the index simulated.

Currently only msd and ccc tests are implemented. One can compare msd simulation results with \cite{LIN2000} and ccc one with \cite{LIN1989}.

main.py -s msd
main.py -s ccc

References

Bibtex is available here.

Troubleshooting

For VS Code users on Windows, using a venv to run the script can be prohibited due to ExecutionPolicy.

Get-ExecutionPolicy -List
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

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

statisticalagreement-0.6.0.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statisticalagreement-0.6.0-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file statisticalagreement-0.6.0.tar.gz.

File metadata

  • Download URL: statisticalagreement-0.6.0.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for statisticalagreement-0.6.0.tar.gz
Algorithm Hash digest
SHA256 858fc0031ff822f8b26c2b0254f6a47abe2a687c0431eb4a557cdc953b2d5d38
MD5 787a524773092d18f8724810bcab6c53
BLAKE2b-256 992b3b0b4332a57585eb561fc9a24981dc18ec362ddf7d329c80d51a80c37aaa

See more details on using hashes here.

File details

Details for the file statisticalagreement-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for statisticalagreement-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c93f5d54ae9f0fb0a734cba90156f02e880b3785f34caac5ce3ce75261d14487
MD5 92de438d25de8406cb8eb1990814d2ec
BLAKE2b-256 f7d57920d54d28b3869d719d84b799810a543e9db50f009a81efd6995cf14e49

See more details on using hashes here.

Supported by

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