Package 'JMbdirect'

Title: Joint Model for Longitudinal and Multiple Time to Events Data
Description: Provides model fitting, prediction, and plotting for joint models of longitudinal and multiple time-to-event data, including methods from Rizopoulos (2012) <doi:10.1201/b12208>. Useful for handling complex survival and longitudinal data in clinical research.
Authors: Atanu Bhattacharjee [aut, cre, ctb], Bhrigu Kumar Rajbongshi [aut, ctb], Gajendra K Vishwakarma [aut, ctb]
Maintainer: Atanu Bhattacharjee <[email protected]>
License: GPL-3
Version: 0.1.0
Built: 2025-03-12 05:33:49 UTC
Source: https://github.com/cran/JMbdirect

Help Index


Function for bootstrapped confidence interval

Description

Function for bootstrapped confidence interval

Usage

bootciJMCS(object, future_time)

Arguments

object

fitted model

future_time

time sequence at which estimates are required

Value

Returns bootstraped confidence interval for model fitted through FastJM


Joint model for Bidirectional survival data using JMbayes2

Description

The function fits joint model for survival data with two events. It utilizes the JMbayes2 package for obtaining the model parameter estimates.

Usage

jmbB(
  dtlong,
  dtsurv,
  longm,
  survm,
  rd,
  timeVar,
  id,
  samplesize = NULL,
  BIGdata = FALSE,
  niter = 200,
  nburnin = 100,
  nchain = 1
)

Arguments

dtlong

longitudinal data

dtsurv

survival data with two event status along with event time

longm

longitudinal model e.g. list(serBilir~drug * year,serBilir ~ drug * year)

survm

survival model e.g. list(Surv(years,status2)~drug,Surv(time_2,status_2)~drug+age)

rd

random effect component e.g. list(~year|id,~year|id)

timeVar

time variable

id

ID variable

samplesize

samplesize for bigdata

BIGdata

logical argument TRUE or FALSE

niter

number if iteration

nburnin

number of sample to burn

nchain

number of MCMC chain

Value

Estimated model parameters of Joint model with bidirectional survival data

Author(s)

Atanu Bhattacharjee, Bhrigu Kumar Rajbongshi and Gajendra Kumar Vishwakarma

References

Rizopoulos, D., G. Papageorgiou, and P. Miranda Afonso. "JMbayes2: extended joint models for longitudinal and time-to-event data." R package version 0.2-4 (2022).

Bhattacharjee, A., Rajbongshi, B. K., & Vishwakarma, G. K. (2024). jmBIG: enhancing dynamic risk prediction and personalized medicine through joint modeling of longitudinal and survival data in big routinely collected data. BMC Medical Research Methodology, 24(1), 172.

Examples

library(JMbayes2)
st_pbcid<-function(){
  new_pbcid<-pbc2.id
  new_pbcid$time_2<-rexp(n=nrow(pbc2.id),1/10)
  cen_time<-runif(nrow(pbc2.id),min(new_pbcid$time_2),max(new_pbcid$time_2))
  status_2<-ifelse(new_pbcid$time_2<cen_time,1,0)
  new_pbcid$status_2<-status_2
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<cen_time,new_pbcid$time_2,cen_time)
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<new_pbcid$years,new_pbcid$years,new_pbcid$time_2)
  new_pbcid
}
new_pbc2id<-st_pbcid()
pbc2$status_2<-rep(new_pbc2id$status_2,times=data.frame(table(pbc2$id))$Freq)
pbc2$time_2<-rep(new_pbc2id$time_2,times=data.frame(table(pbc2$id))$Freq)
pbc2_new<-pbc2[pbc2$id%in%c(1:100),]
new_pbc2id<-new_pbc2id[new_pbc2id$id%in%c(1:100),]
model_jmbBdirect<-jmbB(dtlong=pbc2_new,dtsurv =new_pbc2id,
                       longm=list(serBilir~drug*year,serBilir~drug*year),
                       survm=list(Surv(years,status2)~drug,Surv(time_2,status_2)~drug+age),
                       rd=list(~year|id,~year|id),
                       id='id',timeVar ='year')
