Skip to content

Rare variants: burden, SKAT and SKAT-O

A single rare variant has little power, so these tests pool a gene's variants. See when pooling cancels out, and how SKAT-O adapts without cheating.

Advanced ~15 min12 steps

What runs in CodeSplash

You will be able to

  • Explain why burden tests lose power when effects point in different directions
  • Say how SKAT avoids that problem, and what it gives up
  • Explain why SKAT-O's p-value is larger than its smallest grid p-value

Read first

01

Too rare to test alone

Read

A variant carried by a handful of people can't reach significance by itself. So you test a set of variants together, usually a gene.

Two questions shape the test:

  • How much does each variant count?
  • Do you expect the effects to share a direction?

This lesson uses hand arithmetic and a run we did ourselves. The last step runs all three tests in CodeSplash.

02

Weights

Read

Rarer variants are given more weight, on the theory that harmful ones stay rare. A common choice is a Beta(1, 25) density at the variant's minor allele frequency:

w(0.01)=25×0.9924≈19.6,w(0.15)=25×0.8524≈0.5w(0.01) = 25 \times 0.99^{24} \approx 19.6, \qquad w(0.15) = 25 \times 0.85^{24} \approx 0.5

A variant at 1% counts about forty times as much as one at 15%. That's a modeling choice, so report it.

03

Burden: add them up

Read

A burden testBurden testAdds a person's rare alleles in a gene into one weighted score and tests that score's association with the outcome. gives each person one score, a weighted count of their rare alleles, and regresses the outcome on it:

Bi=∑jwjGij,g(E[Yi])=XiTβ+γBiB_i = \sum_j w_j G_{ij}, \qquad g(E[Y_i]) = X_i^T\beta + \gamma B_i

Then it tests γ=0\gamma = 0 on one degree of freedom. This has good power if most variants push the same way.

04

When effects disagree

Predict

Predict first

A gene has four rare variants with equal weight. Two raise a trait and two lower it, by the same amount.

The score for variant jj is Sj=∑iGijriS_j = \sum_i G_{ij} r_i, using residuals rir_i from the null model. Here S=(4,4,−4,−4)S = (4, 4, -4, -4). The burden statistic works with the sum of the scores.

What happens?

Burden finds it easilyBurden misses itBurden gives the wrong sign
Reveal

Burden misses it: 4+4−4−4=04 + 4 - 4 - 4 = 0. The opposite effects cancel in the sum, however strong each one is.

05

SKAT: add the squares

Read

SKATSKATTests a set of variants using a weighted sum of squared variant scores, so opposite effects don't cancel. squares each score first, so signs can't cancel:

Q=∑jwj2Sj2=(y−μ^)TGW2GT(y−μ^)Q = \sum_j w_j^2 S_j^2 = (y - \hat\mu)^T G W^2 G^T (y - \hat\mu)

For those four scores, ∑Sj2=16×4=64\sum S_j^2 = 16 \times 4 = 64.

But QQ isn't chi-square with one degree of freedom per variant. Under the null it is a weighted mixture of chi-squares, which the SKAT package evaluates with Davies' method.

What SKAT gives up: when all effects really do share a direction, a burden test is usually stronger.

06

Which should you use?

Reflect

You don't know yet whether a gene's variants act in one direction. You could run both tests and quote the better p-value.

Why is that a problem? What would you need to change so that a search over both tests stays honest?

07

SKAT-O

Read

SKAT-OSKAT-OSearches a grid between SKAT and the burden test, then adjusts its p-value for that search. blends the two with a parameter ρ\rho: ρ=0\rho = 0 is SKAT, and ρ=1\rho = 1 is the burden test.

Qρ=(1−ρ)QSKAT+ρQburden,T=min⁡ρpρQ_\rho = (1 - \rho) Q_{\text{SKAT}} + \rho Q_{\text{burden}}, \qquad T = \min_\rho p_\rho

It takes the smallest p-value over a grid, then adjusts for having searched. So the smallest grid p-value is not the SKAT-O p-value.

