svgqr-process
Quantile process
Does a predictor's effect change across the outcome's distribution?
How to read it
- Read one panel per predictor; the x axis is the quantile τ.
- Compare the line with the dashed OLS estimate.
- A rising line means the predictor's effect is stronger in the upper part of the outcome.
- Callout 1: The coefficient at low quantiles.
- Callout 2: It grows across quantiles here.
- Callout 3: Dashed lines: the OLS estimate and interval.
Watch out
- Extreme quantiles have wide bands with few rows: don't over-read their ends.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing inferential.
- One panel per term (up to six); bands are the engine's pointwise intervals (nid / kernel SEs or the rank inversion), not simultaneous bands.
- A flat process inside the OLS band means the predictor shifts the whole distribution; a slope means it changes the spread or shape.
# Quantile process — Codesplash Chart Lab (recipe "qr-process")
# 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("qr-process-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["term"] = pd.Categorical(df["term"].astype("string"), categories=["income", "household size"])
_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")
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
T = "tau"
E = "coefficient"
LO = "low"
HI = "high"
TERM = "term"
O = "OLS"
OL = "OLS low"
OH = "OLS high"
d = df.dropna(subset=[T, E])
terms = levels_of(d[TERM])[:6] if TERM else [None]
cols = 1 if len(terms) <= 1 else 2 if len(terms) <= 4 else 3
rows = int(np.ceil(len(terms) / cols))
fig, axes = plt.subplots(rows, cols, figsize=(4.2 * cols, 3 * rows), squeeze=False)
for ax, term in zip(axes.flat, terms):
s = (d[d[TERM].astype(str) == str(term)] if TERM else d).sort_values(T)
if LO and HI:
ax.fill_between(s[T], s[LO], s[HI], color=PALETTE[0], alpha=0.18, lw=0)
ax.plot(s[T], s[E], color=PALETTE[0], marker="o", markersize=3)
if O and s[O].notna().any():
ax.axhline(s[O].dropna().iloc[0], color=REF, linestyle="--")
if OL and OH:
ax.axhline(s[OL].dropna().iloc[0], color=REF, linestyle=":")
ax.axhline(s[OH].dropna().iloc[0], color=REF, linestyle=":")
ax.axhline(0, color=GREY, linewidth=0.8)
ax.set_title(str(term) if term is not None else E, fontsize=9, loc="left")
ax.set_xlabel("quantile τ")
for ax in list(axes.flat)[len(terms):]:
ax.set_visible(False)
plt.show()Needs pandas, numpy, matplotlib · reads qr-process-demo.csv · app theme from the optional codesplash helper
# Quantile process — Codesplash Chart Lab (recipe "qr-process")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
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("qr-process-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["term"] = pd.Categorical(df["term"].astype("string"), categories=["income", "household size"])
_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")
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
T = "tau"
E = "coefficient"
LO = "low"
HI = "high"
TERM = "term"
O = "OLS"
OL = "OLS low"
OH = "OLS high"
d = df.dropna(subset=[T, E])
terms = levels_of(d[TERM])[:6] if TERM else [None]
cols = 1 if len(terms) <= 1 else 2 if len(terms) <= 4 else 3
rows = int(np.ceil(len(terms) / cols))
fig = make_subplots(rows=rows, cols=cols, subplot_titles=[str(t) for t in terms])
for i, term in enumerate(terms):
r, cc = i // cols + 1, i % cols + 1
s = (d[d[TERM].astype(str) == str(term)] if TERM else d).sort_values(T)
if LO and HI:
fig.add_scatter(x=np.r_[s[T], s[T][::-1]], y=np.r_[s[HI], s[LO][::-1]], fill="toself", mode="none", fillcolor="rgba(8, 89, 172, 0.18)", showlegend=False, row=r, col=cc)
fig.add_scatter(x=s[T], y=s[E], mode="lines+markers", line_color=PALETTE[0], showlegend=False, row=r, col=cc)
if O and s[O].notna().any():
fig.add_hline(y=float(s[O].dropna().iloc[0]), line_dash="dash", line_color=REF, row=r, col=cc)
fig.show()Needs pandas, numpy, plotly · reads qr-process-demo.csv · app theme from the optional codesplash helper
# Quantile process — Codesplash Chart Lab (recipe "qr-process")
# 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("qr-process-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["term"]] <- factor(df[["term"]], levels = c("income", "household size"))
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
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
t_col <- "tau"
e_col <- "coefficient"
lo_col <- "low"
hi_col <- "high"
term_col <- "term"
o_col <- "OLS"
ol_col <- "OLS low"
oh_col <- "OLS high"
d <- df[!is.na(df[[t_col]]) & !is.na(df[[e_col]]), ]
num_or_na <- function(col) if (is.null(col)) NA_real_ else d[[col]]
d <- data.frame(tau = d[[t_col]], est = d[[e_col]], lo = num_or_na(lo_col), hi = num_or_na(hi_col), ols = num_or_na(o_col),
ols_lo = num_or_na(ol_col), ols_hi = num_or_na(oh_col), term = if (is.null(term_col)) e_col else as.character(d[[term_col]]))
d <- d[d$term %in% head(unique(d$term), 6), ]
d$term <- factor(d$term, levels = unique(d$term))
p <- ggplot(d, aes(tau, est)) +
{ if (!all(is.na(d$lo))) geom_ribbon(aes(ymin = lo, ymax = hi), fill = cs_cat[1], alpha = 0.18) } +
geom_line(colour = cs_cat[1]) + geom_point(colour = cs_cat[1], size = 1) +
{ if (!all(is.na(d$ols))) geom_hline(aes(yintercept = ols), linetype = "dashed", colour = ref_col) } +
{ if (!all(is.na(d$ols_lo))) geom_hline(aes(yintercept = ols_lo), linetype = "dotted", colour = ref_col) } +
{ if (!all(is.na(d$ols_hi))) geom_hline(aes(yintercept = ols_hi), linetype = "dotted", colour = ref_col) } +
geom_hline(yintercept = 0, colour = grey_col) + facet_wrap(~term, scales = "free_y") + labs(x = "quantile τ", y = e_col) + theme_cs
print(p)Needs ggplot2 · reads qr-process-demo.csv · app theme from the optional codesplashr helper