model_jmbBdirect

Joint model for Bidirectional survival data using FastJM

Description

The function fits joint model for survival data with two events. It utilizes the FastJM package for obtaining the model parameter estimates.

Usage

jmcsB(
  dtlong,
  dtsurv,
  longm,
  survm,
  rd,
  id,
  timeVar,
  BIGdata = FALSE,
  samplesize = 200
)

Arguments

dtlong

longitudinal data

dtsurv

survival data with two event status along with event time

longm

longitudinal model e.g. list(serBilir~drug * year,serBilir ~ drug * year)

survm

survival model e.g. list(Surv(years,status2)~drug,Surv(time_2,status_2)~drug+age)

rd

random effect component e.g. list(~year|id,~year|id)

id

ID variable

timeVar

time variable

BIGdata

logical argument TRUE or FALSE

samplesize

samplesize for bigdata

Value

Estimated model parameters of Joint model with bidirectional survival data

Author(s)

Atanu Bhattacharjee, Bhrigu Kumar Rajbongshi and Gajendra Kumar Vishwakarma

References

Li, Shanpeng, et al. "Efficient Algorithms and Implementation of a Semiparametric Joint Model for Longitudinal and Competing Risk Data: With Applications to Massive Biobank Data." Computational and Mathematical Methods in Medicine 2022 (2022).

Bhattacharjee, A., Rajbongshi, B. K., & Vishwakarma, G. K. (2024). jmBIG: enhancing dynamic risk prediction and personalized medicine through joint modeling of longitudinal and survival data in big routinely collected data. BMC Medical Research Methodology, 24(1), 172.

Examples

library(FastJM)
library(JMbayes2)
st_pbcid<-function(){
  new_pbcid<-pbc2.id
  new_pbcid$time_2<-rexp(n=nrow(pbc2.id),1/10)
  cen_time<-runif(nrow(pbc2.id),min(new_pbcid$time_2),max(new_pbcid$time_2))
  status_2<-ifelse(new_pbcid$time_2<cen_time,1,0)
  new_pbcid$status_2<-status_2
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<cen_time,new_pbcid$time_2,cen_time)
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<new_pbcid$years,new_pbcid$years,new_pbcid$time_2)
  new_pbcid
}
new_pbc2id<-st_pbcid()
pbc2$status_2<-rep(new_pbc2id$status_2,times=data.frame(table(pbc2$id))$Freq)
pbc2$time_2<-rep(new_pbc2id$time_2,times=data.frame(table(pbc2$id))$Freq)
pbc2_new<-pbc2[pbc2$id%in%c(1:50),]
new_pbc2id<-new_pbc2id[new_pbc2id$id%in%c(1:50),]
model_jmcs<-jmcsB(dtlong=pbc2_new,dtsurv=new_pbc2id,
                  longm=list(serBilir~drug*year,
                             serBilir~drug*year),
                  survm=list(Surv(years,status2)~drug,
                             Surv(time_2,status_2)~drug+age),
                  rd=list(~1|id,~1|id),
                  id='id',timeVar='year')
model_jmcs

Joint model for Bidirectional survival data using joineRML

Description

The function fits joint model for survival data with two events. It utilizes the joineRML package for obtaining the model parameter estimates.

Usage

jmrmlB(
  dtlong,
  dtsurv,
  longm,
  survm,
  rd,
  timeVar,
  id,
  samplesize = 200,
  BIGdata = FALSE
)

Arguments

dtlong

longitudinal data

dtsurv

survival data with two event status along with event time

longm

longitudinal model e.g. list(serBilir~drug * year,serBilir ~ drug * year)

survm

survival model e.g. list(Surv(years,status2)~drug,Surv(time_2,status_2)~drug+age)

rd

random effect component e.g. list(~year|id,~year|id)

timeVar

time variable

id

ID variable

samplesize

samplesize for bigdata

BIGdata