09

One run, three answers

Predict

Predict first

We ran the guide's R script with the SKAT package: 200 people, 12 variants, Beta(1, 25) weights, and no genetic effect in the simulation. We then added the burden and SKAT-O calls.

The grid runs from SKAT to burden. Where does the adjusted SKAT-O p-value land?

Equal to the smallest grid pLarger than the smallest grid pSmaller than the smallest grid p
Reveal

Larger. With no real effect none of them should stand out, and none does:

SKAT    (rho = 0)        p = 0.366
Burden  (rho = 1)        p = 0.789
Smallest p over the grid p = 0.366
SKAT-O, adjusted         p = 0.554
10

Check your understanding

Checkpoint

Check yourself

Four equally weighted variants have scores S=(6,2,−3,3)S = (6, 2, -3, 3). What is the sum of the scores, which the burden statistic works with?

Show the answer

Answer: 8

6+2−3+3=86 + 2 - 3 + 3 = 8. The −3-3 and the +3+3 cancel. SKAT would use their squares instead.

Check yourself

Which situation favors SKAT over a burden test?

Show the answer

Answer: b

SKAT's squares stop opposite effects canceling. When effects share a direction, a burden test usually has more power, and SKAT-O tries to hedge between the two.

Check yourself

A grid of ρ\rho values gives a smallest unadjusted p of 0.020.02. What can you say about the SKAT-O p-value?

Show the answer

Answer: b

The search is built into the calibration. The adjustment accounts for the correlation between grid points, so it isn't a plain Bonferroni multiplication.

11

Run it in CodeSplash

In the app

Burden, SKAT and SKAT-O are one CodeSplash method, Rare-variant set tests (SKAT, SKAT-O, burden): its Test option picks among them. Run the guide's SKAT-O example here, or open it as a notebook or in the Genetics studio to use your own variants. Genetics methods aren't in Analyze's list.

SKAT-ORecorded · Python and R agreeRecorded 2026-11-17 · 28 values compared · largest relative difference 6.6e-16
R

SKAT-O, 12 variants, N = 200, p = .554

Variants tested
12
Cumulative minor-allele count
379
Q
—
p (SKAT-O)
.554

Assumptions

  • Correct null model — Linear null model with 1 covariate.
  • Unrelated people — Not checkable here: relatives would need a kinship model.
  • Weights and set fixed in advance — Beta(MAF; 1, 25) weights on 12 variants.
  • Enough cases (binary traits) — A continuous trait: not applicable.

SKAT, burden and SKAT-O

TestQp
SKAT (ρ = 0)4173.720.3655
Weighted burden (ρ = 1)260.740.7892
SKAT-O (min over ρ, adjusted)—0.5539

SKAT-O grid

ρQ_ρp_ρ (unadjusted)
04173.720.3655
0.01004134.590.3716
0.04004017.200.3899
0.09003821.550.4206
0.25003195.470.5123
0.50002217.230.6298
1264.650.7889

Variants in the set

VariantAllele countedMAFMinor-allele countRecoded to minorWeight
v01B0.0050222.166
v02B0.0200815.395
v03B0.02501013.616
v04B0.0425178.816
v05B0.0725294.107
v06B0.0600245.663
v07B0.0675274.672
v08B0.1075431.631
v09B0.1175471.245
v10B0.1275510.9469
v11B0.1450580.5823
v12B0.1575630.4089
  • Research use only: not for clinical or diagnostic decisions. Genotypes are personal data.
  • Q follows a mixture of 1-df chi-squares (eigenvalues of the weighted score covariance); a χ² with one df per variant would be wrong.
  • SKAT-O's smallest grid p was 0.3655 at ρ = 0; the SKAT-O p-value accounts for searching the grid, so it is larger.
