JenniNiku / gllvm

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

Error when predicting on new data when row.eff is structured #86

Closed hrlai closed 1 year ago

hrlai commented 1 year ago

Hi there, the following code will error when the model has structured row effects (supplied with studyDesign), and then if we want to predict onto new data.

data(antTraits)
y <- as.matrix(antTraits$abund)
X <- scale(antTraits$env[, 1:3])
fake_site <- data.frame(site = rep(1:3, each = 10))

# Fit gllvm model
fit <- gllvm(y = y, X, 
             family = poisson(), 
             studyDesign = fake_site, 
             row.eff = ~ (1|site))

# predict with new data
xnew <- cbind(rnorm(10), rnorm(10), rnorm(10))
colnames(xnew) <- colnames(X)
predfit <- predict(fit, newX = xnew, type = "response", level = 0)

The error message:

Error in object$TMBfn$env$data$dr0 %*% object$params$row.params : 
  non-conformable arguments

Is there a way to marginalise across the (nested) random effects?

Thanks!

BertvanderVeen commented 1 year ago

Is there a way to marginalise across the (nested) random effects?

No. There is currently no method in GLLVM to marginalize over the random-effect for prediction.

@JenniNiku it looks to me like this is cause by L306-308 in predict.gllvm.R, which seems to be redundant lines of code.