logical argument TRUE or FALSE

Value

Estimated model parameters of Joint model with bidirectional survival data

Author(s)

Atanu Bhattacharjee, Bhrigu Kumar Rajbongshi and Gajendra Kumar Vishwakarma

References

Hickey, Graeme L., et al. "joineRML: a joint model and software package for time-to-event and multivariate longitudinal outcomes." BMC medical research methodology 18 (2018): 1-14.

Bhattacharjee, A., Rajbongshi, B. K., & Vishwakarma, G. K. (2024). jmBIG: enhancing dynamic risk prediction and personalized medicine through joint modeling of longitudinal and survival data in big routinely collected data. BMC Medical Research Methodology, 24(1), 172.

Examples

##
library(JMbayes2)
library(joineRML)
jmrmlBModel<-jmrmlB(dtlong=new_long2[new_long2$id%in%c(1:80),],
                    dtsurv=new_surv2[new_surv2$id%in%c(1:80),],
                    longm=list(y~x7+visit,y~x7+visit),survm=list(Surv(time,status)~x1+visit,
                    Surv(time_2,status_2)~x1+visit),rd=list(~visit|id,~visit|id),id='id',
                    timeVar='visit',samplesize=40,BIGdata=TRUE)
jmrmlBModel
##

Joint model for Bidirectional survival data using rstanarm

Description

The function fits joint model for survival data with two events. It utilizes the rstanarm package for obtaining the model parameter estimates.

Usage

jmstB(
  dtlong,
  dtsurv,
  longm,
  survm,
  timeVar,
  id,
  nchain = 1,
  refresh = 1000,
  BIGdata = FALSE,
  samplesize = 200
)

Arguments

dtlong

longitudinal data

dtsurv

survival data with two event status along with event time

longm

longitudinal model e.g. list(serBilir~drug * year+(year|id),serBilir ~ drug * year+(year|id))

survm

survival model e.g. list(Surv(years,status2)~drug,Surv(time_2,status_2)~drug+age)

timeVar

time variable

id

ID variable

nchain

number of MCMC chain

refresh

number of refresh sample

BIGdata

logical argument TRUE or FALSE

samplesize

samplesize for bigdata

Value

Estimated model parameters of Joint model with bidirectional survival data

Author(s)

Atanu Bhattacharjee, Bhrigu Kumar Rajbongshi and Gajendra Kumar Vishwakarma

References

Goodrich, B., et al. "rstanarm: Bayesian applied regression modeling via Stan. R package version 2.17. 4." Online< http://mc-stan. org (2018).

Bhattacharjee, A., Rajbongshi, B. K., & Vishwakarma, G. K. (2024). jmBIG: enhancing dynamic risk prediction and personalized medicine through joint modeling of longitudinal and survival data in big routinely collected data. BMC Medical Research Methodology, 24(1), 172.

Examples

##
library(JMbayes2)
library(rstanarm)
st_pbcid<-function(){
  new_pbcid<-pbc2.id
  new_pbcid$time_2<-rexp(n=nrow(pbc2.id),1/10)
  cen_time<-runif(nrow(pbc2.id),min(new_pbcid$time_2),max(new_pbcid$time_2))
  status_2<-ifelse(new_pbcid$time_2<cen_time,1,0)
  new_pbcid$status_2<-status_2
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<cen_time,new_pbcid$time_2,cen_time)
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<new_pbcid$years,new_pbcid$years,
                           new_pbcid$time_2)
  new_pbcid
}
new_pbc2id<-st_pbcid()
pbc2$status_2<-rep(new_pbc2id$status_2,times=data.frame(table(pbc2$id))$Freq)
pbc2$time_2<-rep(new_pbc2id$time_2,times=data.frame(table(pbc2$id))$Freq)
pbc2_new<-pbc2[pbc2$id%in%c(1:50),]
new_pbc2id<-new_pbc2id[new_pbc2id$id%in%c(1:50),]
model_jmstBdirect<-jmstB(
  dtlong=pbc2_new,
  dtsurv = new_pbc2id,
  longm=list(serBilir~drug*year+(year|id),albumin~drug+year+(year|id)),
  survm=list(Surv(years,status2)~drug,Surv(time_2,status_2)~drug),
  timeVar="year",
  id='id',
  refresh=400,
  nchain=1)