The exact R script · R R version 4.5.1 (2025-06-13)
# Rare-variant set tests (SKAT, SKAT-O, burden)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method genetics.setassoc 1.0.1 · spec 78ba3c357337b47f
# Dataset: ge_skat_guide (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # cs_gen_* (genotypes, design), cs_skat_* (SKAT, burden, SKAT-O; Wu et al. 2011, Lee et al. 2012)

# %% Data (no rows dropped here: genotype no-calls and missing values are handled by the analysis)
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ge_skat_guide.parquet", col_select = c("y", "age", "v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12")))
n_input <- nrow(df)
warnings <- list()
research_note <- "Research use only: not for clinical or diagnostic decisions. Genotypes are personal data."

# %% People: trait and covariates (people missing either are left out; genotype no-calls stay)
outcome <- "y"
covariates <- c("age")
variants <- c("v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12")
kinds <- list(
  "y" = "numeric",
  "age" = "numeric",
  "v01" = "numeric",
  "v02" = "numeric",
  "v03" = "numeric",
  "v04" = "numeric",
  "v05" = "numeric",
  "v06" = "numeric",
  "v07" = "numeric",
  "v08" = "numeric",
  "v09" = "numeric",
  "v10" = "numeric",
  "v11" = "numeric",
  "v12" = "numeric"
)
keep <- stats::complete.cases(df[c(outcome, covariates)])
n_left <- sum(!keep)
if (n_left > 0) warnings <- c(warnings, sprintf("%d of %d people were left out because the trait or a covariate was missing.", n_left, n_input))
df <- df[keep, , drop = FALSE]
if (nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c(outcome, covariates))  # infinite values stop the run (registry/errors.yaml)
y <- as.numeric(df[[outcome]])
des <- cs_gen_design(df[covariates], kinds, length(y))
x <- des$x
x_names <- des$names
# Each test fits the covariates and one marker and needs at least one residual degree of freedom.
if (length(y) < ncol(x) + 2) cs_error("CS_E_TOO_FEW_ROWS", what = "The association test", min = ncol(x) + 2, n = length(y))
if (all(y == y[1])) cs_error("CS_E_CONSTANT", column = outcome)
outcome_type <- "auto"
is01 <- all(y == 0 | y == 1) && length(unique(y)) == 2
if (outcome_type == "auto") outcome_type <- if (is01) "binary" else "continuous"
if (outcome_type == "binary" && !is01) stop(sprintf("A binary trait must hold only 0 and 1, with both present; %s doesn't.", outcome), call. = FALSE)
binary <- outcome_type == "binary"
dm <- cs_gen_dose_matrix(df[variants])
g <- dm$g
counted <- dm$counted
other <- dm$other
test <- "skato"
weights <- "beta"
beta_a <- 1
beta_b <- 25
rho_grid <- cs_skat_rho_grid("adj")
max_missing <- 0.15

# %% Variants: minor-allele coding, no-calls filled with the mean, weights
prep <- cs_skat_prepare(g, max_missing, beta_a, beta_b, weights)
kept <- variants[prep$keep]
if (!length(kept)) cs_error("CS_E_UNDEFINED", what = "The set test", reason = "every variant is monomorphic here or has too many no-calls")
if (prep$n_dropped_missing > 0) {
  warnings <- c(warnings, sprintf("%d variants had more than %.0f%% no-calls and were left out.", as.integer(prep$n_dropped_missing), 100 * max_missing))
}
if (prep$n_monomorphic > 0) warnings <- c(warnings, sprintf("%d variants are monomorphic in these people and were left out.", as.integer(prep$n_monomorphic)))
n_fill <- sum(is.na(g[, prep$keep, drop = FALSE]))
if (n_fill > 0) warnings <- c(warnings, sprintf("%d no-calls were filled with twice the variant's minor-allele frequency.", as.integer(n_fill)))
w_kept <- prep$weights[prep$keep]
maf_kept <- prep$maf[prep$keep]

