Skip to content
svggwas-qq

QQ plot of p-values (with λ_GC)

Do the p-values of a scan follow the null except for a few real signals, or are they inflated across the board?

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

How to read it

  1. Read the dashed line as what p-values look like when no marker is associated; points on it are null.
  2. Points that follow the line and rise only at the top right are compatible with a few real signals on a calibrated test.
  3. Points that leave the line early and stay above it, with λ_GC well above 1, suggest inflation from structure, relatedness or a mis-specified test.
  1. Callout 1: λ_GC: median χ² relative to the null.
  2. Callout 2: Most markers on the null line.
  3. Callout 3: A few strong signals leave the line at the end.

Watch out

  • λ_GC needs hundreds of mostly null markers; with a handful of markers or a candidate set it means little.
  • A polygenic trait in a large sample raises λ without any structure; LD score regression separates the two, a QQ plot cannot.

Defaults

λ_GC from the method
0
The engine's λ_GC to show; 0 estimates it from the p-values drawn (median χ²₁ over 0.4549).
Range 0 to 100, step 0.001
95% band
On
Pointwise 95% range of each ordered p under the null, from Beta(i, n − i + 1).

Pinned in the code

  • Draws the genetics method's published numbers as given (codesplash ≡ codesplashr); only the labelled reference curves are computed for display.
  • Expected p-values are R's ppoints(n): (i − a)/(n + 1 − 2a) with a = 3/8 for n ≤ 10 and ½ otherwise; p outside (0, 1] is left out.
  • λ_GC = median of the χ²₁ upper quantiles of p, divided by qchisq(0.5, 1) = 0.4549 (Devlin & Roeder 1999); a λ given by the method is shown as given.
  • The band holds the i-th smallest of n uniform p-values with 95% probability (Beta(i, n − i + 1)); it is pointwise, not simultaneous. Above 400 p-values it is evaluated at log-spaced ranks.

Use with care

Research use only: genotype charts describe a sample; they are not a clinical or diagnostic result.

# QQ plot of p-values (with λ_GC) — Codesplash Chart Lab (recipe "gwas-qq")
# controls: lambda=0, band=true
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats

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("gwas-qq-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")
P = "p"
LAMBDA, BAND = 0, True  # λ_GC from the method (0 = estimate from these p-values), 95% band
p = pd.to_numeric(df[P], errors="coerce")
p = np.sort(p[(p > 0) & (p <= 1)].to_numpy())
n = len(p)
a = 3 / 8 if n <= 10 else 0.5
e = (np.arange(1, n + 1) - a) / (n + 1 - 2 * a)  # R's ppoints(n)
lam = LAMBDA if LAMBDA > 0 else np.median(stats.chi2.isf(p, 1)) / stats.chi2.ppf(0.5, 1)  # Devlin & Roeder (1999)
i = np.arange(1, n + 1)
band_lo, band_hi = -np.log10(stats.beta.ppf(0.975, i, n - i + 1)), -np.log10(stats.beta.ppf(0.025, i, n - i + 1))  # every rank (the app samples ranks above 400)
ex, ob = -np.log10(e), -np.log10(p)
fig, ax = plt.subplots(figsize=(6, 6))
if BAND and n:
    ax.fill_between(ex, band_lo, band_hi, color=PALETTE[0], alpha=0.16, linewidth=0, label="95% band")
lim = ex.max() if n else 1
ax.plot([0, lim], [0, lim], color=REF, linestyle="--", linewidth=1, label="expected under the null")
ax.scatter(ex, ob, s=8, color=PALETTE[0], linewidths=0, label="markers")
ax.text(0.03, 0.97, f"λ_GC = {lam:.3f}", transform=ax.transAxes, va="top")
ax.set_xlabel("expected −log₁₀ p")
ax.set_ylabel("observed −log₁₀ p")
ax.set_xlim(0, None)
ax.set_ylim(0, None)
ax.legend(frameon=False, loc="lower right")
plt.show()

Needs pandas, numpy, matplotlib, scipy · reads gwas-qq-demo.csv · app theme from the optional codesplash helper