Skip to content

limma-voom

limma is one of the oldest and most trusted packages in Bioconductor. It was originally designed for microarray data. The voom transformation extends limma to work with RNA-seq count data. Together they give a fast and flexible route to differential expression.

RNA-seq counts have a specific property: genes with higher expression also have higher variance. This is called the mean-variance relationship. The voom function models this relationship and assigns a precision weight to each observation. limma then uses these weights in its linear model fitting. This approach converts the count data problem into a standard linear modeling problem that limma handles well.

The page runs on the airway dataset that the workflow & the dataset page describes.

The count object comes from Michael Love’s airway 1.32.0 data package, which declares LGPL. It represents the Himes and colleagues experiment, deposited as GSE52778 and SRP033351. The source and license notice identifies the original object. This lesson derives its summaries and analysis results from that object.

library(tidyverse)
library(airway)
library(edgeR)
library(limma)
data("airway")
counts <- assay(airway, "counts")
metadata <- colData(airway) |>
as_tibble(rownames = "sample") |>
select(sample, cell, dex)
# airway ships dex with trt as its first level, so model.matrix would name the
# coefficient dexuntrt and it would measure the comparison backwards. Make untrt
# the reference, which is what the DESeq2 page does too.
metadata$dex <- relevel(factor(metadata$dex), ref = "untrt")
levels(metadata$dex)
[1] "untrt" "trt"

The first step is to create a DGEList object from the edgeR package. This holds the count matrix and sample information together. limma-voom requires this format as input.

dge <- DGEList(
counts = counts,
samples = metadata
)
dim(dge)
[1] 63677 8

The object starts with 63,677 genes and 8 samples.

dge$samples$lib.size
[1] 20637971 18809481 25348649 15163415 24448408 30818215 19126151 21164133

Library sizes vary from about 15 million to 31 million reads across samples. This variation must be accounted for during normalization.

filterByExpr is the edgeR filter that the edgeR page explains. Here it reads the treatment groups rather than the design matrix. Given group, it asks for the cutoff in as many samples as the smallest treatment group holds, a stricter minimum than the one the edgeR page derives from its design, so this page keeps 15,926 genes where edgeR keeps 16,860.

keep <- filterByExpr(dge, group = metadata$dex)
dge <- dge[keep, , keep.lib.sizes = FALSE]
nrow(dge)
[1] 15926

This filter is more aggressive than our DESeq2 filter. It retains 15,926 genes compared to 22,369. The stricter filtering is appropriate because limma benefits from removing noisy low-count genes before the voom transformation.

Trimmed Mean of M-values normalization corrects for composition bias, which the edgeR page explains.

dge <- calcNormFactors(dge, method = "TMM")
dge$samples$norm.factors
[1] 1.0554452 1.0212137 0.9904567 0.9484696 1.0309324 0.9779832 1.0269341
[8] 0.9538599

The factors run from 0.9484696 to 1.0554452, close to the ones the edgeR page computes on its own gene set, so composition differs little between these libraries.

The design matrix encodes the experimental setup. We include cell line and treatment, just as we did in DESeq2.

design <- model.matrix(~ cell + dex, data = metadata)
design
(Intercept) cellN061011 cellN080611 cellN61311 dextrt
1 1 0 0 1 0
2 1 0 0 1 1
3 1 0 0 0 0
4 1 0 0 0 1
5 1 0 1 0 0
6 1 0 1 0 1
7 1 1 0 0 0
8 1 1 0 0 1
attr(,"assign")
[1] 0 1 1 1 2
attr(,"contrasts")
attr(,"contrasts")$cell
[1] "contr.treatment"
attr(,"contrasts")$dex
[1] "contr.treatment"

Each row is a sample. The dextrt column is the coefficient of interest. It will capture the log2 fold change between treated and untreated samples after accounting for cell line differences.

# voom draws the mean-variance trend to the current device, so open a file
# device around it and the figure below is the one this code produced.
dir.create("outputs", showWarnings = FALSE, recursive = TRUE)
png("outputs/limma-voom-plot.png", width = 800, height = 600)
v <- voom(dge, design, plot = TRUE)
invisible(dev.off())

The voom function does three things:

  1. Converts counts to log-counts-per-million values.
  2. Estimates the mean-variance trend from the data.
  3. Computes precision weights for each observation based on the trend.

voom mean-variance plot showing the relationship between mean expression and variance

The voom plot shows the mean-variance trend. Each point is a gene. The x-axis is the average log2 count of the gene, which voom labels log2( count size + 0.5 ). The y-axis is the square root of the residual standard deviation. The red line is the fitted trend. Low-expression genes have higher variance. The trend flattens out for highly expressed genes. This curve is used to assign precision weights.

limma fits the model in two steps. First, lmFit fits a linear model for each gene using the voom weights. Then, eBayes applies empirical Bayes shrinkage to the variance estimates. This borrows information across genes to improve the estimates, which helps most when an experiment has few replicates.