# %% Tests
r <- cs_skat_set_test(y, x, prep$g, w_kept, binary, rho_grid)
n <- length(y)
label <- switch(test, skat = "SKAT", burden = "weighted burden test", skato = "SKAT-O")
p <- switch(test, skat = r$p_skat, burden = r$p_burden, skato = r$p_skato)
q <- switch(test, skat = r$q_skat, burden = r$q_burden, skato = NA)
cases <- if (binary) as.integer(sum(y)) else NA
if (r$p_skat_method == "liu") warnings <- c(warnings, "The exact mixture tail couldn't be resolved for SKAT, so its p-value uses Liu's moment matching.")

# %% Assumptions
assumptions <- list(
  list(key = "null_model", label = "Correct null model", status = "info",
       detail = paste0(sprintf("%s null model with %d covariate%s", if (binary) "Logistic" else "Linear", length(covariates), if (length(covariates) != 1) "s" else ""),
                       if (!length(covariates)) ": add ancestry principal components if people come from different populations." else ".")),
  list(key = "unrelated", label = "Unrelated people", status = "info", detail = "Not checkable here: relatives would need a kinship model."),
  list(key = "weights_fixed", label = "Weights and set fixed in advance", status = "info",
       detail = paste0(if (weights == "beta") sprintf("Beta(MAF; %s, %s) weights", format(beta_a), format(beta_b)) else "Equal weights", sprintf(" on %d variants.", length(kept))))
)
if (binary) {
  small <- cases < 100 || n - cases < 100
  assumptions[[4]] <- list(key = "sample_size", label = "Enough cases (binary traits)", status = if (small) "warn" else "pass",
                           detail = paste0(sprintf("%d cases and %d controls", cases, n - cases), if (small) ": asymptotic p-values may be anti-conservative here." else "."))
} else {
  assumptions[[4]] <- list(key = "sample_size", label = "Enough cases (binary traits)", status = "info", detail = "A continuous trait: not applicable.")
}

# %% Result
cmac <- sum(prep$mac[prep$keep])
summary <- sprintf("%s of %d variants (cumulative minor-allele count %d) with %s in %d people%s: %s.",
                   label, length(kept), as.integer(cmac), outcome, n, if (binary) sprintf(" (%d cases)", cases) else "", cs_fmt_p(p))
apa <- sprintf("%s, %d variants, N = %d, %s", label, length(kept), n, cs_fmt_p(p))
idx <- match(kept, variants)
variant_rows <- lapply(seq_along(kept), function(i) list(variant = kept[i], counted = counted[idx[i]], maf = maf_kept[i], mac = prep$mac[idx[i]],
                                                       flipped = if (prep$flipped[idx[i]]) "yes" else "", weight = w_kept[i]))
grid_rows <- lapply(seq_along(rho_grid), function(i) list(rho = rho_grid[i], q = r$q_rho[i], p = r$p_rho[i]))
tests <- list(list(test = "SKAT (ρ = 0)", q = r$q_skat, p = r$p_skat),
              list(test = "Weighted burden (ρ = 1)", q = r$q_burden, p = r$p_burden),
              list(test = "SKAT-O (min over ρ, adjusted)", q = NA, p = r$p_skato))
notes <- list(research_note,
              "Q follows a mixture of 1-df chi-squares (eigenvalues of the weighted score covariance); a χ² with one df per variant would be wrong.",
              sprintf("SKAT-O's smallest grid p was %s at ρ = %s; the SKAT-O p-value accounts for searching the grid, so it is larger.",
                      formatC(r$p_min, digits = 4, format = "g"), format(r$rho_best)))
