diff --git a/R/accuracy_measures.R b/R/accuracy_measures.R index 990c9c12..86048a7a 100644 --- a/R/accuracy_measures.R +++ b/R/accuracy_measures.R @@ -141,7 +141,7 @@ print.tvROC <- function (x, digits = 4, ...) { d <- d[!is.na(d$qSN) & !is.na(d$qSP), ] d <- d[!duplicated(d[c("SN", "SP")]), ] row.names(d) <- 1:nrow(d) - print(d) + print(d, digits = digits) cat("\n") invisible(x) } diff --git a/R/basic_methods.R b/R/basic_methods.R index d569a24b..3f96de91 100644 --- a/R/basic_methods.R +++ b/R/basic_methods.R @@ -595,19 +595,24 @@ crisk_setup <- function (data, statusVar, censLevel, nameStrata = "strata", dataOut } -predict.jm <- function (object, newdata = NULL, newdata2 = NULL, - times = NULL, all_times = FALSE, times_per_id = FALSE, +predict.jm <- function (object, newdata = NULL, newdata2 = NULL, times = NULL, process = c("longitudinal", "event"), type_pred = c("response", "link"), type = c("subject_specific", "mean_subject"), - level = 0.95, return_newdata = FALSE, use_Y = TRUE, - return_mcmc = FALSE, n_samples = 200L, n_mcmc = 55L, - parallel = c("snow", "multicore"), - cores = NULL, seed = 123L, ...) { + control = NULL, ...) { process <- match.arg(process) type_pred <- match.arg(type_pred) type <- match.arg(type) - parallel <- match.arg(parallel) + con <- list(all_times = FALSE, times_per_id = FALSE, level = 0.95, + return_newdata = FALSE, use_Y = TRUE, return_mcmc = FALSE, + n_samples = 200L, n_mcmc = 55L, + parallel = c("snow", "multicore"), cores = NULL, seed = 123L) + control <- c(control, list(...)) + namC <- names(con) + con[(namc <- names(control))] <- control + if (length(noNms <- namc[!namc %in% namC]) > 0) { + warning("unknown names in control: ", paste(noNms, collapse = ", ")) + } id_var <- object$model_info$var_names$idVar time_var <- object$model_info$var_names$time_var Time_var <- object$model_info$var_names$Time_var @@ -687,21 +692,23 @@ predict.jm <- function (object, newdata = NULL, newdata2 = NULL, check_varNames(object, newdata2, id_var, "E") check_varNames(object, newdata2, id_var, "L") } - if (is.null(cores)) { + if (is.null(con$cores)) { n <- if (!is.data.frame(newdata)) length(unique(newdata$newdataL[[id_var]])) else length(unique(newdata[[id_var]])) cores <- if (n > 20) 4L else 1L } components_newdata <- - get_components_newdata(object, newdata, n_samples, - n_mcmc, parallel, cores, seed, use_Y) + get_components_newdata(object, newdata, con$n_samples, + con$n_mcmc, con$parallel, con$cores, con$seed, + con$use_Y) if (process == "longitudinal") { predict_Long(object, components_newdata, newdata, newdata2, times, - all_times, times_per_id, type, type_pred, level, - return_newdata, return_mcmc) + con$all_times, con$times_per_id, type, type_pred, con$level, + con$return_newdata, con$return_mcmc) } else { predict_Event(object, components_newdata, newdata, newdata2, times, - times_per_id, level, return_newdata, return_mcmc) + con$times_per_id, con$level, con$return_newdata, + con$return_mcmc) } } @@ -1018,18 +1025,25 @@ rc_setup <- function(rc_data, trm_data, } predict.jmList <- function (object, weights, newdata = NULL, newdata2 = NULL, - times = NULL, all_times = FALSE, times_per_id = FALSE, - process = c("longitudinal", "event"), + times = NULL, process = c("longitudinal", "event"), type_pred = c("response", "link"), type = c("subject_specific", "mean_subject"), - level = 0.95, return_newdata = FALSE, - return_mcmc = FALSE, n_samples = 200L, n_mcmc = 55L, - parallel = c("snow", "multicore"), - cores = parallelly::availableCores(omit = 1L), ...) { + control = NULL, ...) { process <- match.arg(process) type_pred <- match.arg(type_pred) type <- match.arg(type) parallel <- match.arg(parallel) + con <- list(all_times = FALSE, times_per_id = FALSE, level = 0.95, + return_newdata = FALSE, use_Y = TRUE, return_mcmc = FALSE, + n_samples = 200L, n_mcmc = 55L, + parallel = c("snow", "multicore"), + cores = parallelly::availableCores(omit = 1L), seed = 123L) + control <- c(control, list(...)) + namC <- names(con) + con[(namc <- names(control))] <- control + if (length(noNms <- namc[!namc %in% namC]) > 0) { + warning("unknown names in control: ", paste(noNms, collapse = ", ")) + } obj <- object[[1L]] id_var <- obj$model_info$var_names$idVar time_var <- obj$model_info$var_names$time_var @@ -1153,7 +1167,7 @@ predict.jmList <- function (object, weights, newdata = NULL, newdata2 = NULL, "variable(s): ", paste(missing_vars, collapse = ", "), ".\n") } } - cores <- min(cores, length(object)) + cores <- min(con$cores, length(object)) if (cores > 1L) { have_mc <- have_snow <- FALSE if (parallel == "multicore") { @@ -1169,11 +1183,13 @@ predict.jmList <- function (object, weights, newdata = NULL, newdata2 = NULL, preds <- parallel::mclapply(object, predict, newdata = newdata, newdata2 = newdata2, times = times, - all_times = all_times, - times_per_id = times_per_id, + all_times = con$all_times, + times_per_id = con$times_per_id, process = process, type_pred = type_pred, - type = type, level = level, n_samples = n_samples, - n_mcmc = n_mcmc, return_newdata = return_newdata, + type = type, level = con$level, + n_samples = con$n_samples, + n_mcmc = con$n_mcmc, + return_newdata = con$return_newdata, return_mcmc = TRUE, mc.cores = cores) } else { cl <- parallel::makePSOCKcluster(rep("localhost", cores)) @@ -1181,11 +1197,13 @@ predict.jmList <- function (object, weights, newdata = NULL, newdata2 = NULL, preds <- parallel::parLapply(cl, object, predict, newdata = newdata, newdata2 = newdata2, times = times, - all_times = all_times, - times_per_id = times_per_id, + all_times = con$all_times, + times_per_id = con$times_per_id, process = process, type_pred = type_pred, - type = type, level = level, n_samples = n_samples, - n_mcmc = n_mcmc, return_newdata = return_newdata, + type = con$type, level = con$level, + n_samples = con$n_samples, + n_mcmc = con$n_mcmc, + return_newdata = con$return_newdata, return_mcmc = TRUE) parallel::stopCluster(cl) } @@ -1193,10 +1211,10 @@ predict.jmList <- function (object, weights, newdata = NULL, newdata2 = NULL, preds <- lapply(object, predict, newdata = newdata, newdata2 = newdata2, times = times, - all_times = all_times, times_per_id = times_per_id, + all_times = con$all_times, times_per_id = con$times_per_id, process = process, type_pred = type_pred, - type = type, level = level, n_samples = n_samples, - n_mcmc = n_mcmc, return_newdata = return_newdata, + type = type, level = con$level, n_samples = con$n_samples, + n_mcmc = con$n_mcmc, return_newdata = con$return_newdata, return_mcmc = TRUE) } extract_mcmc <- function (x) { diff --git a/docs/articles/Causal_Effects.html b/docs/articles/Causal_Effects.html index 6a7d427e..6e0d576d 100644 --- a/docs/articles/Causal_Effects.html +++ b/docs/articles/Causal_Effects.html @@ -135,7 +135,7 @@

Causal Effects

Dimitris Rizopoulos

-

2024-04-22

+

2024-05-25

Source: vignettes/Causal_Effects.Rmd @@ -206,7 +206,7 @@

Causal Effects from Joint Models#> iterations per chain: 3500 #> burn-in per chain: 500 #> thinning: 1 -#> time: 19 sec +#> time: 20 sec

The coefficient for drugD-penicil for the survival outcome in the output produced by the summary() method denotes the residual/direct effect of treatment on the risk of the @@ -259,12 +259,13 @@

Causal Effects from Joint Models
 # estimate 
 Pr1$pred[2L] - Pr0$pred[2L]
-#> [1] 0.002916962
-
+#> [1] 0.002916423
+
+
 # MCMC variability
 quantile(Pr1$mcmc[2L, ] - Pr0$mcmc[2L, ], probs = c(0.025, 0.975))
 #>       2.5%      97.5% 
-#> -0.1790865  0.1952537
+#> -0.1790905 0.1952539

Time-varying treatments

diff --git a/docs/articles/Competing_Risks.html b/docs/articles/Competing_Risks.html index ecdf7565..dfdaadf3 100644 --- a/docs/articles/Competing_Risks.html +++ b/docs/articles/Competing_Risks.html @@ -135,7 +135,7 @@

Competing Risks

Dimitris Rizopoulos

-

2024-04-22

+

2024-05-25

Source: vignettes/Competing_Risks.Rmd @@ -150,28 +150,29 @@

Competing Risks

Prepare data

-

The first step to fit a joint model for competing events in +

The first step in fitting a joint model for competing events in JMbayes2 is to prepare the data for the event process. If there are \(K\) competing events, -then each subject needs to have \(K\) -rows, one for each possible cause. The observed event time \(T_i\) of each subject is repeated \(K\) times, and there are two indicator -variables, namely one identifying the cause, and one indicating whether +each subject must have \(K\) rows, one +for each possible cause. The observed event time \(T_i\) of each subject is repeated \(K\) times, and there are two indicator +variables, namely one identifying the cause and one indicating whether the corresponding event type is the one that occurred. Standard survival -datasets that included a single row per patient, can be easily -transformed to the competing risks long format using function +datasets that include a single row per patient can be easily transformed +to the competing risks long format using the function crisk_setup(). This function accepts as main arguments the -survival data in the standard format that has a single row per patient, -the name of the status variable, and the level in this status variable -that corresponds to censoring. We illustrate the use of this function in -the PBC data, in which we treat as competing risks transplantation and +survival data in the standard format with a single row per patient, the +name of the status variable, and the level in this status variable that +corresponds to censoring. We illustrate the use of this function in the +PBC data, in which we treat as competing risks transplantation and death:

 pbc2.id[pbc2.id$id %in% c(1, 2, 5), c("id", "years", "status")]
 #>   id     years       status
 #> 1  1  1.095170         dead
 #> 2  2 14.152338        alive
-#> 5  5  4.120578 transplanted
-
+#> 5  5  4.120578 transplanted
+
+
 pbc2.idCR <- crisk_setup(pbc2.id, statusVar = "status", censLevel = "alive", 
                          nameStrata = "CR")
 
@@ -199,21 +200,21 @@ 

Fit models
+
 CoxFit_CR <- coxph(Surv(years, status2) ~ (age + drug) * strata(CR),
                      data = pbc2.idCR)
-

For the longitudinal process, we include two longitudinal outcomes, -namely serum bilirubin and the prothrombin time. For the former we use +

We include two longitudinal outcomes for the longitudinal process, +namely serum bilirubin and the prothrombin time. For the former, we use quadratic orthogonal polynomials in the fixed- and random-effects parts, -and for the latter linear evolutions:

-
+and for the latter, linear evolutions:

+
 fm1 <- lme(log(serBilir) ~ poly(year, 2) * drug, data = pbc2, 
            random = ~ poly(year, 2) | id)
 fm2 <- lme(prothrombin ~ year * drug, data = pbc2, random = ~ year | id)

To specify that each longitudinal outcome has a separate association coefficient per competing risk, we define the corresponding functional forms:

-
+
 CR_forms <- list(
     "log(serBilir)" = ~ value(log(serBilir)):CR,
     "prothrombin" = ~ value(prothrombin):CR
@@ -222,7 +223,7 @@ 

Fit modelsjm() (due to the complexity of the model, we have increased the number of MCMC iterations and the burn-in period per chain):

-
+
 jFit_CR <- jm(CoxFit_CR, list(fm1, fm2), time_var = "year", 
               functional_forms = CR_forms, 
               n_iter = 25000L, n_burnin = 5000L, n_thin = 5L)
@@ -296,35 +297,35 @@ 

Fit models#> iterations per chain: 25000 #> burn-in per chain: 5000 #> thinning: 5 -#> time: 6.4 min

+#> time: 6.5 min

Dynamic predictions

Based on the fitted competing risks joint model, we will illustrate -how (dynamic) predictions for the cause-specific cumulative risk -probabilities can be calculated. As an example, we will show these -calculations for Patient 81 from the PBC dataset. First, we extract the -data of this subject.

-
+how (dynamic) predictions can be calculated for the cause-specific
+cumulative risk probabilities. We will show these calculations for
+Patient 81 from the PBC dataset as an example. First, we extract the
+data on this subject.

+
 ND_long <- pbc2[pbc2$id == 81, ]
 ND_event <- pbc2.idCR[pbc2.idCR$id == 81, ]
 ND_event$status2 <- 0
 ND <- list(newdataL = ND_long, newdataE = ND_event)

The first line extracts the longitudinal measurements, and the second line extracts the event times per cause (i.e., death and -transplantation). This particular patient died at 6.95 years, but to -make the calculation of cause-specific cumulative risk more relevant, we -presume that she did not have the event, and we set the event status -variable status2 to zero. The last line combines the two -datasets in a list. Note: this last step is a prerequisite from -the predict() method for competing risks joint model. That -is, the datasets provided in the arguments newdata and +transplantation). This patient died at 6.95 years, but to make the +calculation of cause-specific cumulative risk more relevant, we presume +that she did not have the event, and we set the event status variable +status2 to zero. The last line combines the two datasets in +a list. Note: this last step is a prerequisite from the +predict() method for competing risks joint model. That is, +the datasets provided in the arguments newdata and newdata2 need to be named lists with two components. The first component needs to be named newdataL and contain the -dataset with the longitudinal measurements, and the second component -needs to be named newdataE and contain the dataset with the -event information.

+dataset with the longitudinal measurements. The second component needs +to be named newdataE and contain the dataset with the event +information.

The predictions are calculated using the predict() method. The first call to this function calculates the prediction for the longitudinal outcomes at the times provided in the @@ -333,7 +334,7 @@

Dynamic predictionsplot() method to depict the predictions:

-
+
 predLong <- predict(jFit_CR, newdata = ND, return_newdata = TRUE,
                     times = seq(6.5, 15, length = 25))
 
@@ -345,7 +346,7 @@ 

Dynamic predictions= c("#03BF3D4D", "#FF00004D"), pos_ylab_long = c(1.5, 11.5)) legend(x = 8.1, y = 0.45, legend = levels(pbc2.idCR$CR), lty = 1, lwd = 2, col = c("#03BF3D", "#FF0000"), bty = "n", cex = 0.8)

-

+

diff --git a/docs/articles/Competing_Risks_files/figure-html/CIFs-1.png b/docs/articles/Competing_Risks_files/figure-html/CIFs-1.png index d5987b1e..25dba47c 100644 Binary files a/docs/articles/Competing_Risks_files/figure-html/CIFs-1.png and b/docs/articles/Competing_Risks_files/figure-html/CIFs-1.png differ diff --git a/docs/articles/Dynamic_Predictions.html b/docs/articles/Dynamic_Predictions.html index eae098ca..53c60d5a 100644 --- a/docs/articles/Dynamic_Predictions.html +++ b/docs/articles/Dynamic_Predictions.html @@ -135,7 +135,7 @@

Dynamic Predictions

Dimitris Rizopoulos

-

2024-04-22

+

2024-05-25

Source: vignettes/Dynamic_Predictions.Rmd @@ -165,10 +165,10 @@

Theory \theta)} \; p\{b_j \mid T_j^* > t, \mathcal Y_j(t), \theta\} \; p(\theta \mid \mathcal D_n) \; db_j d\theta, \end{array}\] where \(S(\cdot)\) -denotes the survival function conditional on the random effects, and +denotes the survival function conditional on the random effects and \(\mathcal Y_j(t) = \{\mathcal Y_{1j}(t), \ldots, \mathcal Y_{Kj}(t)\}\). Combining the three terms in the -integrand we can device a Monte Carlo scheme to obtain estimates of +integrand, we can devise a Monte Carlo scheme to obtain estimates of these probabilities, namely,

  1. Sample a value \(\tilde \theta\) @@ -177,8 +177,9 @@

    Theory
  2. Sample a value \(\tilde b_j\) from the posterior of the random effects \([b_j \mid T_j^* > t, \mathcal Y_j(t), \tilde \theta]\).

  3. -
  4. Compute the ratio of survival probabilities \(S(u \mid \tilde b_j, \tilde \theta) \Big / S(t -\mid \tilde b_j, \tilde \theta)\).

  5. +
  6. Compute the ratio of survival probabilities \(S(u \mid \tilde b_j, +\tilde \theta) \Big / S(t \mid \tilde b_j, \tilde +\theta)\).

