DESeq2 - Error in lfcShrink: 'coef' should specify same coefficient as in results 'res' I have created a DESeq object (dds) and now I want to access the results and apply the lfc shrinkage on them.
res &lt;- results(dds, alpha=0.05)
resultsNames(dds) 
[1] &quot;Intercept&quot;                                                  &quot;Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages&quot;
[3] &quot;Cell_type_T_cells_vs_Alveolar_macrophages&quot;

Here we see all the coefficients I got from the results function.
Now I try to use the lfcShrink() function on the second coefficient:
res_im_vs_am &lt;- lfcShrink(dds, coef=2, res=res, type=&quot;apeglm&quot;)
Error in lfcShrink(dds, coef = 2, res = res, type = &quot;apeglm&quot;) : 
  'coef' should specify same coefficient as in results 'res'

it doesn't work, so I try with the name directly copy-pasted from the above code:
res_im_vs_am &lt;- lfcShrink(dds, coef = &quot;Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages&quot;, res=res, type=&quot;apeglm&quot;)
Error in lfcShrink(dds, coef = &quot;Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages&quot;,  : 
  'coef' should specify same coefficient as in results 'res'    

Same error.
According to the ?lfcShrink for coef: the name or number of the coefficient (LFC) to shrink, consult resultsNames(dds) after running DESeq(dds).
So I do not understand why it is not working. Anyone can help?
We use an example dataset:
library(DESeq2)
mat = matrix(rnbinom(9000,mu=100,size=1),ncol=9)
rownames(mat) = paste0(&quot;gene&quot;,1:1000)
grps = rep(c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;),each=3)

dds = DESeqDataSetFromMatrix(mat,data.frame(grps),~grps)
dds = DESeq(dds)

resultsNames(dds) 
[1] &quot;Intercept&quot;   &quot;grps_B_vs_A&quot; &quot;grps_C_vs_A&quot;

When you call results, by default it takes the last coefficient, in this example is C vs A:
res &lt;- results(dds, alpha=0.05)

log2 fold change (MLE): grps C vs A 
Wald test p-value: grps C vs A 
DataFrame with 6 rows and 6 columns
              baseMean     log2FoldChange             lfcSE               stat
             &lt;numeric&gt;          &lt;numeric&gt;         &lt;numeric&gt;          &lt;numeric&gt;
gene1 74.3974631643997 -0.439258650876538  1.22842645044656 -0.357578307367818
gene2 99.4576039995999    1.2903547180366  1.12500005531808   1.14698191518912
gene3 87.1593850381565  -3.11763876685787  1.19848628038255  -2.60131368868297
gene4   51.47821785473  -2.16622171024749 0.953571440023498  -2.27169315200349
gene5 62.4630151830988   1.05879388186169  1.31999477669387  0.802119751195993
gene6 111.967714581788  -1.23916751032406  1.17612862134365  -1.05359863524824

If you want to look at the second comparison:
res &lt;- results(dds, alpha=0.05,name=&quot;grps_B_vs_A&quot;)
res_lfc &lt;- lfcShrink(dds, coef=2, res=res, type=&quot;apeglm&quot;)

log2 fold change (MAP): grps B vs A 
Wald test p-value: grps B vs A 
DataFrame with 6 rows and 5 columns
              baseMean      log2FoldChange             lfcSE            pvalue
             &lt;numeric&gt;           &lt;numeric&gt;         &lt;numeric&gt;         &lt;numeric&gt;
gene1 74.3974631643997 0.00143892076074213 0.275057978370776 0.987946388824352
gene2 99.4576039995999  -0.031292774512063 0.276439771853046 0.632995722892249
gene3 87.1593850381565 0.00806769808245902 0.274672487627629                NA
gene4   51.47821785473 -0.0394804572502463 0.274244572145665 0.609999235800452
gene5 62.4630151830988   0.065875708916621 0.288411208595865 0.234448669110134
gene6 111.967714581788 -0.0871847461207727 0.295733383995144 0.153081913500716

or simply:
res_lfc &lt;- lfcShrink(dds, coef=2, type=&quot;apeglm&quot;)