inlabru-org / inlabru

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

Survival Analysis: support for inla.surv in formula #65

Open DBecker7 opened 4 years ago

DBecker7 commented 4 years ago

Minimal Example:

library(INLA)
library(inlabru)

data("veteran", package = "survival")
veteran$time.m <- round(veteran$time / 30, 3)

exp.vet <- inla(inla.surv(time.m, status) ~ 1,
    data = veteran, family = "exponential.surv")
summary(exp.vet)

# Attempted inlabru version:
exp.vet2 <- bru(components = inla.surv(time.m, status) ~ 1,
    family = like(family = "lognormal.surv",
        formula = inla.surv(time.m, status) ~ 1,
        data = veteran))
Error in eval.if.function(y, points) : unsupported data.

The error is generated by the make.stack() function, which sends as.data.frame(lhood$data)[, lhood$response] into the eval.if.function() function, which tests whether it's a function or if it's numeric. Since lhood$response is a character vector with the names in inla.surv() (in this case, "time.m" and "status"), the result is a data frame and thus it is neither numeric nor a function. The else in eval.if.function() is triggered, which reports the error.

finnlindgren commented 4 years ago

Thanks for the test case!

For future devel reference: inla.surv() generates a list of variables, that converts survival type data into information needed by the .surv response models. Current inlabru code can only handle numeric vectors as observation variables, so it needs to be either extended to handle collections of vectors, or there needs to be a special like() feature to handle survival data, or a combination of those.