nyiuab / NBZIMM

NBZIMM (Negative Binomial and Zero-Inflated Mixed Models)
Other
33 stars 12 forks source link

error: offset() terms are not supported? #7

Open biocsmith opened 2 years ago

biocsmith commented 2 years ago

I'm running this model for mms:

`N <- metadf[, "sampling_depth"] Pigment <- metadf$pigment tank <- metadf$tank

f_zinb <- mms(y = otu_t, fixed = ~ Pigment + offset(log(N)), random =~ 1 | tank, data = metadf, min.p = 0.2, method = "zinb", zi_fixed = ~1, zi_random = NULL)`

and getting this error y1 error: offset() terms are not supported and the model fails. When I was running this last month, I was not getting this error.

Is stats::offset(log(N)) and appropriate work around? After extracted the estimates and pvalues with fixed(f_zinb)$dist this causes one of the variables to be stats::offset(log(N)) and I'm not sure if this was in results previously.

roulan2000 commented 2 years ago

I came across the same error today. According to the Change Log of nlme and #17880 they check the offset term and threw an error at the latest version. I think NBZIMM can figure out this BUG if they ignore the offset term when pass formula to nlme. Temporarily, I suggest to re-install an old version of nlme: remotes::install_version("nlme", version = "3.1.152", repos = "http://cran.us.r-project.org")

biocsmith commented 2 years ago

Thanks! I will try that!

Edit: Unfortunately , ran the code to install an older version of nlme and am still running into that error.

harD2 commented 2 years ago

I came across the same error today. According to the Change Log of nlme and #17880 they check the offset term and threw an error at the latest version. I think NBZIMM can figure out this BUG if they ignore the offset term when pass formula to nlme. Temporarily, I suggest to re-install an old version of nlme: remotes::install_version("nlme", version = "3.1.152", repos = "http://cran.us.r-project.org")

Thanks - ran into the same issue and this workaround worked for me after restarting R.

EOMAK91 commented 2 years ago

Can someone help me out with this error? I tried installing the older version as recommended in this thread, but I get this error instead:

`Downloading package from url: http://cran.us.r-project.org/src/contrib/Archive/nlme/nlme_3.1-152.tar.gz

Any help would be greatly appreciated.

bbolker commented 2 years ago

If you still care, follow the instructions here to install gfortran on your system.

cmainov commented 1 year ago

has anybody been able to figure out a workaround for this? Still getting error messages when trying to install an archived version of nlme. I've installed gfortran and all but still get error messages

bbolker commented 1 year ago

I think MRAN is still supported for now (until 1 July 2023), so you could try the snapshot package to install the older version ... However, you should be aware that this is actually flagging a bug in the package: offsets are silently ignored by nlme in earlier versions!! I would be interested in hearing from the package maintainers whether I'm wrong/this is a problem that can be ignored, or whether the package needs to be adjusted somehow.

To go into a little bit more detail:

IIRC this package uses glmmPQL from MASS, which in turn calls lme with a set of weights that incorporates the expected mean-variance relationship of the response. In general people don't implement offsets for linear models because in this case it's just as easy to subtract the offset from the response variable, i.e y - v ~ 1 + x rather than y ~ 1 + x + offset(v). This doesn't work for GLMs, which is why the machinery of offsets exists in the first place. It might be possible to implement the equivalent of offsets in this case by modifying the response variable, but I really don't know.