Fits multivariate joint models for longitudinal and time-to-event data.

jm(Surv_object, Mixed_objects, time_var, recurrent = FALSE,
  functional_forms = NULL, data_Surv = NULL, id_var = NULL, priors = NULL,
  control = NULL, ...)

value(x)
slope(x, eps = 0.001, direction = "both")
area(x)

vexpit(x)
Dexpit(x)

vexp(x)
Dexp(x)

vlog(x)
vlog2(x)
vlog10(x)

vsqrt(x)
poly2(x)
poly3(x)
poly4(x)

tv(x, knots = NULL, ord = 2L)

Arguments

Surv_object

an object:

  • of class 'coxph' fitted by function coxph() from package survival, or

  • of class 'survreg' fitted by function survreg() from package survival.

Mixed_objects

a list of objects or a single object. Objects may be:

  • of class 'lme' fitted by function lme() from package nlme, or

  • of class 'MixMod' fitted by function mixed_model() from package GLMMadaptive.

time_var

a character string indicating the time variable in the mixed-effects model(s).

recurrent

a character string indicating "calendar" or "gap" timescale to fit a recurrent event model.

functional_forms

a list of formulas. Each formula corresponds to one longitudinal outcome and specifies the association structure between that outcome and the survival submodel as well as any interaction terms between the components of the longitudinal outcome and the survival submodel. See Examples.

data_Surv

the data.frame used to fit the Cox/AFT survival submodel.

id_var

a character string indicating the id variable in the survival submodel.

priors

a named list of user-specified prior parameters:

mean_betas_HC

the prior mean vector of the normal prior for the regression coefficients of the covariates of the longitudinal model(s), which were hierarchically centered.

Tau_betas_HC

the prior precision matrix of the normal prior for the regression coefficients of the longitudinal model(s), which were hierarchically centered.

mean_betas_nHC

a list of the prior mean vector(s) of the normal prior(s) for the regression coefficients of the covariates of the longitudinal model(s), which were not hierarchically centered.

Tau_betas_nHC

a list of the prior precision matrix(ces) of the normal prior(s) for the regression coefficients of the longitudinal model(s), which were not Hierarchically Centered.

mean_bs_gammas

the prior mean vector of the normal prior for the B-splines coefficients used to approximate the baseline hazard.

Tau_bs_gammas

the prior precision matrix of the normal prior for the B-splines coefficients used to approximate the baseline hazard.

A_tau_bs_gammas

the prior shape parameter of the gamma prior for the precision parameter of the penalty term for the B-splines coefficients for the baseline hazard.

B_tau_bs_gammas

the prior rate parameter of the gamma prior for the precision parameter of the penalty term for the B-splines coefficients for the baseline hazard.

rank_Tau_bs_gammas

the prior rank parameter for the precision matrix of the normal prior for the B-splines coefficients used to approximate the baseline hazard.

mean_gammas

the prior mean vector of the normal prior for the regression coefficients of baseline covariates.

Tau_gammas

the prior precision matrix of the normal prior for the regression coefficients of baseline covariates.

penalty_gammas

a character string with value 'none', 'ridge', or 'horseshoe' indicating whether the coefficients of the baseline covariates included in the survival submodel should not be shrunk, shrank using ridge prior, or shrank using horseshoe prior, respectively.

A_lambda_gammas

the prior shape parameter of the gamma prior for the precision parameter of the local penalty term for the baseline regression coefficients. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

B_lambda_gammas

the prior rate parameter of the gamma prior for the precision parameter of the local penalty term for the baseline regression coefficients. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

A_tau_gammas

the prior shape parameter of the gamma prior for the precision parameter of the global penalty term for the baseline regression coefficients. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

B_tau_gammas

the prior rate parameter of the gamma prior for the precision parameter of the global penalty term for the baseline regression coefficients. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

A_nu_gammas

the prior shape parameter of the gamma prior for the variance hyperparameter for the precision parameter of the local penalty term for the baseline regression coefficients. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

B_nu_gammas

the prior rate parameter of the gamma prior for the variance hyperparameter for the precision parameter of the local penalty term for the baseline regression coefficients. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

A_xi_gammas

the prior shape parameter of the gamma prior for the variance hyperparameter for the precision parameter of the global penalty term for the baseline regression coefficients. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

B_xi_gammas

the prior rate parameter of the gamma prior for the variance hyperparameter for the precision parameter of the global penalty term for the baseline regression coefficients. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

mean_alphas

the prior mean vector of the normal prior for the association parameter(s).

Tau_alphas

