type='apeglm' shrinkage only for use with 'coef'
2
4
Entering edit mode
18 months ago
wuyingncu ▴ 40
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 • 5.3k views
0
Entering edit mode
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'

0
Entering edit mode

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

0
Entering edit mode

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

6
Entering edit mode
12 months ago
ATpoint 57k

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.

2
Entering edit mode
18 months ago

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

0
Entering edit mode

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