## Functional Forms

### Simplified syntax

We have previously seen that function jm() via its functional_forms argument allows the specification of different functional forms to link the longitudinal and event time outcomes. This argument accepts either a single formula or a list of formulas per longitudinal outcome with the terms we wish to include.

We will illustrate some of these possibilities using 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 whether the patients experienced hepatomegaly during follow-up. We will describe the patient-specific profiles over time for this biomarker using a mixed-effects logistic model, where both in the fixed- and random-effects we include an intercept and the time effect. The syntax to fit this model with mixed_model() is:

fm <- mixed_model(hepatomegaly ~ year, data = pbc2, random = ~ year | id,
family = binomial())

The default call to jm()adds the subject-specific linear predictor of the mixed-effects logistic regression as a time-varying covariate in the survival relative risk model:

jointFit1 <- jm(CoxFit, fm, time_var = "year")
summary(jointFit1)
#>
#> Call:
#> jm(Surv_object = CoxFit, Mixed_objects = fm, time_var = "year")
#>
#> Data Descriptives:
#> Number of Groups: 312        Number of events: 169 (54.2%)
#> Number of Observations:
#>   hepatomegaly: 1884
#>
#>                  DIC     WAIC      LPML
#> marginal    3076.205 3065.354 -1532.943
#> conditional 4991.480 4852.734 -2659.933
#>
#> Random-effects covariance matrix:
#>
#>        StdDev   Corr
#> (Intr) 3.2958 (Intr)
#> year   0.5347 -0.1476
#>
#> Survival Outcome:
#>                        Mean  StDev    2.5%  97.5%      P   Rhat
#> sexfemale           -0.4765 0.3128 -1.0750 0.1416 0.1353 1.0039
#> value(hepatomegaly)  0.3497 0.0477  0.2597 0.4526 0.0000 1.0117
#>
#> Longitudinal Outcome: hepatomegaly (family = binomial, link = logit)
#>               Mean  StDev    2.5%  97.5%      P   Rhat
#> (Intercept) 0.0537 0.2257 -0.3793 0.5127 0.8229 1.0014
#> year        0.2868 0.0604  0.1705 0.4061 0.0000 1.0033
#>
#> MCMC summary:
#> chains: 3
#> iterations per chain: 3500
#> burn-in per chain: 500
#> thinning: 1
#> time: 15 sec

In the output this is named as value(hepatomegaly) to denote that the current value functional form is used. That is, we assume that the risk at a specific time $$t$$ is associated with the value of the linear predictor of the longitudinal outcome at the same time point $$t$$. In this particular case, the subject-specific linear predictor denotes the log odds of experiencing hepatomegaly at time $$t$$.

### Transformation functions

The fact that the default version of the current value functional form is on the linear predictor scale of the mixed model may be problematic to interpret when this linear predictor is connected with a nonlinear link function to mean of the longitudinal outcome. In these situations we may want to transform the subject-specific linear predictor back to the scale of the outcome. To achieve this we can use a transformation function. Continuing on the previous example, we update jointFit1 by now linking the expit transformation of the linear predictor (i.e., $$\mbox{expit}(x) = \exp(x) / \{1 + \exp(x)\}$$) with the risk of an event. This is done using the vexpit() function:

jointFit2 <- update(jointFit1, functional_forms = ~ vexpit(value(hepatomegaly)))
summary(jointFit2)
#>
#> Call:
#> jm(Surv_object = CoxFit, Mixed_objects = fm, time_var = "year",
#>     functional_forms = ~vexpit(value(hepatomegaly)))
#>
#> Data Descriptives:
#> Number of Groups: 312        Number of events: 169 (54.2%)
#> Number of Observations:
#>   hepatomegaly: 1884
#>
#>                  DIC     WAIC      LPML
#> marginal    3068.808 3060.348 -1530.929
#> conditional 5012.867 4912.148 -2702.286
#>
#> Random-effects covariance matrix:
#>
#>        StdDev   Corr
#> (Intr) 3.3879 (Intr)
#> year   0.5357 -0.3303
#>
#> Survival Outcome:
#>                                Mean  StDev    2.5%  97.5%     P   Rhat
#> sexfemale                   -0.3580 0.2796 -0.8821 0.1917 0.214 1.0015
#> vexpit(value(hepatomegaly))  3.2301 0.4682  2.3663 4.2126 0.000 1.0321
#>
#> Longitudinal Outcome: hepatomegaly (family = binomial, link = logit)
#>               Mean  StDev    2.5%  97.5%      P   Rhat
#> (Intercept) 0.0647 0.2365 -0.3946 0.5437 0.7904 1.0055
#> year        0.2386 0.0661  0.1140 0.3753 0.0004 1.0362
#>
#> MCMC summary:
#> chains: 3
#> iterations per chain: 3500
#> burn-in per chain: 500
#> thinning: 1
#> time: 18 sec

Other available functions to use in the definition of the functional_forms argument are vexp() for calculating the exponent, vlog() for calculating the natural logarithm, and vsqrt() for calculating the square root.

If we want to include the time-varying slope of the transformed linear predictor, we also have the Dexpit() and Dexp() functions available. As an example, we extend jointFit2 by including the derivative of the $$\mbox{expit}()$$ transformation:

forms <- ~ vexpit(value(hepatomegaly)) + Dexpit(slope(hepatomegaly))
jointFit3 <- update(jointFit1, functional_forms = forms)
summary(jointFit3)
#>
#> Call:
#> jm(Surv_object = CoxFit, Mixed_objects = fm, time_var = "year",
#>     functional_forms = forms)
#>
#> Data Descriptives:
#> Number of Groups: 312        Number of events: 169 (54.2%)
#> Number of Observations:
#>   hepatomegaly: 1884
#>
#>                  DIC     WAIC      LPML
#> marginal    3068.544 3059.792 -1531.497
#> conditional 4993.071 4891.747 -2710.920
#>
#> Random-effects covariance matrix:
#>
#>        StdDev   Corr
#> (Intr) 3.4635 (Intr)
#> year   0.5539 -0.4767
#>
#> Survival Outcome:
#>                                                    Mean  StDev    2.5%   97.5%
#> sexfemale                                       -0.3394 0.2819 -0.8594  0.2176
#> vexpit(value(hepatomegaly))                      3.2826 0.4488  2.4248  4.1828
#> Dexpit(value(hepatomegaly)):slope(hepatomegaly) -0.9609 0.5039 -2.3017 -0.2278
#>                                                      P   Rhat
#> sexfemale                                       0.2447 1.0035
#> vexpit(value(hepatomegaly))                     0.0000 1.0183
#> Dexpit(value(hepatomegaly)):slope(hepatomegaly) 0.0096 1.3228
#>
#> Longitudinal Outcome: hepatomegaly (family = binomial, link = logit)
#>               Mean  StDev    2.5%  97.5%      P   Rhat
#> (Intercept) 0.1437 0.2423 -0.3223 0.6279 0.5493 1.0021
#> year        0.1638 0.0702  0.0259 0.3020 0.0216 1.0954
#>
#> MCMC summary:
#> chains: 3
#> iterations per chain: 3500
#> burn-in per chain: 500
#> thinning: 1
#> time: 20 sec

The call to Dexpit(slope(hepatomegaly)) is internally transformed to Dexpit(value(hepatomegaly)):slope(hepatomegaly), which calculates the derivative of the $$\mbox{expit}()$$ evaluated at the linear predictor times the derivative of the linear predictor. This is because $\frac{d}{dt} \mbox{expit}\{\eta(t)\} = \mbox{expit}\{\eta(t)\} \, \Bigl [ 1 - \mbox{expit}\{\eta(t)\} \Bigr ] \times \frac{d}{dt}\eta(t)$

### The Slope functional form

As we have seen in previous examples, the slope() function is used to specify the slope functional form $$d \eta(t)/dt$$. According to the definition of the derivative, this corresponds to the change in the longitudinal profile $$\{\eta(t + \varepsilon) - \eta(t)\}/ \varepsilon$$ as $$\varepsilon$$ approaches zero. However, the interpretation of this term may be challenging in some settings. A possible alternative would be to increase the value of $$\varepsilon$$, e.g., $$\varepsilon = 1$$. For example, if the time scale is years, this would quantify the change of the longitudinal profile in the last year before $$t$$.

To fit a joint model with such a term, we can use the eps and direction arguments of the slope() function. We illustrate this in the following example, in which we use the serum bilirubin

gm <- lme(log(serBilir) ~ ns(year, 2), data = pbc2, random = ~ ns(year, 2) | id,
control = lmeControl(opt = "optim"))

We first fit the joint model with time-varying slope term:

jFit1 <- jm(CoxFit, gm, time_var = "year",
functional_forms = ~ value(log(serBilir)) + slope(log(serBilir)))

To specify that we want to include the change in the log serum bilirubin levels during the last year before $$t$$, we specify eps = 1 and direction = "back" in the call to slope(). This calculates the term $$\{\eta(t) - \eta(t - \varepsilon)\} / \varepsilon$$ for $$\varepsilon$$ set equal to eps = 1:

jFit2 <- jm(CoxFit, gm, time_var = "year",
functional_forms = ~ value(log(serBilir)) +
slope(log(serBilir), eps = 1, direction = "back"))

We compare the two fits

summary(jFit1)$Survival #> Mean StDev 2.5% 97.5% P #> sexfemale -0.1825798 0.2747308 -0.701782 0.3749103 0.5068889 #> value(log(serBilir)) 1.2196325 0.1037270 1.019953 1.4204795 0.0000000 #> slope(log(serBilir)) 2.8849520 0.6364478 1.690983 4.1335804 0.0000000 #> Rhat #> sexfemale 1.002555 #> value(log(serBilir)) 1.090875 #> slope(log(serBilir)) 1.032619 summary(jFit2)$Survival
#>                                                         Mean     StDev
#> sexfemale                                         -0.1721437 0.2772843
#> value(log(serBilir))                               1.1915668 0.1019399
#> slope(log(serBilir), eps = 1, direction = "back")  2.7746586 0.6433714
#>                                                         2.5%     97.5%     P
#> sexfemale                                         -0.6969171 0.3884404 0.536
#> value(log(serBilir))                               0.9983677 1.3973167 0.000
#> slope(log(serBilir), eps = 1, direction = "back")  1.5855079 4.0632999 0.000
#>                                                       Rhat
#> sexfemale                                         1.000181
#> value(log(serBilir))                              1.014478
#> slope(log(serBilir), eps = 1, direction = "back") 1.014757