the prior mean vector of the normal prior for the association parameter(s).

penalty_alphas

a character string with value 'none', 'ridge', 'horseshoe' indicating whether the coefficients association parameters should not be shrunk, shrank using ridge prior, or shrank using horseshoe prior, respectively.

A_lambda_alphas

the prior shape parameter of the gamma prior for the precision parameter of the local penalty term for the association parameters. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

B_lambda_alphas

the prior rate parameter of the gamma prior for the precision parameter of the local penalty term for the association parameters. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

A_tau_alphas

the prior shape parameter of the gamma prior for the precision parameter of the global penalty term for the association parameters. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

B_tau_alphas

the prior rate parameter of the gamma prior for the precision parameter of the global penalty term for the association parameters. Only relevant when penalty_gammas = 'ridge' or penalty_gammas = 'horseshoe'.

A_nu_alphas

the prior shape parameter of the gamma prior for the variance hyperparameter for the precision parameter of the local penalty term for the association parameters. Only relevant when penalty_gammas = 'ridge', or penalty_gammas = 'horseshoe'.

B_nu_alphas

the prior rate parameter of the gamma prior for the variance hyperparameter for the precision parameter of the local penalty term for the association parameters. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

A_xi_alphas

the prior shape parameter of the gamma prior for the variance hyperparameter for the precision parameter of the global penalty term for the association parameters. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

B_xi_alphas

the prior rate parameter of the gamma prior for the variance hyperparameter for the precision parameter of the global penalty term for the association parameters. Only relevant when penalty_gammas = 'ridge' or when penalty_gammas = 'horseshoe'.

gamma_prior_D_sds

logical; if TRUE, a gamma prior will be used for the standard deviations of the D matrix (variance-covariance matrix of the random effects). Defaults to TRUE

D_sds_df

the prior degrees of freedom parameter for the half-t prior for the standard deviations of the D matrix (variance-covariance matrix of the random effects).

D_sds_sigma

the prior sigma parameter vector for the half-t prior for the standard deviations of the D matrix (variance-covariance matrix of the random effects).

D_sds_shape

the prior shape parameter for the gamma prior for the standard deviations of the D matrix (variance-covariance matrix of the random effects).

D_sds_mean

the prior mean parameter vector for the gamma prior for the standard deviations of the D matrix (variance-covariance matrix of the random effects).

D_L_etaLKJ

the prior eta parameter for the LKJ prior for the correlation matrix of the random effects.

sigmas_df

the prior degrees of freedom parameter for the half-t prior for the error term(s).

sigmas_sigma

the prior sigma parameter for the half-t prior for the error term(s).

control

a list of control values with components:

GK_k

the number of quadrature points for the Gauss Kronrod rule; options 15 and 7.

Bsplines_degree

the degree of the splines in each basis; default quadratic splines.

base_hazard_segments

the number of segments to split the follow-up period. Defaults to 10.

diff

the order of the difference used in the penalty matrix for the B-splines for h_0. Defaults to 2.

n_chains

an integer specifying the number of chains for the MCMC. Defaults to 3.

n_burnin

an integer specifying the number of burn-in iterations. Defaults to 500.

n_iter

an integer specifying the number of total iterations per chain. Defaults to 3500.

n_thin

an integer specifying the thinning of the chains. Defaults to 1.

seed

the seed used in the sampling procedures. Defaults to 123.

MALA

a logical; if TRUE, the MALA algorithm is used when updating the elements of the Cholesky factor of the D matrix. Defaults to FALSE.

save_random_effects

a logical; if TRUE, the full MCMC results of the random effects will be saved and returned with the jm object. Defaults to FALSE.

cores

an integer specifying the number of cores to use. Defaults to the available cores minus one.

x

a numeric input variable.

knots

a numeric vector of knots.

ord

an integer denoting the order of the spline.

eps

numeric scalar denoting the step-size for the finite difference approximation.

direction

character string for the direction of the numerical derivative, options are "both", and "backward".

...

arguments passed to control.

Details

The mathematical details regarding the definition of the multivariate joint model, and the capabilities of the package can be found in the vignette in the doc directory.

Value

A list of class jm with components:

mcmc

a list of the MCMC samples for each parameter.

acc_rates

a list of the acceptance rates for each parameter.

logLik

a matrix of dimensions [((n_iter - n_burnin)/n_thin)*n_thin, number of individuals], with element [i, j] being the conditional log-Likelihood value of the \(i^{th}\) iteration for the \(j^{th}\) individual.

mlogLik