result_values <- list(
  n = n, n_variants_input = length(variants), n_variants = length(kept), n_dropped_missing = prep$n_dropped_missing,
  n_monomorphic = prep$n_monomorphic, n_flipped = sum(prep$flipped & prep$keep), cmac = cmac, outcome_type = outcome_type,
  test = test, test_label = label, p = p, q = q, p_skat = r$p_skat, q_skat = r$q_skat, p_skat_liu = r$p_skat_liu,
  p_skat_method = r$p_skat_method, p_burden = r$p_burden, q_burden = r$q_burden, p_skato = r$p_skato, p_min = r$p_min,
  rho_best = r$rho_best, rho = I(rho_grid), p_rho = I(r$p_rho), q_rho = I(r$q_rho), maf = I(unname(maf_kept)), weight = I(unname(w_kept)),
  s2 = r$s2, n_covariates = length(covariates)
)
cs_publish(list(
  method = "genetics.setassoc",
  methodVersion = "1.0.1",
  title = label,
  engine = cs_engine_info("stats", "nanoparquet"),
  n = n,
  summary = summary,
  apa = apa,
  statistics = list(
    list(key = "n_variants", label = "Variants tested", value = length(kept)),
    list(key = "cmac", label = "Cumulative minor-allele count", value = cmac),
    list(key = "q", label = "Q", value = q),
    list(key = "p", label = sprintf("p (%s)", label), value = p, format = "p")
  ),
  tables = list(
    list(key = "tests", title = "SKAT, burden and SKAT-O",
         columns = list(list(key = "test", label = "Test", type = "string"), list(key = "q", label = "Q", type = "number"), list(key = "p", label = "p", type = "p")),
         rows = tests),
    list(key = "rho_grid", title = "SKAT-O grid",
         columns = list(list(key = "rho", label = "ρ", type = "number"), list(key = "q", label = "Q_ρ", type = "number"), list(key = "p", label = "p_ρ (unadjusted)", type = "p")),
         rows = grid_rows),
    list(key = "variants", title = "Variants in the set",
         columns = list(list(key = "variant", label = "Variant", type = "string"), list(key = "counted", label = "Allele counted", type = "string"),
                        list(key = "maf", label = "MAF", type = "number"), list(key = "mac", label = "Minor-allele count", type = "number"),
                        list(key = "flipped", label = "Recoded to minor", type = "string"), list(key = "weight", label = "Weight", type = "number")),
         rows = variant_rows)
  ),
  assumptions = assumptions,
  warnings = warnings,
  notes = notes,
  charts = list(),
  values = result_values
))
Python

SKAT-O, 12 variants, N = 200, p = .554

Variants tested
12
Cumulative minor-allele count
379
Q
—
p (SKAT-O)
.554

Assumptions

  • Correct null model — Linear null model with 1 covariate.
  • Unrelated people — Not checkable here: relatives would need a kinship model.
  • Weights and set fixed in advance — Beta(MAF; 1, 25) weights on 12 variants.
  • Enough cases (binary traits) — A continuous trait: not applicable.

SKAT, burden and SKAT-O

TestQp
SKAT (ρ = 0)4173.720.3655
Weighted burden (ρ = 1)260.740.7892
SKAT-O (min over ρ, adjusted)—0.5539

SKAT-O grid

ρQ_ρp_ρ (unadjusted)
04173.720.3655
0.01004134.590.3716
0.04004017.200.3899
0.09003821.550.4206
0.25003195.470.5123
0.50002217.230.6298
1264.650.7889

Variants in the set

VariantAllele countedMAFMinor-allele countRecoded to minorWeight
v01B0.0050222.166
v02B0.0200815.395
v03B0.02501013.616
v04B0.0425178.816
v05B0.0725294.107
v06B0.0600245.663
v07B0.0675274.672
v08B0.1075431.631
v09B0.1175471.245
v10B0.1275510.9469
v11B0.1450580.5823
v12B0.1575630.4089
  • Research use only: not for clinical or diagnostic decisions. Genotypes are personal data.
  • Q follows a mixture of 1-df chi-squares (eigenvalues of the weighted score covariance); a χ² with one df per variant would be wrong.
  • SKAT-O's smallest grid p was 0.3655 at ρ = 0; the SKAT-O p-value accounts for searching the grid, so it is larger.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Rare-variant set tests (SKAT, SKAT-O, burden)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method genetics.setassoc 1.0.1 · spec 78ba3c357337b47f
