inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
78 stars 21 forks source link

Adding support for special response objects #93

Open finnlindgren opened 3 years ago

finnlindgren commented 3 years ago

Code example from Haavard Rue for how to combine special response objects and multi-likelihood models in inla:

n <- 5
na <- rep(NA, n)
Y1 <- inla.mdata(c(1:n, na, na),  1)
Y2 <- inla.surv(c(na, 1:n, na), 1)
Y3 <- c(na, na, 1:n)
intercept <- as.factor(c(rep(1, n), rep(2, n), rep(3, n)))
data <- list(YY = list(Y1, Y2, Y3),
             intercept = intercept)
r <- inla(YY ~ -1 + intercept, data = data,
          control.inla = list(diagonal = 1),
          family = c("nmix", "exponentialsurv", "poisson"))

It looks like what inlabru needs to do is to

  1. Call inla.stack to join the response variables with the needed extra NA:s (already available)
  2. Call inla.mdata, inla.surv or nothing, on the corresponding column (or list element) of the NA-expanded columns from the stack, and join the results into a list.

Each special response class will likely need its own wrapper likelihood method in inlabru (like the "cp" Cox Process model implementation) since inlabru needs to do the actual calling of the special functions, not the user; they can only be called after joining the models (or special code to alter already created objects would be needed).

It will be more complicated if the other arguments to inla.mdata and inla.surv also need extra handling.