Skip to content
svgmantel-correlogram

Mantel correlogram

Over what distances are rows more alike (or less alike) than average?

Demo data · seed 20261101 · 10 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read x as distance classes, y as Mantel r in each class.
  2. Filled points are significant.
  3. Positive at short distances and falling suggests rows close together are alike.
  1. Callout 1: At short distances: rows are alike.
  2. Callout 2: No association here.
  3. Callout 3: Hollow: not significant.

Watch out

  • Each class is one test: use the corrected p-values shown.

Defaults

Significance level
0.05
The α below which a point counts as significant.
Range 0.001 to 0.2, step 0.005

Pinned in the code

  • For each distance class the model matrix is 0 for pairs in the class and 1 otherwise, so r > 0 means pairs that close together are more similar than average (positive autocorrelation).
  • Filled points are significant at α after the progressive Bonferroni correction (class c's p times c, kept monotone), reading from the shortest distances outwards.
  • Classes beyond about half the largest distance contain few, edge-biased pairs; read them with care (Legendre & Legendre 2012).
# Mantel correlogram — Codesplash Chart Lab (recipe "mantel-correlogram")
# controls: alpha=0.05
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("mantel-correlogram-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
MID = "distance class (m)"
R = "Mantel r"
P = "progressive p"
PAIRS = "pairs"
ALPHA = 0.05  # filled points: corrected p below α
d = df.dropna(subset=[MID, R]).sort_values(MID)
sig = (d[P] < ALPHA).to_numpy() if P else np.zeros(len(d), bool)
fig, ax = plt.subplots(figsize=(7, 4.5))
ax.axhline(0, color=GREY, linestyle="--", linewidth=1)
ax.plot(d[MID], d[R], color=PALETTE[0], linewidth=1.6)
ax.scatter(d[MID][sig], d[R][sig], s=40, color=PALETTE[0], zorder=3, label=f"significant (p < {ALPHA:g})")
ax.scatter(d[MID][~sig], d[R][~sig], s=40, facecolors="white", edgecolors=REF, zorder=3, label="not significant")
if PAIRS:  # how many pairs each class holds (few pairs: read with care)
    for xv, yv, nv in zip(d[MID], d[R], d[PAIRS]):
        ax.annotate(f"{nv:.0f}", (xv, yv), xytext=(0, 7), textcoords="offset points", ha="center", fontsize=7, color=REF)
lim = max(0.05, d[R].abs().max()) * 1.15
ax.set_ylim(-lim, lim)
ax.set_xlabel(MID)
ax.set_ylabel("Mantel r")
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads mantel-correlogram-demo.csv · app theme from the optional codesplash helper