dwarton / mvabund

mvabund updates
10 stars 14 forks source link

Error with GAMMA manyglm var.est #91

Open BenMaslen opened 3 years ago

BenMaslen commented 3 years ago

Currently manyglm is struggling to handle majority of gamma distributed data that I have been attempting to model.

The RtoGlm function easily results in NA's for the z$var.estimator when the gamma family is used (below code from manyglm)....

      z <- RtoGlm(modelParam, Y, X, O)
      if (any(z$var.est == 0)) {
        z$var.estimator = pmax(z$var.est, 1e-06) 
        z$residuals = (Y - z$fit)/sqrt(z$var.est)

Which stops the model estimation at the above step because any(z$var.est == 0) returns an NA. Not sure why RtoGlm is returning NA's here quite often for gamma data which glm has no issues fitting. Perhaps best to replace NA's with 0 and then run the model replacing the var.estimator appropriately for example below (using tidyverse replace_na).

      z <- RtoGlm(modelParam, Y, X, O)
      z$var.est[is.na(z$var.est)]<-0
      if (any(replace_na(z$var.est,0) == 0)) {
        z$var.estimator = pmax(z$var.est, 1e-06)
        z$residuals = (Y - z$fit)/sqrt(z$var.est)

Happy to provide data and further discussion if need be. This issue makes it really hard for gamma function to be taken up and applied widely!

cheers

Ben ben.maslen95@gmail.com

NJOram commented 1 year ago

Hello, I am haivng a similar issue (https://github.com/dwarton/mvabund/issues/117#issue-1909517971), and wonder if there is any update regarding handling gamma distributed data?