model_jmstBdirect
##

longitudinal- survival dataset

Description

A longitudinal dataset with single marker , with different numeric and categorical covariate

Usage

data(new_long2)

Format

a tibble of 13 columns and 5639 observations,

id

id value for subjects

status

survival status

time

survival time

y

longitudinal marker

visit

visit time of longitudinal measurements

x1,x2,...,x7

different numeric and categorical variable


survival data

Description

A survival dataset related the long2 dataset, with different numeric and categorical covariate

Usage

data(new_surv2)

Format

a tibble of 13 columns and 1000 observations,

id

id value for subjects

status

survival status

time

survival time

visit

visit time of longitudinal measurements

x1,x2,...,x7

different numeric and categorical variable


Prediction plot from jmbB()

Description

Prediction plot from jmbB()

Usage

## S3 method for class 'jmbB'
plot(x, y, ...)

Arguments

x

fitted model

y

newdata

...

others

Value

Returns prediction plot for the newdata using the model fitted through jmbB().

Note

In the example code we use newdata as the data for ID 2 in the PBC2 dataset, it has follow up information till 8.832. Now suppose we want to look at the survival of ID 2 under joint model 1 after time 4 and for joint model 2 after time 9. For that we created the newdata as if the individual is followed till for a time period less than min(4,9).

Examples

##
library(JMbayes2)
st_pbcid<-function(){
  new_pbcid<-pbc2.id
  new_pbcid$time_2<-rexp(n=nrow(pbc2.id),1/10)
  cen_time<-runif(nrow(pbc2.id),min(new_pbcid$time_2),max(new_pbcid$time_2))
  status_2<-ifelse(new_pbcid$time_2<cen_time,1,0)
  new_pbcid$status_2<-status_2
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<cen_time,new_pbcid$time_2,cen_time)
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<new_pbcid$years,new_pbcid$years,new_pbcid$time_2)
  new_pbcid
}
new_pbc2id<-st_pbcid()
pbc2$status_2<-rep(new_pbc2id$status_2,times=data.frame(table(pbc2$id))$Freq)
pbc2$time_2<-rep(new_pbc2id$time_2,times=data.frame(table(pbc2$id))$Freq)
pbc2_new<-pbc2[pbc2$id%in%c(1:100),]
new_pbc2id<-new_pbc2id[new_pbc2id$id%in%c(1:100),]
model_jmbBdirect<-jmbB(dtlong=pbc2_new,dtsurv = new_pbc2id,
                       longm=list(serBilir ~ drug*year,serBilir ~ drug*year),
                       survm=list(Surv(years,status2) ~ drug,
                                  Surv(time_2,status_2) ~ drug+age),
                       rd=list(~year|id,~year|id),
                       id='id',timeVar ='year')

t0<-4
nd <- pbc2[pbc2$id %in% c(2), ]
nd<-nd[nd$year<t0,]
nd$status2<-0
nd$years<-t0
nd$time_2<-9
nd$status_2<-0
plot(model_jmbBdirect,nd)
nd <- pbc2[pbc2$id %in% c(2), ]
nd<-nd[nd$year<12,]
nd$status2<-0
nd$years<-12
nd$time_2<-9
nd$status_2<-0
plot(model_jmbBdirect,nd)
##

Prediction plot from jmcsB()

Description

Prediction plot from jmcsB()

Usage

## S3 method for class 'jmcsB'
plot(x, y, ...)

Arguments

x

fitted model object

y

newdata longitudinal

...

other

Value

Returns prediction plot for the newdata using the model fitted through jmcsB()

Note

