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, zero_ind = NULL)
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 for running the chains in parallel; no point of setting this greater than n_chains.

knots

a numeric vector with the position of the knots for the B-spline approximation of the log baseline hazard function.

x

a numeric input variable.

knots

a numeric vector of knots.

ord

an integer denoting the order of the spline.

zero_ind

a list with integer vectors indicating which coefficients are set to zero in the calculation of the value term. This can be used to include for example only the random intercept; default is NULL.

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

methods.jm, coda_methods.jm

## 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    4195.141 4987.952 -2953.673
#> conditional 3338.762 3171.818 -1813.218
#>
#> Random-effects covariance matrix:
#>
#>        StdDev   Corr
#> (Intr) 0.9736 (Intr)
#> year   0.1768 0.3441
#>
#> Survival Outcome:
#>                         Mean  StDev    2.5%  97.5%      P
#> drugD-penicil        -0.0310 0.2374 -0.4828 0.4437 0.8902
#> age                   0.0636 0.0094  0.0456 0.0823 0.0000
#> value(log(serBilir))  1.4102 0.1065  1.2142 1.6330 0.0000
#>
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#>                   Mean  StDev    2.5%   97.5%      P
#> (Intercept)     0.2508 0.3558 -0.4540  0.9410 0.4798
#> year            0.2257 0.0366  0.1552  0.2980 0.0000
#> sexfemale      -0.2433 0.1797 -0.5980  0.1055 0.1802
#> I(year^2)       0.0028 0.0010  0.0009  0.0049 0.0000
#> age            -0.0017 0.0053 -0.0121  0.0089 0.7414
#> prothrombin     0.0525 0.0084  0.0359  0.0691 0.0000
#> year:sexfemale -0.0870 0.0379 -0.1616 -0.0124 0.0218
#> sigma           0.3458 0.0067  0.3328  0.3588 0.0000
#>
#> MCMC summary:
#> chains: 1
#> iterations per chain: 11000
#> burn-in per chain: 1000
#> thinning: 1
#> time: 33 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    6630.115 6821.290 -3693.464
#> conditional 9035.592 8737.179 -4830.832
#>
#> Random-effects covariance matrix:
#>
#>        StdDev   Corr
#> (Intr) 0.9892 (Intr)   year (Intr)    year  (Intr)
#> year   0.1756 0.4002
#> (Intr) 3.1951 0.5330 0.3405
#> year   0.5688 0.0813 0.3809 -0.2976
#> (Intr) 2.7886 0.6227 0.4995 0.5672  -0.0429
#> year   0.4039 0.3902 0.6382 0.3263  0.3757  -0.0305
#>
#> Survival Outcome:
#>                         Mean  StDev    2.5%  97.5%      P
#> drugD-penicil        -0.1939 0.2592 -0.7057 0.3312 0.4522
#> age                   0.0319 0.0148  0.0020 0.0587 0.0388
#> value(log(serBilir))  0.6496 0.2412  0.1772 1.1145 0.0084
#> value(hepatomegaly)  -0.0410 0.0892 -0.2029 0.1702 0.5714
#> value(ascites)        0.5745 0.2028  0.1670 1.0333 0.0020
#>
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#>                   Mean  StDev    2.5%   97.5%      P
#> (Intercept)     0.6705 0.1381  0.4023  0.9419 0.0000
#> year            0.2438 0.0277  0.1900  0.2985 0.0000
#> sexfemale      -0.2008 0.1425 -0.4806  0.0756 0.1638
#> year:sexfemale -0.0611 0.0286 -0.1191 -0.0057 0.0306
#> sigma           0.3478 0.0068  0.3348  0.3617 0.0000
#>
#> Longitudinal Outcome: hepatomegaly (family = binomial, link = logit)
#>                Mean  StDev    2.5%  97.5%      P
#> (Intercept)  0.1727 0.9375 -1.6684 2.0412 0.8526
#> sexfemale   -0.7740 0.5203 -1.8245 0.2393 0.1278
#> age          0.0126 0.0152 -0.0172 0.0425 0.4054
#> year         0.2613 0.0683  0.1256 0.3960 0.0000
#>
#> Longitudinal Outcome: ascites (family = binomial, link = logit)
#>                Mean  StDev     2.5%   97.5% P
#> (Intercept) -8.7944 0.9053 -10.6241 -7.0491 0
#> year         0.5707 0.0651   0.4506  0.7068 0
#> age          0.0782 0.0150   0.0496  0.1078 0
#>
#> MCMC summary:
#> chains: 1
#> iterations per chain: 11000
#> burn-in per chain: 1000
#> thinning: 1
#> time: 1.3 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    6641.257 6936.844 -4059.640
#> conditional 9140.916 8858.333 -4886.228
#>
#> Random-effects covariance matrix:
#>
#>        StdDev   Corr
#> (Intr) 0.9879 (Intr)   year (Intr)    year  (Intr)
#> year   0.1782 0.4161
#> (Intr) 3.4591 0.5329 0.3432
#> year   0.5962 0.0352 0.3667 -0.3763
#> (Intr) 2.8089 0.6033 0.5235 0.5229  -0.0157
#> year   0.4190 0.4411 0.6311 0.4102  0.2451  0.0260
#>
#> Survival Outcome:
#>                         Mean  StDev    2.5%  97.5%      P
#> drugD-penicil        -0.1710 0.2705 -0.7073 0.3552 0.5176
#> age                   0.0395 0.0131  0.0142 0.0656 0.0008
#> value(log(serBilir))  0.6889 0.2031  0.2901 1.0942 0.0000
#> slope(log(serBilir))  1.4593 1.3682 -1.3638 4.1803 0.2666
#> area(hepatomegaly)   -0.0176 0.0859 -0.1722 0.1542 0.8108
#> value(ascites)        0.5700 0.3708 -0.3893 1.1153 0.2250
#> area(ascites)        -0.1280 0.3049 -0.5445 0.6911 0.4280
#>
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#>                   Mean  StDev    2.5%   97.5%      P
#> (Intercept)     0.6774 0.1400  0.4051  0.9517 0.0000
#> year            0.2516 0.0305  0.1916  0.3129 0.0000
#> sexfemale      -0.2110 0.1441 -0.4989  0.0701 0.1430
#> year:sexfemale -0.0660 0.0304 -0.1269 -0.0067 0.0312
#> sigma           0.3482 0.0066  0.3357  0.3616 0.0000
#>
#> Longitudinal Outcome: hepatomegaly (family = binomial, link = logit)
#>                Mean  StDev    2.5%  97.5%      P
#> (Intercept)  0.2497 0.9846 -1.6657 2.1666 0.8066
#> sexfemale   -0.8461 0.5244 -1.9153 0.1487 0.0960
#> age          0.0131 0.0162 -0.0182 0.0449 0.4222
#> year         0.2569 0.0695  0.1295 0.3973 0.0000
#>
#> Longitudinal Outcome: ascites (family = binomial, link = logit)
#>                Mean  StDev     2.5%   97.5% P
#> (Intercept) -8.8906 1.0476 -10.9855 -6.8138 0
#> year         0.5818 0.0770   0.4318  0.7295 0
#> age          0.0789 0.0170   0.0453  0.1139 0
#>
#> MCMC summary:
#> chains: 1
#> iterations per chain: 11000
#> burn-in per chain: 1000
#> thinning: 1
#> time: 1.6 min

# }