a matrix of dimensions [((n_iter - n_burnin)/n_thin)*n_thin, number of individuals], with element [i, j] being the marginal log-Likelihood value of the \(i^{th}\) iteration for the \(j^{th}\) individual.

running_time

an object of class proc_time with the time used to run jm.

statistics

a list with posterior estimates of the parameters (means, medians, standard deviations, standard errors, effective sample sizes, tail probabilities, upper and lower bounds of credible intervals, etc.).

fit_stats

a list of lists with fit statistics (DIC, pD, LPML, CPO, WAIC) for both conditional and marginal formulations.

model_data

a list of data used to fit the model.

model_info

a list of components of the fit useful to other functions.

initial_values

a list with the initial values of the parameters.

control

a copy of the control values used to fit the model.

priors

a copy of the priors used to fit the model.

call

the matched call.

Author

Dimitris Rizopoulos d.rizopoulos@erasmusmc.nl

Examples

# \donttest{
################################################################################

##############################################
# Univariate joint model for serum bilirubin #
# 1 continuous outcome                       #
##############################################

# [1] Fit the mixed model using lme().
fm1 <- lme(fixed = log(serBilir) ~ year * sex + I(year^2) +
           age + prothrombin, random =  ~ year | id, data = pbc2)

# [2] Fit a Cox model, specifying the baseline covariates to be included in the
# joint model.
fCox1 <- coxph(Surv(years, status2) ~ drug + age, data = pbc2.id)

# [3] The basic joint model is fitted using a call to jm() i.e.,
joint_model_fit_1 <- jm(fCox1, fm1, time_var = "year",
        n_chains = 1L, n_iter = 11000L, n_burnin = 1000L)
summary(joint_model_fit_1)
#> 
#> Call:
#> jm(Surv_object = fCox1, Mixed_objects = fm1, time_var = "year", 
#>     n_chains = 1L, n_iter = 11000L, n_burnin = 1000L)
#> 
#> Data Descriptives:
#> Number of Groups: 312		Number of events: 140 (44.9%)
#> Number of Observations:
#>   log(serBilir): 1945
#> 
#>                  DIC       WAIC       LPML
#> marginal    13966.03 1628207.76 -188861.00
#> conditional 11063.27   33358.69  -29382.82
#> 
#> Random-effects covariance matrix:
#>                      
#>        StdDev   Corr 
#> (Intr) 1.5803 (Intr) 
#> year   0.2648 -0.1879
#> 
#> Survival Outcome:
#>                         Mean  StDev    2.5%  97.5%     P
#> drugD-penicil        -0.1514 0.3379 -0.8235 0.4932 0.667
#> age                   0.0600 0.0161  0.0310 0.0935 0.000
#> value(log(serBilir))  0.9593 0.2283  0.4401 1.3691 0.000
#> 
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#>                   Mean  StDev    2.5%  97.5%      P
#> (Intercept)    -0.5284 1.1333 -2.9353 1.6606 0.6288
#> year            0.3316 0.4166 -0.4488 1.2267 0.3820
#> sexfemale      -0.2387 0.4957 -1.2259 0.7427 0.6140
#> I(year^2)      -0.0135 0.0407 -0.1011 0.0615 0.7264
#> age            -0.0078 0.0240 -0.0602 0.0381 0.7428
#> prothrombin     0.1132 0.0814 -0.0366 0.2868 0.1392
#> year:sexfemale -0.0459 0.0678 -0.1791 0.0893 0.4796
#> sigma           0.9215 0.2808  0.5825 1.6435 0.0000
#> 
#> MCMC summary:
#> chains: 1 
#> iterations per chain: 11000 
#> burn-in per chain: 1000 
#> thinning: 1 
#> time: 34 sec
traceplot(joint_model_fit_1)




























################################################################################

##########################################################################
# Multivariate joint model for serum bilirubin, hepatomegaly and ascites #
# 1 continuous outcome, 2 categorical outcomes                           #
##########################################################################

# [1] Fit the mixed-effects models using lme() for continuous
# outcomes and mixed_model() for categorical outcomes.
fm1 <- lme(fixed = log(serBilir) ~ year * sex,
           random = ~ year | id, data = pbc2)

fm2 <- mixed_model(hepatomegaly ~ sex + age + year, data = pbc2,
                   random = ~ year | id, family = binomial())

fm3 <- mixed_model(ascites ~ year + age, data = pbc2,
                   random = ~ year | id, family = binomial())

# [2] Save all the fitted mixed-effects models in a list.
Mixed <- list(fm1, fm2, fm3)

