dwarton/mvabund

Var.est error with gamma manyglm

Opened this issue · 5 comments

Hi,

I am trying to run a manyglm with a gamma distribution but am getting a strange error which I don't understand.

My error can be replicated with (shortened version):

mydata <- read.csv("https://raw.githubusercontent.com/HaydenSchilling/MGLMs-Otoliths/master/Data/Otolith_data_mmol_mol_Ca.csv")
E_data <- mydata[,c(2:8,10:14)]
elements <- mvabund(E_data) # select only element data
gamma_glm <- manyglm(elements ~ 1, family="gamma")

The error says:

Error in if (any(z$var.est == 0)) { : 
  missing value where TRUE/FALSE needed

It is possible to run a univariate glm with gamma distribution on all of variables I'm trying to use in the manyglm

glm1 <- glm(elements[,1] ~ 1, family =Gamma(link="log"))

Any ideas would be very much appreciated,
Thanks!

I'm facing the same issue. Could you figure out a workaround? Thanks!

I ended up using the manyany function and passing the gamma distribution as a special form of the Tweedie distribution.
A Tweedie distribution with variance power 2 which is equivalent to a gamma distribution.

An example of my null model was then:

fitN <- manyany("glm", elements, data = mydata, elements ~ 1, family = tweedie(var.power = 2, link.power = 0), var.power = 2)

Thanks a ton! I tried that (and the Tweedie distribution might actually be more appropriate for my data), but I am now struggling to get the multivariate and univariate results through the anova function, which insists on a second manyany object for comparison (unlike for manyglm, where the anova call outputs all that). How did you get that?

you can use the anova.manyany function to test between two models, one of which is nested in the other. The p-values given will then be for the factor which varies between the models. My example was as follows to test the term pop.

# Gamma Function
fit3 <- manyany("glm", elements, data = mydata, elements ~ pop, 
                family = tweedie(var.power = 2, link.power = 0), var.power = 2)
# # Null model for Gamma
fitN <- manyany("glm", elements, data = mydata, elements ~ 1, 
                 family = tweedie(var.power = 2, link.power = 0), var.power = 2)

anova_results <- anova(fitN, fit3, p.uni = "unadjusted", nBoot = 999)

Note it can be particularly slow.

NJOram commented

Hello! I am having a similar issue now, and wonder if there has been any update since 2021.
My multivariate dataset is example_data1, and I am trying to explain these with three factors in example_data2
example_data1.csv
example_data2.csv

This is my code:
remotes::install_github("aliceyiwang/mvabund")
library(tidyverse)
library(mvabund)

########## Example

load matrix data and explanatory variables

data1<-read.csv("example_data1.csv")%>%
column_to_rownames(var = "obs")%>%
as.matrix()
data2<-read.csv("example_data2.csv")

manyglm

set.seed(210)
mod1 <- manyglm(data1 ~ factor1 x factor2 x factor3,
family=Gamma(link = "log"),
data=data2
)

with family = Gamma, I get the following error:

Error in if (any(z$var.est == 0)) { :
missing value where TRUE/FALSE needed


Any idea why this is happening or how to fix it? all univariate GLMs run fine.

Many thanks!