I’m wondering if it is possible to include a covariate in the longitudinal submodel of a joint model as a spline, probably with one or two knots at most, when using stan_jm
. The longitudinal covariate I’m working with has a definite non-linear relationship with time. I haven’t had any luck googling the issue since any search with spline and stan_jm
just returns hits about modeling the baseline hazard as b-splines or m-splines.
For an example, here is a slightly modified version of the model from the Estimating Joint Models vignette where logBili is just a function of time.
library(rstanarm)
mod1 <- stan_jm(formulaLong = logBili ~ year + (year | id),
dataLong = pbcLong,
formulaEvent = survival::Surv(futimeYears, death) ~ sex + trt,
dataEvent = pbcSurv,
time_var = "year",
chains = 1, refresh = 2000, seed = 12345)
Let’s imagine that the relationship between logBili and year is non-linear and would be best modeled with a spline. I’d like to be able to fit something like:
library(rstanarm)
mod1 <- stan_jm(formulaLong = logBili ~ s(year) + (year | id),
dataLong = pbcLong,
formulaEvent = survival::Surv(futimeYears, death) ~ sex + trt,
dataEvent = pbcSurv,
time_var = "year",
chains = 1, refresh = 2000, seed = 12345)
but it doesn’t seem possible to run that chunk as is. Is there some way to incorporate a spline in this model without writing my own custom stan code?