type='apeglm' shrinkage only for use with 'coef'
2
5
Entering edit mode
3.8 years ago
wuyingncu ▴ 50
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 • 15k views
ADD COMMENT
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'

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
10
Entering edit mode
3.3 years ago
ATpoint 82k

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:

ADD COMMENT
0
Entering edit mode

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")
ADD REPLY
2
Entering edit mode
3.8 years ago

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

ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 3164 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6