fit <- lmFit(v, design)
fit <- eBayes(fit)
colnames(fit$coefficients)
[1] "(Intercept)" "cellN061011" "cellN080611" "cellN61311" "dextrt"

The dextrt coefficient is our treatment effect.

topTable(fit, coef = "dextrt", number = 10) |>
as_tibble(rownames = "gene")
# A tibble: 10 × 7
gene logFC AveExpr t P.Value adj.P.Val B
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 ENSG00000165995 3.28 3.68 33.8 1.20e-10 0.00000192 14.3
2 ENSG00000120129 2.94 6.65 28.4 5.57e-10 0.00000207 13.7
3 ENSG00000157214 1.97 6.79 27.6 7.23e-10 0.00000207 13.5
4 ENSG00000162493 1.88 5.19 27.5 7.39e-10 0.00000207 13.4
5 ENSG00000189221 3.33 5.95 26.8 9.26e-10 0.00000207 13.2
6 ENSG00000162614 2.03 7.64 26.1 1.17e- 9 0.00000207 13.0
7 ENSG00000101347 3.76 8.14 25.6 1.37e- 9 0.00000207 12.8
8 ENSG00000125148 2.20 7.02 25.6 1.39e- 9 0.00000207 12.8
9 ENSG00000139132 2.22 5.42 25.3 1.52e- 9 0.00000207 12.7
10 ENSG00000106976 -1.77 5.10 -25.2 1.57e- 9 0.00000207 12.7

The output columns are:

  • logFC: The log2 fold change. Same interpretation as DESeq2.
  • AveExpr: The average log2 expression across all samples.
  • t: The moderated t-statistic from empirical Bayes.
  • P.Value: The raw p-value.
  • adj.P.Val: The Benjamini-Hochberg adjusted p-value.
  • B: The log-odds that the gene is differentially expressed.

The top genes overlap heavily with the DESeq2 results. ENSG00000165995, ENSG00000120129, ENSG00000101347 and ENSG00000189221 are in the top ten here and in the DESeq2 top five. The one that does not carry over is ENSG00000152583, which DESeq2 ranks first and limma-voom leaves outside its top ten, because the two rank on different statistics over different gene sets.

topTable(fit, coef = "dextrt", number = Inf) |>
as_tibble(rownames = "gene") |>
summarize(
total = n(),
sig = sum(adj.P.Val < 0.05),
up = sum(adj.P.Val < 0.05 & logFC > 0),
down = sum(adj.P.Val < 0.05 & logFC < 0)
)
# A tibble: 1 × 4
total sig up down
<int> <int> <int> <int>
1 15926 5014 2582 2432

limma-voom calls 5014 genes at an FDR of 0.05, 2582 up and 2432 down, out of the 15926 it tests. The edgeR page sets this count beside the DESeq2 and edgeR counts, and explains why the three counts do not rank the methods.

library(ggplot2)
volcano_data <- topTable(fit, coef = "dextrt", number = Inf) |>
as_tibble(rownames = "gene") |>
mutate(significant = adj.P.Val < 0.05 & abs(logFC) > 1)
volcano_plot <- ggplot(
volcano_data,
aes(x = logFC, y = -log10(adj.P.Val), color = significant)
) +
geom_point(size = 0.6, alpha = 0.5) +
scale_color_manual(values = c("grey70", "steelblue"), guide = "none") +
geom_hline(yintercept = -log10(0.05), linetype = "dashed", alpha = 0.5) +
geom_vline(xintercept = c(-1, 1), linetype = "dashed", alpha = 0.5) +
labs(
title = "limma-voom, dexamethasone against untreated",
x = "log2 fold change",
y = "-log10(adjusted p-value)"
) +
theme_minimal()
ggsave("outputs/limma-volcano.png", volcano_plot,
width = 7, height = 5, dpi = 150, bg = "white")

Volcano plot from limma-voom analysis

The visualization page explains how to read a volcano plot, drawn there from the DESeq2 results. This one has a much shorter vertical axis than that one, because the smallest adjusted p-value limma-voom reports is 0.00000192. limma tests a moderated t statistic with few degrees of freedom on eight samples, while the DESeq2 Wald test compares its statistic to a normal distribution, so the DESeq2 p-values reach far lower.

The edgeR page compares DESeq2, edgeR and limma-voom in one table, with the case where each one fits best.

Next: Over-Representation Analysis

Himes and colleagues, 2014 report the airway smooth muscle RNA-seq experiment that the airway data package holds.

Chen and colleagues, 2025 describe edgeR version 4 and its differential analysis of sequencing count data.

Ritchie and colleagues, 2015 describe limma and its linear models for differential expression in microarray and RNA-seq data.

The limma voom reference explains the mean-variance trend and observation weights. These weights distinguish this analysis from an unweighted fit to log counts.

The limma linear-model reference defines the design matrix and fitted coefficients. It supports the donor-adjusted treatment comparison used here.