Include "step" function into Joint longitudinal and time to event model

I am fitting a joint longitudinal and time to event model on production data with the aim of making dynamic predictions of the time of assembly of a machine. I am using JMbayes R package.

Among the time-dependent variables in the longitudinal part of the model I have a dummy variable that tells whether the mechanical part of the assembly is finished or not, this variable is 0 up to a certain time point, thereafter it becomes one from the time the mechanical part is completed to the time of the event (the assembly has been completed). So basically it is a one step function.

Now I am fitting a binomial(link=“logit”) longitudinal model for this variable using time fixed effect and a random effect for the order number related to the machine being assembled. I am linking this longitudinal model to the time event component using the “current value” association.

The idea is that if I complete the mechanical part ahead of the historical average, it is likely that the time of assembly will be lower, coversely if I spend much more time, it is likely that the final time of assembly will be higher.

I am sure this is not the right way to include this kind of variable in the model, both in modelling it in the longitudinal part of the model without taking into account that this is a binary step function over time so monotone non-decreasing, and also for the way I linked it to the time component i.e. using the current value association.

Could you help me correct the model definition?

I don’t think I understand the question completly, but this seems to be tightly bound the the JMBayes package and I don’t think many people have experience with that pacakge - I am not even sure if it uses Stan for most of its work (and whether it is thus on-topic here). I know the package author (@drizopoulos) is a member on the forums but they were never really active, so not sure if they can respond. I also noted @jroon has posted about the package a few times so maybe he can help.

In any case, it would be useful if you posted the code you use to run your current model and a sample of the data you have as it is hard for me to understand what is going on just from the verbal description.

Best of luck with your model!

1 Like

Hi @carlocav. Like @martinmodrak I’m not completely clear on your question/model, but I’ll give best answer I can.

First is that JMBayes R package only uses Stan for one function (mvglmer) so this is probably not the right forum for your questions. A more general data analysis forum that might be helpful is:

To your questions about your model. First thing to know is that @drizopoulos has released JMBayes2 which has a wider range of longitudinal families (JMbayes2 • JMbayes2), but so far I don’t think it has a prediction function. However, with the description of your data - I’m not sure joint modelling is the correct approach. Is your only longitudinal data this 0/1 variable that only goes in one direction - i.e. 0 to 1 ? In that case you might be better with something like a multistate survival model. These are extensions to survival models where your outcome can take more than just a 0/1 state. So for example you could model 0 = healthy, 1 = sick, 2 = dead. Or in your case, 0 = part under constructions, 1 = part made, 2 = assembly completed. However I’ve never used such models in practice so I can’t really tell you anything more. I don’t know if these have been implemented in Stan yet.


Thank you @martinmodrak and @jroon
Yes, I definitely need multi state survival models, thank you, but still I have standard longitudinal data such as the number of missing components needed for assembly. So I think that what I need is a joint model for longitudinal and multi state process, but I have not found an R package to fit those models and make dynamic predictions.
Unfortunately even if JmBayes and JmBayes2 allow to fit them, they do not make dynamic predictions.
Do you know any alternatives? In case I try to ask also in the forum suggested by @jroon.

JMbayes does do dynamic prediction and has multistate options in the mvJointModelBayes() command, though I dont’ know if you can do dynamic prediction from a multistate model. I’d say keep watching JMbayes2 - its very new and Dimitris is adding stuff to it all the time. The other package that comes to mind is the merlin package from Michael Crowther in R and Stata. It allows multiple longitudinal models and joint models of various sorts and fancy combinations of those. I’ve not used it myself so cna’t advise further, but I know its also undergoing very active development.

You could of course build a bespoke model in Stan from scratch but thats beyond my abilities!

1 Like

Unfortunately JMBayes doesn’t allow to make dynamic predictions from a multistate model, only fit. I didn’t know Merlin, I will check if it allows to make dynamic predictions from joint models of longitudinal and multistate data. Thank you

Edit: unfortunately it looks like that even merlin doesn’t allows to make dynamic predictions, it is referred to as a forthcoming development.