satijalab / sctransform

R package for modeling single cell UMI expression data using regularized negative binomial regression
GNU General Public License v3.0
206 stars 33 forks source link

`poisson` is used when `nb`? #52

Closed pengyu closed 4 years ago

pengyu commented 4 years ago

I see this it. glm(..., family = poisson) is also used for nb in get_model_pars(). Is it because glm.nb fails for some input, in which case it has to fall back to the poisson model?

                                   if (method == 'nb') {
                                     fit <- 0
                                     try(fit <- glm.nb(as.formula(model_str), data = data_step1), silent=TRUE)
                                     if (inherits(x = fit, what = 'numeric')) {
                                       fit <- glm(as.formula(model_str), data = data_step1, family = poisson)
                                       fit$theta <- as.numeric(x = theta.ml(y = y, mu = fit$fitted))
                                     }   
                                     return(c(fit$theta, fit$coefficients))
ChristophH commented 4 years ago

Yes, glm.nb sometimes fails due to convergence problems. In those cases, the poisson model is used and theta is estimated using maximum-likelihood.