JenniNiku / gllvm

Generalized Linear Latent Variable Models
https://jenniniku.github.io/gllvm/
48 stars 19 forks source link

error with simulate and multiple random effects #177

Closed AlainZuur closed 3 months ago

AlainZuur commented 3 months ago

Hello, I have a Tweedie GLLVM with a row.effect that contains three random effects:

row.eff = ~ (1 | Day) + (1 | Fisher) + (1 | Area),

The development version gives me this error:

Ysim <- gllvm::simulate(M2, nsim = NSim, conditional = FALSE) Error in if (all.vars(object$call$row.eff) %in% colnames(newX)) { : the condition has length > 1

Something goes wrong with the row effect I think. I don't get it with only 1 random effect.

Kind regards,

Alain

BertvanderVeen commented 3 months ago

I've pushed a bugfix, see if that solves it?

AlainZuur commented 3 months ago

No sorry...I still have:

Error in if (all.vars(object$call$row.eff) %in% colnames(newX)) { : the condition has length > 1

This is the model:

M2 <- gllvm(y = SpecData, X = CovX.s, studyDesign = ExtraVariables, formula = ~ Depth + Wave_exposure + Temp_mean, row.eff = ~ (1 | Fisher) + (1 | Day) + (1 | Area), num.lv = 2, family = "tweedie", control = list(optimizer = "optim"), #alabama control.start = list(n.init = 5, jitter.var = 0.1))

It is an example where all three sigmas have very low values...not sure if that plays a role in the error. I can look up a better example? It is more a 'this is how you can do it...but it is not really needed in this case' example.

I use the simulate function to communicate with DHARMa.

Alain

BertvanderVeen commented 3 months ago

I'm afraid I cannot reproduce your issue Alain, my commit fixed the issue for me. Can you provide a reproducible example? (sorry to be a pain)

Either way, simulate and predict do not yet work for "new" row effect variables, so even if you get the code to work it will just throw a warning at you.

AlainZuur commented 3 months ago

Hello Bert.... I've reinstalled the development version (using a proper wifi this time and not via a 4G mobile), restarted everything, and it is fine now.

Thanks.

Alain