Tutorials › High-Dimensional Genomic Data Analysis › Phenotype Permutations for GSEA Significance

Gene Set and Pathway Enrichment · Tutorial 465 of 795

Phenotype Permutations for GSEA Significance

See how to recompute gene-level rankings and GSEA enrichment scores under design-appropriate phenotype permutations to assess significance.

Intermediate 12 min read

What You'll Learn

  • State the exchangeability assumption behind phenotype-label permutations.
  • Recompute gene-level statistics, rankings, and enrichment scores for each permutation.
  • Calculate empirical permutation p-values and distinguish exact from Monte Carlo procedures.
  • Restrict permutations appropriately for paired and blocked study designs.
  • Recognize when confounding or too few valid permutations make results unreliable.

Why Permute Phenotype Labels?

A GSEA enrichment score (ES) measures how strongly the genes in a set tend to occur near one end of a ranked gene list. To judge whether an observed ES is unusual, we need a reference distribution representing what could happen when the phenotype labels carry no association with expression. Phenotype permutation constructs that reference by rearranging the sample labels, then repeating the gene-level analysis and GSEA calculation each time.

The important feature is that the whole expression profile for a sample stays together. Permuting labels in this way retains the relationships among genes within each sample, while changing which samples are assigned to each phenotype group. The validity of the resulting null distribution depends on whether those label rearrangements are justified by the study design and null hypothesis.

Definition: Let \(Y_{gi}\) denote the expression measurement for gene \(g\) in sample \(i\), and let \(Z_i\) denote that sample’s phenotype label. A phenotype permutation rearranges the \(Z_i\) labels among samples according to a specified set of allowable rearrangements, leaving each sample’s complete expression profile unchanged. For each rearrangement, recompute the gene-level statistics, ranked list, and gene-set ES.

Assumptions and the Permutation Procedure

The central assumption is exchangeability under the null: under the null hypothesis being tested, the observed labels and the allowed rearrangements of those labels are equally plausible, conditional on the design features that must be preserved. In a completely randomized two-group study, the random assignment of subjects to groups can justify permutations that preserve the group sizes. In an observational study, exchangeability is a substantive assumption; labels are not automatically interchangeable just because the samples are independent.

For example, if all controls were measured in one batch and all treated samples in another, a free shuffle of treatment labels would break the treatment–batch relationship in the observed design. A null distribution built from such shuffles may not represent the uncertainty in the actual study. Likewise, measurements from the same person, family, or matched set are not independent exchangeable sample units. The permutation scheme must reflect those dependencies.

For a two-group comparison, let \(T_g(Z)\) be the gene-level statistic for gene \(g\), calculated using labels \(Z\). It might be a signed test statistic or another statistic chosen for ranking. For the observed labels \(Z^{(0)}\), sort genes by \(T_g(Z^{(0)})\) and calculate the observed ES for a gene set \(S\). Under each allowable permutation \(b\), calculate \(T_g(Z^{(b)})\) for every gene, rank the genes again, and calculate \(ES^{(b)}\). Reusing the observed ranking would fail to represent the effect of the phenotype labels on the enrichment statistic.

1
Specify the valid rearrangements.
Use the study design and null hypothesis to decide which phenotype-label permutations are allowed. Keep group sizes and any required pairing or blocking structure intact.
2
Recalculate gene-level statistics.
For each allowed label arrangement, recompute every gene’s statistic using the same analysis choices as for the observed labels.
3
Rerank and recalculate ES.
Construct a new ranked list from that permutation’s statistics, then compute the ES for each gene set using the same running-sum definition.
4
Compare with the null distribution.
Count how often the permuted ES is at least as extreme as the observed ES in the direction being tested, and report the resulting empirical p-value.

The gene universe, gene-set membership, statistic definition, and any data-processing steps that do not depend on the labels should be held fixed across permutations. If a preprocessing or model-fitting step uses the phenotype labels, it must be repeated within each permutation for the null distribution to reflect that step as well. Ties in gene-level statistics should be handled consistently, using a fixed tie rule or a prespecified randomization rule.

Empirical Significance and a Short Justification

