All participants have different backgrounds and interests. For this reason we tend to provide more exercises than you can solve in this week. Exercises that cover fundamental concepts are marked with ★. We recommend that everyone has a look at them. Exercises that are more advanced are marked with ♛.
For most exercises we provide hints and solutions for R, Julia, and (still a bit less polished) for Python. You can attempt the exercises in any other language you are comfortable with, however, in some cases you may find it difficult to find corresponding packages.
R is a popular free software environment for statistical computing, with an wide range of packages for a extensive array of statistical procedures, plotting options, data handling, and more. See this overview. However, as an interpreted language, R’s performance may be slow, and deploying it in a production environment can pose certain limitations.
Julia is a more recent, well designed language developed at MIT aiming at scientific computation. It utilizes a highly efficient just-in-time compilation for execution speeds comparable to those of C or Fortran. This makes Julia a great option for computationally intensive tasks like Bayesian inference. Being a newer language than R, you may find more rough edges in some libraries and less online resources. The core language, however, is stable and very well documented. Note, for the exercises in this course you will not benefit a lot from the faster speed as all our example models are tiny. Julia may even appear slower than R in interactive use due to the compilation step. However, the faster execution speed of Julia makes this a worthwhile trade-off for larger problems. Another distinct advantage of Julia is the availability of Automatic Differentiation that can help a lot with optimization and posterior sampling.
Python is a versatile and widely-used programming language known for its readability and simplicity. It has a rich ecosystem of libraries and frameworks for various applications. Libraries for data handling are comparable ot R (e.g., Pandas, NumPy) and deep learning learning frameworks such as Pytorch, Jax, Tensorflow are usually best integrated with Python. As an interpreted language, Python, like R, belongs to the slower languages (although Cython and Numba can often optimize performance-critical parts of the code).
Run this code once to install all required packages for this course. Check careful for any error messages!
## all packages that we need to install
pkgs <- c("mcmcensemble", "IDPmisc", "FME", "rootSolve", "EasyABC",
"adaptMCMC", "mvtnorm", "sensitivity", "deSolve")
## install packages if needed
for(pkg in pkgs){
if(!(pkg %in% row.names(installed.packages()))){
print(paste("-- Install: ", pkg))
install.packages(pkg, dependencies = TRUE)
}
}
Download and install the latest stable Julia version from the official webpage. Read the platform specific instructions carefully.
If you do not have a favorite text editor, install Visual Studio Code, and the Visual Studio Code Julia Plugin following this instructions.
Optional: install packages for a better user experience. Packages
are installed by typing ] add packagename
in the Julia
interpreter.
Julia has a build-in package manager that also handles environments
(for Python users, think pip
and virtualenv
combined), see the documentation here. The required packages
used in the exercises are defined in the files:
Project.toml
(defines the needed
packages)Manifest.toml
(defines all indirect
dependencies and exact versions)Save them at a convenient location and run the following code to install and precompile all packages. Note, the precompilation may take several minutes!
import Pkg
Pkg.activate("path to *directory* containing Manifest.toml and Project.toml")
Pkg.instantiate()
Pkg.status()
Later activate the environment at the beginning of every script
(before using
the packages) with:
import Pkg
Pkg.activate("path to *directory* containing Manifest.toml and Project.toml")
using ...
Official Julia webpage with downloads and links to many other resources.
Official Julia documentation, rather technical.
A brief Julia introduction for programmers.
Julia forum, here you find most questions answered.
Noteworthy Differences from other Languages such as Matlab, Python, R.
Juliahub, search for packages and documentation
JuliaNotes, tips on workflows and other topics
Modern Julia Workflows, a collection of best practices for Julia development
Introduction to computational thinking A very cool MIT lecture using Julia and interactive notebooks.
Python can be installed in many ways. For this exercises we used a
miniconda
installation.
Install miniconda
following the instructions given
here.
If you do not have a favorite text editor, install Visual Studio Code and the Python extension.
The packages required are defined in environment.yml
.
The file defines the conda
environment SummerSchoolExercises
. Download it to your
working directory and create the SummerSchoolExercises
environment with:
conda env create -f environment.yml
Then, before you run your code make sure you activate the environment:
conda activate SummerSchoolExercises
Download this zip
file and extract it to convenient location. It contains all
csv
files needed for the exercises.
The example models are defined in this file. Save it in a convenient location.
The easiest way to load the models into your scripts is by storing the models.py file in the same location as the scripts. If models.py are not stored in the same directory as the scripts, one should change the working directory to the given location before importing the functions.
Sunday: Review of probability calculus, basics of R, Julia, and Python
Monday: Deriving and implementing likelihood functions, sensitivity analysis
Tuesday: Bayesian computations, MCMC
Wednesday: Adaptive Bayesian computations, MCMC
This exercises may use additional software packages.
Thursday A: Inference for Hierarchical models with STAN and JAGS
Thursday B: Approximative Bayesian Computation (ABC)
If you find any typos, errors, confusing instructions, bad solutions, or you have general suggestions how to improve the exercises, please open an issue here (PRs are welcome too). Thanks a lot!
## R version 4.4.3 (2025-02-28)
## Platform: aarch64-apple-darwin24.2.0
## Running under: macOS Sequoia 15.5
##
## Matrix products: default
## BLAS: /opt/homebrew/Cellar/openblas/0.3.29/lib/libopenblasp-r0.3.29.dylib
## LAPACK: /opt/homebrew/Cellar/r/4.4.3/lib/R/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] sensitivity_1.30.1 FME_1.3.6.3 coda_0.19-4.1 rootSolve_1.8.2.4 deSolve_1.40
## [6] EasyABC_1.5.2 abc_2.2.2 locfit_1.5-9.12 MASS_7.3-64 quantreg_6.1
## [11] SparseM_1.84-2 nnet_7.3-20 abc.data_1.1 reticulate_1.42.0 JuliaCall_0.17.6
## [16] knitr_1.50 rmarkdown_2.29
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.2.1 dplyr_1.1.4 farver_2.1.2 fastmap_1.2.0 tensorA_0.36.2.1
## [6] shinyjs_2.1.0 promises_1.3.3 numbers_0.8-5 digest_0.6.37 mime_0.12
## [11] lifecycle_1.0.4 cluster_2.1.8 survival_3.8-3 magrittr_2.0.3 compiler_4.4.3
## [16] rlang_1.1.5 sass_0.4.9 tools_4.4.3 yaml_2.3.10 mnormt_2.1.1
## [21] plyr_1.8.9 RColorBrewer_1.1-3 withr_3.0.2 grid_4.4.3 stats4_4.4.3
## [26] xtable_1.8-4 ggplot2_3.5.2 scales_1.4.0 iterators_1.0.14 cli_3.6.4
## [31] generics_0.1.3 RcppParallel_5.1.10 RSpectra_0.16-2 reshape2_1.4.4 minqa_1.2.8
## [36] cachem_1.1.0 proxy_0.4-27 stringr_1.5.1 modeltools_0.2-24 splines_4.4.3
## [41] parallel_4.4.3 vctrs_0.6.5 boot_1.3-31 Matrix_1.7-2 jsonlite_1.9.0
## [46] minpack.lm_1.2-4 ggrepel_0.9.6 clue_0.3-66 foreach_1.5.2 jquerylib_0.1.4
## [51] pls_2.8-5 glue_1.8.0 dtw_1.23-1 codetools_0.2-20 flexclust_1.5.0
## [56] stringi_1.8.7 gtable_0.3.6 later_1.4.2 tibble_3.2.1 pillar_1.10.2
## [61] htmltools_0.5.8.1 R6_2.6.1 lhs_1.2.0 evaluate_1.0.3 shiny_1.10.0
## [66] lattice_0.22-6 png_0.1-8 dtwclust_6.0.0 httpuv_1.6.16 bslib_0.9.0
## [71] class_7.3-23 MatrixModels_0.5-4 Rcpp_1.0.14 xfun_0.51 pkgconfig_2.0.3
## Julia Version 1.11.5
## Commit 760b2e5b739 (2025-04-14 06:53 UTC)
## Build Info:
## Official https://julialang.org/ release
## Platform Info:
## OS: macOS (arm64-apple-darwin24.0.0)
## CPU: 12 × Apple M4 Pro
## WORD_SIZE: 64
## LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
## Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
## Environment:
## DYLD_FALLBACK_LIBRARY_PATH = /Users/scheidan/.julia/artifacts/c1600fa286afe4bf3616780a19b65285c63968ca/lib:/Users/scheidan/.julia/artifacts/b820a0a437e8501d06a17439abd84feaa5b6cca3/lib:/Users/scheidan/.julia/artifacts/a313d7c1b6344b380ad5425226ece4d3952012c3/lib:/Users/scheidan/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/lib/julia:/Users/scheidan/.julia/artifacts/c99c0e2b61a41b4b2294b30e9f7f26e50c2e38eb/lib:/Users/scheidan/.julia/artifacts/9410bad2635eda2239b4a72ba4316c4aa8f5b76e/lib:/Users/scheidan/.julia/artifacts/93cd40a14bb74dde9e76f2960a698cdb52554387/lib:/Users/scheidan/.julia/artifacts/21209a2ac399ce693d73daf1aa8d670fbc84d70f/lib:/Users/scheidan/.julia/artifacts/c59059ef20910985e15a497e3f3f9f5a01df2645/lib:/Users/scheidan/.julia/artifacts/c4b9929ae9f0b6e0230d975f1e65ec59507e3e80/lib:/Users/scheidan/.julia/artifacts/365365262519d2f165f6ca9bdc0f104718889a88/lib:/Users/scheidan/.julia/artifacts/becfd6f89f1a272ace2375b067f1153515ca70b3/lib:/Users/scheidan/.julia/artifacts/f00ec04851ced5895bd99297d49916ba59ca783d/lib:/Users/scheidan/.julia/artifacts/9afa0c7d7942a5f55d570fe7a49075105ace80b0/lib:/Users/scheidan/.julia/artifacts/1994697285dfe8747ff7ec6927666edc88750202/lib:/Users/scheidan/.julia/artifacts/c5d5b7c7e77b04af2eabde40ebbf379932d8bfd7/lib:/Users/scheidan/.julia/artifacts/7fefc9739781f053e15aeb2e61c2ba767c275222/lib:/Users/scheidan/.julia/artifacts/a3e73ecf5d803bb3792a23f0382a2b5573383647/lib:/Users/scheidan/.julia/artifacts/67723a86975c82b43f01cda306999b382d3435f0/lib:/Users/scheidan/.julia/artifacts/115f3a18328d7b88e31c9e3f095aeb12eb381710/lib:/Users/scheidan/.julia/artifacts/ca2831bf6edc5088aec5b329ea98364951d6cad0/lib:/Users/scheidan/.julia/artifacts/477447566a69a531a7a3f8e0130cbfe460b37eec/lib:/Users/scheidan/.julia/artifacts/b58891667c46c467bd51be0e963c1ef1f0314934/lib:/Users/scheidan/.julia/artifacts/0db9c3f6cf936a0da49e2ba954ba3e10bed6ad72/lib:/Users/scheidan/.julia/artifacts/1a7e22e66b523d9cb884cf85c3ec065b5fb3e5c3/lib:/Users/scheidan/.julia/artifacts/84fa3b322bb3bbb0d733f9f1498ca286422dfab3/lib:/Users/scheidan/.julia/artifacts/83ff444c229f9dd64a13999123a4eb14e632d67a/lib:/Users/scheidan/.julia/artifacts/6095fcd268ea712c0f786f5ff1a45bf0eb7b005e/lib:/Users/scheidan/.julia/artifacts/7ead0a440ba045155db235bff6602a984f08a651/lib:/Users/scheidan/.julia/artifacts/9d8a957aa3387b17b8639251016c87710db1a175/lib:/Users/scheidan/.julia/artifacts/63d48e4aab8721470f588bdeb1e2b462ee3b6a68/lib:/Users/scheidan/.julia/artifacts/4ed6227ff66b34dcd65f011ad8b91bdf545ac4d8/lib:/Users/scheidan/.julia/artifacts/8da603395acfbdbef8c5de3b7223aeb9276ecbdb/lib:/Users/scheidan/.julia/artifacts/932f282690a789f3744abcd83fb9f68ba7ed4c19/lib:/Users/scheidan/.julia/artifacts/4b3b2d79556cc3aef6e3d8a234649cc85b91bb87/lib:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtConcurrent.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtCore.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtDBus.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtGui.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtNetwork.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtOpenGL.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtOpenGLWidgets.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtPrintSupport.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtSql.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtTest.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtWidgets.framework/Versions/A:/Users/scheidan/.julia/artifacts/9306f53cf2947dcfc1fbf5195cbd66b4d6d0114c/lib/QtXml.framework/Versions/A:/Users/scheidan/.julia/artifacts/17eeee83b1236d140f28cbf5f05482a9fbee1a7e/lib:/Users/scheidan/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/bin/../lib/julia:/Users/scheidan/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/bin/../lib:/opt/homebrew/Cellar/r/4.4.3/lib/R/lib
## Status `~/Desktop/SiamSummerSchoolExercises/src/Project.toml`
## [717c3277] AdaptiveMCMC v0.1.4
## [be4af45d] BarkerMCMC v0.2.0
## [336ed68f] CSV v0.10.15
## [b0b7db55] ComponentArrays v0.15.27
## [a93c6f00] DataFrames v1.7.0
## [31c24e10] Distributions v0.25.120
## [bbc10e6e] DynamicHMC v3.5.1
## ⌅ [f6369f11] ForwardDiff v0.10.38
## [38e38edf] GLM v1.9.0
## [af5da776] GlobalSensitivity v2.7.0
## [79d62d8d] KissMCMC v0.2.1
## [996a588d] LogDensityProblemsAD v1.13.0
## [c7f686f2] MCMCChains v7.1.0
## ⌃ [429524aa] Optim v1.12.0
## [1dea7af3] OrdinaryDiffEq v6.98.0
## [91a5bcdd] Plots v1.40.13
## [2e0e63f1] SimulatedAnnealingABC v0.4.0
## [10745b16] Statistics v1.11.1
## [2913bbd2] StatsBase v0.34.5
## [f3b207a7] StatsPlots v0.15.7
## [84d833dd] TransformVariables v0.8.17
## [f9bc47f6] TransformedLogDensities v1.1.1
## [3a884ed6] UnPack v1.0.2
## [37e2e46d] LinearAlgebra v1.11.0
## Info Packages marked with ⌃ and ⌅ have new versions available. Those with ⌃ may be upgradable, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated`
## package version requirement channel
## 1 blas 1.0 blas=1.0 pkgs/main
## 2 bottleneck 1.4.2 bottleneck=1.4.2 pkgs/main
## 3 brotli-python 1.0.9 brotli-python=1.0.9 pkgs/main
## 4 ca-certificates 2025.2.25 ca-certificates=2025.2.25 pkgs/main
## 5 contourpy 1.2.1 contourpy=1.2.1 pkgs/main
## 6 cycler 0.11.0 cycler=0.11.0 pkgs/main
## 7 dill 0.3.8 dill=0.3.8 pkgs/main
## 8 emcee 3.1.6 emcee=3.1.6 conda-forge
## 9 fonttools 4.55.3 fonttools=4.55.3 pkgs/main
## 10 freetype 2.13.3 freetype=2.13.3 pkgs/main
## 11 importlib_resources 6.4.0 importlib_resources=6.4.0 pkgs/main
## 12 jpeg 9e jpeg=9e pkgs/main
## 13 kiwisolver 1.4.4 kiwisolver=1.4.4 pkgs/main
## 14 lcms2 2.16 lcms2=2.16 pkgs/main
## 15 lerc 4.0.0 lerc=4.0.0 pkgs/main
## 16 libcxx 14.0.6 libcxx=14.0.6 pkgs/main
## 17 libdeflate 1.22 libdeflate=1.22 pkgs/main
## 18 libffi 3.4.4 libffi=3.4.4 pkgs/main
## 19 libgfortran 5.0.0 libgfortran=5.0.0 pkgs/main
## 20 libgfortran5 11.3.0 libgfortran5=11.3.0 pkgs/main
## 21 libopenblas 0.3.29 libopenblas=0.3.29 pkgs/main
## 22 libpng 1.6.39 libpng=1.6.39 pkgs/main
## 23 libtiff 4.7.0 libtiff=4.7.0 pkgs/main
## 24 libwebp-base 1.3.2 libwebp-base=1.3.2 pkgs/main
## 25 llvm-openmp 14.0.6 llvm-openmp=14.0.6 pkgs/main
## 26 lz4-c 1.9.4 lz4-c=1.9.4 pkgs/main
## 27 matplotlib 3.9.2 matplotlib=3.9.2 pkgs/main
## 28 matplotlib-base 3.9.2 matplotlib-base=3.9.2 pkgs/main
## 29 multiprocess 0.70.15 multiprocess=0.70.15 pkgs/main
## 30 ncurses 6.4 ncurses=6.4 pkgs/main
## 31 numexpr 2.10.1 numexpr=2.10.1 pkgs/main
## 32 numpy 1.26.4 numpy=1.26.4 pkgs/main
## 33 numpy-base 1.26.4 numpy-base=1.26.4 pkgs/main
## 34 openjpeg 2.5.2 openjpeg=2.5.2 pkgs/main
## 35 openssl 3.0.16 openssl=3.0.16 pkgs/main
## 36 packaging 24.2 packaging=24.2 pkgs/main
## 37 pandas 2.2.3 pandas=2.2.3 pkgs/main
## 38 patsy 1.0.1 patsy=1.0.1 pkgs/main
## 39 pillow 11.1.0 pillow=11.1.0 pkgs/main
## 40 pip 25.1 pip=25.1 pkgs/main
## 41 pybind11-abi 4 pybind11-abi=4 pkgs/main
## 42 pyparsing 3.2.0 pyparsing=3.2.0 pkgs/main
## 43 python 3.9.21 python=3.9.21 pkgs/main
## 44 python-dateutil 2.9.0post0 python-dateutil=2.9.0post0 pkgs/main
## 45 python-tzdata 2025.2 python-tzdata=2025.2 pkgs/main
## 46 pytz 2024.1 pytz=2024.1 pkgs/main
## 47 readline 8.2 readline=8.2 pkgs/main
## 48 salib 1.4.7 salib=1.4.7 pkgs/main
## 49 scipy 1.13.1 scipy=1.13.1 pkgs/main
## 50 seaborn 0.13.2 seaborn=0.13.2 pkgs/main
## 51 setuptools 78.1.1 setuptools=78.1.1 pkgs/main
## 52 six 1.17.0 six=1.17.0 pkgs/main
## 53 sqlite 3.45.3 sqlite=3.45.3 pkgs/main
## 54 statsmodels 0.14.4 statsmodels=0.14.4 pkgs/main
## 55 tk 8.6.14 tk=8.6.14 pkgs/main
## 56 tornado 6.5 tornado=6.5 pkgs/main
## 57 tzdata 2025b tzdata=2025b pkgs/main
## 58 unicodedata2 15.1.0 unicodedata2=15.1.0 pkgs/main
## 59 wheel 0.45.1 wheel=0.45.1 pkgs/main
## 60 xz 5.6.4 xz=5.6.4 pkgs/main
## 61 zipp 3.21.0 zipp=3.21.0 pkgs/main
## 62 zlib 1.2.13 zlib=1.2.13 pkgs/main
## 63 zstd 1.5.6 zstd=1.5.6 pkgs/main
Built at 18 June, 2025.
This work is licensed under a Creative
Commons Attribution-NonCommercial-ShareAlike 4.0 International
License.