Skip to content

ADirections & cycles · circular.correlation

Circular correlation (angle–angle and angle–linear)

Is a direction or time of day associated with another direction, or with an ordinary numeric variable?

Jammalamadaka–SenGupta correlation between two angles (wind and gust direction, departure and arrival times) and Mardia's circular–linear correlation between an angle and a measurement (wind direction and speed, hour of day and spend), with large-sample or permutation p-values.

Verified in Python and R Python and R agree to 10 decimals Seeded Also called circular correlation, angular correlation, Jammalamadaka-SenGupta correlation…

A real result

Example “Wind gust direction”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Circular correlationRecorded · Python and R agreeRecorded 2026-11-17 · 12 values compared
R

r = 0.92, p < .001, n = 240

Circular correlation r (Jammalamadaka–SenGupta)
0.9153
p
< .001

Plots

gust_direction against directionHow do two numeric variables move together?
View data
directiongust_direction
182.70175
228.50249.40
313.40285.70
353.10353.40
308.70340.10
249.60269.70
242.20258.30
281295.20
231197.20
158.10177.90
344.3031.100
247.60243.60
231.50241.80
284.20310.90
234.50266
328.40342.50
308.50347.90
190.40188.10
318.70269.90
332.70333.80
245.70256.70
277.20244.40
251267.60
302303.10
306.60309.30
184.50171.30
183.20197
333323.40
345.4012.500
231.50234.90
213.20207.60
269.10295.90
222.90229.80
273.30239.20
189.50194.20
252.50236.90
212.80217.30
228.10226.20
228.60229.20
271.90256.20
273.80237.70
242.80264.20
45.70059.300
205.10204.50
297.90332.20
281265.10
281.10257.60
351.20334.30
286300.40
258.30246.70
221.60223.80
230.60245.70
257.50261.60
283.40267.30
293.50294.20
221.40228.60
313.50332.40
254.90260.80
269.30292
302.30259.20

First 60 of 240 rows.

Assumptions

  • Independent pairs — One pair of values per unit (no repeated readings).
  • p-value: large-sample.
Python

r = 0.92, p < .001, n = 240

Circular correlation r (Jammalamadaka–SenGupta)
0.9153
p
< .001

To keep this page light, the plots are shown once, under the R tab.

Assumptions

  • Independent pairs — One pair of values per unit (no repeated readings).
  • p-value: large-sample.

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Wind gust directionci_wind · angle: direction · other: gust_direction
  • Wind speed linearci_wind · angle: direction · other: speed
  • Wind speed permutationci_wind · angle: direction · other: speed
  • Turtles unrelated permutationci_turtles · angle: heading · other: scattered
  • Degenerate n1ci_wind · angle: direction · other: gust_direction
  • Degenerate constantci_wind · angle: direction · other: gust_direction

In the guides

Where it sits in the decision guides

  • Continuous–continuous: Pearson / Spearman / Kendall · Statistics Guide · C — Test association

What you need

Direction or timenumeric / temporal · 1 column
Angles, clock times, weekdays, months or timestamps.
Second variablenumeric / temporal · 1 column
Another angle in the same units, or an ordinary measurement.

Choices you make

hypothesis

The second variable isdefault circular

Whether the second variable is also an angle (circular–circular) or an ordinary number (circular–linear).

  • Another angle (same units)(default) — Jammalamadaka–SenGupta r between −1 and 1.
  • An ordinary measurement — Mardia's R between 0 and 1: does the measurement vary sinusoidally with the angle?

options

Angles are indefault degrees

How the column measures direction. Timestamps are placed in their daily, weekly or yearly cycle (UTC).

  • Degrees (0–360)(default) — Compass bearings, wind directions, orientations.
  • Radians (0–2π) — Reads values as radians from 0 to 2π; pick it for angles from math libraries.
  • Hours of the day (0–24) — Clock times as decimal hours; 23:30 and 00:30 are an hour apart.
  • Day of the week (1 = Monday … 7) — Reads values as weekdays, 1 = Monday to 7; pick it for weekly cycles.
  • Month (1–12) — December and January are neighbors.
  • Day of the year (1–366) — Reads values as day of the year, 1 to 366; pick it for seasonal cycles.
  • Another cycle (set the period) — Any repeating scale: phase of a 28-day cycle, tide hours …
  • Time of day — Position within the day (UTC).
  • Day and time of the week — Monday 00:00 is the start of the cycle (UTC).
  • Time of year — Fraction of the calendar year (leap years have 366 days).
