Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drizopoulos committed Oct 13, 2023
1 parent 7fd9cc2 commit 40d2b71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
31 changes: 16 additions & 15 deletions docs/articles/Time_Varying_Effects.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions vignettes/Time_Varying_Effects.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ jointFit1 <- jm(CoxFit, fm, time_var = "year")
summary(jointFit1)
```

To specify that the association of serum bilirubin may change over 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 knots 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:
To specify that the association of serum bilirubin may change over 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:
```{r}
form_splines <- ~ value(log(serBilir)) * ns(year, k = c(3, 6, 9), B = c(0, 14.5))
jointFit2 <- update(jointFit1, functional_forms = form_splines,
n_iter = 6500L, n_burnin = 2500L)
summary(jointFit2)
```

The spline coefficients do not have a straightforward interpretation. We therefore visualize the time-varying association of serum bilirubin using the following piece of code:
The spline coefficients do not have a straightforward interpretation. We therefore visualize the time-varying association of log serum bilirubin with the hazard of the composite event using the following piece of code:
```{r, fig.align = "center", fig.width = 8.5, fig.height = 7.5}
x_times <- seq(0.001, 12, length = 501)
X <- cbind(1, ns(x_times, knots = c(3, 6, 9), B = c(0, 14.5)))
Expand All @@ -60,7 +60,7 @@ log_hr_upp <- apply(log_hr, 1, quantile, probs = 0.975)
matplot(x_times, cbind(exp(log_hr_mean), exp(log_hr_low), exp(log_hr_upp)),
type = "l", col = c("red", "black", "black"), lty = c(1, 2, 2), lwd = 2,
xlab = "Follow-up Time (years)", ylab = "Hazard Ratio serum Bilirubin",
xlab = "Follow-up Time (years)", ylab = "Hazard Ratio log serum Bilirubin",
ylim = c(0.5, 6.4))
abline(h = exp(coef(jointFit1)$association), lty = 2, col = "red")
abline(h = 1, lty = 2)
Expand All @@ -73,4 +73,4 @@ We observe that the 95% credible interval for the time-varying coefficient inclu
compare_jm(jointFit1, jointFit2)
```

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

0 comments on commit 40d2b71

Please sign in to comment.