# [3] Fit a Cox model, specifying the baseline covariates to be included in the
# joint model.
fCox1 <- coxph(Surv(years, status2) ~ drug + age, data = pbc2.id)

# [4] The joint model is fitted using a call to jm() i.e.,
joint_model_fit_2 <- jm(fCox1, Mixed, time_var = "year",
      n_chains = 1L, n_iter = 11000L, n_burnin = 1000L)
summary(joint_model_fit_2)
#> 
#> Call:
#> jm(Surv_object = fCox1, Mixed_objects = Mixed, time_var = "year", 
#>     n_chains = 1L, n_iter = 11000L, n_burnin = 1000L)
#> 
#> Data Descriptives:
#> Number of Groups: 312		Number of events: 140 (44.9%)
#> Number of Observations:
#>   log(serBilir): 1945
#>   hepatomegaly: 1884
#>   ascites: 1885
#> 
#>                   DIC      WAIC      LPML
#> marginal     7056.398  8022.876 -4696.621
#> conditional 10743.373 11951.752 -7460.211
#> 
#> Random-effects covariance matrix:
#>                                                    
#>        StdDev   Corr                               
#> (Intr) 0.9937 (Intr)   year (Intr)    year  (Intr) 
#> year   0.1735 0.3752                               
#> (Intr) 3.5858 0.5200 0.3360                        
#> year   0.6435 0.0362 0.3191 -0.3627                
#> (Intr) 3.3243 0.5719 0.4781 0.5056  -0.0611        
#> year   0.5038 0.3874 0.5549 0.3335  0.2833  -0.0923
#> 
#> Survival Outcome:
#>                         Mean  StDev    2.5%  97.5%      P
#> drugD-penicil        -0.2091 0.2746 -0.7489 0.3237 0.4552
#> age                   0.0388 0.0160  0.0046 0.0684 0.0280
#> value(log(serBilir))  0.7651 0.2276  0.2770 1.1979 0.0000
#> value(hepatomegaly)  -0.0090 0.0708 -0.1520 0.1297 0.8990
#> value(ascites)        0.4082 0.1502  0.1699 0.7574 0.0000
#> 
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#>                   Mean  StDev    2.5%  97.5%      P
#> (Intercept)     0.6941 0.2435  0.2179 1.1711 0.0062
#> year            0.2487 0.0631  0.1286 0.3758 0.0004
#> sexfemale      -0.2260 0.2544 -0.7208 0.2732 0.3696
#> year:sexfemale -0.0695 0.0647 -0.1974 0.0546 0.2886
#> sigma           0.3812 0.0148  0.3574 0.4175 0.0000
#> 
#> Longitudinal Outcome: hepatomegaly (family = binomial, link = logit)
#>                Mean  StDev    2.5%  97.5%      P
#> (Intercept)  0.3949 1.3936 -2.3425 3.1004 0.7854
#> sexfemale   -0.9742 0.7668 -2.5468 0.4604 0.1898
#> age          0.0128 0.0224 -0.0314 0.0567 0.5726
#> year         0.2576 0.1550 -0.0445 0.5612 0.0964
#> 
#> Longitudinal Outcome: ascites (family = binomial, link = logit)
#>                Mean  StDev     2.5%   97.5%     P
#> (Intercept) -9.8154 1.8844 -13.7603 -6.3624 0e+00
#> year         0.6413 0.1860   0.2954  1.0331 0e+00
#> age          0.0873 0.0265   0.0374  0.1413 2e-04
#> 
#> MCMC summary:
#> chains: 1 
#> iterations per chain: 11000 
#> burn-in per chain: 1000 
#> thinning: 1 
#> time: 1.2 min
traceplot(joint_model_fit_2)




















































################################################################################

######################
# Slope & Area Terms #
######################

# We extend model 'joint_model_fit_2' by including the value and slope term for
# bilirubin, the area term for hepatomegaly (in the log-odds scale), and the
# value and area term for spiders (in the log-odds scale).
# To include these terms into the model, we specify the 'functional_forms'
# argument. This should be a list of right side formulas. Each component of the
# list should have as name the name of the corresponding outcome variable. In
# the right side formula we specify the functional form of the association using
# functions 'value()', 'slope()' and 'area()'.
# Notes: (1) For terms not specified in the 'functional_forms' list, the default
# value functional form is used.

# [1] Fit the mixed-effects models using lme() for continuous outcomes
# and mixed_model() for categorical outcomes.
fm1 <- lme(fixed = log(serBilir) ~ year * sex, random = ~ year | id, data = pbc2)

fm2 <- mixed_model(hepatomegaly ~ sex + age + year, data = pbc2,
                   random = ~ year | id, family = binomial())