Value of one full turndefault 28

The scale value that brings you back to the start (e.g. 28 for a 28-day cycle).

Axial data (0° and 180° are the same)default off

Orientations without a head or tail: angles are doubled first.

statistics

p-valuedefault approximate

How the p-value is computed: a large-sample formula, or by permutation or simulation (slower, fewer assumptions).

  • Large-sample(default) — Normal (angle–angle) or χ² on 2 df (angle–linear); fine from about 25 pairs.
  • Permutation — Shuffles the second variable against the angle; reliable for small samples.
Permutationsdefault 9999

Number of random permutations behind the p-value. More gives a more precise p-value; results are seeded.

Checks and remedies

CodeSplash checks each testable assumption on every run and shows the result on the card; premises the data can’t test are marked. If a check fails, these are the ways forward.

  • Independent pairs

    One pair per unit; serially correlated readings (hourly weather) overstate the evidence.

What it reports

  • Tests: The angle is associated with the second variable
n
How many independent units the analysis used; it sets precision and power.
other_type
circular when the second variable is also an angle (angle–angle), linear when it is an ordinary number (angle–linear).
r
A number from −1 to 1 for how closely two variables move together; Pearson measures straight-line association.
p
How surprising your data would be if the null hypothesis were true, as a probability.
z
An estimate in standard-error units, compared with the standard normal distribution.
r2
The share of the outcome's variance explained by the model, from 0 to 1.
statistic
One test of "every component null holds" from several independent tests' p-values.
r_xc
Measurements on a loop — compass bearings, clock times, weekdays, months — where the end meets the start.
r_xs
Measurements on a loop — compass bearings, clock times, weekdays, months — where the end meets the start.
r_cs
Measurements on a loop — compass bearings, clock times, weekdays, months — where the end meets the start.
p_asymptotic
How surprising your data would be if the null hypothesis were true, as a probability.
n_perm
How many independent units the analysis used; it sets precision and power.

Python and R

Python and R agree to 10 decimals (relative tolerance 1e-10). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.

Python

The exact script CodeSplash ran for example “Wind gust direction” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0

# Circular correlation (angle–angle and angle–linear)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method circular.correlation 1.0.1 · spec 211ae55e6629e72e
# Dataset: ci_wind (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import numpy as np
import pandas as pd

import codesplash as cs
from codesplash.errors import check_not_constant
from codesplash.stats import circular

# %% Data
df = pd.read_parquet("tests/parity/fixtures/ci_wind.parquet", columns=["direction", "gust_direction"])
n_input = len(df)
df = df.dropna(subset=["direction", "gust_direction"])  # listwise deletion over the analysis columns
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
    warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
    cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["direction", "gust_direction"])  # infinite values stop the run (registry/errors.yaml)

# %% Angles
# Angles become radians in [0, 2π): numeric values in the chosen unit, or a timestamp's position in its
# daily / weekly / yearly cycle (UTC). Axial data (0° ≡ 180°) are doubled before testing.
units = "degrees"
period = None
disp_units = {"time_of_day": "hours", "day_of_week": "weekday", "day_of_year": "doy"}.get(units, units)
axial = False
a_name = "direction"
theta = circular.angles(df[a_name] if units in circular.CYCLES else df[a_name].to_numpy(dtype=float), units, period)
work = circular.wrap(2.0 * theta) if axial else theta
turn = 2.0 * np.pi * (0.5 if axial else 1.0)
unit_scale = circular.period_of(disp_units, period)[0] / (2.0 * np.pi)  # radians → display units


def show(rad):
    """A direction in the user's units (axial: halved back to the axis)."""
    return float(circular.from_radians(np.mod(rad, turn), disp_units, period))


def lab(rad):
    return circular.label(np.mod(rad, turn), units, period)


chart_angles = circular.from_radians(theta, disp_units, period)  # what the charts draw
chart_controls = {"units": disp_units if disp_units != "custom" else "radians", "orientation": "compass" if disp_units in ("degrees", "hours") else "math"}
if disp_units == "custom":
    chart_angles = theta

# %% Correlation
o_name = "gust_direction"
kind = "circular"
calibration = "approximate"
seed = 42  # shared Wichmann–Hill stream: R draws the same permutations
if kind == "circular":
    other = circular.angles(df[o_name] if units in circular.CYCLES else df[o_name].to_numpy(dtype=float), units, period)
    other_work = circular.wrap(2.0 * other) if axial else other
else:
    other = df[o_name].to_numpy(dtype=float)
    other_work = other