In the example code we use newdata as the data for ID 2 in the PBC2 dataset, it has follow up information till 8.832. Now suppose we want to look at the survival of ID 2 under joint model 1 after time 4 and for joint model 2 after time 9. For that we created the newdata as if the individual is followed till for a time period less than min(4,9).

Examples

library(JMbayes2)
 library(FastJM)
  st_pbcid<-function(){
  new_pbcid<-pbc2.id
  new_pbcid$time_2<-rexp(n=nrow(pbc2.id),1/10)
  cen_time<-runif(nrow(pbc2.id),min(new_pbcid$time_2),max(new_pbcid$time_2))
  status_2<-ifelse(new_pbcid$time_2<cen_time,1,0)
  new_pbcid$status_2<-status_2
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<cen_time,new_pbcid$time_2,cen_time)
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<new_pbcid$years,new_pbcid$years,new_pbcid$time_2)
  new_pbcid}
new_pbc2id<-st_pbcid()
pbc2$status_2<-rep(new_pbc2id$status_2,times=data.frame(table(pbc2$id))$Freq)
pbc2$time_2<-rep(new_pbc2id$time_2,times=data.frame(table(pbc2$id))$Freq)
pbc2_new<-pbc2[pbc2$id%in%c(1:50),]
new_pbc2id<-new_pbc2id[new_pbc2id$id%in%c(1:50),]
model_jmcs<-jmcsB(dtlong=pbc2_new,dtsurv = new_pbc2id,
                  longm=list(serBilir~drug*year,
                             serBilir~drug*year),
                  survm=list(Surv(years,status2)~drug,
                             Surv(time_2,status_2)~drug+age),
                  rd=list(~1|id,~1|id),
                  id='id',timeVar='year')

t0<-4
nd<-pbc2[pbc2$id %in% c(2),]
nd<-nd[nd$year<t0,]
nd$status2<-0
nd$years<-t0
nd$time_2<-9
nd$status_2<-0
plot(x=model_jmcs,y=nd)
##

Prediction plot from jmrmlB()

Description

Prediction plot from jmrmlB()

Usage

## S3 method for class 'jmrmlB'
plot(x, y, ...)

Arguments

x

fitted model object

y

newdata

...

others

Value

Returns prediction plot for the newdata using the model fitted through jmrmlB().

Note

In the example code we use newdata as the data for ID 2 in the PBC2 dataset, it has follow up information till 8.832. Now suppose we want to look at the survival of ID 2 under joint model 1 after time 4 and for joint model 2 after time 9. For that we created the newdata as if the individual is followed till for a time period less than min(4,9).

Examples

##
library(JMbayes2)
library(joineRML)
jmrmlBModel<-jmrmlB(dtlong=new_long2[new_long2$id<=400,],
                    dtsurv=new_surv2[new_surv2$id<=400,],
                    longm=list(y~x7+visit,y~x7+visit),
                    survm=list(Surv(time,status)~x1+visit,
                               Surv(time_2,status_2)~x1+visit),
                    rd=list(~visit|id,~visit|id),
                    id='id',
                    timeVar='visit',
                    samplesize=200,
                    BIGdata=TRUE)
t0<-6
ndBIG<-new_long2[new_long2$id==10,]
ndBIG<-ndBIG[ndBIG$visit<t0,]
ndBIG$status<-0
ndBIG$time<-t0
ndBIG$time_2<-10
ndBIG$status_2<-0
plot(jmrmlBModel,ndBIG)
##

Prediction plot from jmstB()

Description

Prediction plot from jmstB()

Usage

## S3 method for class 'jmstB'
plot(x, y, ...)

Arguments

x

fitted model object

y

newdata

...

others

Value

Returns prediction plot for the newdata using the model fitted through jmstB().

Note

In the example code we use newdata as the data for ID 2 in the PBC2 dataset, it has follow up information till 8.832. Now suppose we want to look at the survival of ID 2 under joint model 1 after time 4 and for joint model 2 after time 9. For that we created the newdata as if the individual is followed till for a time period less than min(4,9).

Examples