# Dataset: ge_skat_guide (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import math

import numpy as np
import pandas as pd

import codesplash as cs
from codesplash.stats import genetics as gen  # genotype parsing, design matrix (twins of cs_gen_*)
from codesplash.stats import genetics_skat as skat  # SKAT, burden, SKAT-O (Wu et al. 2011; Lee et al. 2012; twins of cs_skat_*)

# %% Data (no rows dropped here: genotype no-calls and missing values are handled by the analysis)
df = pd.read_parquet("tests/parity/fixtures/ge_skat_guide.parquet", columns=["y", "age", "v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12"])
n_input = len(df)
warnings = []
research_note = "Research use only: not for clinical or diagnostic decisions. Genotypes are personal data."

# %% People: trait and covariates (people missing either are left out; genotype no-calls stay)
outcome = "y"
covariates = ["age"]
variants = ["v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12"]
kinds = {"age":"numeric","v01":"numeric","v02":"numeric","v03":"numeric","v04":"numeric","v05":"numeric","v06":"numeric","v07":"numeric","v08":"numeric","v09":"numeric","v10":"numeric","v11":"numeric","v12":"numeric","y":"numeric"}
keep = df[[outcome] + covariates].notna().all(axis=1).to_numpy()
n_left = int((~keep).sum())
if n_left:
    warnings.append(f"{n_left} of {n_input} people were left out because the trait or a covariate was missing.")
df = df[keep].reset_index(drop=True)
if not len(df):
    cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, [outcome] + covariates)  # infinite values stop the run (registry/errors.yaml)
y = df[outcome].astype(float).to_numpy()
x, x_names = gen.design({c: df[c].to_numpy() for c in covariates}, kinds, len(y))
# Each test fits the covariates and one marker and needs at least one residual degree of freedom.
if len(y) < x.shape[1] + 2:
    cs.cs_error("CS_E_TOO_FEW_ROWS", what="The association test", min=x.shape[1] + 2, n=len(y))
if np.all(y == y[0]):
    cs.cs_error("CS_E_CONSTANT", column=outcome)
outcome_type = "auto"
is01 = bool(np.all((y == 0) | (y == 1))) and len(np.unique(y)) == 2
if outcome_type == "auto":
    outcome_type = "binary" if is01 else "continuous"
if outcome_type == "binary" and not is01:
    raise ValueError(f"A binary trait must hold only 0 and 1, with both present; {outcome} doesn't.")
binary = outcome_type == "binary"
g, counted, other = gen.dose_matrix({v: df[v].to_numpy() for v in variants})
test = "skato"
weights = "beta"
beta_a, beta_b = float(1), float(25)
rho_grid = skat.RHO_ADJ if "adj" == "adj" else skat.RHO_EVEN
max_missing = float(0.15)

# %% Variants: minor-allele coding, no-calls filled with the mean, weights
prep = skat.prepare(g, max_missing, beta_a, beta_b, weights)
kept = [v for v, k in zip(variants, prep["keep"]) if k]
if not kept:
    cs.cs_error("CS_E_UNDEFINED", what="The set test", reason="every variant is monomorphic here or has too many no-calls")
if prep["n_dropped_missing"]:
    warnings.append(f"{prep['n_dropped_missing']} variants had more than {max_missing:.0%} no-calls and were left out.")
if prep["n_monomorphic"]:
    warnings.append(f"{prep['n_monomorphic']} variants are monomorphic in these people and were left out.")
n_fill = int(np.sum(np.isnan(g[:, prep["keep"]])))
if n_fill:
    warnings.append(f"{n_fill} no-calls were filled with twice the variant's minor-allele frequency.")
w_kept = prep["weights"][prep["keep"]]
maf_kept = prep["maf"][prep["keep"]]