# A correlation needs pairs that vary: 2 pairs for two angles, 3 for an angle and a linear variable.
cs.check_rows(len(work), 2 if kind == "circular" else 3, "A circular correlation")
check_not_constant(theta, a_name)
check_not_constant(other, o_name)
r = circular.correlation(work, other_work, kind=kind, calibration=calibration, n_perm=int(9999), seed=seed)
n = len(work)

# %% Assumptions
assumptions = [{"key": "independence", "label": "Independent pairs", "status": "info", "detail": "One pair of values per unit (no repeated readings)."}]
if n < 25 and calibration != "permutation":
    warnings.append("Fewer than 25 pairs: the large-sample p-value is approximate; use permutation.")

# %% Result
p = r["p"]
if kind == "circular":
    stat, stat_label, symbol = r["r"], "Circular correlation r (Jammalamadaka–SenGupta)", "r"
    test_txt = f"z = {r['z']:.3f}"
else:
    stat, stat_label, symbol = r["r"], "Circular–linear correlation R (Mardia)", "R"
    test_txt = f"nR² = {r['statistic']:.3f} on 2 df"
values = {"n": n, "other_type": kind, "r": r["r"], "p": p, "z": r.get("z"), "r2": r.get("r2"), "statistic": r.get("statistic"),
          "r_xc": r.get("r_xc"), "r_xs": r.get("r_xs"), "r_cs": r.get("r_cs"), "p_asymptotic": r.get("p_asymptotic"), "n_perm": r.get("n_perm")}
how = f"permutation ({r['n_perm']} shuffles, seed {seed})" if calibration == "permutation" else "large-sample"
summary = (f"{'Circular' if kind == 'circular' else 'Circular–linear'} correlation between {a_name} and {o_name} (n = {n}): {symbol} = {stat:.3f} "
           f"({test_txt}, {cs.fmt_p(p)}). " + ("The two are associated." if p < 0.05 else "No evidence of an association."))
if kind == "linear":
    summary += " R is between 0 and 1 and has no sign: it measures how well a sinusoidal pattern in the angle predicts the linear variable."
chart_x = np.asarray(chart_angles)
chart_y = circular.from_radians(other, disp_units, period) if kind == "circular" else other
cs.publish({
    "method": "circular.correlation",
    "methodVersion": "1.0.1",
    "title": "Circular correlation",
    "engine": cs.engine_info("pandas", "numpy", "scipy"),
    "n": n,
    "summary": summary,
    "apa": f"{symbol} = {cs.fmt_num(stat)}, {cs.fmt_p(p)}, n = {n}",
    "statistics": [{"key": "r", "label": stat_label, "value": stat}, {"key": "p", "label": "p", "value": p, "format": "p"}],
    "assumptions": assumptions,
    "warnings": warnings,
    "notes": [f"p-value: {how}."],
    "values": values,
    "charts": [cs.chart("scatter", "scatter", f"{o_name} against {a_name}",
                        {"x": cs.col(a_name, chart_x[:5000], "numeric"), "y": cs.col(o_name, np.asarray(chart_y)[:5000], "numeric")}, {"fit": "none"})],
})
R

The exact script CodeSplash ran for example “Wind gust direction” · R version 4.5.1 (2025-06-13)

# Circular correlation (angle–angle and angle–linear)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method circular.correlation 1.0.1 · spec 211ae55e6629e72e
# Dataset: ci_wind (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ci_wind.parquet", col_select = c("direction", "gust_direction")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("direction", "gust_direction")]), , drop = FALSE]  # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
  warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("direction", "gust_direction"))  # infinite values stop the run (registry/errors.yaml)

# %% Angles
# Angles become radians in [0, 2*pi): numeric values in the chosen unit, or a timestamp's position in
# its daily / weekly / yearly cycle (UTC). Axial data (0° = 180°) are doubled before testing.
units <- "degrees"
period <- NULL
disp_units <- switch(units, time_of_day = "hours", day_of_week = "weekday", day_of_year = "doy", units)
axial <- FALSE
a_name <- "direction"
theta <- cs_circ_angles(df[[a_name]], units, period)
work <- if (axial) cs_circ_wrap(2 * theta) else theta
turn <- 2 * pi * (if (axial) 0.5 else 1)
unit_scale <- (if (disp_units == "custom") period else switch(disp_units, degrees = 360, radians = 2 * pi, hours = 24, weekday = 7, month = 12, doy = 365.25)) / (2 * pi)

