Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

stats.kendalltau

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.

How it works

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.

Syntax

scipy.stats.kendalltau(x, y, *, nan_policy='propagate', method='auto', variant='b', alternative='two-sided', axis=None, keepdims=False)

Parameters

NameTypeDescription
xarray_likeFirst sequence of paired observations or array-like values.
yarray_likeSecond sequence of paired observations; it must correspond elementwise with x.
nan_policy{‘propagate’, ‘omit’, ‘raise’}, optionalHow to handle NaN values: 'propagate', 'omit', or 'raise'.
method{‘auto’, ‘exact’, ‘asymptotic’}, optionalCalculation strategy; 'auto' selects a method automatically, while 'exact' and 'asymptotic' request specific approaches where supported.
variant{‘b’, ‘c’}, optionalKendall variant: 'b' for tau-b or 'c' for Stuart’s tau-c.
alternative{‘two-sided’, ‘less’, ‘greater’}, optionalDefines the alternative hypothesis: 'two-sided', 'less', or 'greater'.
axisint or None, optionalAxis along which to compute the statistic; None uses flattened inputs.
keepdimsbool, optionalIf true, retain reduced axes in the output shape.

Returns

A SignificanceResult containing statistic, the Kendall tau value, and pvalue, the associated hypothesis-test p-value.

Key points

  • Use kendalltau when the relationship of interest is between ordinal rankings rather than necessarily linear numeric values.
  • Interpret the statistic’s sign as direction of ranking agreement and its magnitude as strength, with zero indicating little ordinal association.
  • The function supports tau-b by default and Stuart’s tau-c through the variant argument.
  • The returned p-value tests the null hypothesis that the rankings have no association when the default two-sided alternative is used.

Common mistakes

  • Without an axis, multidimensional inputs are flattened, so verify the input shape or pass an axis explicitly.
  • Changing between tau-b and tau-c changes the normalization of the statistic but not the hypothesis-test p-values.

Example: Compute Kendall's tau

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.

When to use it

Ranking agreement

Comparing two rankings of the same items.

Ordinal association testing

Testing whether ordinal measurements are associated.

Tie-aware correlation

Analyzing paired observations with ties.

Axis-wise analysis

Running vectorized ranking comparisons across array dimensions.

Interview questions

QWhat does scipy.stats.kendalltau return and what does it measure?

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.

QWhat are the available variants and how should their statistics be interpreted?

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.

QHow does kendalltau handle missing values and method selection?

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.spearmanr
  • scipy.stats.pearsonr
  • scipy.stats.weightedtau

Source: scipy.stats.kendalltau. Checked 2026-10-15.