Skip to contents

Please use the instructions below to install and check your installation. If you run into issues, you can post a question with information about what you tried and what didn’t work, on the course github discussion page and Finn will reply when he’s able. Since 29 April 2025, the latest INLA package is built for R 4.5, so if you’re able to upgrade your R installation, please do so to avoid unnecessary issues. The package will in many cases also work with older R versions, but compatibility is sometimes difficult.

Installing INLA and inlabru

Due to the work involved in building the binaries for the INLA package C software for different architectures, the INLA package is not on CRAN, but it can be installed from its own distribution repository. The easiest approach is to add the repository to your local R options, e.g. in ~/.Rprofile, so that install.packages("INLA") can work as usual. Alternatively, the same repository information can be supplied via install.packages("INLA", repos = ...).

In ~/.Rprofile, add the following lines, or run the code in your R session:

local({
  r <- c(INLA = "https://inla.r-inla-download.org/R/testing",
         CRAN = "https://cloud.r-project.org/",
         inlabru_universe = "https://inlabru-org.r-universe.dev")
  options(repos = r)
})

Note: if you have installed INLA from the "stable" repository instead of "testing", you may need to upgrade to the "testing" version, which typically contains bug fixes and improvements, and is the version inlabru is tested against.

The third repository is optional, and gives you easy access to the development versions of inlabru (2.12.0.9016 or later) and fmesher (0.3.0.9008 or later, which is a package dependency of INLA and inlabru). Most of the tutorials in this course will work with the CRAN versions of inlabru and fmesher, 2.12.0, but installing the development version from r-universe.dev is recommended, and required for a few new features and contains bug fixes, see the inlabru changelog.

To install the packages, including optional dependencies many of which are required for data analysis, run the following code in your R session:

install.packages(c("INLA", "inlabru"), dependencies = TRUE)

The warning about the unavailable HKprocess package can safely be ignored. INLA also suggests two Bioconductor packages, graph and Rgraphviz, which are not essential for this course, but can be installed with

if (!requireNamespace("BiocManager", quietly = TRUE)) {
  install.packages("BiocManager")
}
BiocManager::install(c("graph", "Rgraphviz"), dep = TRUE)

Installation check

Please check your installation using the basic model runs below. If you run into issues, you can post a question with information about what you tried and what didn’t work, on the course github discussion page and Finn will reply when he’s able. Since 29 April 2025, the latest INLA package is built for R 4.5, so if you’re able to upgrade your R installation, please do so to avoid unnecessary issues. The package will in many cases also work with older R versions, but compatibility is sometimes difficult.

You can check that INLA is correctly installed by running

df <- data.frame(y = rnorm(100) + 10)
fit <- INLA::inla(
  y ~ 1,
  data = df
)
summary(fit)
#> Time used:
#>     Pre = 0.39, Running = 0.248, Post = 0.0149, Total = 0.653 
#> Fixed effects:
#>               mean    sd 0.025quant 0.5quant 0.975quant   mode kld
#> (Intercept) 10.071 0.105      9.865   10.071     10.277 10.071   0
#> 
#> Model hyperparameters:
#>                                          mean   sd 0.025quant 0.5quant
#> Precision for the Gaussian observations 0.924 0.13      0.687    0.918
#>                                         0.975quant  mode
#> Precision for the Gaussian observations       1.20 0.905
#> 
#> Marginal log-Likelihood:  -158.73 
#>  is computed 
#> Posterior summaries for the linear predictor and the fitted values are computed
#> (Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')

If the simple inla() call fails with a crash, you may need to install different inla binaries for your hardware/software combination, with INLA::inla.binary.install().

When inla() works, you can check that inlabru is installed correctly by running the same model in inlabru:

fit <- inlabru::bru(
  y ~ Intercept(1, prec.linear = exp(-7)),
  data = df
)
summary(fit)
#> inlabru version: 2.12.0.9016
#> INLA version: 25.05.18-1
#> Components:
#> Intercept: main = linear(1), group = exchangeable(1L), replicate = iid(1L), NULL
#> Observation models:
#>   Family: 'gaussian'
#>     Tag: ''
#>     Data class: 'data.frame'
#>     Response class: 'numeric'
#>     Predictor: y ~ .
#>     Additive/Linear: TRUE/TRUE
#>     Used components: effects[Intercept], latent[]
#> Time used:
#>     Pre = 0.236, Running = 0.262, Post = 0.0364, Total = 0.535 
#> Fixed effects:
#>             mean    sd 0.025quant 0.5quant 0.975quant   mode kld
#> Intercept 10.071 0.105      9.865   10.071     10.277 10.071   0
#> 
#> Model hyperparameters:
#>                                          mean   sd 0.025quant 0.5quant
#> Precision for the Gaussian observations 0.924 0.13      0.687    0.918
#>                                         0.975quant  mode
#> Precision for the Gaussian observations       1.20 0.905
#> 
#> Deviance Information Criterion (DIC) ...............: 296.69
#> Deviance Information Criterion (DIC, saturated) ....: 104.35
#> Effective number of parameters .....................: 1.99
#> 
#> Watanabe-Akaike information criterion (WAIC) ...: 296.96
#> Effective number of parameters .................: 2.19
#> 
#> Marginal log-Likelihood:  -163.19 
#>  is computed 
#> Posterior summaries for the linear predictor and the fitted values are computed
#> (Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')