show <- function(rad) cs_circ_from_radians(rad %% turn, disp_units, period)
lab <- function(rad) cs_circ_label(rad %% turn, units, period)

chart_angles <- cs_circ_from_radians(theta, disp_units, period)
chart_controls <- list(units = if (disp_units != "custom") disp_units else "radians",
                       orientation = if (disp_units %in% c("degrees", "hours")) "compass" else "math")
if (disp_units == "custom") chart_angles <- theta

# %% Correlation
o_name <- "gust_direction"
kind <- "circular"
calibration <- "approximate"
seed <- 42  # shared Wichmann-Hill stream: Python draws the same permutations
if (kind == "circular") {
  other <- cs_circ_angles(df[[o_name]], units, period)
  other_work <- if (axial) cs_circ_wrap(2 * other) else other
} else {
  other <- as.numeric(df[[o_name]])
  other_work <- other
}
# A correlation needs pairs that vary: 2 pairs for two angles, 3 for an angle and a linear variable.
cs_check_rows(length(work), if (kind == "circular") 2 else 3, "A circular correlation")
cs_check_not_constant(theta, a_name)
cs_check_not_constant(other, o_name)
r <- cs_circ_correlation(work, other_work, kind = kind, calibration = calibration, n_perm = 9999, seed = seed)
n <- length(work)

# %% Assumptions
assumptions <- list(list(key = "independence", label = "Independent pairs", status = "info", detail = "One pair of values per unit (no repeated readings)."))
if (n < 25 && calibration != "permutation") warnings <- c(warnings, "Fewer than 25 pairs: the large-sample p-value is approximate; use permutation.")

# %% Result
p <- r$p
if (kind == "circular") {
  stat <- r$r
  stat_label <- "Circular correlation r (Jammalamadaka–SenGupta)"
  symbol <- "r"
  test_txt <- sprintf("z = %.3f", r$z)
} else {
  stat <- r$r
  stat_label <- "Circular–linear correlation R (Mardia)"
  symbol <- "R"
  test_txt <- sprintf("nR² = %.3f on 2 df", r$statistic)
}
values <- list(n = n, other_type = kind, r = r$r, p = p, z = r$z, r2 = r$r2, statistic = r$statistic,
               r_xc = r$r_xc, r_xs = r$r_xs, r_cs = r$r_cs, p_asymptotic = r$p_asymptotic, n_perm = r$n_perm)
how <- if (calibration == "permutation") sprintf("permutation (%d shuffles, seed %d)", as.integer(r$n_perm), as.integer(seed)) else "large-sample"
summary <- paste0(sprintf("%s correlation between %s and %s (n = %d): %s = %.3f (%s, %s). ", if (kind == "circular") "Circular" else "Circular–linear",
                          a_name, o_name, n, symbol, stat, test_txt, cs_fmt_p(p)),
                  if (p < 0.05) "The two are associated." else "No evidence of an association.")
if (kind == "linear") summary <- paste0(summary, " R is between 0 and 1 and has no sign: it measures how well a sinusoidal pattern in the angle predicts the linear variable.")
chart_x <- chart_angles
chart_y <- if (kind == "circular") cs_circ_from_radians(other, disp_units, period) else other
take <- seq_len(min(n, 5000))
cs_publish(list(
  method = "circular.correlation",
  methodVersion = "1.0.1",
  title = "Circular correlation",
  engine = cs_engine_info("stats", "nanoparquet"),
  n = n,
  summary = summary,
  apa = sprintf("%s = %s, %s, n = %d", symbol, cs_fmt_num(stat), cs_fmt_p(p), n),
  statistics = list(list(key = "r", label = stat_label, value = stat), list(key = "p", label = "p", value = p, format = "p")),
  assumptions = assumptions,
  warnings = warnings,
  notes = list(sprintf("p-value: %s.", how)),
  values = values,
  charts = list(cs_chart("scatter", "scatter", paste(o_name, "against", a_name),
                         list(x = cs_col(a_name, chart_x[take], "numeric"), y = cs_col(o_name, chart_y[take], "numeric")), list(fit = "none")))
))

Sources

  • Jammalamadaka, S. R., & SenGupta, A. (2001). Topics in Circular Statistics. World Scientific, §8.2.
  • Mardia, K. V. (1976). Linear–circular correlation coefficients and rhythmometry. Biometrika, 63, 403–405.
  • Mardia, K. V., & Jupp, P. E. (2000). Directional Statistics. Wiley, §11.2.

From the CodeSplash method registry · circular.correlation v1.0.1.