# Enable universe(s) by inlabru-org
options(repos = c(
inlabruorg = "https://inlabru-org.r-universe.dev",
INLA = "https://inla.r-inla-download.org/R/testing",
CRAN = "https://cloud.r-project.org"
))
# Install some packages
install.packages("inlabru")Software Installation
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 we will try reply.
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.
Check your
Rversion.Install R-INLA, instructions can be found here
Install
inlabru(available from CRAN)
Make sure you have the latest
R-INLA,inlabruandRversions installed.Install the following libraries:
install.packages(c(
"car",
"CARBayesdata",
"DAAG",
"dplyr",
"ggplot2",
"lubridate",
"mapview",
"patchwork",
"scico",
"sdmTMB",
"sf",
"spatstat",
"spdep",
"terra",
"tidyr",
"tidyterra",
"tidyverse"
))
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.
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.547, Running = 0.193, Post = 0.00884, Total = 0.749
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) 10.085 0.093 9.902 10.085 10.269 10.085 0
Model hyperparameters:
mean sd 0.025quant 0.5quant
Precision for the Gaussian observations 1.17 0.164 0.869 1.16
0.975quant mode
Precision for the Gaussian observations 1.51 1.15
Marginal log-Likelihood: -146.84
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.13.0.9033
INLA version: 26.02.06
Latent components:
Intercept: main = linear(1)
Observation models:
Model tag: <No tag>
Family: 'gaussian'
Data class: 'data.frame'
Response class: 'numeric'
Predictor: y ~ Intercept
Additive/Linear/Rowwise: TRUE/TRUE/TRUE
Used components: effect[Intercept], latent[]
Time used:
Pre = 0.489, Running = 0.186, Post = 0.0141, Total = 0.69
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
Intercept 10.085 0.093 9.902 10.085 10.269 10.085 0
Model hyperparameters:
mean sd 0.025quant 0.5quant
Precision for the Gaussian observations 1.17 0.164 0.869 1.16
0.975quant mode
Precision for the Gaussian observations 1.51 1.15
Marginal log-Likelihood: -151.30
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)')