Replicating these steps \(L\) times, we can estimate the conditional cumulative risk probabilities by \[1 - \frac{1}{L} \sum_{l=1}^L \frac{S(u \mid @@ -193,7 +194,7 @@

ExampleWe will illustrate the calculation of dynamic predictions using package JMbayes2 from a trivariate joint model fitted to the PBC dataset for the longitudinal outcomes serBilir -(continuous), prothrombin time (continuous) and +(continuous), prothrombin time (continuous), and ascites (dichotomous). We start by fitting the univariate mixed models. For the two continuous outcomes, we allow for nonlinear subject-specific time effects using natural cubic splines. For @@ -228,25 +229,25 @@

Examplet0 <- 5 ND <- pbc2[pbc2$id %in% c(25, 93), ] ND <- ND[ND$year < t0, ] -ND$status2 <- 0 +ND$event <- 0 ND$years <- t0

-

We will only use the first five years of follow-up (line three), and -further we specify that the patients were event-free up to this time -point (lines four and five).

+

We will only use the first five years of follow-up (line three) and +specify that the patients were event-free up to this point (lines four +and five).

We start with predictions for the longitudinal outcomes. These are produced by the predict() method for class jm -objects, and follow the same lines as the procedure described above for +objects and follow the same lines as the procedure described above for cumulative risk probabilities. The only difference is in Step 3, where -instead of calculating the cumulative risk we calculate the predicted +instead of calculating the cumulative risk, we calculate the predicted values for the longitudinal outcomes. There are two options controlled by the type_pred argument, namely predictions at the scale of the response/outcome (default) or at the linear predictor level. The -type argument controls if the predictions will be for the -mean subject (i.e., including only the fixed effects) or -subject-specific including both the fixed and random effects. In the +type argument controls whether the predictions will be for +the mean subject (i.e., including only the fixed effects) or +subject-specific, including both the fixed and random effects. In the newdata argument we provide the available measurements of -the two patients. This will be used to sample their random effects at -Step 2 presented above. This is done with a Metropolis-Hastings +the two patients. This will be used to sample their random effects in +Step 2, presented above. This is done with a Metropolis-Hastings algorithm that runs for n_mcmc iterations; all iterations but the last one are discarded as burn-in. Finally, argument n_samples corresponds to the value of \(L\) defined above and specifies the number @@ -255,15 +256,15 @@

ExamplepredLong1 <- predict(jointFit, newdata = ND, return_newdata = TRUE)

Argument return_newdata specifies that the predictions are returned as extra columns of the newdata data.frame. By -default the 95% credible intervals are also included. Using the +default, the 95% credible intervals are also included. Using the plot() method for objects returned by predict.jm(..., return_newdata = TRUE), we can display the -predictions. With the following code we do that for the first +predictions. With the following code, we do that for the first longitudinal outcome:

 plot(predLong1)

-

When we want to calculate predictions for other, future time points, +

When we want to calculate predictions for other future time points, we can accordingly specify the times argument. In the following example, we calculate predictions from time t0 to time 12:

@@ -292,28 +293,28 @@

Example
 plot(predLong2, predSurv)

-

Again by default, the plot is for the predictions of the first -subject (i.e., Patient 25) and for the first longitudinal outcome (i.e., +

Again, by default, the plot is for the predictions of the first +subject (i.e., Patient 25) and the first longitudinal outcome (i.e., log(serBilir)). However, the plot() method has -a series of arguments that allows users to customize the plot. We +a series of arguments that allow users to customize the plot. We illustrate some of these capabilities with the following figure. First, we specify that we want to depict all three outcomes using outcomes = 1:3 (note: a max of three outcomes can be simultaneously displayed). Next, we specify via the subject -argument that we want to show the predictions of Patient 93. Note, that -for serum bilirubin we used the log transformation in the specification +argument that we want to show the predictions of Patient 93. Note that +for serum bilirubin, we used the log transformation in the specification of the linear mixed model. Hence, we receive predictions on the transformed scale. To show predictions on the original scale, we use the fun_long argument. Because we have three outcomes, this needs to be a list of three functions. The first one, corresponding to -serum bilirubin is the exp() and for the other two the +serum bilirubin, is the exp(), and for the other two the identity() because we do not wish to transform the predictions. Analogously, we also have the fun_event argument to transform the predictions for the event outcome, and in the -example below we set that we want to obtain survival probabilities. +example below, we set the goal of obtaining survival probabilities. Using the arguments bg, col_points, col_line_long, col_line_event, -fill_CI_long, and fill_CI_event we have +fill_CI_long, and fill_CI_event, we have changed the appearance of the plot to a dark theme. Finally, the pos_ylab_long specifies the relative positive of the y-axis labels for the three longitudinal outcomes.

@@ -351,66 +352,69 @@

Predictive accuracy#> #> At time: 8 #> Using information up to time: 5 (202 subjects still at risk) +#> Accounting for censoring using model-based weights #> -#> cut-off SN SP qSN qSP -#> 1 0.06 0.04245478 1.00000000 0.03287933 1.000000000 -#> 2 0.07 0.06368217 1.00000000 0.04956683 1.000000000 -#> 3 0.09 0.13824070 0.99039566 0.10270423 0.757490419 -#> 4 0.11 0.15946809 0.99039566 0.12027230 0.784435928 -#> 5 0.14 0.17720224 0.98287707 0.12981598 0.685560692 -#> 6 0.15 0.19842963 0.98287707 0.14780414 0.711763968 -#> 7 0.16 0.21965702 0.98287707 0.16598264 0.733935970 -#> 8 0.19 0.24088441 0.98287707 0.18435453 0.752940544 -#> 9 0.22 0.28333920 0.98287707 0.22169095 0.783822976 -#> 10 0.23 0.28333920 0.97642092 0.21748388 0.719825009 -#> 11 0.25 0.30456659 0.97642092 0.23653506 0.735390286 -#> 12 0.26 0.32579398 0.97642092 0.25579444 0.749317113 -#> 13 0.27 0.34702137 0.96996477 0.27126141 0.711089652 -#> 14 0.32 0.37433642 0.96536013 0.29394390 0.695771598 -#> 15 0.36 0.38028575 0.95425727 0.29275549 0.630398775 -#> 16 0.38 0.40151314 0.95425727 0.31310031 0.644614207 -#> 17 0.39 0.41300182 0.95129532 0.32243639 0.635616827 -#> 18 0.43 0.43422921 0.94483917 0.33938902 0.615776271 -#> 19 0.44 0.47668399 0.94483917 0.38181384 0.640564899 -#> 20 0.46 0.47732481 0.93857792 0.37893889 0.612273095 -#> 21 0.49 0.49855220 0.93857792 0.40063635 0.624022395 -#> 22 0.52 0.51977959 0.93857792 0.42259212 0.635080560 -#> 23 0.54 0.52965629 0.93512569 0.43108126 0.625582558 -#> 24 0.58 0.57211107 0.92866954 0.47296608 0.620822291 -#> 25 0.60 0.60273913 0.92507253 0.50465003 0.621616281 -#> 26 0.63 0.60273913 0.90570408 0.49530380 0.557028461 -#> 27 0.64 0.60799325 0.90084593 0.49882681 0.544792672 -#> 28 0.66 0.62922064 0.89438978 0.51988827 0.536233371 -#> 29 0.68 0.62951537 0.88156712 0.51403965 0.501594951 -#> 30 0.69 0.62951537 0.87511097 0.51086344 0.485151330 -#> 31 0.70 0.63284491 0.86321132 0.50883889 0.458209535 -#> 32 0.71 0.63597971 0.85125244 0.50649598 0.433075346 -#> 33 0.72 0.63597971 0.84479629 0.50316150 0.419423165 -#> 34 0.73 0.63597971 0.83188399 0.49635549 0.393581535 -#> 35 0.74 0.65998105 0.82627151 0.52302897 0.394945617 -#> 36 0.76 0.65998105 0.81335921 0.51631107 0.371642681 -#> 37 0.77 0.66418799 0.80172642 0.51547124 0.354011885 -#> 38 0.78 0.68541538 0.79527027 0.53952106 0.353821788 -#> 39 0.79 0.69553457 0.77252334 0.54102972 0.324260513 -#> 40 0.80 0.71836140 0.76655365 0.56900760 0.326340532 -#> 41 0.82 0.72629360 0.74314156 0.56805709 0.298845892 -#> 42 0.83 0.72999422 0.72489863 0.56367067 0.278305494 -#> 43 0.84 0.72999422 0.71198633 0.55657588 0.263559976 -#> 44 0.85 0.73639713 0.67519682 0.54489077 0.228114791 -#> 45 0.86 0.80007930 0.67519682 0.64575455 0.254429059 -#> 46 0.87 0.80724902 0.63864053 0.63948428 0.223461563 -#> 47 0.88 0.82996019 0.61326721 0.66652388 0.210908847 -#> 48 0.89 0.83566180 0.59563285 0.66803683 0.199194476 -#> 49 0.90 0.85819121 0.58311655 0.70468685 0.197995653 -#> 50 0.91 0.85819121 0.55729195 0.69198521 0.179568567 -#> 51 0.92 0.86201058 0.50680438 0.67207221 0.148499865 -#> 52 0.93 0.88498038 0.44922896 0.69021383 0.123970472 -#> 53 0.94 0.88851980 0.41156854 0.67363769 0.106292074 -#> 54 0.95 0.91060251 0.37309178 0.70873720 0.095460992 -#> 55 0.96 0.91195076 0.30248418 0.65125594 0.066899363 -#> 56 0.97 0.93402438 0.19298699 0.59614921 0.035404565 -#> 57 0.98 0.99950031 0.06440953 0.98990626 0.015680861 -#> 58 0.99 1.00000000 0.01291230 1.00000000 0.003041425

+#> cut-off SN SP qSN qSP +#> 1 0.03 0.01512648 0.9981213 0.01022662 0.620510794 +#> 2 0.08 0.03647635 0.9981213 0.02684112 0.810255397 +#> 3 0.09 0.03647635 0.9916764 0.02195087 0.439546614 +#> 4 0.11 0.10052597 0.9916764 0.07299105 0.719773307 +#> 5 0.12 0.11870892 0.9907204 0.08707283 0.732218266 +#> 6 0.13 0.11870892 0.9842755 0.08236702 0.602957113 +#> 7 0.14 0.11870892 0.9778306 0.07761245 0.502420662 +#> 8 0.16 0.15223323 0.9750608 0.10340896 0.542026099 +#> 9 0.18 0.17358310 0.9750608 0.12138835 0.580190590 +#> 10 0.20 0.21628284 0.9750608 0.15792092 0.640163363 +#> 11 0.21 0.23763271 0.9750608 0.17648025 0.664152472 +#> 12 0.25 0.25898258 0.9750608 0.19523915 0.685142943 +#> 13 0.27 0.28033245 0.9750608 0.21420084 0.703663946 +#> 14 0.30 0.32303219 0.9750608 0.25274592 0.734857215 +#> 15 0.31 0.34438206 0.9686159 0.26831589 0.698115054 +#> 16 0.33 0.37464683 0.9648622 0.29429418 0.691398129 +#> 17 0.36 0.41734657 0.9584173 0.33127276 0.676934077 +#> 18 0.37 0.41842352 0.9522975 0.32869458 0.643114275 +#> 19 0.40 0.43977339 0.9522975 0.34962198 0.655860194 +#> 20 0.44 0.47216995 0.9491872 0.38010657 0.657860624 +#> 21 0.46 0.49351982 0.9491872 0.40170178 0.668897378 +#> 22 0.48 0.53621956 0.9491872 0.44565888 0.688964204 +#> 23 0.52 0.53621956 0.9427423 0.44235923 0.659821993 +#> 24 0.53 0.53621956 0.9362974 0.43902007 0.632345052 +#> 25 0.55 0.53621956 0.9298525 0.43564067 0.606394607 +#> 26 0.56 0.57891930 0.9298525 0.48135182 0.627110681 +#> 27 0.58 0.60026917 0.9298525 0.50462805 0.636671945 +#> 28 0.65 0.60026917 0.9234076 0.50157020 0.613208373 +#> 29 0.66 0.62161904 0.9234076 0.52526116 0.622642315 * +#> 30 0.67 0.62430121 0.9113275 0.52269713 0.583445256 +#> 31 0.68 0.62430121 0.9048825 0.51967623 0.563324433 +#> 32 0.69 0.62466999 0.8985490 0.51709132 0.544597586 +#> 33 0.70 0.62466999 0.8921041 0.51399575 0.526196096 +#> 34 0.71 0.65737984 0.8697537 0.54166045 0.484122447 +#> 35 0.72 0.66079584 0.8514502 0.53703215 0.444313562 +#> 36 0.73 0.68214571 0.8450053 0.56022899 0.440911811 +#> 37 0.74 0.68625616 0.8398012 0.56292237 0.432277849 +#> 38 0.75 0.68827502 0.8210759 0.55656024 0.397622177 +#> 39 0.76 0.69335815 0.8032756 0.55437659 0.369232958 +#> 40 0.78 0.71470802 0.7839409 0.57311867 0.348597962 +#> 41 0.79 0.71976998 0.7725792 0.57438748 0.334217236 +#> 42 0.80 0.72024855 0.7662787 0.57189551 0.325547155 +#> 43 0.82 0.72769560 0.7491920 0.57360086 0.305983473 +#> 44 0.83 0.72996525 0.7369874 0.57049591 0.291619335 +#> 45 0.84 0.75693255 0.7193484 0.60081606 0.282384516 +#> 46 0.85 0.77905271 0.7002462 0.62494662 0.270478730 +#> 47 0.86 0.80261723 0.6880249 0.65628174 0.267221367 +#> 48 0.87 0.80680110 0.6699532 0.65463559 0.250905036 +#> 49 0.88 0.80680110 0.6635083 0.65155198 0.244763080 +#> 50 0.89 0.83360725 0.6393758 0.68587537 0.233199012 +#> 51 0.90 0.85677754 0.6077008 0.71355508 0.215401552 +#> 52 0.91 0.86058921 0.5572922 0.69719376 0.179568961 +#> 53 0.92 0.88370870 0.5256018 0.72999030 0.166709301 +#> 54 0.93 0.88683742 0.4298727 0.68251609 0.114109911 +#> 55 0.94 0.92953716 0.4040931 0.78434100 0.114902975 +#> 56 0.95 0.95218510 0.3271461 0.81776209 0.087808771 +#> 57 0.96 0.97587237 0.2440679 0.87503125 0.063200701 +#> 58 0.97 0.97828843 0.1545686 0.82457055 0.035157330 +#> 59 0.98 0.97828843 0.0965644 0.72589148 0.018849510 +#> 60 0.99 0.99988700 0.0128557 0.98858703 0.002984257

In the first line we define the event indicator as we did in the pbc2.id data.frame. The cut-point with the asterisk on the right maximizes the Youden’s @@ -424,16 +428,17 @@

Predictive accuracy#> #> Time-dependent AUC for the Joint Model jointFit #> -#> Estimated AUC: 0.8088 +#> Estimated AUC: 0.8282 #> At time: 8 -#> Using information up to time: 5 (202 subjects still at risk) +#> Using information up to time: 5 (202 subjects still at risk) +#> Accounting for censoring using model-based weights

This function either accepts an object of class tvROC or of class jm. In the latter case, the user must also provide the newdata, Tstart and Dt or Thoriz arguments. Here we have used the same dataset as the one to fit the model, but, in principle, discrimination could be (better) assessed in another dataset.

-

To assess the accuracy of the predictions we produce a calibration +

To assess the accuracy of the predictions, we produce a calibration plot:

 calibration_plot(jointFit, newdata = pbc2, Tstart = t0, Dt = 3)
@@ -449,7 +454,7 @@

Predictive accuracy
 calibration_metrics(jointFit, pbc2, Tstart = 5, Dt = 3)
 #>        ICI        E50        E90 
-#> 0.05763675 0.04720823 0.12893676
+#> 0.06123482 0.05621041 0.11553538

The ICI is the mean absolute difference between the observed and predicted probabilities, E50 is the median absolute difference, and E90 is the 90% percentile of the absolute differences. Finally, we calculate @@ -460,7 +465,7 @@

Predictive accuracy#> #> Prediction Error for the Joint Model 'jointFit' #> -#> Estimated Brier score: 0.1268 +#> Estimated Brier score: 0.1242 #> At time: 8 #> For the 202 subjects at risk at time 5 #> Number of subjects with an event in [5, 8): 40 @@ -492,7 +497,7 @@

Predictive accuracy#> #> Prediction Error for the Joint Model 'jointFit' #> -#> Estimated Integrated Brier score: 0.0844 +#> Estimated Integrated Brier score: 0.0834 #> In the time interval: [5, 8) #> For the 202 subjects at risk at time 5 #> Number of subjects with an event in [5, 8): 40 @@ -502,17 +507,17 @@

Predictive accuracyDimitris Rizopoulos

-

2024-04-22

+

2024-05-25

Source:
vignettes/JMbayes2.Rmd @@ -164,13 +164,13 @@

Univariate
 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:

+

We aim to assess the strength of the association between the risk of +the composite event and the serum bilirubin levels 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 @@ -227,7 +227,7 @@

Univariatejm() 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 +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 @@ -252,9 +252,9 @@

Multivariatejm(). 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 +of the presence or absence of ascites as time-varying covariates in the relative risk model for the composite event. Ascites is a dichotomous -outcome and therefore we fit a mixed-effects logistic regression model +outcome, and therefore, we fit a mixed-effects logistic regression model for it using the mixed_model() function from the GLMMadaptive package. The use of || in the random argument of mixed_model() specifies @@ -266,7 +266,7 @@

Multivariate. Because this joint model is more complex, we increase the number of MCMC iterations, -the number of burn-in iterations and the thinning per chain, using the +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)
@@ -291,58 +291,57 @@ 

Multivariate#> ascites: 1885 #> #> DIC WAIC LPML -#> marginal 11662.89 13317.72 -7329.236 -#> conditional 12896.62 12617.05 -6818.800 +#> marginal 11655.22 16089.26 -8730.453 +#> conditional 12879.91 12590.61 -6812.813 #> #> Random-effects covariance matrix: #> #> StdDev Corr -#> (Intr) 1.0025 (Intr) year (Intr) year (Intr) -#> year 0.1871 0.4492 -#> (Intr) 0.7605 -#> year 0.3267 -0.0176 -#> (Intr) 2.7436 0.5091 0.4815 0.3349 -0.0226 -#> year 0.4645 0.4108 0.6663 -0.0788 0.3288 +#> (Intr) 1.0022 (Intr) year (Intr) year (Intr) +#> year 0.1866 0.4490 +#> (Intr) 0.7625 +#> year 0.3241 -0.0122 +#> (Intr) 2.7049 0.5177 0.4745 0.3283 -0.0298 +#> year 0.4613 0.4057 0.6660 -0.0592 0.3448 #> #> Survival Outcome: #> Mean StDev 2.5% 97.5% P Rhat -#> sexfemale -0.6375 0.3592 -1.3698 0.0500 0.0670 1.0251 -#> value(log(serBilir)) 0.5184 0.1755 0.1557 0.8521 0.0060 1.0827 -#> value(prothrombin) -0.0335 0.1119 -0.2734 0.1714 0.7897 1.0632 -#> value(ascites) 0.5795 0.1266 0.3452 0.8489 0.0000 1.1487 +#> sexfemale -0.6621 0.3613 -1.3655 0.0338 0.0607 1.0140 +#> value(log(serBilir)) 0.4863 0.1786 0.1096 0.8212 0.0147 1.0545 +#> value(prothrombin) -0.0583 0.1244 -0.3296 0.1735 0.6293 1.0612 +#> value(ascites) 0.6227 0.1460 0.3708 0.9518 0.0000 1.0703 #> #> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity) -#> Mean StDev 2.5% 97.5% P Rhat -#> (Intercept) 0.6908 0.1693 0.3521 1.0291 0.0000 1.0009 -#> year 0.2700 0.0352 0.2024 0.3404 0.0000 1.0018 -#> sexfemale -0.2333 0.1798 -0.5840 0.1248 0.1913 1.0019 -#> year:sexfemale -0.0809 0.0364 -0.1533 -0.0111 0.0240 1.0005 -#> sigma 0.3480 0.0068 0.3350 0.3615 0.0000 0.9999 +#> Mean StDev 2.5% 97.5% P Rhat +#> (Intercept) 0.6926 0.1691 0.3584 1.0311 0.000 1.0003 +#> year 0.2694 0.0349 0.2005 0.3383 0.000 1.0004 +#> sexfemale -0.2357 0.1795 -0.5953 0.1183 0.190 1.0002 +#> year:sexfemale -0.0800 0.0362 -0.1508 -0.0097 0.024 1.0022 +#> sigma 0.3480 0.0068 0.3347 0.3617 0.000 1.0047 #> #> Longitudinal Outcome: prothrombin (family = gaussian, link = identity) #> Mean StDev 2.5% 97.5% P Rhat -#> (Intercept) 10.9798 0.1709 10.6450 11.3154 0.0000 1.0035 -#> year 0.2121 0.0772 0.0635 0.3630 0.0043 1.0067 -#> sexfemale -0.4366 0.1798 -0.7928 -0.0911 0.0137 1.0052 -#> year:sexfemale 0.0429 0.0808 -0.1143 0.1994 0.5877 1.0081 -#> sigma 1.0573 0.0202 1.0191 1.0972 0.0000 1.0000 +#> (Intercept) 10.9863 0.1728 10.6532 11.3254 0.0000 1.0033 +#> year 0.2081 0.0774 0.0592 0.3599 0.0070 1.0065 +#> sexfemale -0.4422 0.1831 -0.8040 -0.0912 0.0100 1.0051 +#> year:sexfemale 0.0470 0.0809 -0.1130 0.2029 0.5577 1.0088 +#> sigma 1.0569 0.0202 1.0185 1.0975 0.0000 1.0004 #> #> Longitudinal Outcome: ascites (family = binomial, link = logit) #> Mean StDev 2.5% 97.5% P Rhat -#> (Intercept) -4.5322 0.6852 -5.9742 -3.2827 0.0000 1.0437 -#> year 0.6389 0.0752 0.4951 0.7872 0.0000 1.2966 -#> sexfemale -0.5600 0.6653 -1.8317 0.7706 0.3933 1.0042 +#> (Intercept) -4.4912 0.6735 -5.9197 -3.2356 0.0000 1.0121 +#> year 0.6393 0.0684 0.5128 0.7854 0.0000 1.0651 +#> sexfemale -0.5556 0.6565 -1.8222 0.7787 0.3913 1.0021 #> #> MCMC summary: #> chains: 3 #> iterations per chain: 12000 #> burn-in per chain: 2000 #> thinning: 5 -#> time: 1.8 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.

+#> time: 2 min +

The survival submodel output now contains the estimated coefficients +for value(prothrombin) and value(ascites), as +well as parameter estimates for all three longitudinal submodels.

Functional forms @@ -350,28 +349,26 @@

Functional formsAs 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 +just one of the many possibilities for linking 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)\).

+experience, two extra functional forms are provided: 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 +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 current value functional form. The corresponding syntax to fit this model is:

 fForms <- list(
@@ -395,61 +392,61 @@ 

Functional forms#> ascites: 1885 #> #> DIC WAIC LPML -#> marginal 11666.74 12712.68 -6982.086 -#> conditional 12731.24 12458.34 -6763.103 +#> marginal 11692.23 12995.55 -7306.362 +#> conditional 12656.91 12381.64 -6669.114 #> #> Random-effects covariance matrix: #> #> StdDev Corr -#> (Intr) 0.9945 (Intr) year (Intr) year (Intr) -#> year 0.1861 0.4621 -#> (Intr) 0.7573 -#> year 0.3257 -0.0166 -#> (Intr) 2.6363 0.5455 0.4677 0.3328 -0.0735 -#> year 0.4496 0.4475 0.6749 -0.0672 0.3544 +#> (Intr) 0.9989 (Intr) year (Intr) year (Intr) +#> year 0.1853 0.4548 +#> (Intr) 0.7500 +#> year 0.3232 -0.0047 +#> (Intr) 2.5559 0.5529 0.4692 0.3487 -0.0775 +#> year 0.4361 0.4303 0.6690 -0.0720 0.3773 #> #> Survival Outcome: -#> Mean StDev 2.5% 97.5% P Rhat -#> sexfemale 0.2641 0.9399 -1.5059 2.1004 0.7927 1.0628 -#> slope(log(serBilir)) 4.4155 2.2522 0.1458 8.8060 0.0427 1.0502 -#> slope(log(serBilir)):sexfemale -3.7942 2.8217 -9.3871 1.2246 0.1647 1.1375 -#> area(prothrombin) -0.2819 0.2510 -0.7735 0.1738 0.2777 1.7284 -#> value(ascites) 0.9501 0.1967 0.6093 1.3780 0.0000 1.4029 +#> Mean StDev 2.5% 97.5% P Rhat +#> sexfemale 0.3595 0.9644 -1.3670 2.3829 0.7557 1.0662 +#> slope(log(serBilir)) 4.3938 2.5197 -0.0624 9.5851 0.0577 1.1294 +#> slope(log(serBilir)):sexfemale -4.3880 3.0045 -11.1525 0.5844 0.1020 1.1396 +#> area(prothrombin) -0.4097 0.3097 -0.9998 0.1627 0.1957 1.3476 +#> value(ascites) 1.0639 0.2373 0.6257 1.5698 0.0000 1.3015 #> #> Longitudinal Outcome: log(serBilir) (family = gaussian, link = identity) #> Mean StDev 2.5% 97.5% P Rhat -#> (Intercept) 0.6713 0.1647 0.3556 0.9981 0.0000 1.0006 -#> year 0.2662 0.0334 0.2025 0.3332 0.0000 1.0065 -#> sexfemale -0.2084 0.1757 -0.5552 0.1283 0.2370 1.0003 -#> year:sexfemale -0.0739 0.0344 -0.1425 -0.0074 0.0287 1.0063 -#> sigma 0.3483 0.0067 0.3354 0.3620 0.0000 1.0029 +#> (Intercept) 0.6684 0.1660 0.3397 0.9945 0.0003 1.0079 +#> year 0.2658 0.0336 0.2025 0.3346 0.0000 1.0005 +#> sexfemale -0.2049 0.1768 -0.5497 0.1392 0.2433 1.0087 +#> year:sexfemale -0.0745 0.0348 -0.1450 -0.0079 0.0270 1.0008 +#> sigma 0.3483 0.0066 0.3352 0.3615 0.0000 1.0046 #> #> Longitudinal Outcome: prothrombin (family = gaussian, link = identity) #> Mean StDev 2.5% 97.5% P Rhat -#> (Intercept) 10.9891 0.1682 10.6545 11.3202 0.0000 1.0024 -#> year 0.1919 0.0768 0.0475 0.3468 0.0107 1.0144 -#> sexfemale -0.4481 0.1792 -0.7986 -0.0929 0.0153 1.0017 -#> year:sexfemale 0.0625 0.0809 -0.1007 0.2208 0.4293 1.0134 -#> sigma 1.0581 0.0203 1.0187 1.0983 0.0000 1.0133 +#> (Intercept) 10.9993 0.1684 10.6565 11.3294 0.0000 1.0003 +#> year 0.1839 0.0764 0.0325 0.3362 0.0140 1.0056 +#> sexfemale -0.4574 0.1786 -0.7983 -0.1039 0.0140 1.0006 +#> year:sexfemale 0.0702 0.0806 -0.0884 0.2279 0.3857 1.0058 +#> sigma 1.0591 0.0203 1.0197 1.0994 0.0000 1.0152 #> #> Longitudinal Outcome: ascites (family = binomial, link = logit) #> Mean StDev 2.5% 97.5% P Rhat -#> (Intercept) -4.4620 0.6429 -5.7500 -3.2232 0.0000 1.0493 -#> year 0.6412 0.0779 0.4904 0.8015 0.0000 1.2321 -#> sexfemale -0.4484 0.6183 -1.6790 0.7589 0.4547 1.0035 +#> (Intercept) -4.4105 0.6235 -5.7030 -3.2274 0.0000 1.0378 +#> year 0.6304 0.0777 0.4830 0.7938 0.0000 1.2194 +#> sexfemale -0.4225 0.6122 -1.6453 0.7616 0.4833 1.0057 #> #> MCMC summary: #> chains: 3 #> iterations per chain: 12000 #> burn-in per chain: 2000 #> thinning: 5 -#> time: 1.9 min

+#> 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 +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.

@@ -459,23 +456,23 @@

Penalized Coefficients us

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 +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 +facilitate this selection, jm() allows penalizing 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.2640842 -0.5163933
-#> association.slope(log(serBilir))              4.4155400  2.2405660
-#> association.slope(log(serBilir)):sexfemale   -3.7942189 -0.7917386
-#> association.area(prothrombin)                -0.2818671 -0.1076875
-#> association.value(ascites)                    0.9500576  0.8039421
+#> gammas.Mean 0.3594950 -0.5053443 +#> association.slope(log(serBilir)) 4.3938467 2.0175752 +#> association.slope(log(serBilir)):sexfemale -4.3879624 -0.8996426 +#> association.area(prothrombin) -0.4096893 -0.1321933 +#> association.value(ascites) 1.0639313 0.8572684

Apart from the Horseshoe prior, the ridge prior is also provided.

diff --git a/docs/articles/JMbayes2_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/JMbayes2_files/figure-html/unnamed-chunk-5-1.png index b58ec5ea..3a6a671c 100644 Binary files a/docs/articles/JMbayes2_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/JMbayes2_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/Multi_State_Processes.html b/docs/articles/Multi_State_Processes.html index 2a1e78c8..bb1c6839 100644 --- a/docs/articles/Multi_State_Processes.html +++ b/docs/articles/Multi_State_Processes.html @@ -135,7 +135,7 @@

Multi-State Processes

Grigorios Papageorgiou

-

2024-04-22

+

2024-05-25

Source: vignettes/Multi_State_Processes.Rmd @@ -150,10 +150,10 @@

Multi-state Processes

Introduction

-

It is often the case that a subject may transition between multiple -states and we are interested to assess the association of longitudinal -marker(s) with each of these transitions. In this vignette we will -illustrate how to achieve this using JMbayes2.

+

A subject may often transition between multiple states, and we are +interested in assessing the association of longitudinal marker(s) with +each of these transitions. In this vignette, we will illustrate how to +achieve this using JMbayes2.

We will consider a simple case with one longitudinal outcome and a three-state (illness-death) model, but this application can be extended for the cases of multiple longitudinal markers and more than three @@ -162,24 +162,23 @@

Introduction

Data

-

First we will simulate data from a joint model with a single linear +

First, we will simulate data from a joint model with a single linear mixed effects model and a multi-state process with three possible -states. The multi-state process can be visualized as:

-

-

where all subjects start from state “Healthy” and then can transition -to either state “Illness” and then state “Death” or directly to state -“Death”. In this case, states “Healthy” and “Illness” are +states. The multi-state process can be visualized as: +

+

where all subjects start from the state “Healthy” and then can +transition to either state “Illness” and then state “Death” or directly +to state “Death.” In this case, states “Healthy” and “Illness” are transient states as the subject, when occupying these states, -can still transition to other states whereas “Death” is an absorbing +can still transition to other states, whereas “Death” is an absorbing state as when a subject reaches this state then no further transitions can occur. This means that three transitions are possible: \(1 \rightarrow 2\), \(1 \rightarrow 3\) and \(2 \rightarrow 3\) with transition intensities \(h_{12}\left(t\right)\), \(h_{13}\left(t\right)\) and \(h_{23}\left(t\right)\) respectively.

-

For our example the default functional form is assumed, i.e., that +

For our example, the default functional form is assumed, i.e., that the linear predictor \(\eta(t)\) of the -mixed model is associated with the each transition intensity at time -\(t\). The following piece of code -simulates the data:

+mixed model is associated with each transition intensity at time \(t\). The following piece of code simulates +the data:

 set.seed(1234)
 # number of subjects
@@ -354,38 +353,38 @@ 

Data #> 1.3 1 2 3 3 4.392984 9.094447 0 1.984455 #> 2.1 2 1 2 1 0.000000 1.552122 0 7.673231 #> 2.2 2 1 3 2 0.000000 1.552122 0 7.673231

-

for example subject 1 experienced the following transition: \(1 \rightarrow 2\) and therefore is +

for example, subject 1 experienced the following transition: \(1 \rightarrow 2\) and therefore is represented in 3 rows, one for each transition, because all of these -transitions were plausible. On the other hand subject 2 is only +transitions were plausible. On the other hand, subject 2 is only represented by two rows, only for transitions \(1 \rightarrow 2\) and \(1 \rightarrow 3\) since these are the only -transitions that are possible from state 1. That is, since subject 2 -never actually transitioned to state 2, transition \(2 \rightarrow 3\) was never possible and -therefore no row for this transition is in the dataset. It is also +transitions possible from state 1. That is since subject 2 never +actually transitioned to state 2, transition \(2 \rightarrow 3\) was never possible, and +therefore, no row for this transition is in the dataset. It is also important to note that the time in the dataset follows the counting process formulation with intervals specified by Tstart and Tstop and that there is a variable (in this case -transition) which indicates to which transition the row -corresponds to.

+transition) indicating which transition the row corresponds +to.

Fitting the model

-

As soon data in the appropriate format are available, fitting the +

When the data in the appropriate format are available, fitting the model is very straightforward. First we fit a linear mixed model using the lme() function from package nlme:

-mixedmodel <- lme(y ~ time + X, random = ~ time | id, data = DF)
-

then we fit a multi-state model using function coxph() +mixedmodel <- lme(y ~ time + X, data = DF, random = ~ time | id)

+

Then, we fit a multi-state model using function coxph() from package survival making sure we use the counting process specification and that we add strata(transition) to stratify by the transition indicator variable in the dataset. -Furthermore we add an interaction between covariate X and +Furthermore, we add an interaction between covariate X and each transition to allow the effect of this covariate to vary across transitions.

 msmodel <- coxph(Surv(Tstart, Tstop, status) ~ X * strata(transition), 
                  data = data_mstate)
-

Finally, to fit the joint model we simply run:

+

Finally, to fit the joint model, we simply run:

 jm_ms_model <- jm(msmodel, mixedmodel, time_var = "time", 
                   functional_forms = ~ value(y):transition, n_iter = 10000L)
@@ -432,12 +431,12 @@ 

Fitting the model#> iterations per chain: 10000 #> burn-in per chain: 500 #> thinning: 1 -#> time: 2.8 min

+#> time: 3.1 min

which differs from a default call to jm() by the -addition of the functional_forms argument by which we -specify that we want an “interaction” between the value of the marker -and each transition which translates into a separate association -parameter for the longitudinal marker and each transition.

+addition of the functional_forms argument specifying that +we want an “interaction” between the marker’s value and each transition, +which translates into a separate association parameter for the +longitudinal marker and each transition.

diff --git a/docs/articles/Multi_State_Processes_files/figure-html/ms_figure-1.png b/docs/articles/Multi_State_Processes_files/figure-html/ms_figure-1.png index fe2b6e37..03404b7a 100644 Binary files a/docs/articles/Multi_State_Processes_files/figure-html/ms_figure-1.png and b/docs/articles/Multi_State_Processes_files/figure-html/ms_figure-1.png differ diff --git a/docs/articles/Non_Gaussian_Mixed_Models.html b/docs/articles/Non_Gaussian_Mixed_Models.html index 379c7e3b..6bbf0577 100644 --- a/docs/articles/Non_Gaussian_Mixed_Models.html +++ b/docs/articles/Non_Gaussian_Mixed_Models.html @@ -135,7 +135,7 @@

Non-Gaussian Mixed Models

Dimitris Rizopoulos

-

2024-04-22

+

2024-05-25

Source: vignettes/Non_Gaussian_Mixed_Models.Rmd @@ -160,23 +160,23 @@

Non-Gaussian Joint Models with

Beta mixed models

With very few exceptions, continuous outcomes that we wish to analyze -have some natural bounds. For example, the levels of blood biomarker for -a set of patients. However, often, the majority of the observations are -located far away from these natural bounds, and an assumption of a -normal distribution for the outcome can be safely done. In some settings +have some natural bounds. For example, the levels of blood biomarkers +for a set of patients. However, most observations are often located far +away from these natural bounds, and an assumption of a normal +distribution for the outcome can be safely made. In some settings, though, we can have outcomes for which a substantial percentage of the observations are located near the boundaries leading to skewed or -U-shaped distributions. For such longitudinal outcomes, a linear mixed -model with normal error terms often does not provide a good fit. A +U-shaped distributions. A linear mixed model with normal error terms +often does not provide a good fit for such longitudinal outcomes. A natural alternative is to select a distribution that respects the bounded nature of the outcome. The most well-known distribution for such outcomes is the Beta distribution defined in the \((0, 1)\) interval (note: a bounded outcome \(Y^*\) in the \((a, b)\) interval can be transformed to the \(Y = (Y^* - a) / (b - a)\) in the \((0, 1)\) interval).

-

The following piece of code illustrates how to simulate data from a -joint model with a Beta mixed effects model. The default functional form -is assumed, i.e., that the linear predictor \(\eta(t)\) of the mixed model is associated +

The following code illustrates how to simulate data from a joint +model with a Beta mixed effects model. The default functional form is +assumed, i.e., that the linear predictor \(\eta(t)\) of the mixed model is associated with the hazard of an event at time \(t\). The linear predictor is related to the mean \(\mu(t)\) of the Beta distribution under the logit link function, i.e., \(\log[\mu(t) / \{1 - \mu(t)\}] = @@ -320,13 +320,13 @@

Censored linear mixed models
set.seed(1234)
@@ -459,15 +459,15 @@ 

Censored linear mixed models

Students’s-t mixed models

-

Outlying observations is a common occurring issue in practice. -Several methods have been proposed in the literature for identifying -such observations in the context of longitudinal data. However, removing -such values from the analysis is in general not recommended unless we -also have external information why these values are outlying. Hence, in -these settings we would need to fit mixed models to accommodate these -observations. A well-known approach to achieve this is to replace the -normal distribution for the error terms in the linear mixed model with a -Student’s-t distribution that has heavier tails.

+

Outlying observations are a common issue in practice. Several methods +have been proposed in the literature for identifying such observations +in the context of longitudinal data. However, removing such values from +the analysis is generally not recommended unless we also have external +information as to why these values are outlying. Hence, we would need to +fit mixed models to accommodate these observations in these settings. A +well-known approach to achieve this is replacing the normal distribution +for the error terms in the linear mixed model with a Student’s-t +distribution with heavier tails.

The following syntax simulates data from a joint model with a Student’s-t mixed effects model:

@@ -602,12 +602,12 @@ 

Students’s-t mixed modelsNegative binomial mixed models

Count longitudinal outcomes are typically modeled with the Poisson -distribution. However, often these outcomes exhibit more variance than -what is allowed from the Poisson distribution leading to the well-known -problem of over-dispersion. To accommodate this over-dispersion -typically the Negative Binomial distribution is used.

+distribution. However, these outcomes often exhibit more variance than +what is allowed from the Poisson distribution, leading to the well-known +problem of over-dispersion. To accommodate this over-dispersion, +typically, the negative binomial distribution is used.

The following piece of code simulates data from a joint model for -count longitudinal data that follow the Negative Binomial +count longitudinal data that follow the negative binomial distribution:

+#> time: 26 sec
Back to top
@@ -742,11 +742,11 @@

Negative binomial mixed models

Beta-binomial longitudinal outcomes

-

As for count data also for Binomial data we may have the -over-dispersion problem. In this case, we can change to standard -Binomial distribution to a Beta-Binomial one to accommodate this.

+

For count data and binomial data, we may have an over-dispersion +problem. To accommodate this, we can change the standard binomial +distribution to a beta-binomial one.

The following piece of code simulates data from a joint model for -binomial longitudinal data that follow the Beta-Binomial +binomial longitudinal data that follow the beta-binomial distribution:

 set.seed(1234)
@@ -876,10 +876,7 @@ 

Beta-binomial longitudinal outcomes #> iterations per chain: 3500 #> burn-in per chain: 500 #> thinning: 1 -#> time: 48 sec

-
-Back to top -
+#> time: 51 sec

diff --git a/docs/articles/Recurring_Events.html b/docs/articles/Recurring_Events.html index 6550329d..f6895fe7 100644 --- a/docs/articles/Recurring_Events.html +++ b/docs/articles/Recurring_Events.html @@ -135,7 +135,7 @@

Recurrent Events

Pedro Miranda Afonso

-

2024-04-22

+

2024-05-25

Source: vignettes/Recurring_Events.Rmd @@ -150,12 +150,12 @@

Recurrent events

Introduction

-

JMbayes2 provides also the capability to fit joint -models with a recurrent event process possibly combined with a +

JMbayes2 also provides the capability to fit joint +models with a recurrent event process, possibly combined with a terminating event. Recurrent events are correlated events that may occur more than once over the follow-up period for a given subject. Our current implementation allows for multiple longitudinal markers with -different distributions, and various functional forms to link these +different distributions and various functional forms to link these markers with the risk of recurrent and terminal events. Furthermore, it enables the risk intervals to be defined in terms of the gap or calendar timescales. The two timescales use a different @@ -164,9 +164,9 @@

Introduction -<b>Figure 1</b> Visual representation of an hazard function under the gap or calendar timescale. During the folow-up the subject experienced three events.

+<b>Figure 1</b> Visual representation of an hazard function under the gap or calendar timescale. During the follow-up, the subject experienced three events.

Figure 1 Visual representation of an hazard function under the -gap or calendar timescale. During the folow-up the subject experienced +gap or calendar timescale. During the follow-up, the subject experienced three events.

@@ -175,10 +175,10 @@

Introduction -<b>Figure 2</b> Visual representation of an hazard function under the gap or calendar timescale, while accounting for non-risk periods (gray areas). During the folow-up the subject experienced three events.

+<b>Figure 2</b> Visual representation of an hazard function under the gap or calendar timescale, while accounting for non-risk periods (gray areas). During the follow-up, the subject experienced three events.

Figure 2 Visual representation of an hazard function under the gap or calendar timescale, while accounting for non-risk periods (gray -areas). During the folow-up the subject experienced three events. +areas). During the follow-up, the subject experienced three events.

A joint model with \(p\) normally @@ -213,9 +213,9 @@

Introduction\(i = 1, \ldots, n\). For the -longitudinal outcomes we specify linear mixed-effects models, and for -the terminal and recurrence processes, we use proportional hazard +

where \(i = 1, \ldots, n\). We +specify linear mixed-effects models for the longitudinal outcomes, and +for the terminal and recurrence processes, we use proportional hazard models. The longitudinal and event time processes are linked via a latent structure of random effects, highlighted by the same color in the equations above. The terms \(\mathcal{f}_{R_j}\left\{\eta_{j_i}(t)\right\}\) @@ -224,7 +224,7 @@

Introduction\(b_{F_i}\) is a random effect that accounts for the correlations in the recurrent events. The coefficient \(\alpha_{F}\) quantifies the strength of the association between the terminal and recurrent event processes. For -notational simplicity, in the formulation presented above we have shown +notational simplicity, in the formulation presented above, we have shown normally distributed longitudinal outcomes; however, JMbayes2 provides the option to consider longitudinal outcomes with different @@ -237,13 +237,13 @@

ExampleData

We simulate data from a joint model with three outcomes: one -longitudinal outcome, one terminal failure-time, and one recurrent -failure-time. We assume that the underlying value of the longitudinal +longitudinal outcome, one terminal failure time, and one recurrent +failure time. We assume that the underlying value of the longitudinal outcome is associated with both risk models and use the gap timescale. The reader can easily extend this example to accommodate -multiple longitudinal markers with other forms of association, include -competing risks, consider only the recurrent events process, or use a -different timescale.

+multiple longitudinal markers with other forms of association, including +competing risks, considering only the recurrent events process, or using +a different timescale.

 gen_data <- function(){
   n <- 500 # desired number of subjects 
@@ -397,11 +397,11 @@ 

Data recu_data <- fake_data$rec # recurrent events data lme_data <- fake_data$long # longitudial marker data

We now have three data frames, each one corresponding to a different -outcome. To fit the joint model, the user needs to organize the -failure-time data in the counting process formulation by combining the -data for the terminal and recurrent events. Using then a strata variable -to distinguish between the two processes. To facilitate this, we provide -in the package the rc_setup() function:

+outcome. To fit the joint model, the user must organize the failure-time +data in the counting process formulation by combining the data for the +terminal and recurrent events. Then, a strata variable is used to +distinguish between the two processes. To facilitate this, we provide in +the package the rc_setup() function:

 cox_data <- rc_setup(rc_data = recu_data, trm_data = term_data,
                      idVar = "id", statusVar = "status",
@@ -412,12 +412,12 @@ 

Data their recurrent risk periods plus one for the terminal event. The data frame follows the counting process formulation with the risk intervals delimited by start and stop variables. The -strata variable denotes if the type of event, -1 if recurrent or 2 terminal. The -status equals 1 if the subject had an event -and 0 otherwise. As shown below and in Figure 3, the -subject 1 experienced seven recurrent events during the follow up; the -eighth recurrent event was censored by the terminal event.

+strata variable denotes the type of event, 1 +if recurrent, or 2 terminal. The status equals +1 if the subject had an event and 0 otherwise. +As shown below and in Figure 3, subject 1 experienced seven recurrent +events during the follow-up; the terminal event censored the eighth +recurrent event.

 cox_data[cox_data$id == 1, c("id", "tstart", "tstop", "status", "strata")]
 #>   id    tstart     tstop status strata
@@ -431,19 +431,19 @@ 

Data #> 8 1 3.6251219 4.0375415 0 R #> 9 1 0.0000000 4.0375415 1 T1

-<b>Figure 3</b> Visual representation of the failure-time data during the follow-up for subject 1. The horizontal black line denotes risk periods, while the blue line non-risk periods. 'R' and 'T' represent a recurrent and terminal event, respectively.

+<b>Figure 3</b> Visual representation of the failure-time data during the follow-up for subject 1. The horizontal black line denotes risk periods, while the blue line denotes non-risk periods. 'R' and 'T' represent a recurrent and terminal event, respectively.

Figure 3 Visual representation of the failure-time data during the follow-up for subject 1. The horizontal black line denotes risk -periods, while the blue line non-risk periods. ‘R’ and ‘T’ represent a -recurrent and terminal event, respectively. +periods, while the blue line denotes non-risk periods. ‘R’ and ‘T’ +represent a recurrent and terminal event, respectively.

Fitting the model

-

The user then needs to use the nlme::lme() function to -first fit the linear mixed model that describes the longitudinal +

The user then needs to use the nlme::lme() function +first to fit the linear mixed model that describes the longitudinal outcome,

 lme_fit <- lme(y ~ ns(time, k =  c(1, 3), B = c(0, 7)), 
@@ -459,7 +459,7 @@ 

Fitting the modeljm() function. The user specifies the desired functional forms for the mixed model in each relative-risk model. And with the recurrent -argument specifies the desired timescale,

+argument specifying the desired timescale,

 jm_fit <- jm(cox_fit, lme_fit, time_var = "time", recurrent = "gap",
              functional_forms =  ~ value(y):strata)
diff --git a/docs/articles/Super_Learning.html b/docs/articles/Super_Learning.html
index 30d696f7..9f21373d 100644
--- a/docs/articles/Super_Learning.html
+++ b/docs/articles/Super_Learning.html
@@ -136,7 +136,7 @@ 

Combined Dynamic Predictions via Super

Dimitris Rizopoulos

-

2024-04-22

+

2024-05-25

Source: vignettes/Super_Learning.Rmd @@ -159,10 +159,10 @@

Motivation and TheoryMotivation and Theory\(\mathcal{L} = \{M_1, \ldots, M_L\}\) denote a library with \(L\) models. -There are no restrictions to the models included in this library, and -actually, it is recommended to consider a wide range of possible models. -Among others, these joint models differ in the specification of the time -trend in the longitudinal submodels and the functions form and event -submodel. We split the original dataset \(\mathcal{D}_n\) in \(V\) folds. The choice of \(V\) will depend on the size and number of +There are no restrictions to the models included in this library, and it +is recommended to consider a wide range of possible models. Among +others, these joint models differ in the specification of the time trend +in the longitudinal submodels and the functions form and event submodel. +We split the original dataset \(\mathcal{D}_n\) in \(V\) folds. The choice of \(V\) will depend on the size and number of events in \(\mathcal{D}_n\). In particular, for each fold, we need to have a sufficient number of events -to robustly quantify the predictive performance. Using the +to quantify the predictive performance robustly. Using the cross-validation method, we fit the \(L\) models in the combined \(v-1\) folds, and we will calculate predictions for the \(v\)-th fold we left outside. Due to the dynamic nature of the predictions, we want to @@ -283,8 +283,8 @@

ExampleJMbayes2 in each worker. The output of this function should be a list of the fitted joint models with class "jmList". Assigning this class to the resulting list will -facilitate combining the predictions later. For our example we use the -following specification:

+facilitate combining the predictions later. For our example, we use the +following specifications:

 fit_models <- function (data) {
     library("JMbayes2")
@@ -315,18 +315,18 @@ 

ExampleserBilir and the composite event transplantation or death. The first three models consider a simple linear mixed effects model for serum bilirubin with random intercepts -and random slopes per subject, and no other covariates. Also, in the Cox -model for the composite event we do not specify any baseline covariates; -hence, the risk of the composite event depends only on serum bilirubin. -The three models differ in the corresponding functional forms, i.e., the -current value of log serum bilirubin, the current slope/velocity of log -serum bilirubin, and the current value plus the area under the log serum -bilurubin trajectory. The last models consider a more elaborate -specification of the linear mixed model that includes natural cubic -splines in both the fixed and random effects to allow for -non-linearities in the log serum bilirubin trajectories, and the main +and random slopes per subject and no other covariates. Also, in the Cox +model for the composite event, we do not specify any baseline +covariates; hence, the risk of the composite event depends only on serum +bilirubin. The three models differ in the corresponding functional +forms, i.e., the current value of log serum bilirubin, the current +slope/velocity of log serum bilirubin, and the current value plus the +area under the log serum bilirubin trajectory. The last models consider +a more elaborate specification of the linear mixed model that includes +natural cubic splines in both the fixed and random effects to allow for +non-linearities in the log serum bilirubin trajectories and the main effects of sex and age in both the mixed and Cox models. The functional -forms are again the current value and the current slope.

+forms are, again, the current value and the current slope.

We fit these models in the training datasets using parallel computing as facilitated using the parallel package (note: this and the subsequent computations require some time @@ -338,12 +338,12 @@

ExampleModels_folds <- parallel::parLapply(cl, CVdats$training, fit_models) parallel::stopCluster(cl)

We calculate the weights to combine the predictions from these five -models to optimize the integrated Brier score the expected predictive -cross-entropy at follow-up time \(t = -6\) years and for a relevant window of \(\Delta t = 2\) years. Function -tvBrier() automatically performs this task by providing as -a first argument the list of joint models fitted in the training -datasets. The integrated Brier score is calculated using the testing +models to optimize the integrated Brier score and the expected +predictive cross-entropy at follow-up time \(t += 6\) years and for a relevant window of \(\Delta t = 2\) years. The function +tvBrier() automatically performs this task by providing the +list of joint models fitted in the training datasets as a first +argument. The integrated Brier score is calculated using the testing datasets that are provided in the newdata argument:

We observe that the first two models dominate the weights. We also note that the integrated Brier score based on the combined predictions is smaller than the integrated Brier score of each individual model. To -calculate the model weights using the expected predictive cross-entropy +calculate the model weights using the expected predictive cross-entropy, use function tvEPCE() with an almost identical call as for the Brier score:

-

The EPCE results are similar with the ones from the integrated Brier +

The EPCE results are similar to those from the integrated Brier score; however, now only models M2 and M3 -share the weights. Again we see that the EPCE based on the combined +share the weights. Again, we see that the EPCE based on the combined cross-validated predictions is smaller than the EPCE based on the cross-validated predictions of each individual model.

-

To put these weights in practice we need first to refit the five -joint models we considered in the original dataset.

+

To use these weights in practice, we must first refit the five joint +models we considered in the original dataset.

 Models <- fit_models(pbc2)
-

Then we construct the dataset with the subjects at risk at year six +

Then, we construct the dataset with the subjects at risk at year six and consider the longitudinal measurements collected before this follow-up time. Also, we set in this dataset the observed event time to -six, and the event variable to zero, i.e., indicating that patients were +six and the event variable to zero, i.e., indicating that patients were event-free up to this time:

-

Our aim is to assess the strength of the association between the risk -of the composite event and the level of serum bilirubin. We will -describe the patient-specific profiles over time for this biomarker -using a linear mixed-effects model, where both in the fixed- and -random-effects we include an intercept, the linear and quadratic time -effect. In the fixed-effects we also include the interaction of the time -effect and sex. The syntax to fit this model with lme() -is:

+

We aim to assess the strength of the association between the risk of +the composite event and the serum bilirubin level. We will describe the +patient-specific profiles over time for this biomarker using a linear +mixed-effects model, where we include an intercept in both the fixed and +random effects, as well as the linear and quadratic time effects. In the +fixed effects, we also include the interaction of the time effect and +sex. The syntax to fit this model with lme() is:

 fm <- lme(log(serBilir) ~ poly(year, 2) * sex, data = pbc2, 
           random = ~ poly(year, 2) | id, control = lmeControl(opt = 'optim'))
@@ -219,13 +218,13 @@

Non Proportional Hazards#> thinning: 1 #> time: 17 sec

To specify that the association of serum bilirubin may change over -time we include an interaction of this time-varying covariate with a +time, we include an interaction of this time-varying covariate with a natural cubic spline of time using function ns() from the -splines package. Important Note: for -this to work correctly we need to explicitly specify the internal and -boundary knots for the B-splines basis, i.e., in the following example -we set the internal knots at 3, 6 and 9 years, and the boundary knots at -0 and 14.5 years:

+splines package. Important Note: For +this to work correctly, we need to explicitly specify the internal and +boundary knots for the B-splines basis, i.e., in the following example, +we set the internal knots at 3, 6, and 9 years, and the boundary knots +at 0 and 14.5 years:

 form_splines <- ~ value(log(serBilir)) * ns(year, k = c(3, 6, 9), B = c(0, 14.5))
 jointFit2 <- update(jointFit1, functional_forms = form_splines, 
@@ -292,7 +291,7 @@ 

Non Proportional Hazards#> thinning: 1 #> time: 36 sec

The spline coefficients do not have a straightforward interpretation. -We therefore visualize the time-varying association of log serum +We, therefore, visualize the time-varying association of log serum bilirubin with the hazard of the composite event using the following piece of code:

-

Both the WAIC and LPML indicate that jointFit1 is a -better model than jointFit2. The DIC has the same magnitude -for both models.

+

The WAIC and LPML indicate that jointFit1 is a better +model than jointFit2. The DIC has the same magnitude for +both models.

diff --git a/docs/articles/Transformation_Functions.html b/docs/articles/Transformation_Functions.html index 8abec458..4c9b9aed 100644 --- a/docs/articles/Transformation_Functions.html +++ b/docs/articles/Transformation_Functions.html @@ -136,7 +136,7 @@

Transformation Functions for Functional

Dimitris Rizopoulos

-

2024-04-22

+

2024-05-25

Source:
vignettes/Transformation_Functions.Rmd @@ -166,9 +166,9 @@

Simplified syntaxmixed_model() +time for this biomarker using a mixed-effects logistic model, where we +include an intercept and the time effect in both fixed and random +effects. The syntax to fit this model with mixed_model() is:

 fm <- mixed_model(hepatomegaly ~ year, data = pbc2, random = ~ year | id, 
@@ -214,11 +214,11 @@ 

Simplified syntax#> burn-in per chain: 500 #> thinning: 1 #> time: 15 sec

-

In the output this is named as value(hepatomegaly) to +

In the output, this is named 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 +\(t\). In this case, the subject-specific linear predictor denotes the log odds of experiencing hepatomegaly at time \(t\).

@@ -228,10 +228,10 @@

Transformation functionsThe 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 +nonlinear link function to the 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 @@ -274,12 +274,11 @@

Transformation functions#> iterations per chain: 3500 #> burn-in per chain: 500 #> thinning: 1 -#> time: 17 sec +#> time: 16 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.

+functional_forms argument are vexp() to +calculate the exponent, vlog() to calculate the natural +logarithm, and vsqrt() to calculate 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 @@ -381,8 +380,9 @@

The Slope functional form#> Rhat #> sexfemale 1.008869 #> value(log(serBilir)) 1.010025 -#> slope(log(serBilir)) 1.043587 - +#> slope(log(serBilir)) 1.043587 +
+
 summary(jFit2)$Survival
 #>                                                         Mean     StDev
 #> sexfemale                                         -0.1647358 0.2732504
diff --git a/docs/index.html b/docs/index.html
index f794a747..89ff4b22 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -135,7 +135,7 @@
 

-

The package JMbayes2 fits joint models for longitudinal and time-to-event data. It can accommodate multiple longitudinal outcomes of different type (e.g., continuous, dichotomous, ordinal, counts), and assuming different distributions, i.e., Gaussian, Student’s-t, Gamma, Beta, unit Lindley, censored Normal, Binomial, Poisson, Negative Binomial, and Beta-Binomial. For the event time process, right, left and interval censored data can be handled, while competing risks and multi-sate processes are also covered.

+

The package JMbayes2 fits joint models for longitudinal and time-to-event data. It can accommodate multiple longitudinal outcomes of different type (e.g., continuous, dichotomous, ordinal, counts), and assuming different distributions, i.e., Gaussian, Student’s-t, Gamma, Beta, unit Lindley, censored Normal, Binomial, Poisson, Negative Binomial, and Beta-Binomial. For the event time process, right, left and interval censored data can be handled, while competing risks, multi-sate and recurrent-event processes are also covered..

JMbayes2 fits joint models using Markov chain Monte Carlo algorithms implemented in C++. Besides the main modeling function, the package also provides a number of functions to summarize and visualize the results.

Installation diff --git a/docs/news/index.html b/docs/news/index.html index a936f4df..73020582 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -99,8 +99,9 @@

Changelog

Major

-
  • -jm() now allows for zero-correlations constraints in the covariance matrix of the random effects. When the mixed models provided in the Mixed_objects argument have been fitted assuming a diagonal matrix for the random effects, this will also be assumed in the joint model (in previous versions, this was ignored). In addition, the new argument which_independent can be used to specify which longitudinal outcomes are to be assumed independent.
  • +
    • jm() now allows for zero-correlations constraints in the covariance matrix of the random effects. When the mixed models provided in the Mixed_objects argument have been fitted assuming a diagonal matrix for the random effects, this will also be assumed in the joint model (in previous versions, this was ignored). In addition, the new argument which_independent can be used to specify which longitudinal outcomes are to be assumed independent.

    • +
    • A bug in the predict() method causing low AUC values has been corrected.

    • +
    • The time-varying ROC and AUC now allow to correct for censoring in the interval Tstart to Thoriz using inverse probability of censoring weighting. The default remains model-based weights

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index c857057a..737f6efc 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -12,7 +12,7 @@ articles: Super_Learning: Super_Learning.html Time_Varying_Effects: Time_Varying_Effects.html Transformation_Functions: Transformation_Functions.html -last_built: 2024-04-25T17:58Z +last_built: 2024-05-25T18:21Z urls: reference: https://drizopoulos.github.io/JMbayes2/reference article: https://drizopoulos.github.io/JMbayes2/articles diff --git a/docs/reference/JMbayes2.html b/docs/reference/JMbayes2.html index 45962834..ebd2e673 100644 --- a/docs/reference/JMbayes2.html +++ b/docs/reference/JMbayes2.html @@ -104,7 +104,7 @@

Extended Joint Models for Longitudinal and Time-to-Event Data

Details

-
Package:JMbayes2
Type:Package
Version:0.5-0
Date:2024-04-15
License:GPL (>=3)

This package fits joint models for longitudinal and time-to-event data. It can accommodate multiple longitudinal outcomes of different type (e.g., continuous, dichotomous, ordinal, counts), and assuming different distributions, i.e., Gaussian, Student's-t, Gamma, Beta, unit Lindley, censored Normal, Binomial, Poisson, Negative Binomial, and Beta-Binomial. For the event time process, right, left and interval censored data can be handled, while competing risks and multi-sate processes are also covered.

+
Package:JMbayes2
Type:Package
Version:0.5-0
Date:2024-04-24
License:GPL (>=3)

This package fits joint models for longitudinal and time-to-event data. It can accommodate multiple longitudinal outcomes of different type (e.g., continuous, dichotomous, ordinal, counts), and assuming different distributions, i.e., Gaussian, Student's-t, Gamma, Beta, unit Lindley, censored Normal, Binomial, Poisson, Negative Binomial, and Beta-Binomial. For the event time process, right, left and interval censored data can be handled, while competing risks and multi-sate processes are also covered.

JMbayes2 fits joint models using Markov chain Monte Carlo algorithms implemented in C++. The package also offers several utility functions that can extract useful information from fitted joint models. The most important of those are included in the See also Section below.

diff --git a/docs/reference/Rplot005.png b/docs/reference/Rplot005.png index 399a2103..e9b8d820 100644 Binary files a/docs/reference/Rplot005.png and b/docs/reference/Rplot005.png differ diff --git a/docs/reference/Rplot006.png b/docs/reference/Rplot006.png index d6ed83c3..cacccea3 100644 Binary files a/docs/reference/Rplot006.png and b/docs/reference/Rplot006.png differ diff --git a/docs/reference/Rplot007.png b/docs/reference/Rplot007.png index aecd8621..81027cb8 100644 Binary files a/docs/reference/Rplot007.png and b/docs/reference/Rplot007.png differ diff --git a/docs/reference/Rplot008.png b/docs/reference/Rplot008.png index 77be071b..caa344b8 100644 Binary files a/docs/reference/Rplot008.png and b/docs/reference/Rplot008.png differ diff --git a/docs/reference/accuracy-1.png b/docs/reference/accuracy-1.png index 4ab302e8..3cddbb26 100644 Binary files a/docs/reference/accuracy-1.png and b/docs/reference/accuracy-1.png differ diff --git a/docs/reference/accuracy.html b/docs/reference/accuracy.html index 610a0846..a34254a3 100644 --- a/docs/reference/accuracy.html +++ b/docs/reference/accuracy.html @@ -105,13 +105,13 @@

Time-Dependent Predictive Accuracy Measures for Joint Models

# S3 method for jm tvROC(object, newdata, Tstart, Thoriz = NULL, - Dt = NULL, ...) + Dt = NULL, type_weights = c("model-based", "IPCW"), ...) tvAUC(object, newdata, Tstart, ...) # S3 method for jm tvAUC(object, newdata, Tstart, Thoriz = NULL, - Dt = NULL, ...) + Dt = NULL, type_weights = c("model-based", "IPCW"), ...) # S3 method for tvROC tvAUC(object, ...) @@ -334,87 +334,88 @@

Examples

#> #> At time: 7 #> Using information up to time: 4 (225 subjects still at risk) +#> Accounting for censoring using model-based weights #> #> cut-off SN SP qSN qSP -#> 1 0.02 0.01108858 0.99724832 0.006673795 0.380872674 -#> 2 0.03 0.02514248 0.99525214 0.016399360 0.465865684 -#> 3 0.05 0.06892037 0.99525214 0.052068245 0.732932842 -#> 4 0.06 0.08095754 0.99274214 0.060070216 0.673396462 -#> 5 0.07 0.08095754 0.98716536 0.055778300 0.518701008 -#> 6 0.08 0.10284649 0.98716536 0.074038808 0.587458007 -#> 7 0.13 0.12166020 0.98080508 0.085062712 0.520127029 -#> 8 0.14 0.14354915 0.98080508 0.103714225 0.568114326 -#> 9 0.15 0.16543809 0.98080508 0.122540050 0.607376660 -#> 10 0.18 0.18732704 0.98080508 0.141542644 0.640095272 -#> 11 0.19 0.18732704 0.97522830 0.137493317 0.571259000 -#> 12 0.20 0.21598454 0.97137598 0.159983433 0.570639729 -#> 13 0.21 0.25144573 0.96925708 0.190265812 0.593108474 -#> 14 0.22 0.26517610 0.96717847 0.201278366 0.589730914 -#> 15 0.23 0.28706504 0.96717847 0.221308904 0.611324024 -#> 16 0.25 0.32170969 0.96485154 0.251885684 0.623409353 -#> 17 0.26 0.36163014 0.95271519 0.281833903 0.574436700 -#> 18 0.30 0.36163014 0.94713841 0.278225028 0.542543894 -#> 19 0.31 0.36163014 0.94156162 0.274579700 0.513013518 -#> 20 0.34 0.40540802 0.94156162 0.317432682 0.546598793 -#> 21 0.36 0.42729697 0.93598484 0.335782567 0.535373830 -#> 22 0.37 0.44918591 0.93598484 0.357859226 0.549893398 -#> 23 0.41 0.47107486 0.93598484 0.380165849 0.563532992 -#> 24 0.42 0.47621158 0.93171677 0.382971762 0.548125692 -#> 25 0.45 0.48770517 0.92349150 0.390125203 0.521821859 -#> 26 0.46 0.48770517 0.91791471 0.386881188 0.500832721 -#> 27 0.47 0.48770517 0.91233793 0.383602478 0.480948274 -#> 28 0.50 0.50959412 0.91233793 0.406767075 0.494257293 -#> 29 0.51 0.51873208 0.90908928 0.414674154 0.488627225 -#> 30 0.52 0.54062103 0.90908928 0.438259407 0.501099732 -#> 31 0.54 0.56594137 0.90438674 0.463389055 0.499698057 -#> 32 0.55 0.59478617 0.88942858 0.487791504 0.470668716 -#> 33 0.56 0.60174621 0.88562505 0.493745179 0.463867402 -#> 34 0.57 0.64552410 0.88004826 0.541625987 0.470801157 -#> 35 0.58 0.68930199 0.88004826 0.593563643 0.490770925 -#> 36 0.61 0.68930199 0.87447148 0.591186822 0.476964496 -#> 37 0.62 0.68930199 0.85774113 0.583886587 0.438451824 -#> 38 0.63 0.69436107 0.85345328 0.588211022 0.431499794 -#> 39 0.65 0.71625001 0.85345328 0.615399115 0.441135390 -#> 40 0.66 0.71625001 0.84787650 0.613068201 0.429536863 -#> 41 0.68 0.71738117 0.83143434 0.607473848 0.397979780 -#> 42 0.69 0.74394216 0.82704788 0.639918659 0.401319587 * -#> 43 0.70 0.74394216 0.82147110 0.637653996 0.391378740 -#> 44 0.71 0.74842069 0.81703534 0.641738327 0.385566434 -#> 45 0.72 0.74842069 0.81145855 0.639456405 0.376149629 -#> 46 0.73 0.74842069 0.78915142 0.630030429 0.341098191 -#> 47 0.74 0.77030964 0.78915142 0.659997817 0.350124243 -#> 48 0.75 0.77030964 0.77799785 0.655464454 0.333993563 -#> 49 0.76 0.77030964 0.77242107 0.653152135 0.326246592 -#> 50 0.77 0.77258431 0.75627025 0.649530619 0.305833004 -#> 51 0.78 0.77258431 0.74511669 0.644662989 0.291990800 -#> 52 0.79 0.77258431 0.73953990 0.642178115 0.285322909 -#> 53 0.80 0.79680419 0.73455699 0.675751367 0.288991930 -#> 54 0.81 0.82257740 0.72439304 0.710724025 0.287223379 -#> 55 0.82 0.83099390 0.69865345 0.714087427 0.263011148 -#> 56 0.83 0.85699425 0.68297059 0.750571367 0.256962309 -#> 57 0.84 0.85750577 0.66637056 0.745546012 0.241751267 -#> 58 0.85 0.86178006 0.65072920 0.747158648 0.229549697 -#> 59 0.86 0.86767004 0.60761556 0.741093565 0.197395457 -#> 60 0.87 0.87371786 0.58684926 0.744022696 0.184570916 -#> 61 0.88 0.87371786 0.54781178 0.726793454 0.159154137 -#> 62 0.89 0.87429563 0.52007507 0.714308251 0.142991188 -#> 63 0.90 0.88007572 0.46020308 0.693375427 0.113472209 -#> 64 0.91 0.88189088 0.44393519 0.687358210 0.106324407 -#> 65 0.92 0.90607043 0.43336521 0.742266431 0.108441768 -#> 66 0.93 0.90709287 0.38343466 0.713642407 0.087321036 -#> 67 0.94 0.92977785 0.33344642 0.749206620 0.074231134 -#> 68 0.95 0.99609393 0.27784399 0.982422667 0.071513706 -#> 69 0.96 0.99928239 0.18385102 0.995107180 0.043575415 -#> 70 0.97 0.99955729 0.10584609 0.994757348 0.023375585 -#> 71 0.98 0.99990285 0.02228238 0.994535469 0.004586136 +#> 1 0.01 0.01305524 0.99776480 0.008649236 0.497080443 +#> 2 0.03 0.02703047 0.99576564 0.018304284 0.523634851 +#> 3 0.05 0.04879765 0.99576564 0.035943566 0.682423234 +#> 4 0.06 0.06076768 0.99325202 0.043768005 0.620425952 +#> 5 0.07 0.06076768 0.98766727 0.039421496 0.445027347 +#> 6 0.08 0.08253487 0.98766727 0.057398837 0.537522789 +#> 7 0.09 0.10430205 0.98766727 0.075541108 0.603590962 +#> 8 0.10 0.12606923 0.98766727 0.093850588 0.653142092 +#> 9 0.13 0.14477820 0.98129789 0.105000442 0.579202616 +#> 10 0.17 0.15942148 0.97947013 0.116214171 0.580070929 +#> 11 0.18 0.18118866 0.97947013 0.135058445 0.615065019 +#> 12 0.19 0.18118866 0.97388539 0.130978532 0.548016396 +#> 13 0.20 0.23145370 0.97002752 0.172617620 0.578511977 +#> 14 0.21 0.28848471 0.96790557 0.222859516 0.619934389 +#> 15 0.22 0.30213854 0.96582395 0.234054494 0.615519441 +#> 16 0.23 0.32390572 0.96023921 0.250634421 0.593355534 +#> 17 0.25 0.34567291 0.96023921 0.271170315 0.611035728 +#> 18 0.26 0.36360375 0.94808544 0.280456500 0.550739420 +#> 19 0.30 0.36360375 0.94250070 0.276822441 0.520839180 +#> 20 0.32 0.38537093 0.94250070 0.298012485 0.537952066 +#> 21 0.34 0.40713811 0.94250070 0.319418754 0.553884754 +#> 22 0.36 0.42890530 0.93691596 0.337647897 0.542131961 +#> 23 0.37 0.45067248 0.93691596 0.359592271 0.556440337 +#> 24 0.41 0.49420685 0.93691596 0.404170370 0.582532082 +#> 25 0.45 0.50563644 0.92867893 0.411471950 0.554243315 +#> 26 0.46 0.50563644 0.92309419 0.408341482 0.532329521 +#> 27 0.47 0.51426257 0.91413788 0.412414399 0.504641639 +#> 28 0.51 0.52845754 0.90661036 0.423385584 0.487495889 +#> 29 0.54 0.53186968 0.89631632 0.421267460 0.457469108 +#> 30 0.55 0.55363686 0.88514683 0.438929016 0.438218206 +#> 31 0.56 0.56055812 0.88133786 0.444525719 0.431936558 +#> 32 0.57 0.60409249 0.87575312 0.490976060 0.440889023 +#> 33 0.58 0.64762686 0.87575312 0.541711231 0.462393292 +#> 34 0.60 0.66939404 0.87575312 0.567521274 0.472536814 +#> 35 0.61 0.66939404 0.87016837 0.564992159 0.459034890 +#> 36 0.62 0.66939404 0.85899889 0.559844137 0.433477677 +#> 37 0.63 0.69619207 0.85470490 0.590677937 0.436355197 +#> 38 0.65 0.71795925 0.85470490 0.617715854 0.445908499 +#> 39 0.66 0.71795925 0.84912015 0.615398981 0.434200573 +#> 40 0.68 0.71908398 0.83823924 0.612232488 0.412964969 +#> 41 0.69 0.74085116 0.83823924 0.640071061 0.422282985 * +#> 42 0.70 0.74085116 0.83265449 0.637835477 0.411675953 +#> 43 0.71 0.74530474 0.82821239 0.641834790 0.405350586 +#> 44 0.72 0.74530474 0.82262765 0.639582178 0.395321531 +#> 45 0.73 0.74530474 0.80587342 0.632651066 0.366978548 +#> 46 0.74 0.76707192 0.80587342 0.661878597 0.376021711 +#> 47 0.75 0.77171790 0.78472646 0.659844550 0.345452060 +#> 48 0.76 0.77171790 0.77914171 0.657576847 0.337425138 +#> 49 0.77 0.77397988 0.76296783 0.654050833 0.316253369 +#> 50 0.78 0.77397988 0.75738309 0.651681318 0.309002478 +#> 51 0.79 0.77397988 0.74621361 0.646843559 0.295037797 +#> 52 0.80 0.79806496 0.74122356 0.680032502 0.298497603 +#> 53 0.81 0.82369474 0.72546035 0.712545765 0.289983657 +#> 54 0.82 0.83206421 0.69968397 0.715898095 0.265531437 +#> 55 0.83 0.85791982 0.67839395 0.750249691 0.254006591 +#> 56 0.84 0.85842846 0.66177022 0.745171223 0.238983003 +#> 57 0.85 0.86267886 0.63493703 0.742522870 0.217722197 +#> 58 0.86 0.86853589 0.59176181 0.735898000 0.187136338 +#> 59 0.87 0.87327113 0.57622248 0.738403706 0.178017748 +#> 60 0.88 0.87327113 0.54829877 0.725826961 0.160059697 +#> 61 0.89 0.87384555 0.53727666 0.721718125 0.153554871 +#> 62 0.90 0.88081208 0.46087765 0.695258163 0.114580082 +#> 63 0.91 0.90438431 0.43900179 0.740800831 0.111094391 +#> 64 0.92 0.92842931 0.42283198 0.796159436 0.110528737 +#> 65 0.93 0.92944603 0.37841489 0.776413461 0.091839944 +#> 66 0.94 0.93023762 0.33394005 0.750848645 0.074916739 +#> 67 0.95 0.99618475 0.27825826 0.982831374 0.072046335 +#> 68 0.96 0.99935537 0.18971586 0.995734090 0.045476795 +#> 69 0.97 0.99962873 0.11718434 0.996022143 0.026306256 +#> 70 0.98 0.99990340 0.02789893 0.995653157 0.005805723 #> tvAUC(roc) #> #> Time-dependent AUC for the Joint Model jointFit #> -#> Estimated AUC: 0.8362 +#> Estimated AUC: 0.8374 #> At time: 7 #> Using information up to time: 4 (225 subjects still at risk) +#> Accounting for censoring using model-based weights #> plot(roc, legend = TRUE, optimal_cutoff = "Youden") diff --git a/docs/reference/coda_methods-10.png b/docs/reference/coda_methods-10.png index 480f4893..3ab5e58a 100644 Binary files a/docs/reference/coda_methods-10.png and b/docs/reference/coda_methods-10.png differ diff --git a/docs/reference/coda_methods-11.png b/docs/reference/coda_methods-11.png index 281eb273..527dafd2 100644 Binary files a/docs/reference/coda_methods-11.png and b/docs/reference/coda_methods-11.png differ diff --git a/docs/reference/coda_methods-12.png b/docs/reference/coda_methods-12.png index 76c6863f..a3d75dc1 100644 Binary files a/docs/reference/coda_methods-12.png and b/docs/reference/coda_methods-12.png differ diff --git a/docs/reference/coda_methods-29.png b/docs/reference/coda_methods-29.png index 89845f57..a835c7de 100644 Binary files a/docs/reference/coda_methods-29.png and b/docs/reference/coda_methods-29.png differ diff --git a/docs/reference/coda_methods-30.png b/docs/reference/coda_methods-30.png index 98ef1654..dd86b68a 100644 Binary files a/docs/reference/coda_methods-30.png and b/docs/reference/coda_methods-30.png differ diff --git a/docs/reference/coda_methods-31.png b/docs/reference/coda_methods-31.png index 4294f3dd..5db9cf2f 100644 Binary files a/docs/reference/coda_methods-31.png and b/docs/reference/coda_methods-31.png differ diff --git a/docs/reference/coda_methods-32.png b/docs/reference/coda_methods-32.png index 87cab7cb..85617a38 100644 Binary files a/docs/reference/coda_methods-32.png and b/docs/reference/coda_methods-32.png differ diff --git a/docs/reference/coda_methods-33.png b/docs/reference/coda_methods-33.png index 989d02fb..2df12678 100644 Binary files a/docs/reference/coda_methods-33.png and b/docs/reference/coda_methods-33.png differ diff --git a/docs/reference/coda_methods-34.png b/docs/reference/coda_methods-34.png index 9da073f3..a4aeaee1 100644 Binary files a/docs/reference/coda_methods-34.png and b/docs/reference/coda_methods-34.png differ diff --git a/docs/reference/coda_methods-35.png b/docs/reference/coda_methods-35.png index b2a05583..ce30cf00 100644 Binary files a/docs/reference/coda_methods-35.png and b/docs/reference/coda_methods-35.png differ diff --git a/docs/reference/coda_methods-36.png b/docs/reference/coda_methods-36.png index c4aaf0b3..201477cb 100644 Binary files a/docs/reference/coda_methods-36.png and b/docs/reference/coda_methods-36.png differ diff --git a/docs/reference/coda_methods-37.png b/docs/reference/coda_methods-37.png index 3cce12c0..6f5cbc80 100644 Binary files a/docs/reference/coda_methods-37.png and b/docs/reference/coda_methods-37.png differ diff --git a/docs/reference/coda_methods-38.png b/docs/reference/coda_methods-38.png index c9b87aa4..ad31ab4e 100644 Binary files a/docs/reference/coda_methods-38.png and b/docs/reference/coda_methods-38.png differ diff --git a/docs/reference/coda_methods-39.png b/docs/reference/coda_methods-39.png index 33c36414..ce0f9420 100644 Binary files a/docs/reference/coda_methods-39.png and b/docs/reference/coda_methods-39.png differ diff --git a/docs/reference/coda_methods-40.png b/docs/reference/coda_methods-40.png index 385c898f..7fefe8eb 100644 Binary files a/docs/reference/coda_methods-40.png and b/docs/reference/coda_methods-40.png differ diff --git a/docs/reference/coda_methods-41.png b/docs/reference/coda_methods-41.png index 294ebcc0..2d4882f0 100644 Binary files a/docs/reference/coda_methods-41.png and b/docs/reference/coda_methods-41.png differ diff --git a/docs/reference/coda_methods-42.png b/docs/reference/coda_methods-42.png index e3c889f5..8d8bbc6e 100644 Binary files a/docs/reference/coda_methods-42.png and b/docs/reference/coda_methods-42.png differ diff --git a/docs/reference/coda_methods-7.png b/docs/reference/coda_methods-7.png index 98e64b44..e02cd9c4 100644 Binary files a/docs/reference/coda_methods-7.png and b/docs/reference/coda_methods-7.png differ diff --git a/docs/reference/coda_methods-8.png b/docs/reference/coda_methods-8.png index faa599e8..a8b8a215 100644 Binary files a/docs/reference/coda_methods-8.png and b/docs/reference/coda_methods-8.png differ diff --git a/docs/reference/coda_methods-9.png b/docs/reference/coda_methods-9.png index 72ce641f..b2de618b 100644 Binary files a/docs/reference/coda_methods-9.png and b/docs/reference/coda_methods-9.png differ diff --git a/docs/reference/jm.html b/docs/reference/jm.html index a0c19e71..eb885312 100644 --- a/docs/reference/jm.html +++ b/docs/reference/jm.html @@ -333,17 +333,26 @@

Arguments

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

MALA
-

a logical; if TRUE, the MALA algorithm is used when updating the elements +

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 +

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

+ +
save_logLik_contributions
+

logical; if TRUE, the log-likelihood contributions are + saved in the mcmc component of 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.

+
parallel
+

a character string indicating how the parallel sampling of the chains will + be performed. Options are "snow" (default) and multicore.

+
knots

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

diff --git a/docs/reference/predict-5.png b/docs/reference/predict-5.png index 3ad73089..232f5966 100644 Binary files a/docs/reference/predict-5.png and b/docs/reference/predict-5.png differ diff --git a/docs/reference/predict-6.png b/docs/reference/predict-6.png index 42e545cf..0388e237 100644 Binary files a/docs/reference/predict-6.png and b/docs/reference/predict-6.png differ diff --git a/docs/reference/predict-7.png b/docs/reference/predict-7.png index 9965411f..5004ebf4 100644 Binary files a/docs/reference/predict-7.png and b/docs/reference/predict-7.png differ diff --git a/docs/reference/predict-8.png b/docs/reference/predict-8.png index 60ebdbc4..f2fc97db 100644 Binary files a/docs/reference/predict-8.png and b/docs/reference/predict-8.png differ diff --git a/man/predict.Rd b/man/predict.Rd index c4c51cb9..f07e205a 100644 --- a/man/predict.Rd +++ b/man/predict.Rd @@ -14,15 +14,12 @@ Predict method for object of class \code{"jm"}. \usage{ -\method{predict}{jm}(object, newdata = NULL, newdata2 = NULL, times = NULL, - all_times = FALSE, times_per_id = FALSE, - process = c("longitudinal", "event"), - type_pred = c("response", "link"), - type = c("subject_specific", "mean_subject"), - level = 0.95, return_newdata = FALSE, use_Y = TRUE, return_mcmc = FALSE, - n_samples = 200L, n_mcmc = 55L, parallel = c("snow", "multicore"), - cores = NULL, seed = 123L, - \dots) +\method{predict}{jm}(object, + newdata = NULL, newdata2 = NULL, times = NULL, + process = c("longitudinal", "event"), + type_pred = c("response", "link"), + type = c("subject_specific", "mean_subject"), + control = NULL, \dots) \method{plot}{predict_jm}(x, x2 = NULL, subject = 1, outcomes = 1, fun_long = NULL, fun_event = NULL, CI_long = TRUE, CI_event = TRUE, @@ -36,15 +33,12 @@ Predict method for object of class \code{"jm"}. col_axis = "black", pos_ylab_long = c(0.1, 2, 0.08), bg = "white", \dots) -\method{predict}{jmList}(object, weights, newdata = NULL, newdata2 = NULL, - times = NULL, all_times = FALSE, times_per_id = FALSE, - process = c("longitudinal", "event"), - type_pred = c("response", "link"), - type = c("subject_specific", "mean_subject"), - level = 0.95, return_newdata = FALSE, - return_mcmc = FALSE, n_samples = 200L, n_mcmc = 55L, - parallel = c("snow", "multicore"), - cores = parallelly::availableCores(omit = 1L), \dots) +\method{predict}{jmList}(object, + weights, newdata = NULL, newdata2 = NULL, + times = NULL, process = c("longitudinal", "event"), + type_pred = c("response", "link"), + type = c("subject_specific", "mean_subject"), + control = NULL, \dots) } \arguments{ @@ -56,17 +50,19 @@ Predict method for object of class \code{"jm"}. \item{times}{a numeric vector of future times to calculate predictions.} -\item{all_times}{logical; if \code{TRUE} predictions for the longitudinal outcomes are calculated for all the times -given in the \code{times} argumet, not only the ones after the last longitudinal measurement.}. - -\item{times_per_id}{logical; if \code{TRUE} the \code{times} argument is a vector of times equal to the number of -subjects in \code{newdata}.} - \item{process}{for which process to calculation predictions, for the longitudinal outcomes or the event times.} +\item{type}{level of predictions; only relevant when \code{type_pred = "longitudinal"}. Option \code{type = "subject_specific"} combines the fixed- and random-effects parts, whereas \code{type = "mean_subject"} uses only the fixed effects.} + \item{type_pred}{type of predictions; options are \code{"response"} using the inverse link function in GLMMs, and \code{"link"} that correspond to the linear predictor.} -\item{type}{level of predictions; only relevant when \code{type_pred = "longitudinal"}. Option \code{type = "subject_specific"} combines the fixed- and random-effects parts, whereas \code{type = "mean_subject"} uses only the fixed effects.} +\item{control}{a named \code{list} of control parameters: + \describe{ + \item{all_times}{logical; if \code{TRUE} predictions for the longitudinal outcomes are calculated for all the times +given in the \code{times} argumet, not only the ones after the last longitudinal measurement.}. + + \item{times_per_id}{logical; if \code{TRUE} the \code{times} argument is a vector of times equal to the number of +subjects in \code{newdata}.} \item{level}{the level of the credible interval.} @@ -85,6 +81,8 @@ subjects in \code{newdata}.} \item{cores}{how many number of cores to use. If there more than 20 subjects in \code{newdata}, parallel computing is invoked with four cores by default. If \code{cores = 1}, no parallel computing is used.} \item{seed}{an integer denoting the seed.} + } +} \item{x, x2}{objects returned by \code{predict.jm()} with argument \code{return_data} set to \code{TRUE}.} @@ -107,7 +105,7 @@ longitudinal outcomes are plotted.} \item{ylim_long_outcome_range}{logical; if \code{TRUE}, the range of the y-axis spans across the range of the outcome in the data used to fit the model; not only the range of values of the specific subject being plotted.} -\item{\dots}{extra aguments; currently none is used.} +\item{\dots}{extra aguments passed to control.} } \details{ diff --git a/vignettes/Super_Learning.Rmd b/vignettes/Super_Learning.Rmd index 2b7a2163..d5e1732f 100644 --- a/vignettes/Super_Learning.Rmd +++ b/vignettes/Super_Learning.Rmd @@ -101,14 +101,14 @@ Brier_weights <- tvBrier(Models_folds, newdata = CVdats$testing, Brier_weights ``` -We observe that the first two models dominate the weights. We also note that the integrated Brier score based on the combined predictions is smaller than the integrated Brier score of each individual model. To calculate the model weights using the expected predictive cross-entropy, use function `tvEPCE()` with an almost identical call as for the Brier score: +We observe that the fourth model dominates the weights. We also note that the integrated Brier score based on the combined predictions is smaller than the integrated Brier score of each individual model. To calculate the model weights using the expected predictive cross-entropy, use function `tvEPCE()` with an almost identical call as for the Brier score: ```{r, "calculate EPCE weights"} EPCE_weights <- tvEPCE(Models_folds, newdata = CVdats$testing, Tstart = tstr, Thoriz = thor) EPCE_weights ``` -The EPCE results are similar to those from the integrated Brier score; however, now only models `M2` and `M3` share the weights. Again, we see that the EPCE based on the combined cross-validated predictions is smaller than the EPCE based on the cross-validated predictions of each individual model. +The EPCE results indicate that models `M2` and `M3` share the most weight. Again, we see that the EPCE based on the combined cross-validated predictions is smaller than the EPCE based on the cross-validated predictions of each individual model. To use these weights in practice, we must first refit the five joint models we considered in the original dataset. ```{r, "fit the model in the original dataset", warning = FALSE}