Learn R Programming

mariposa (version 0.7.3)

kendall_tau: Kendall's Tau Correlation Analysis

Description

Calculates Kendall's tau-b rank correlation coefficients between variables with support for weighted correlations, grouped data, and multiple variable pairs. Provides significance testing and SPSS-compatible output formatting.

The function computes tau-b, which is adjusted for ties and is particularly suitable for ordinal data or when the assumptions of Pearson correlation are not met. For weighted correlations, it uses survey-weighted rank calculations.

Usage

kendall_tau(
  data,
  ...,
  weights = NULL,
  alternative = c("two.sided", "less", "greater"),
  use = c("pairwise", "listwise"),
  na.rm = NULL
)

Value

Correlation results showing rank-based relationships between variables, including the tau-b coefficient, p-value, z-score, and sample size for each pair. For multiple variables, correlation, significance, and sample size matrices are also provided. Use summary() for the full SPSS-style output with toggleable sections.

Arguments

data

Your survey data (a data frame or tibble)

...

The variables you want to correlate. List two for a single correlation or more for a correlation matrix. You can use helpers like starts_with("trust").

weights

Optional survey weights for population-representative results.

alternative

Direction of the test:

  • "two.sided" (default): Two-tailed test

  • "less": One-tailed test (negative correlation)

  • "greater": One-tailed test (positive correlation)

use

How to handle missing values:

  • "pairwise" (default): Pairwise deletion - each correlation uses all available cases

  • "listwise": Listwise deletion - only complete cases across all variables

na.rm

Deprecated. Use use instead.

Details

Understanding the Results

Kendall's tau measures how often pairs of observations are in the same order (concordant) versus different order (discordant). It is particularly useful for ordinal data, data with outliers, small sample sizes, and non-linear but monotonic relationships.

The tau value ranges from -1 to +1:

  • Strong positive (0.5 to 1.0): High values of one variable tend to go with high values of the other

  • Moderate positive (0.3 to 0.5): Some tendency for values to increase together

  • Weak positive (0 to 0.3): Slight tendency for values to increase together

  • No correlation (near 0): No relationship between the variables

  • Negative values: As one variable increases, the other tends to decrease

The output also provides:

  • p-value: Probability of seeing this correlation by chance (smaller = stronger evidence)

  • n: Number of observations used

  • significance stars: Quick visual indicator of statistical significance

When to Use This

Choose Kendall's tau when:

  • Your data is ordinal (ranked categories)

  • You have a small sample size (< 30 observations)

  • Your data has outliers that might affect Pearson correlation

Weighted variants

The weighted tau-b is an exact frequency-weighted computation (it reproduces the unweighted tau when all weights equal 1, enforced by an internal invariance suite), but its z statistic and p-value use a no-ties normal approximation. SPSS NONPAR CORR ignores WEIGHT BY, so weighted results have no SPSS reference; see vignette("spss-compatibility") for validation status.

  • You want a more conservative measure than Spearman's rho

References

Kendall, M. G. (1938). A new measure of rank correlation. Biometrika, 30(1/2), 81--93.

Kendall, M. G. (1945). The treatment of ties in ranking problems. Biometrika, 33(3), 239--251.

Agresti, A. (2010). Analysis of Ordinal Categorical Data (2nd ed.). John Wiley & Sons.

See Also

cor with method = "kendall" for the base R implementation.

spearman_rho for Spearman's rank correlation.

pearson_cor for Pearson correlation analysis.

summary.kendall_tau for detailed output with toggleable sections.

Other correlation: partial_cor(), pearson_cor(), spearman_rho()

Examples

Run this code
# Load required packages and data
library(dplyr)
data(survey_data)

# Kendall's tau is O(n^2); the examples run on a subset for speed.
# On your own data, simply drop the subsetting.
mini_survey <- survey_data[1:300, ]

# Basic correlation between two variables
mini_survey %>%
  kendall_tau(life_satisfaction, political_orientation)

# Correlation matrix for multiple variables
mini_survey %>%
  kendall_tau(life_satisfaction, political_orientation, trust_media)

# Weighted correlations
mini_survey %>%
  kendall_tau(age, income, weights = sampling_weight)

# Listwise deletion for missing data
mini_survey %>%
  kendall_tau(age, income, use = "listwise")

# One-tailed test
mini_survey %>%
  kendall_tau(age, income, alternative = "greater")

# \donttest{
# Grouped correlations
mini_survey %>%
  group_by(region) %>%
  kendall_tau(age, income, life_satisfaction)

# Using tidyselect helpers for ordinal variables
mini_survey %>%
  kendall_tau(starts_with("trust"), weights = sampling_weight)

# --- Three-layer output ---
result <- mini_survey %>%
  kendall_tau(life_satisfaction, political_orientation, trust_media,
              weights = sampling_weight)
result              # compact one-line overview
summary(result)     # full correlation, p-value, and N matrices
summary(result, pvalue_matrix = FALSE)  # hide p-values
# }

Run the code above in your browser using DataLab