What is a design matrix in RNA-seq? A plain-language guide
An RNA-seq design matrix is a table that tells the statistical model which samples belong to which group. It has one row per sample and one column per effect the model estimates, and tools like DESeq2, edgeR and limma build it from your sample sheet and a design formula. Once you can read one, most design errors stop being mysterious.
What is a design matrix?
Your sample sheet says things like “sample 3 is treated and was sequenced in batch B.” The model needs the same facts as numbers. The design matrix is that translation: each row is a sample, each column is a quantity the model will estimate, and the entries are mostly 0 and 1.
What does a design matrix look like?
Take four samples, two control and two treated, and the formula ~ condition. R builds this matrix with its default coding:
| Sample | Condition | (Intercept) | conditiontreated |
|---|---|---|---|
| s1 | control | 1 | 0 |
| s2 | control | 1 | 0 |
| s3 | treated | 1 | 1 |
| s4 | treated | 1 | 1 |
The intercept column is all ones and stands for the baseline group, here control. The second column is 1 only for treated samples, so its coefficient is the difference between treated and control. That difference is what a differential expression test looks at. You can print the matrix yourself with model.matrix(~ condition, data = coldata).
How does the design formula change the matrix?
Each variable you add to the formula adds columns. With ~ batch + condition and four samples that are balanced across two batches:
| Sample | Batch | Condition | (Intercept) | batchB | conditiontreated |
|---|---|---|---|---|---|
| s1 | A | control | 1 | 0 | 0 |
| s2 | B | control | 1 | 1 | 0 |
| s3 | A | treated | 1 | 0 | 1 |
| s4 | B | treated | 1 | 1 | 1 |
Now the model can estimate a batch difference and a treatment difference separately, because the batchB column and the conditiontreated column follow different patterns.
What does full rank mean for a design matrix?
A matrix is full rank when no column can be built from the others. In plain terms, every column has to carry its own information. Look at what happens when batch and condition line up perfectly: s1 and s2 are control in batch A, and s3 and s4 are treated in batch B. The batchB column reads 0, 0, 1, 1, and so does the conditiontreated column. They are identical, so the model has no way to split the effect between them, and DESeq2 stops with the “not full rank” error. The fixes are in our guide to DESeq2 design formula errors, and the underlying problem is the one described in our post on batch effects and confounding.
How do I check my design matrix before running the analysis?
- Print it with
model.matrix()and read the columns. Each one should match something you meant to model. - Cross-tabulate your variables with
table(coldata$batch, coldata$condition). Empty cells and perfect alignment are warning signs. - Check the rank in R:
qr(mm)$rank == ncol(mm), wheremmis the matrix, is TRUE when it is full rank. - Confirm the sample sheet order matches the count matrix columns before you build anything.
What this cannot tell you
A design matrix is only as correct as the sample sheet it comes from. If two samples carry each other’s labels, the matrix is still valid and full rank, and the model confidently estimates the wrong thing. Checking that labels match the data is a separate step. Our QC checklist lists the checks that can be run from a count matrix, and the sample audit report shows how CodeISB reports them.
Common questions
Do I have to build the design matrix myself in DESeq2?
No. DESeq2 builds it from the sample sheet and your formula. limma and edgeR’s generalized linear model functions take a design matrix as an input, usually made with model.matrix().
What is the difference between a design formula and a design matrix?
The formula is the instruction, such as ~ batch + condition. The matrix is the table the software builds by applying that instruction to your sample sheet.
Why is the first group missing from the columns?
It is the reference group, and it is absorbed into the intercept. The other columns are differences from it. Choose it deliberately by setting the order of the factor levels.
Do not find out after it costs you
CodeISB checks your count matrix and sample sheet for swapped samples, weak libraries and batch confounding, and returns a one-page report. No raw reads or patient identifiers needed.
The first audit is free. Current prices hold for 12 months from your first project; later customers pay list.
Get your free audit