##
library(JMbayes2)
library(rstanarm)
st_pbcid<-function(){
  new_pbcid<-pbc2.id
  new_pbcid$time_2<-rexp(n=nrow(pbc2.id),1/10)
  cen_time<-runif(nrow(pbc2.id),min(new_pbcid$time_2),max(new_pbcid$time_2))
  status_2<-ifelse(new_pbcid$time_2<cen_time,1,0)
  new_pbcid$status_2<-status_2
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<cen_time,new_pbcid$time_2,cen_time)
  new_pbcid$time_2<-ifelse(new_pbcid$time_2<new_pbcid$years,new_pbcid$years,new_pbcid$time_2)
  new_pbcid
}
new_pbc2id<-st_pbcid()
pbc2$status_2<-rep(new_pbc2id$status_2,times=data.frame(table(pbc2$id))$Freq)
pbc2$time_2<-rep(new_pbc2id$time_2,times=data.frame(table(pbc2$id))$Freq)
pbc2_new<-pbc2[pbc2$id%in%c(1:50),]
new_pbc2id<-new_pbc2id[new_pbc2id$id%in%c(1:50),]
model_jmstBdirect<-jmstB(
  dtlong=pbc2_new,
  dtsurv = new_pbc2id,
  longm=list(serBilir ~ drug * year+(year|id),albumin~drug+year+(year|id)),
  survm=list(Surv(years,status2) ~ drug,Surv(time_2,status_2) ~ drug),
  timeVar="year",
  id='id',
  refresh=400,
  nchain=1)
t0<-4
nd<-pbc2[pbc2$id %in% c(2), ]
nd<-nd[nd$year<t0,]
nd$status2<-0
nd$years<-t0
nd$time_2<-9
nd$status_2<-0
plot(x=model_jmstBdirect,y = nd)
##

predict.jmbB

Description

predict.jmbB

Usage

## S3 method for class 'jmbB'
predict(object, newdata, ...)

Arguments

object

fitted model

newdata

newdata

...

others

Value

Survival Prediction for newdata from model fitted through jmbB()


predict.jmcsB

Description

predict.jmcsB

Usage

## S3 method for class 'jmcsB'
predict(object, newdata, ...)

Arguments

object

fitted model

newdata

newdata

...

others

Value

Survival Prediction for newdata from model fitted through jmcsB()


predict.jmrmlB

Description

predict.jmrmlB

Usage

## S3 method for class 'jmrmlB'
predict(object, newdata, ...)

Arguments

object

fitted model

newdata

newdata

...

others

Value

Survival Prediction for newdata from model fitted through jmrmlB()


predict.jmstB

Description

predict.jmstB

Usage

## S3 method for class 'jmstB'
predict(object, newdata, ...)

Arguments

object

fitted model

newdata

newdata

...

others

Value

Survival Prediction for newdata from model fitted through jmstB()


print.

Description

print method for class 'jmbB'

Usage

## S3 method for class 'jmbB'
print(x, ...)

Arguments

x

fitted object

...

others

Value

prints table containing various parameter estimates, SE, P- value for both survival and longitudinal submodel, if the model is bayesian it includes their credible interval too.


print.

Description

print method for class 'jmcsB'

Usage

## S3 method for class 'jmcsB'
print(x, ...)

Arguments

x

fittedobject

...

others

Value

prints table containing various parameter estimates, SE, P- value for both survival and longitudinal submodel, if the model is bayesian it includes their credible interval too.


print.

Description

print method for class 'jmrmlB'

Usage

## S3 method for class 'jmrmlB'
print(x, ...)

Arguments

x

fitted object

...

others

Value

prints table containing various parameter estimates, SE, P- value for both survival and longitudinal submodel, if the model is bayesian it includes their credible interval too.


print.

Description

print method for class 'jmstB'

Usage

## S3 method for class 'jmstB'
print(x, ...)

Arguments

x

fitted object

...

others

Value

prints table containing various parameter estimates, SE, P- value for both survival and longitudinal submodel, if the model is bayesian it includes their credible interval too.