Thanks a lot for taking the time to answer. I'm sorry, I am indeed using minReplicatesForReplace=Inf, because I want to mark the outliers, but forgot to include it when typing the example.
I also expected that the outlying sample would affect the group3 coefficient in the same way in both designs, but the thing is that, the Cook's distances change a lot with the design, that's why I initially thought maybe using the full model was somehow dampening the Cook's distance of the outlier:
counts(foo,normalized = T)["ENSMUSG00000095937.1",]
s1_g1 s2_g1 s3_g1 s4_g2 s5_g2 s6_g2 s7_g3 s8_g3 s9_g3 s10_g4 s11_g4 s12_g4
4162.4721 3140.3940 1398.9893 872.8687 2000.8897 0.0000 0.0000 0.0000 1060.7122 0.0000 0.0000 0.0000
assays(foo)[["cooks"]]["ENSMUSG00000095937.1",]
s1_g1 s2_g1 s3_g1 s4_g2 s5_g2 s6_g2 s7_g3 s8_g3
0.018470474541 0.000666898518 0.026155874473 0.000768351629 0.115715770099 0.097503104284 0.093973458469 0.099228014040
s9_g3 s10_g4 s11_g4 s12_g4
0.396930191339 0.000001959902 0.000001295067 0.000001252200
assays(foo2)[["cooks"]]["ENSMUSG00000095937.1",]
s7_g3 s8_g3 s9_g3 s10_g4 s11_g4 s12_g4
8.214905241000 8.945367523128 35.783308593148 0.000003927686 0.000002595326 0.000002509419
As you can see, I would need a very low Cook's value filter to flag the gene as an outlier in the full model, and this would lead to flagging thousands of genes as outliers.
See here another example which would look like an outlier for the groups 3 and 4 (this one was not flagged by the filter probably because it didn't reach the 99% quantile of F(4,8), but it has a low enough value that it could maybe be flagged by softly changing the Cook's cut-off threshold). Nonetheless, again the Cook's distances differences are more clear in the subset of the data model:
counts(foo,normalized = T)["ENSMUSG00000058603.10",]
s1_g1 s2_g1 s3_g1 s4_g2 s5_g2 s6_g2 s7_g3 s8_g3 s9_g3 s10_g4 s11_g4 s12_g4
537.06288 394.79153 206.62116 384.42496 354.58168 97.89824 581.50761 606.94055 613.09116 0.00000 973.12305 0.00000
dplyr::arrange(as.data.frame(res),pvalue)["ENSMUSG00000058603.10",]
baseMean log2FoldChange lfcSE stat pvalue padj
ENSMUSG00000058603.10 395.8369 -0.8887796 1.953566 -0.4549524 0.6491435 1
dplyr::arrange(as.data.frame(res2),pvalue)["ENSMUSG00000058603.10",]
baseMean log2FoldChange lfcSE stat pvalue padj
ENSMUSG00000058603.10 462.4437 -0.8886349 3.051692 -0.2911942 NA NA
assays(foo)[["cooks"]]["ENSMUSG00000058603.10",]
s1_g1 s2_g1 s3_g1 s4_g2 s5_g2 s6_g2 s7_g3 s8_g3 s9_g3
0.12296053922 0.00115697258 0.14783345982 0.10147837623 0.05217921638 0.29845818685 0.00071155004 0.00008201613 0.00031380887
s10_g4 s11_g4 s12_g4
0.78333375519 2.70595045140 0.66832480645
assays(foo2)[["cooks"]]["ENSMUSG00000058603.10",]
s7_g3 s8_g3 s9_g3 s10_g4 s11_g4 s12_g4
0.008799736 0.001039258 0.003974644 9.132780779 33.102203471 8.206535740
I also imagine that part of the problem here is having only n=3 per group, although it was very striking that the most significant result of the analysis with the full model was the first outlier.