Official R implementation of B-TAJ DPM, from the following paper:
A Bayesian Threshold-Aligned Joint Disease Progression Model (B-TAJ DPM) for Alzheimer’s Disease.
Rong Wu, Duygu Tosun, Isabella Hausle, Margo Heston, and Aaron Wolfe Scheffler,
University of California San Francisco
for the Alzheimer’s Disease Neuroimaging Initiative
- R 4.6.1 (R 4.5.3 or later may work, but the current workflow was checked with R 4.6.1)
- Rtools for Windows, including
makeandg++, because NIMBLE compiles C++ code - Pandoc 2.8 or later to render an R Markdown file to HTML or PDF
Install the main R packages with:
install.packages(c(
"nimble", "matrixStats", "ggplot2", "splines2", "tidyr",
"dplyr", "mgcv", "MASS", "knitr", "rmarkdown"
))Both commands should return an executable path.
model/contains data generation, model code, custom samplers, and numerical helpers.simulation/contains simulation evaluation scripts.posterior code/contains posterior extraction and posterior-predictive utilities, includingposterior predictive distribution.R.B-TAJ DPM Tutorial.Rmdis the original simulation tutorial.
The tutorial loads the simulation components from model/ and
uses simu() to:
- generate longitudinal amyloid and tau observations;
- fit the simulated data with the B-TAJ model;
- retain posterior draws for trajectories, covariates, variance parameters, correlation, and subject-level random effects.
Open B-TAJ DPM Tutorial.Rmd in RStudio or
run:
setwd("E:/Github/B-TAJ")
knitr::knit("B-TAJ DPM Tutorial.Rmd")The Rmd first runs:
res <- simu(
varying_coef_code_sim,
varying_coef_code,
n_subjects = 1000,
niter = 2000,
nburnin = 1000
)This is the training fit. Its posterior samples are kept fixed and are used as the fitted population-level model.
The Rmd then creates a new simulation with:
data_1 <- generate_d1(n_subjects = 2, ...)
simudata <- generate_vc(varying_coef_code_sim, data_1, ...)This N=2 dataset is not refit as a new population model. Instead, its
observed amyloid and tau data are passed to
posterior_predictions_code.
The fixed training posterior supplies the population trajectory and variance
parameters, while the new data update the subject-specific alpha random
effects.
The Rmd then reports posterior threshold-age predictions. Amyloid predictions
are produced for both new subjects; tau predictions are produced only for
subjects included in tau_amy_link and therefore having tau observations.
The Rmd may take several minutes because it compiles NIMBLE models and runs MCMC twice: once for the N=1000 training simulation and once for the N=2 posterior prediction.
If you use this implementation, cite:
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
© 2025 Rong Wu.