Suppose \(B\) randomly sampled valid permutations are compared with the observed statistic. For a positive observed ES, a one-sided empirical p-value estimates the fraction of the null distribution at least as large as that ES. For a negative observed ES, the corresponding lower tail is used. If the direction was not specified in advance, a two-sided comparison can use absolute ES values, provided that this is the stated testing rule.

$$ \hat{p}_{\mathrm{perm}} = \frac{1 + \sum_{b=1}^{B} I\left(ES^{(b)} \ge ES^{(0)}\right)} {B+1} \quad \text{for a positive, upper-tail test.} $$

Here \(I(\cdot)\) equals 1 when its condition is true and 0 otherwise. The added 1 in the numerator and denominator accounts for the observed arrangement alongside the sampled null arrangements. This convention prevents a Monte Carlo permutation p-value from being zero. If every allowable label arrangement is enumerated, including the observed arrangement, the exact randomization p-value is the proportion of all those arrangements with a statistic at least as extreme as the observed one.

The justification follows directly from exchangeability. Under the null, if the observed labeling and the allowable permuted labelings are equally plausible, the observed statistic has no special position among the statistics produced by those labelings. Therefore, its rank among the null statistics is uniform, apart from ties, and the fraction of arrangements at least as extreme gives a valid tail probability. If exchangeability fails, that rank argument no longer applies; calculating the fraction accurately cannot repair an invalid set of rearrangements.

These p-values measure how often an ES at least this extreme would arise under the specified permutation null. They are not the probability that the null hypothesis is true. They also do not, by themselves, account for testing many gene sets; that is a separate multiple-testing step.

Worked Example: A Small Exact Permutation Test

Consider a hypothetical study with four independent samples, two assigned to each of two conditions. For one gene set, suppose the observed labels produce a positive ES of \(0.667\). The gene-level statistics and ranks are recomputed for each possible assignment of two of the four samples to the first condition. There are \(\binom{4}{2}=6\) assignments, including the observed assignment.

Suppose the six resulting ES values, including the observed value, are \(0.667,\ 0.667,\ 0.333,\ 0.000,\ 0.333,\) and \(-0.333\). The exact upper-tail p-value is the fraction of all six assignments with ES at least \(0.667\):

