Free audit for one project, up to 30 samples. No payment today. Request yours

CodeISB / Blog

DESeq2 design formula errors: characters, factors and “model matrix is not full rank”

2026-11-07 · 6 min read

Most DESeq2 design formula errors come from the sample sheet, not from the formula. A warning about characters and factors is usually harmless. An error that says the model matrix is not full rank means two columns in your sample sheet carry the same information, or some combination of groups has no samples. Here is how to tell which, and how to fix it.

Is “some variables in design formula are characters, converting to factors” an error?

No, it is a warning, and DESeq2 keeps going. It tells you that a column used in the design was stored as text and has been converted to a factor, which is a column of named groups. That is what you want for a column like condition.

It becomes a problem when a column that should be numeric was read in as text. A column of ages, times or RNA quality scores, stored as characters, turns into a factor with one level per value, and the model is then asked to estimate a separate effect for nearly every sample. Check your columns with str(coldata). Convert numbers with as.numeric(), and set groups yourself so the reference level is the one you intend:

  • coldata$condition <- factor(coldata$condition, levels = c("control", "treated"))

R orders factor levels alphabetically by default, so without this step the reference group is whichever name comes first in the alphabet.

What does “the model matrix is not full rank” mean?

DESeq2 turns your design formula and sample sheet into a design matrix, with one column for each effect it must estimate. Full rank means every column adds information the others do not. The error appears for two reasons, both described in the DESeq2 vignette section on the model matrix:

  • A variable is confounded with another. Suppose all control samples were sequenced in batch 1 and all treated samples in batch 2. The batch column and the condition column are the same pattern, so the model cannot say which one caused a difference.
  • A combination of levels has no samples. If your formula includes an interaction and one cell of the table is empty, that cell produces a column of zeros.

How do I fix a design that is not full rank?

Start by cross-tabulating the variables in your formula: table(coldata$batch, coldata$condition). Every cell should have samples, and no variable should line up with another. Then pick the fix that matches what you see:

  • Two columns say the same thing. Drop one. Common examples are a sample ID column, or a coarse group and a finer group that contains it.
  • An interaction has an empty cell. Combine the variables into a single group column and compare groups with contrast in results(), as the vignette shows for interactions.
  • A paired design fails. A model with ~ individual + condition can only separate the two when the same individuals appear in more than one condition.
  • Batch and condition are fully confounded. No formula can fix this. The data cannot answer the question, and the honest options are to say so or to add samples. Our guide to batch effects and confounding explains how to check for it before it becomes an error.

Why does DESeq2 say the colData rownames are not in the same order as the countData colnames?

When you build the object from a matrix, DESeq2 pairs the first row of your sample sheet with the first column of the count matrix, and so on. The DESeqDataSet documentation says rows of colData correspond to columns of countData. If the names match but the order differs, DESeq2 stops with this error instead of guessing.

Fix it by reordering the count columns to follow the sample sheet: cts <- cts[, rownames(coldata)]. Then confirm it with all(rownames(coldata) == colnames(cts)). Do not rename or strip the column names just to make the message go away. A sample sheet whose order differs from the count matrix is a classic way for samples to get swapped without anyone noticing, which is why we cover it in our guide to finding a sample swap.

Which variable does results() test?

By default, results() reports the last variable in the design formula, as the DESeq() documentation notes. Put the variable you care about last and the ones you are adjusting for first, for example ~ batch + condition.

What this cannot tell you

A design that fits is not the same as a design that is right. DESeq2 accepts any sample sheet whose columns are consistent, including one where two samples have the wrong label. CodeISB checks the sample sheet against the count matrix for confounded batch and condition, mismatched sample names and sex genes that disagree with the recorded sex. It cannot know which of your labels is the true one.

Quick checklist before you build the object

  • Sample sheet rows and count matrix columns have the same names, in the same order.
  • Numeric variables are numeric, and group variables are factors with a deliberate reference level.
  • No variable in the formula is a copy or a subset of another.
  • A table of batch against condition has samples in every relevant cell.
  • The variable of interest is last in the formula.

For an example of what such checks look like in a report, see our sample audit report.

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