This is a test version of Biostars. For the public version, visit https://www.biostars.org.
type='apeglm' shrinkage only for use with 'coef'
dd2 <- lfcShrink(dds, contrast=contrast, res=dd1)
Error in lfcShrink(dds, contrast = contrast, res = dd1) : 
  type='apeglm' shrinkage only for use with 'coef'

Does anybody know how to explain this? It's stuck on me for a long time!!!!

r rna-seq
  1. contrast <- c("sample", "normal", "cancer")
  2. dd2 <- lfcShrink(dds, contrast=contrast, res=dd1)

thanks, but I don't know why

The error message: Error in lfcShrink(dds, contrast = contrast, res = dd1) : type='apeglm' shrinkage only for use with 'coef'

Use ADD REPLY/ADD COMMENT when responding to existing messages to keep threads logically organized.

Is dd1 one of the members of resultsNames(dds) as required ?

2 answers

The crux here is that you have to modify the reference level of your design so the comparison of interest becomes available via resultsNames.

Here is an example:

library(DESeq2)

#/ Example data with three levels:
dds <- makeExampleDESeqDataSet()
dds$condition <- factor(unlist(lapply(seq(1,3),function(x) rep(LETTERS[x], 4))))

#/ standard workflow
dds <- estimateSizeFactors(dds)
dds <- estimateDispersions(dds)
dds <- nbinomWaldTest(dds)
resultsNames(dds)
[1] "Intercept"        "condition_B_vs_A" "condition_C_vs_A"

As you see you have B_vs_A and C_vs_A for which the MLEs that apeglm needs are available. In case you want to shrink the B_vs_C comparison you would need to relevel the condition. You either have to make B or C the reference. Lets take C.

relevel(dds$condition, ref = "C")
> dds$condition
[1] A A A A B B B B C C C C
Levels: C A B

The design is the same (~condition), only the reference level changed, and since it is the same so we do not need to rerun the dispersion estimation but only the Wald test to get new MLE coefficients for the comparison of interest.

dds <- nbinomWaldTest(dds)
resultsNames(dds)
[1] "Intercept"        "condition_A_vs_C" "condition_B_vs_C"

B_vs_C is now present so we can proceed.

lfcShrink(dds = dds, coef = 3, type = "apeglm")

It is on you to decide whether you want to do that or simply use ashr. Based on the apeglm paper ashr seems to perform decently as well. Don't use type="normal" though, the paper clearly states that it underperforms on comparison to the other two.

Further reading:

Thanks for this answer! One small addition, I had to set dds$condition to relevel to make it to work. e.g.:

dds$condition = relevel(dds$condition, ref = "C")

Set type to something else, such as normal or ashr.

The DESeq2 vignette has a table summarizing the different types ("Extended section on shrinkage estimators" section).

Log in to answer this question.