$$ p_{\mathrm{exact}} = \frac{\#\{ES \ge 0.667\}}{6} = \frac{2}{6} = 0.333. $$

Thus, under this hypothetical design and null, one-third of the allowable assignments produce an ES at least as large as the observed ES. The result is not conventionally small evidence against that permutation null. With only six assignments, the attainable p-values are coarse; the smallest possible exact p-value is \(1/6\).

Respecting Paired and Blocked Designs

When observations are paired, the pair—not an individual sample detached from its partner—is the relevant unit for label rearrangement. For a two-condition paired study, if the null makes the two within-pair labels exchangeable, the labels may be swapped within each pair. This is equivalent to changing the sign of each pair’s condition contrast. With \(m\) pairs, there are at most \(2^m\) such sign patterns. This is not the same as freely shuffling all \(2m\) labels, which would discard the matching structure.

In a blocked design, labels can be rearranged within blocks when the design and null justify doing so. If block \(j\) contains \(n_j\) samples, of which \(k_j\) have the first label, the number of assignments preserving the observed group counts within blocks is \(\prod_j \binom{n_j}{k_j}\). This count also reveals how many distinct arrangements are available. Very small counts limit the resolution of any exact permutation p-value.

Worked Example: Permuting Within Matched Pairs

Suppose a hypothetical study measures expression before and after treatment in three patients. The prespecified analysis uses a signed gene-level statistic based on the within-patient differences. Under a null that justifies swapping the two labels within each patient, there are \(2^3=8\) valid label arrangements. Suppose the observed gene-set ES is \(0.600\), and among the eight arrangements, including the observed one, two have ES at least \(0.600\).

The exact positive-tail p-value is \(2/8=0.250\). The interpretation is that two of the eight allowable within-patient label arrangements produce an ES at least as large as \(0.600\). A permutation that assigns each of the six measurements to either condition without preserving patient pairs would not answer the same design-based question.

The exchangeability condition must still be justified. For example, if the treatment was not randomized and a time trend makes “before” and “after” systematically different under the null of interest, simple within-patient swaps may not be valid. Pairing alone does not guarantee that a label-swap test is appropriate.

Worked Example: Preserving Blocks in a Hypothetical Study

Imagine a randomized experiment with two laboratory batches. Each batch contains four samples, two assigned to treatment and two to control. If assignments are exchangeable within each batch under the null, the valid permutations preserve two treatment labels per batch. Each batch has \(\binom{4}{2}=6\) assignments, so the total number of blocked assignments is \(6 \times 6=36\), including the observed assignment.

Suppose the observed positive ES is \(0.500\), and 5 of the 36 assignments yield an ES at least \(0.500\). The exact upper-tail p-value is:

$$ p_{\mathrm{exact}} = \frac{5}{36} = 0.139. $$

The fraction is calculated from recomputed gene-level statistics and enrichment scores for each of the 36 assignments. If the batch structure were ignored, assignments could move treatment labels between batches and create a reference distribution inconsistent with the design. In an observational data set where treatment and batch are confounded, restricting permutations may not solve the problem: there may be no valid label rearrangements that separate their effects.

Diagnostics, Alternatives, and Limitations

Before interpreting a phenotype-permutation result, check that the permissible rearrangements reflect the experimental or sampling design. Then verify that each permutation regenerates the complete ranking and ES, and inspect how many distinct assignments are available. A large number of repeated random draws does not create more distinct assignments than the design allows. When sampling permutations rather than enumerating them, Monte Carlo uncertainty can also be substantial when \(B\) is small or the tail count is near zero.

ApproachWhat generates the reference distributionKey condition or trade-off
Exact phenotype permutationsAll allowable phenotype-label assignmentsDirectly reflects the specified exchangeability scheme, but can be computationally expensive and may provide coarse p-values when few assignments exist.
Monte Carlo phenotype permutationsA random sample of allowable label assignmentsCan reduce computation, but the empirical tail estimate has simulation uncertainty and depends on sampling valid assignments.
Model-based calibrationA theoretical or fitted null distribution for a statisticCan be useful when label exchangeability is not justified, but depends on the model and its assumptions being adequate.

A phenotype permutation is not a universal remedy for confounding, dependence, or poor study design. If label exchangeability is doubtful, the result should not be presented as design-valid merely because the procedure produced a p-value. Likewise, a small empirical p-value for one set is not a measure of the size or biological importance of its effect. The ES describes the observed ranked-list pattern; the permutation p-value describes its extremeness under the stated null and rearrangement scheme.

Common Mistakes

  • Permuting labels but keeping the observed gene ranking. The ranking depends on the labels, so it must be recalculated for every permutation.
  • Shuffling individual samples in a paired or blocked study. This breaks design structure. Restrict rearrangements to valid swaps or assignments within the relevant units.
  • Assuming observational labels are exchangeable. Independence of samples does not establish exchangeability. Confounding or systematic group differences can invalidate unrestricted permutations.
  • Reporting a zero Monte Carlo p-value. With \(B\) sampled permutations, use the plus-one estimate; for example, zero exceedances gives \(1/(B+1)\), not zero.
  • Treating a phenotype permutation as a causal test by itself. The permutation calculation evaluates a specified null under its design assumptions; it does not establish causality in an observational study.
Key takeaway: A phenotype-permutation GSEA p-value is meaningful only when the allowed label rearrangements are exchangeable under the null. Preserve the study design, recompute gene-level statistics and the ranking for every permutation, and report the empirical tail probability in the context of that null.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. In phenotype permutation, what stays fixed and what must be recalculated for each rearrangement?
  2. A paired study has four pairs. Under a justified within-pair label-swap scheme, how many assignments are available?
  3. In 999 sampled valid permutations, 9 ES values are at least as large as the observed positive ES. Calculate the plus-one empirical p-value.
  4. Why can an unrestricted shuffle of labels be invalid when treatment and laboratory batch are confounded?

Solutions. (1) Each sample’s full expression profile and the fixed gene-set membership stay together; gene-level statistics, the ranked list, and the ES must be recalculated. (2) There are \(2^4=16\) assignments, because each pair can either retain or swap its labels. (3) The estimate is \((1+9)/(999+1)=10/1000=0.0100\). It estimates the upper-tail probability under the specified permutation null. (4) Unrestricted shuffling breaks the observed treatment–batch structure, so the rearrangements may not be equally plausible under the null or represent the study’s assignment mechanism.

Clinical Biostats