################################################################################
# Code supplement
################################################################################
Title: Flexible Bayesian additive joint models with an application to 
      type 1 diabetes research
Authors: Meike Koehler, Nikolaus Umlauf, Andreas Beyerlein, Christiane Winkler,
        Anette-Gabriele Ziegler, Sonja Greven
Main contributors to the code: Meike Koehler, Nikolaus Umlauf
contact: meike.koehler@helmholtz-muenchen.de
################################################################################



Configurations
################
The code has been written using R-3.2.3, R-3.2.4, and R-3.3.2 with package versions 
bamlss_0.1-3, mgcv_1.8-12 and JMbayes_0.7-9. To allow for reproducibility independent 
of new CRAN releases, the package source "bamlss_0.1-3.tar.gz" is provided. 

To reproduce the simulations, the code files "run_simulations.R" and "help_functions.R"
are given. Additionally, the analysis of the application section can be run using 
"applied_analysis.R" and the provided "testdata.RData".




Code execution
################
Place all contents of the zip-file into your preferred main directory. 

To reproduce the results presented in the simulations section of the manuscript, 
run the file "run_simulations.R".
The number of cores (default 2) to run the simulations on and number of simulations 
(default 200) can be specified in line 20 and 22. 
Model fits are stored in the subfolder "output", processed results in the subfolder
"results", figures and tables will be stored in the "figures" subfolder.
Please note that the execution of a single model fitting for the posterior mean 
estimation takes approx. 4-10 hours on one core, depending on CPU. 

To reproduce the results in the application section, run the file "applied_analysis.R".
Model fits and figures are stored in the subfolders "results" and "figures", respectively.



Further notes
################
Due to recent modifications to speedup computations in the bamlss-package the computed 
simulation results will differ slightly from the reported results. However, the main results 
and conclusions from the simulations should not differ.

The presented type 1 diabetes cohort data are not freely available. Therefore test data 
were simulated based on the estimated main model to illustrate the computations.
