The vignette states that:
Instead, one need only run
nbinomWaldTest
to re-estimate MLE coefficients – these are necessary forapeglm
– and then runlfcShrink
specifying the coefficient of interest inresultsNames(dds)
.We give some examples below of producing equivalent designs for use with
coef
. We show how the coefficients change withmodel.matrix
, but the user would, for example, either change the levels ofdds$condition
or replace the design usingdesign(dds)<-
, then runnbinomWaldTest
followed bylfcShrink
.
Which suggests that it is sufficient to replace the design or overwrite the condition factors.
However, it also states:
You should only change the factor levels of variables in the design before running the DESeq2 analysis, not during or afterward.
Which seems contradictory to the above:
cnts <- matrix(rnbinom(n=1000, mu=100, size=1/0.5), ncol=15)
cond <- factor(rep(1:3, each=5))
dds <- DESeq(DESeqDataSetFromMatrix(cnts, DataFrame(cond), ~ cond))
resultsNames(dds)
[1] "Intercept" "cond2vs1" "cond3vs1"
# does not work
dds$cond = relevel(cond, 2)
resultsNames(dds)
[1] "Intercept" "cond2vs1" "cond3vs1"
# works
dds$cond = relevel(cond, 2)
resultsNames(DESeq(dds))
[1] "Intercept" "cond1vs2" "cond3vs2"
And what a user (like me) may incorrectly read from the first paragraph as the "suggested" way:
# did not work when I tried:
dds$cond = relevel(cond, 2)
# I forgot to save the result here:
nbinomWaldTest(dds)
# thus this line was raising an error
lfcShrink(dds, coef='cond_3_vs_2')
Error in lfcShrink(dds, coef = "cond3vs_2") : coef %in% resultsNames(dds) is not TRUE
I think that my confusion arose from the re-use of dds which is used to mean "DESeqDataSetFromMatrix" in one place and "DESeq" in the other. Thinking like a C-programmer I've overwritten the first with the second one. But it might be an issue with the vignette as well.