# Using R

Currently, there are no specific tools available in R for evaluation of a longitudinal surrogate for a failure-true endpoint. One could consider using the *JM* package (Rizopoulos, 2010), which does allow fitting a range of joint models for longitudinal and failure-time data. However, by default, in the joint models available in the package, the fixed-effects part of the LMM (8.1) is included in the PH model (8.2). As a result, the effect of treatment on the failure-time endpoint is estimated while already taking into account the treatment effect on the longitudinal process. Additionally, with, e.g., W(t) = U + U_{2}t + Щу/т, the PH model (8.2) can include random effects of the form W_{2}(t) = y_{2}U_{2} + 7_{3}U_{3} + 74W1 (t), but not W_{2}(t) = 71U1 + y_{2}U_{2} + 73U3 + y_{4}W_{1} (t). Thus, the flexibility of modeling of the association between the longitudinal and failure-time processes is somewhat restricted.

On the other hand, conducting an analysis based on the marginal models for the longitudinal and failure-time endpoints can be conducted in R without much problem with existing tools. Toward this aim, the *nlme* and *survival *packages can be used, for instance. In particular, function lme can be used to fit the LMM (8.1). On the other hand, the marginal PH model can be fitted by using function coxph.

More specifically, assume availability of a data frame psadat, say, that corresponds to the dataset psadat used in the SAS analysis presented in Section 8.3.1.1. Then the following R command fits the LMM (8.9)-(8.10) by using the ML estimation:

lme(logpsa ~ -1 + factor(countryn) + timeyr:factor(countryn)

+ timysqrt:factor(countryn)

+ treat:factor(countryn)

+ treat:timeyr:factor(countryn)

+ treat:timysqrt:factor(countryn), random = ~ 1 + timeyr + timysqrt | patid,

method = "ML", data=psadat)

On the other hand, assume availability of a data frame survdat, say, that corresponds to the dataset survdat used in the SAS analysis presented in Section 8.3.1.1. Then the following R command fits the marginal PH model:

coxph(Surv(survyr,survcens) ~ treat:factor(countryn)

+ strata(countryn),

ties="breslow", data=survdat)

The option ties="breslow" implies using the Breslow method for the construction of the partial likelihood function, which is the default method in SAS’ PROC PHREG.

The so-obtained treatment-effect estimates for the LMM and PH models correspond to those reported in Table 8.2.