-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
glmGamPoi fit fails if normMatrix is provided #29
Comments
Hi Michael, thanks for filing a bug report. I wasn't aware of the
In theory yes. @mikelove, for fixing this bug. I think the solution would be to check here if Best, |
Hi Constantin, Thanks a lot for your answer! It would be great if this worked from within DESeq2, then I can use an API I'm already familiar with |
Thanks Michael and Constantin, I took a shot at addressing this here: 40d3cba Let me know if that makes sense on your end(s). |
Wow, that was quick! Thank you so much. I'm running a large test case now and will let you know if there are any issues. So far it's looking good |
I have now run this for 45 treatment vs. 2947 control cells, and the However, I'm also confused that in contrast to the test case above, I get |
That is great to hear :) It is common that you get very small p-values for a single cell analysis, because you have so many cells. However, keep in mind that cells from the same sample are not independent replicates, so you should be careful how you interpret the results.
That is weird. Can you say a bit more how you exactly do the test? Or provide some example data or subset of the data, so that I can reproduce the problem?
Indeed, |
In this case, I was surprised at the difference between the "normal" DESeq2 LRT (smallest p-values around 1e-30) vs. the glmGamPoi (300 genes < 1e-300)
That was my mistake. I tried to calculate the Wald statistic from the log2FoldChange / lfcSE, which of course didn't work without lfcSE (where I use the LRT results for e.g. MA/volcano plots, but the Wald stat to compare 2 samples on x/y axis)
One of the analyses I do downstream of the DE is to model whether fold changes have a discontinuity along the genome (e.g. due to an amplification). The "raw" log2FCs are too noisy, in order to get anything out I need to weigh them by their SE when using them e.g. in a change point analysis. |
There can be several reasons for the discrepancy:
|
Okay that is reassuring to hear :)
Oh, that is very interesting and a cool use-case I haven't considered so far. When you say, that you weight the log-fold changes by the standard error, do you do something like |
Thanks for the linked figure! It seems to be a DESeq/glmGamPoi difference, no change with setting
No, I want to keep them separate to be able to call break points for different ploidies. In the case of the
I don't think so. If the FCs are not changing, I still want to separate strong evidence for no change (lfc=0, low se, low stat) vs. weak evidence for no change (lfc=0, high se, low stat) (unless I misunderstood and the LRT stat is not testing H0) |
I opened an issue at I am open to add a way to calculate the standard error and provide those estimates, but I would need to spend more time on this, than I currently can spare. I would, however, be open for a PR or any other input, but let's continue the discussion at const-ae/glmGamPoi#12 |
Coming back on-topic: It seems I was too quick to judge the However, when I look at the correlation of the This doesn't look right. The plots are from my own data, but you also see the discrepancy when plotting it for the library(DESeq2)
makeExampleDESeqDataSet = DESeq2:::makeExampleDESeqDataSet
dds <- makeExampleDESeqDataSet(n=100, m=8)
dds$group <- factor(rep(1:2,times=4))
design(dds) <- ~group + condition
res1 <- DESeq(dds, test="LRT", reduced=~1, fitType="glmGamPoi")
nm = matrix(2, nrow=nrow(dds), ncol=ncol(dds))
dds <- estimateSizeFactors(dds, normMatrix=nm)
dds <- estimateDispersions(dds, fitType="glmGamPoi")
res2 <- nbinomLRT(dds, reduced=~1, type="glmGamPoi")
plot(log10(results(res1)$pvalue), log10(results(res2)$pvalue)) |
Okay, I can reproduce the problem. Here is a bit shorter code that shows that the problem library(glmGamPoi)
Y <- matrix(rnbinom(n = 30 * 10, mu = 4, size = 0.3), nrow = 30, ncol =10)
annot <- data.frame(group = sample(c("A", "B"), size = 10, replace = TRUE),
cont1 = rnorm(10), cont2 = rnorm(10, mean = 30))
design <- model.matrix(~ group + cont1 + cont2, data = annot)
reduced_des <- model.matrix(~ group + cont1, data = annot)
fit1 <- glm_gp(Y, design = design)
offset <- matrix(log(fit1$size_factors), byrow = TRUE, nrow = nrow(Y), ncol = ncol(Y))
fit2 <- glm_gp(Y, design = design, offset = offset, size_factors = FALSE)
# The size factor is at the 6th position
testthat::expect_equal(fit1[-6], fit2[-6])
res1 <- test_de(fit1, reduced_design = reduced_des)
res2 <- test_de(fit2, reduced_design = reduced_des)
testthat::expect_equal(res1, res2)
#> Error: `res1` not equal to `res2`.
#> Component "pval": Mean relative difference: 0.5928957
#> Component "adj_pval": Mean relative difference: 0.4650072
#> Component "f_statistic": Mean relative difference: 0.9238129 Created on 2020-11-25 by the reprex package (v0.3.0.9001) The problem is that I currently, ignore the offset when I do the fit with the reduced design |
I fixed the issue in const-ae/glmGamPoi@0deacb3#diff-e923364f1bda63722e222d7080a9a0dd30a5cd77712563c71b0d18eea3ffa239R230 To test the new version, you will need to install library(DESeq2)
dds <- DESeq2:::makeExampleDESeqDataSet(n=100, m=8)
dds$group <- factor(rep(1:2,times=4))
design(dds) <- ~group + condition
res1 <- DESeq(dds, test="LRT", reduced=~1, fitType="glmGamPoi")
nm = matrix(2, nrow=nrow(dds), ncol=ncol(dds))
dds <- estimateSizeFactors(dds, normMatrix=nm)
dds <- estimateDispersions(dds, fitType="glmGamPoi")
plot(log10(results(res1)$pvalue), log10(results(res2)$pvalue)); abline(0,1) Created on 2020-11-25 by the reprex package (v0.3.0.9001) Thank you again @mschubert for your effort to track down the bug :) |
Thanks Michael and Constantin! |
I'm going to close this for now, but please feel free to re-open as needed. |
Looking at the
glmGamPoi
test case:This also works when I call
estimateSizeFactors
andestimateDispersions
manually:However, when I supply the
normMatrix
argument the subsequentglmGamPoi
fails:Is it possible to use
normMatrix
withglmGamPoi
?The reason why I want to do that is that I'm looking at single-cell gene expression changes with chromosome aneuploidies.
(Filing this here instead of Bioc support because I think it's a bug.)
The text was updated successfully, but these errors were encountered: