Ranking agreement
Comparing two rankings of the same items.
SciPy · Function
Computes Kendall’s tau, an ordinal association measure for two rankings. It supports tau-b and tau-c, handles ties and missing values, and returns the statistic with a hypothesis-test p-value.
kendalltau compares the ordering of paired observations by counting concordant and discordant pairs, while accounting for ties according to the selected variant. It returns a statistic describing ordinal association and a p-value for the chosen alternative hypothesis; multidimensional inputs can be reduced along an axis.
scipy.stats.kendalltau(x, y, *, nan_policy='propagate', method='auto', variant='b', alternative='two-sided', axis=None, keepdims=False)| Name | Type | Description |
|---|---|---|
x | array_like | First sequence of paired observations or array-like values. |
y | array_like | Second sequence of paired observations; it must correspond elementwise with x. |
nan_policy | {‘propagate’, ‘omit’, ‘raise’}, optional | How to handle NaN values: 'propagate', 'omit', or 'raise'. |
method | {‘auto’, ‘exact’, ‘asymptotic’}, optional | Calculation strategy; 'auto' selects a method automatically, while 'exact' and 'asymptotic' request specific approaches where supported. |
variant | {‘b’, ‘c’}, optional | Kendall variant: 'b' for tau-b or 'c' for Stuart’s tau-c. |
alternative | {‘two-sided’, ‘less’, ‘greater’}, optional | Defines the alternative hypothesis: 'two-sided', 'less', or 'greater'. |
axis | int or None, optional | Axis along which to compute the statistic; None uses flattened inputs. |
keepdims | bool, optional | If true, retain reduced axes in the output shape. |
A SignificanceResult containing statistic, the Kendall tau value, and pvalue, the associated hypothesis-test p-value.
from scipy.stats import kendalltau
x = [12, 2, 1, 12, 2]
y = [1, 4, 7, 1, 0]
result = kendalltau(x, y)
print(result.statistic, result.pvalue)Computes the default tau-b statistic and its two-sided p-value for two rankings.
Comparing two rankings of the same items.
Testing whether ordinal measurements are associated.
Analyzing paired observations with ties.
Running vectorized ranking comparisons across array dimensions.
It measures correspondence between two rankings using Kendall’s tau. The statistic is based on concordant and discordant pairs and accounts for ties; the result also includes a p-value for testing absence of association.
Follow-up: How do tau-b and tau-c differ? They use different normalization schemes, while their hypothesis-test p-values are identical.
The default variant is tau-b, and tau-c can be selected with variant='c'. Both are bounded between -1 and 1, with values near 1 indicating agreement and values near -1 indicating disagreement.
Follow-up: When would axis matter? For array inputs, axis determines the dimension along which paired calculations are performed; keepdims controls whether that dimension is retained.
nan_policy controls missing-value handling: 'propagate' produces NaN, 'omit' ignores missing observations, and 'raise' reports an error. method='auto' selects the calculation method automatically.
Follow-up: How can a one-sided test be requested? Set alternative='less' or alternative='greater' instead of the default two-sided test.
scipy.stats.spearmanrscipy.stats.pearsonrscipy.stats.weightedtau