svgcullen-frey
Cullen–Frey graph
Which distribution families are compatible with the data's skewness and kurtosis?
How to read it
- Find the solid dot: your data's squared skewness and kurtosis.
- Read the shape of the bootstrap cloud for how uncertain that position is.
- See which family's point, line or region the cloud falls on.
- Callout 1: Your data.
- Callout 2: Bootstrap cloud: how much the position could vary.
- Callout 3: Named points: where exact families sit.
Watch out
- Moments are noisy in small samples, and many families can fit. Check with a fit overlay.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Moments are the engine's unbiased sample skewness and kurtosis (kurtosis on the raw scale: normal = 3), as in fitdistrplus::descdist.
- Theory is exact: normal (0, 3), uniform (0, 1.8), exponential (4, 9), logistic (0, 4.2); gamma on β₂ = 3 + 1.5 β₁; lognormal traced by σ; beta between β₂ = β₁ + 1 and the gamma line.
- Kurtosis increases downward (the classical orientation). Bootstrap points show how uncertain the observed moments are.
# Cullen–Frey graph — Codesplash Chart Lab (recipe "cullen-frey")
# controls: defaults
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("cullen-frey-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["observed", "bootstrap"])
_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")
S = "skewness²"
K = "kurtosis"
KIND = "kind"
d = df.dropna(subset=[S, K]).rename(columns={S: "s", K: "k"})
boot = d[KIND].astype(str).str.contains("boot", case=False) if KIND else pd.Series(False, index=d.index)
obs, bs = d[~boot], d[boot]
x_max = max(4.0, np.ceil(obs["s"].max() * 1.25)) if len(obs) else 4.0
y_max = max(10.0, np.ceil(max(obs["k"].max() if len(obs) else 0, 3 + 1.5 * min(x_max, obs["s"].max() if len(obs) else 0)) * 1.15))
sig = np.arange(0.02, 3, 0.01)
w = np.exp(sig ** 2)
ln_s, ln_k = (w + 2) ** 2 * (w - 1), w ** 4 + 2 * w ** 3 + 3 * w ** 2 - 3 # lognormal (β1, β2)
keep = ln_s <= x_max
theory = {"normal": (0, 3), "uniform": (0, 1.8), "exponential": (4, 9), "logistic": (0, 4.2)}
fig, ax = plt.subplots(figsize=(8, 5))
ax.fill([0, x_max, x_max, 0], [1, x_max + 1, 3 + 1.5 * x_max, 3], color="#19966e", alpha=0.12, lw=0, label="beta")
ax.plot([0, x_max], [3, 3 + 1.5 * x_max], color=PALETTE[0], label="gamma")
ax.plot(ln_s[keep], ln_k[keep], color=PALETTE[1], linestyle="--", label="lognormal")
for name, (sx, kx) in theory.items():
ax.scatter(sx, kx, marker="^", s=60, facecolors="none", edgecolors=REF)
ax.annotate(name, (sx, kx), xytext=(-6 if sx > 0.8 * x_max else 6, 0), textcoords="offset points", ha="right" if sx > 0.8 * x_max else "left", va="center", fontsize=8)
ax.scatter(bs["s"], bs["k"], s=10, facecolors="none", edgecolors=GREY, label="bootstrap")
ax.scatter(obs["s"], obs["k"], s=50, color=plt.rcParams["text.color"], zorder=3, label="observed")
ax.set_xlim(0, x_max)
ax.set_ylim(y_max, 1) # kurtosis increases downward (Cullen & Frey)
ax.set_xlabel("square of skewness")
ax.set_ylabel("kurtosis (normal = 3)")
ax.legend(fontsize=8, loc="lower left")
plt.show()Needs pandas, numpy, matplotlib · reads cullen-frey-demo.csv · app theme from the optional codesplash helper
# Cullen–Frey graph — Codesplash Chart Lab (recipe "cullen-frey")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
df = pd.read_csv("cullen-frey-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["observed", "bootstrap"])
_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")
S = "skewness²"
K = "kurtosis"
KIND = "kind"
d = df.dropna(subset=[S, K]).rename(columns={S: "s", K: "k"})
boot = d[KIND].astype(str).str.contains("boot", case=False) if KIND else pd.Series(False, index=d.index)
obs, bs = d[~boot], d[boot]
x_max = max(4.0, np.ceil(obs["s"].max() * 1.25)) if len(obs) else 4.0
y_max = max(10.0, np.ceil(max(obs["k"].max() if len(obs) else 0, 3 + 1.5 * min(x_max, obs["s"].max() if len(obs) else 0)) * 1.15))
sig = np.arange(0.02, 3, 0.01)
w = np.exp(sig ** 2)
ln_s, ln_k = (w + 2) ** 2 * (w - 1), w ** 4 + 2 * w ** 3 + 3 * w ** 2 - 3 # lognormal (β1, β2)
keep = ln_s <= x_max
theory = {"normal": (0, 3), "uniform": (0, 1.8), "exponential": (4, 9), "logistic": (0, 4.2)}
fig = go.Figure()
fig.add_scatter(x=[0, x_max, x_max, 0, 0], y=[1, x_max + 1, 3 + 1.5 * x_max, 3, 1], fill="toself", mode="none", fillcolor="rgba(25, 150, 110, 0.12)", name="beta")
fig.add_scatter(x=[0, x_max], y=[3, 3 + 1.5 * x_max], mode="lines", line_color=PALETTE[0], name="gamma")
fig.add_scatter(x=ln_s[keep], y=ln_k[keep], mode="lines", line=dict(color=PALETTE[1], dash="dash"), name="lognormal")
fig.add_scatter(x=[v[0] for v in theory.values()], y=[v[1] for v in theory.values()], mode="markers+text", text=list(theory), textposition="middle right", marker=dict(symbol="triangle-up-open", size=11, color=REF), name="theory")
fig.add_scatter(x=bs["s"], y=bs["k"], mode="markers", marker=dict(symbol="circle-open", size=5, color=GREY), name="bootstrap")
fig.add_scatter(x=obs["s"], y=obs["k"], mode="markers", marker=dict(size=11, color=REF), name="observed")
fig.update_xaxes(range=[0, x_max], title="square of skewness")
fig.update_yaxes(range=[y_max, 1], title="kurtosis (normal = 3)")
fig.show()Needs pandas, numpy, plotly · reads cullen-frey-demo.csv · app theme from the optional codesplash helper
# Cullen–Frey graph — Codesplash Chart Lab (recipe "cullen-frey")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("cullen-frey-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["kind"]] <- factor(df[["kind"]], levels = c("observed", "bootstrap"))
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
s_col <- "skewness²"
k_col <- "kurtosis"
kind_col <- "kind"
d <- df[!is.na(df[[s_col]]) & !is.na(df[[k_col]]), ]
boot <- if (is.null(kind_col)) rep(FALSE, nrow(d)) else grepl("boot", as.character(d[[kind_col]]), ignore.case = TRUE)
d <- data.frame(s = d[[s_col]], k = d[[k_col]], boot = boot)
obs <- d[!d$boot, ]
x_max <- max(4, ceiling(max(c(0, obs$s)) * 1.25))
y_max <- max(10, ceiling(max(c(0, obs$k), 3 + 1.5 * min(x_max, max(c(0, obs$s)))) * 1.15))
w <- exp(seq(0.02, 3, by = 0.01)^2)
ln <- data.frame(s = (w + 2)^2 * (w - 1), k = w^4 + 2 * w^3 + 3 * w^2 - 3) # lognormal (β1, β2)
ln <- ln[ln$s <= x_max, ]
th <- data.frame(name = c("normal", "uniform", "exponential", "logistic"), s = c(0, 0, 4, 0), k = c(3, 1.8, 9, 4.2))
p <- ggplot() +
annotate("polygon", x = c(0, x_max, x_max, 0), y = c(1, x_max + 1, 3 + 1.5 * x_max, 3), fill = "#19966e", alpha = 0.12) +
annotate("segment", x = 0, xend = x_max, y = 3, yend = 3 + 1.5 * x_max, colour = cs_cat[1]) +
geom_line(data = ln, aes(s, k), colour = cs_cat[2], linetype = "dashed") +
geom_point(data = th, aes(s, k), shape = 2, size = 2.5, colour = ref_col) +
geom_text(data = th, aes(s, k, label = name), hjust = ifelse(th$s > 0.8 * x_max, 1.2, -0.2), size = 3) +
geom_point(data = d[d$boot, ], aes(s, k), shape = 1, size = 1, colour = grey_col) +
geom_point(data = obs, aes(s, k), size = 3) +
scale_y_reverse(limits = c(y_max, 1)) + coord_cartesian(xlim = c(0, x_max)) + # kurtosis increases downward
labs(x = "square of skewness", y = "kurtosis (normal = 3)") + theme_cs
print(p)Needs ggplot2 · reads cullen-frey-demo.csv · app theme from the optional codesplashr helper