fm3 <- mixed_model(ascites ~ year + age, data = pbc2,
                   random = ~ year | id, family = binomial())

# [2] Save all the fitted mixed-effects models in a list.
Mixed <- list(fm1, fm2, fm3)

# [3] Fit a Cox model, specifying the baseline covariates to be included in the
# joint model.
fCox1 <- coxph(Surv(years, status2) ~ drug + age, data = pbc2.id)

# [4] Specify the list of formulas to be passed to the functional_forms argument
# of jm().
fForms <- list("log(serBilir)" = ~ value(log(serBilir)) + slope(log(serBilir)),
               "hepatomegaly" = ~ area(hepatomegaly),
               "ascites" = ~ value(ascites) + area(ascites))

# [5] The joint model is fitted using a call to jm() and passing the list
# to the functional_forms argument.
joint_model_fit_2 <- jm(fCox1, Mixed, time_var = "year",
                        functional_forms = fForms, n_chains = 1L,
                        n_iter = 11000L, n_burnin = 1000L)
summary(joint_model_fit_2)
#> 
#> Call:
#> jm(Surv_object = fCox1, Mixed_objects = Mixed, time_var = "year", 
#>     functional_forms = fForms, n_chains = 1L, n_iter = 11000L, 
#>     n_burnin = 1000L)
#> 
#> Data Descriptives:
#> Number of Groups: 312		Number of events: 140 (44.9%)
#> Number of Observations:
#>   log(serBilir): 1945
#>   hepatomegaly: 1884
#>   ascites: 1885
#> 
#>                  DIC      WAIC      LPML
#> marginal     7075.70  8486.249 -5082.905
#> conditional 10796.99 12233.354 -7710.996
#> 
#> Random-effects covariance matrix:
#>                                                   
#>        StdDev   Corr                              
#> (Intr) 0.9938 (Intr)   year (Intr)    year  (Intr)
#> year   0.1781 0.4010                              
#> (Intr) 3.6493 0.5174 0.3476                       
#> year   0.6492 0.0548 0.3247 -0.3656               
#> (Intr) 3.1549 0.5785 0.4947 0.5000  -0.0255       
#> year   0.5190 0.4296 0.5819 0.3811  0.2523  0.0042
#> 
#> Survival Outcome:
#>                         Mean  StDev    2.5%  97.5%      P
#> drugD-penicil        -0.1787 0.2746 -0.7067 0.3474 0.5082
#> age                   0.0449 0.0146  0.0163 0.0723 0.0050
#> value(log(serBilir))  0.7998 0.2257  0.3746 1.2501 0.0000
#> slope(log(serBilir))  2.0738 1.3936 -0.7445 4.8070 0.1406
#> area(hepatomegaly)    0.0380 0.0861 -0.1316 0.2103 0.6698
#> value(ascites)        0.1467 0.2761 -0.5709 0.5566 0.5370
#> area(ascites)         0.1440 0.2668 -0.2493 0.8680 0.6192
#> 
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#>                   Mean  StDev    2.5%  97.5%      P
#> (Intercept)     0.7098 0.2423  0.2314 1.1845 0.0050
#> year            0.2556 0.0660  0.1297 0.3853 0.0016
#> sexfemale      -0.2466 0.2526 -0.7444 0.2517 0.3158
#> year:sexfemale -0.0708 0.0668 -0.2004 0.0568 0.2746
#> sigma           0.3825 0.0154  0.3575 0.4174 0.0000
#> 
#> Longitudinal Outcome: hepatomegaly (family = binomial, link = logit)
#>                Mean  StDev    2.5%  97.5%      P
#> (Intercept)  0.4479 1.3826 -2.2777 3.1523 0.7548
#> sexfemale   -1.0281 0.7464 -2.5016 0.4125 0.1628
#> age          0.0129 0.0226 -0.0304 0.0574 0.5744
#> year         0.2726 0.1562 -0.0256 0.5899 0.0720
#> 
#> Longitudinal Outcome: ascites (family = binomial, link = logit)
#>                Mean  StDev     2.5%   97.5%     P
#> (Intercept) -9.6452 1.9125 -13.8396 -6.2949 0e+00
#> year         0.6116 0.1930   0.2653  1.0314 6e-04
#> age          0.0865 0.0273   0.0353  0.1435 6e-04
#> 
#> MCMC summary:
#> chains: 1 
#> iterations per chain: 11000 
#> burn-in per chain: 1000 
#> thinning: 1 
#> time: 1.6 min

# }