# %% Tests
r = skat.set_test(y, x, prep["g"], w_kept, binary, rho_grid)
n = len(y)
label = {"skat": "SKAT", "burden": "weighted burden test", "skato": "SKAT-O"}[test]
p = {"skat": r["p_skat"], "burden": r["p_burden"], "skato": r["p_skato"]}[test]
q = {"skat": r["q_skat"], "burden": r["q_burden"], "skato": None}[test]
cases = int(np.sum(y)) if binary else None
if r["p_skat_method"] == "liu":
    warnings.append("The exact mixture tail couldn't be resolved for SKAT, so its p-value uses Liu's moment matching.")

# %% Assumptions
assumptions = [
    {"key": "null_model", "label": "Correct null model", "status": "info",
     "detail": f"{'Logistic' if binary else 'Linear'} null model with {len(covariates)} covariate{'s' if len(covariates) != 1 else ''}"
               + (": add ancestry principal components if people come from different populations." if not covariates else ".")},
    {"key": "unrelated", "label": "Unrelated people", "status": "info", "detail": "Not checkable here: relatives would need a kinship model."},
    {"key": "weights_fixed", "label": "Weights and set fixed in advance", "status": "info",
     "detail": (f"Beta(MAF; {beta_a:g}, {beta_b:g}) weights" if weights == "beta" else "Equal weights") + f" on {len(kept)} variants."},
]
if binary:
    small = cases < 100 or n - cases < 100
    assumptions.append({"key": "sample_size", "label": "Enough cases (binary traits)", "status": "warn" if small else "pass",
                        "detail": f"{cases} cases and {n - cases} controls" + (": asymptotic p-values may be anti-conservative here." if small else ".")})
else:
    assumptions.append({"key": "sample_size", "label": "Enough cases (binary traits)", "status": "info", "detail": "A continuous trait: not applicable."})

# %% Result
summary = (f"{label} of {len(kept)} variants (cumulative minor-allele count {int(np.sum(prep['mac'][prep['keep']]))}) with {outcome} "
           f"in {n} people{f' ({cases} cases)' if binary else ''}: {cs.fmt_p(p)}.")
apa = f"{label}, {len(kept)} variants, N = {n}, {cs.fmt_p(p)}"
variant_rows = [{"variant": v, "counted": counted[variants.index(v)], "maf": float(maf_kept[i]), "mac": float(prep["mac"][variants.index(v)]),
                 "flipped": "yes" if prep["flipped"][variants.index(v)] else "", "weight": float(w_kept[i])} for i, v in enumerate(kept)]
grid_rows = [{"rho": rho_grid[i], "q": r["q_rho"][i], "p": r["p_rho"][i]} for i in range(len(rho_grid))]
tests = [{"test": "SKAT (ρ = 0)", "q": r["q_skat"], "p": r["p_skat"]},
         {"test": "Weighted burden (ρ = 1)", "q": r["q_burden"], "p": r["p_burden"]},
         {"test": "SKAT-O (min over ρ, adjusted)", "q": None, "p": r["p_skato"]}]
notes = [research_note,
         "Q follows a mixture of 1-df chi-squares (eigenvalues of the weighted score covariance); a χ² with one df per variant would be wrong.",
         f"SKAT-O's smallest grid p was {r['p_min']:.4g} at ρ = {r['rho_best']:g}; the SKAT-O p-value accounts for searching the grid, so it is larger."]
