vignettes/JMbayes2.Rmd
JMbayes2.Rmd
The function that fits joint models in JMbayes2 is
called jm()
. It has three required arguments,
Surv_object
a Cox model fitted by coxph()
or
an Accelerated Failure time model fitted by survreg()
,
Mixed_objects
a single or a list of mixed models fitted
either by the lme()
or mixed_model()
functions, and time_var
a character string indicating the
name of the time variable in the specification of the mixed-effects
models. We will illustrate the basic use of the package in the PBC
dataset. We start by fitting a Cox model for the composite event
transplantation or death, including sex as a baseline covariate:
pbc2.id$status2 <- as.numeric(pbc2.id$status != 'alive')
CoxFit <- coxph(Surv(years, status2) ~ sex, data = pbc2.id)
Our aim is to assess the strength of the association between the risk
of the composite event and the levels of serum bilirubin that has been
collected during follow-up. We will describe the patient-specific
profiles over time for this biomarker using a linear mixed model, with
fixed-effects, time, sex, and their interaction, and as random effects
random intercepts and random slopes. The syntax to fit this model with
lme()
is:
fm1 <- lme(log(serBilir) ~ year * sex, data = pbc2, random = ~ year | id)
The joint model that links the survival and longitudinal submodels is
fitted with the following call to the jm()
function:
jointFit1 <- jm(CoxFit, fm1, time_var = "year")
summary(jointFit1)
#>
#> Call:
#> jm(Surv_object = CoxFit, Mixed_objects = fm1, time_var = "year")
#>
#> Data Descriptives:
#> Number of Groups: 312 Number of events: 169 (54.2%)
#> Number of Observations:
#> log(serBilir): 1945
#>
#> DIC WAIC LPML
#> marginal 4361.435 5361.220 -3356.241
#> conditional 3536.629 3355.317 -1907.678
#>
#> Random-effects covariance matrix:
#>
#> StdDev Corr
#> (Intr) 1.0028 (Intr)
#> year 0.1829 0.3994
#>
#> Survival Outcome:
#> Mean StDev 2.5% 97.5% P Rhat
#> sexfemale -0.1581 0.2717 -0.6499 0.3848 0.5544 1.0015
#> value(log(serBilir)) 1.2433 0.0847 1.0776 1.4140 0.0000 1.0183
#>
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#> Mean StDev 2.5% 97.5% P Rhat
#> (Intercept) 0.7239 0.1720 0.3821 1.0600 0.0000 0.9997
#> year 0.2668 0.0381 0.1929 0.3444 0.0000 1.0024
#> sexfemale -0.2639 0.1823 -0.6192 0.0882 0.1511 0.9999
#> year:sexfemale -0.0886 0.0404 -0.1681 -0.0093 0.0247 1.0028
#> sigma 0.3465 0.0065 0.3342 0.3596 0.0000 1.0101
#>
#> MCMC summary:
#> chains: 3
#> iterations per chain: 3500
#> burn-in per chain: 500
#> thinning: 1
#> time: 15 sec
The output of the summary()
method provides some
descriptive statistics of the sample at hand, followed by some fit
statistics based on the marginal (random effects are integrated out
using the Laplace approximation) and conditional on the random effects
log-likelihood functions, followed by the estimated variance-covariance
matrix for the random effects, followed by the estimates for the
survival submodel, followed by the estimates for the longitudinal
submodel(s), and finally some information for the MCMC fitting
algorithm.
By default, jm()
adds the subject-specific linear
predictor of the mixed model as a time-varying covariate in the survival
relative risk model. In the output this is named as
value(log(serBilir))
to denote that, by default, the
current value functional form is used. That is, we assume that the
instantaneous risk of an event at a specific time \(t\) is associated with the value of the
linear predictor of the longitudinal outcome at the same time point
\(t\).
Standard MCMC diagnostics are available to evaluate convergence. For
example, the traceplot for the association coefficient
value(log(serBilir))
is produced with the following
syntax:
ggtraceplot(jointFit1, "alphas")
and the density plot with the call:
ggdensityplot(jointFit1, "alphas")
To fit a joint model with multiple longitudinal outcomes, we simply
provide a list of mixed models as the second argument of
jm()
. In the following example, we extend the joint model
we fitted above by also including the prothrombin time and the log odds
of the presence or not of ascites as time-varying covariates in the
relative risk model for the composite event. Because this model is more
complex, we increase the number of MCMC iterations, the number of
burn-in iterations and the thinning per chain, using the corresponding
control arguments:
fm2 <- lme(prothrombin ~ year * sex, data = pbc2, random = ~ year | id)
fm3 <- mixed_model(ascites ~ year + sex, data = pbc2,
random = ~ year | id, family = binomial())
jointFit2 <- jm(CoxFit, list(fm1, fm2, fm3), time_var = "year",
n_iter = 12000L, n_burnin = 2000L, n_thin = 5L)
summary(jointFit2)
#>
#> Call:
#> jm(Surv_object = CoxFit, Mixed_objects = list(fm1, fm2, fm3),
#> time_var = "year", n_iter = 12000L, n_burnin = 2000L, n_thin = 5L)
#>
#> Data Descriptives:
#> Number of Groups: 312 Number of events: 169 (54.2%)
#> Number of Observations:
#> log(serBilir): 1945
#> prothrombin: 1945
#> ascites: 1885
#>
#> DIC WAIC LPML
#> marginal 11526.54 16843.97 -9112.336
#> conditional 12582.21 12314.07 -6689.580
#>
#> Random-effects covariance matrix:
#>
#> StdDev Corr
#> (Intr) 0.9877 (Intr) year (Intr) year (Intr)
#> year 0.1904 0.4374
#> (Intr) 0.7799 0.5604 0.4777
#> year 0.3329 0.4206 0.3661 0.0502
#> (Intr) 2.8878 0.5583 0.5209 0.6025 0.2833
#> year 0.4699 0.4395 0.6706 0.2367 0.4803 -0.0036
#>
#> Survival Outcome:
#> Mean StDev 2.5% 97.5% P Rhat
#> sexfemale -0.6661 0.3533 -1.3675 0.0039 0.0523 1.0006
#> value(log(serBilir)) 0.4931 0.1862 0.0843 0.8209 0.0167 1.0858
#> value(prothrombin) 0.0150 0.1231 -0.2453 0.2481 0.8540 1.0346
#> value(ascites) 0.6085 0.1566 0.3530 0.9693 0.0000 1.1432
#>
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#> Mean StDev 2.5% 97.5% P Rhat
#> (Intercept) 0.7040 0.1677 0.3718 1.0262 0.0003 1.0004
#> year 0.2781 0.0339 0.2123 0.3453 0.0000 1.0029
#> sexfemale -0.2465 0.1779 -0.5909 0.1028 0.1720 1.0005
#> year:sexfemale -0.0844 0.0356 -0.1547 -0.0151 0.0140 1.0036
#> sigma 0.3469 0.0065 0.3346 0.3595 0.0000 1.0004
#>
#> Longitudinal Outcome: prothrombin (family = gaussian, link = identity)
#> Mean StDev 2.5% 97.5% P Rhat
#> (Intercept) 10.9410 0.1706 10.6080 11.2734 0.0000 1.0064
#> year 0.2540 0.0752 0.1068 0.4011 0.0003 1.0029
#> sexfemale -0.4033 0.1815 -0.7593 -0.0473 0.0277 1.0072
#> year:sexfemale 0.0499 0.0783 -0.1041 0.2031 0.5207 1.0017
#> sigma 1.0545 0.0203 1.0147 1.0952 0.0000 1.0093
#>
#> Longitudinal Outcome: ascites (family = binomial, link = logit)
#> Mean StDev 2.5% 97.5% P Rhat
#> (Intercept) -4.4387 0.7136 -5.9527 -3.1496 0.000 1.0748
#> year 0.6247 0.0747 0.4877 0.7772 0.000 1.1638
#> sexfemale -0.5083 0.6729 -1.8103 0.8390 0.448 1.0046
#>
#> MCMC summary:
#> chains: 3
#> iterations per chain: 12000
#> burn-in per chain: 2000
#> thinning: 5
#> time: 1.9 min
The output for the survival submodel contains now the estimated
coefficients for value(prothrombin)
and
value(ascites)
, and parameter estimates for all three
longitudinal submodels.
As mentioned above, the default call to jm()
includes
the subject-specific linear predictors of the mixed-effects models as
time-varying covariates in the relative risk model. However, this is
just one of the many possibilities we have to link the longitudinal and
survival outcomes. The argument functional_forms
of
jm()
provides additional options. Based on previous
experience, two extra functional forms are provided, namely, the
time-varying slope and the time-varying normalized
area/cumulative-effect. The time-varying slope is the first order
derivative of the subject-specific linear predictor of the mixed-effect
model with respect to the (follow-up) time variable. The time-varying
normalized area/cumulative-effect is the integral of the
subject-specific linear predictor of the mixed-effect model from zero to
the current (follow-up) time \(t\)
divided by \(t\). The integral is the
area under the subject-specific longitudinal profile; by dividing the
integral by \(t\) we obtain the average
of the subject-specific longitudinal profile over the corresponding
period \((0, t)\).
To illustrate how the functional_forms
argument can be
used to specify these functional forms, we update the joint model
jointFit2
by including the time-varying slope of log serum
bilirubin instead of the value, and also the interaction of this slope
with sex, and for prothrombin we include the normalized cumulative
effect. For ascites, we keep the value functional form. The
corresponding syntax to fit this model is:
fForms <- list(
"log(serBilir)" = ~ slope(log(serBilir)) + slope(log(serBilir)):sex,
"prothrombin" = ~ area(prothrombin)
)
jointFit3 <- update(jointFit2, functional_forms = fForms)
summary(jointFit3)
#>
#> Call:
#> jm(Surv_object = CoxFit, Mixed_objects = list(fm1, fm2, fm3),
#> time_var = "year", functional_forms = fForms, n_iter = 12000L,
#> n_burnin = 2000L, n_thin = 5L)
#>
#> Data Descriptives:
#> Number of Groups: 312 Number of events: 169 (54.2%)
#> Number of Observations:
#> log(serBilir): 1945
#> prothrombin: 1945
#> ascites: 1885
#>
#> DIC WAIC LPML
#> marginal 11510.08 12744.55 -6934.016
#> conditional 12463.00 12223.14 -6615.764
#>
#> Random-effects covariance matrix:
#>
#> StdDev Corr
#> (Intr) 0.9798 (Intr) year (Intr) year (Intr)
#> year 0.1937 0.4597
#> (Intr) 0.7703 0.5596 0.4981
#> year 0.3347 0.4262 0.3766 0.0651
#> (Intr) 2.8598 0.5916 0.5001 0.6141 0.2738
#> year 0.4921 0.4856 0.7205 0.2830 0.5063 0.0467
#>
#> Survival Outcome:
#> Mean StDev 2.5% 97.5% P Rhat
#> sexfemale 0.0884 0.8420 -1.4755 1.7725 0.9563 1.0791
#> slope(log(serBilir)) 4.4293 2.3476 -0.0309 9.1338 0.0520 1.0654
#> slope(log(serBilir)):sexfemale -2.9861 2.4891 -8.2926 1.6414 0.1923 1.1285
#> area(prothrombin) -0.0564 0.2813 -0.6804 0.4339 0.8863 1.4462
#> value(ascites) 0.8356 0.1857 0.4980 1.2620 0.0000 1.9045
#>
#> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity)
#> Mean StDev 2.5% 97.5% P Rhat
#> (Intercept) 0.6696 0.1646 0.3470 0.9885 0.0000 1.0019
#> year 0.2723 0.0327 0.2080 0.3374 0.0000 1.0046
#> sexfemale -0.2096 0.1738 -0.5476 0.1324 0.2177 1.0030
#> year:sexfemale -0.0730 0.0336 -0.1379 -0.0070 0.0303 1.0027
#> sigma 0.3471 0.0067 0.3342 0.3602 0.0000 0.9999
#>
#> Longitudinal Outcome: prothrombin (family = gaussian, link = identity)
#> Mean StDev 2.5% 97.5% P Rhat
#> (Intercept) 10.9313 0.1715 10.5959 11.2711 0.0000 1.0009
#> year 0.2394 0.0739 0.0954 0.3887 0.0010 1.0102
#> sexfemale -0.3890 0.1809 -0.7527 -0.0395 0.0337 1.0009
#> year:sexfemale 0.0671 0.0769 -0.0880 0.2180 0.3780 1.0102
#> sigma 1.0551 0.0205 1.0174 1.0976 0.0000 1.0011
#>
#> Longitudinal Outcome: ascites (family = binomial, link = logit)
#> Mean StDev 2.5% 97.5% P Rhat
#> (Intercept) -4.5835 0.7209 -6.0836 -3.2620 0.0000 1.0416
#> year 0.6595 0.0779 0.5307 0.8439 0.0000 1.1164
#> sexfemale -0.3530 0.6814 -1.7099 0.9853 0.6007 1.0039
#>
#> MCMC summary:
#> chains: 3
#> iterations per chain: 12000
#> burn-in per chain: 2000
#> thinning: 5
#> time: 2 min
As seen above, the functional_forms
argument is a named
list with elements corresponding to the longitudinal outcomes. If a
longitudinal outcome is not specified in this list, then the default,
value functional form, is used for that outcome. Each element of the
list should be a one-sided R formula in which the functions
value()
, slope()
and area()
can
be used. Interaction terms between the functional forms and other
(baseline) covariates are also allowed.
When multiple longitudinal outcomes are considered with possibly
different functional forms per outcome, we require to fit a relative
risk model containing several terms. Moreover, it is often of scientific
interest to select which terms/functional-forms per longitudinal outcome
are more strongly associated with the risk of the event of interest. To
facilitate this selection, jm()
provides the option to
penalize the regression coefficients using shrinkage priors. As an
example, we refit jointFit3
by assuming a Horseshoe prior
for the alphas
coefficients (i.e., the coefficients of the
longitudinal outcomes in the relative risk model):
jointFit4 <- update(jointFit3, priors = list("penalty_alphas" = "horseshoe"))
cbind("un-penalized" = unlist(coef(jointFit3)),
"penalized" = unlist(coef(jointFit4)))
#> un-penalized penalized
#> gammas.Mean 0.08836824 -0.547830896
#> association.slope(log(serBilir)) 4.42927257 2.433785930
#> association.slope(log(serBilir)):sexfemale -2.98611683 -0.672446743
#> association.area(prothrombin) -0.05640063 -0.009282955
#> association.value(ascites) 0.83563144 0.743008430
Apart from the Horseshoe prior, the ridge prior is also provided.