{ } Raw JSON

bundles / scipy 1.17.1 / scipy / stats / contingency / association

function

scipy.stats.contingency:association

source: /scipy/stats/contingency.py :425

Signature

def   association ( observed method = cramer correction = False lambda_ = None )

Summary

Calculates degree of association between two nominal variables.

Extended Summary

The function provides the option for computing one of three measures of association between two nominal variables from the data given in a 2d contingency table: Tschuprow's T, Pearson's Contingency Coefficient and Cramer's V.

Parameters

observed : array-like

The array of observed values

method : {"cramer", "tschuprow", "pearson"} (default = "cramer")

The association test statistic.

correction : bool, optional

Inherited from scipy.stats.contingency.chi2_contingency()

lambda_ : float or str, optional

Inherited from scipy.stats.contingency.chi2_contingency()

Returns

statistic : float

Value of the test statistic

Notes

Cramer's V, Tschuprow's T and Pearson's Contingency Coefficient, all measure the degree to which two nominal or ordinal variables are related, or the level of their association. This differs from correlation, although many often mistakenly consider them equivalent. Correlation measures in what way two variables are related, whereas, association measures how related the variables are. As such, association does not subsume independent variables, and is rather a test of independence. A value of 1.0 indicates perfect association, and 0.0 means the variables have no association.

Both the Cramer's V and Tschuprow's T are extensions of the phi coefficient. Moreover, due to the close relationship between the Cramer's V and Tschuprow's T the returned values can often be similar or even equivalent. They are likely to diverge more as the array shape diverges from a 2x2.

Array API Standard Support

association has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

====================  ====================  ====================
Library               CPU                   GPU
====================  ====================  ====================
NumPy                 ✅                     n/a                 
CuPy                  n/a                   ⛔                   
PyTorch               ⛔                     ⛔                   
JAX                   ⛔                     ⛔                   
Dask                  ⛔                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

Examples

An example with a 4x2 contingency table:
import numpy as np
from scipy.stats.contingency import association
obs4x2 = np.array([[100, 150], [203, 322], [420, 700], [320, 210]])
Pearson's contingency coefficient
association(obs4x2, method="pearson")
Cramer's V
association(obs4x2, method="cramer")
Tschuprow's T
association(obs4x2, method="tschuprow")

Aliases

  • scipy.stats.contingency.association

Referenced by

This package