values = {
    "n": n, "n_variants_input": len(variants), "n_variants": len(kept), "n_dropped_missing": prep["n_dropped_missing"],
    "n_monomorphic": prep["n_monomorphic"], "n_flipped": int(np.sum(prep["flipped"] & prep["keep"])),
    "cmac": float(np.sum(prep["mac"][prep["keep"]])), "outcome_type": outcome_type, "test": test, "test_label": label,
    "p": p, "q": q, "p_skat": r["p_skat"], "q_skat": r["q_skat"], "p_skat_liu": r["p_skat_liu"], "p_skat_method": r["p_skat_method"],
    "p_burden": r["p_burden"], "q_burden": r["q_burden"], "p_skato": r["p_skato"], "p_min": r["p_min"], "rho_best": r["rho_best"],
    "rho": list(rho_grid), "p_rho": r["p_rho"], "q_rho": r["q_rho"], "maf": maf_kept.tolist(), "weight": w_kept.tolist(),
    "s2": r["s2"], "n_covariates": len(covariates),
}
cs.publish({
    "method": "genetics.setassoc",
    "methodVersion": "1.0.1",
    "title": label,
    "engine": cs.engine_info("pandas", "numpy", "scipy"),
    "n": n,
    "summary": summary,
    "apa": apa,
    "statistics": [
        {"key": "n_variants", "label": "Variants tested", "value": len(kept)},
        {"key": "cmac", "label": "Cumulative minor-allele count", "value": values["cmac"]},
        {"key": "q", "label": "Q", "value": q},
        {"key": "p", "label": f"p ({label})", "value": p, "format": "p"},
    ],
    "tables": [
        {"key": "tests", "title": "SKAT, burden and SKAT-O",
         "columns": [{"key": "test", "label": "Test", "type": "string"}, {"key": "q", "label": "Q", "type": "number"}, {"key": "p", "label": "p", "type": "p"}],
         "rows": tests},
        {"key": "rho_grid", "title": "SKAT-O grid",
         "columns": [{"key": "rho", "label": "ρ", "type": "number"}, {"key": "q", "label": "Q_ρ", "type": "number"}, {"key": "p", "label": "p_ρ (unadjusted)", "type": "p"}],
         "rows": grid_rows},
        {"key": "variants", "title": "Variants in the set",
         "columns": [{"key": "variant", "label": "Variant", "type": "string"}, {"key": "counted", "label": "Allele counted", "type": "string"},
                     {"key": "maf", "label": "MAF", "type": "number"}, {"key": "mac", "label": "Minor-allele count", "type": "number"},
                     {"key": "flipped", "label": "Recoded to minor", "type": "string"}, {"key": "weight", "label": "Weight", "type": "number"}],
         "rows": variant_rows},
    ],
    "assumptions": assumptions,
    "warnings": warnings,
    "notes": notes,
    "charts": [],
    "values": values,
})

This teaching script needs no extra package. It shows the cancellation on a small table. It doesn't give p-values, so use the SKAT package for a real analysis.

Python
import numpy as np
from scipy import stats

G = np.zeros((12, 4))
G[[0, 1], 0] = G[[2, 3], 1] = G[[4, 5], 2] = G[[6, 7], 3] = 1
maf = G.mean(axis=0) / 2
w = stats.beta.pdf(maf, 1, 25)

def show(y):
    r = y - y.mean()
    s = G.T @ r
    print("burden", np.sum(w * s) ** 2, "skat", np.sum((w * s) ** 2))

mixed = np.array([2, 2, 2, 2, -2, -2, -2, -2, 0, 0, 0, 0], float)
same = np.array([2, 2, 2, 2, 2, 2, 2, 2, -4, -4, -4, -4], float)
show(mixed)
show(same)
R
G <- matrix(0, 12, 4)
G[1:2, 1] <- 1; G[3:4, 2] <- 1; G[5:6, 3] <- 1; G[7:8, 4] <- 1
maf <- colMeans(G) / 2
w <- dbeta(maf, 1, 25)

show <- function(y) {
  r <- y - mean(y)
  s <- as.vector(t(G) %*% r)
  c(burden = sum(w * s)^2, skat = sum((w * s)^2))
}

mixed <- c(2, 2, 2, 2, -2, -2, -2, -2, 0, 0, 0, 0)
same <- c(2, 2, 2, 2, 2, 2, 2, 2, -4, -4, -4, -4)
show(mixed)
show(same)
12

Recap

Recap
  • Burden tests add weighted scores, so opposite effects cancel.
  • SKAT adds squares, so it handles mixed directions, and its null is a mixture of chi-squares.
  • SKAT-O searches between them and adjusts for that search.
  • State your weights and your variant set.

Concepts in this lesson