Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
R-INLA is an R package for fast, approximate Bayesian inference for latent Gaussian models. It implements the integrated nested Laplace approximation (INLA), and you fit models with a single function, inla(), using a formula much like the one you would give to glm(). It is not distributed through CRAN: you install it from the project’s own repository, as shown below. This guide covers what it is for, the install commands for each R version, a worked model call, how to read the summary, the install problems the project documents, and the free alternatives.
What R-INLA is used for in research
The project’s home page describes the package as “a powerful R package designed to perform fast, approximate Bayesian inference for Latent Gaussian Models”. In practice that family covers the models research groups most often fit with a Bayesian workflow: generalized linear models with random effects, spatial and spatio-temporal models, and survival or longitudinal models. If you want the background on the modelling idea first, read the CASRAI guides on Bayesian regression and Bayesian hierarchical models; for the simulation-based route that INLA is usually compared with, see Markov chain Monte Carlo.
The R-INLA website lists worked tutorials that show the range of use. They are summarised here by what each one demonstrates, with the level the site assigns.
| Tutorial topic | Model type | Level on the site |
|---|---|---|
| Salamander mating | Generalized linear mixed model | Beginner |
| Bivariate meta-analysis of sensitivity and specificity | Bivariate meta-analysis | Intermediate |
| Dengue in Brazil | Non-stationary spatial model (fbesag) | Intermediate |
| School disparities in Brunei | Spatial model | Advanced |
| Joint longitudinal and spatial event-time analysis | Joint model | Advanced |
Each tutorial walks through data preparation, model specification, priors, diagnostics and interpretation, so the beginner example is a sensible first project before you attempt a spatial model. The site also points to two books: Rue and Held on Gaussian Markov random fields, and Gómez-Rubio’s Bayesian Inference with INLA.
How to install or access R-INLA
Install only from the official download page. The stable release is installed from the project’s repository, with the CRAN repository kept alongside it so that dependencies resolve:
install.packages("INLA", repos = c(getOption("repos"), INLA = "https://inla.r-inla-download.org/R/stable"), dep = TRUE)
The testing release uses the same command with https://inla.r-inla-download.org/R/testing as the repository. Once installed, inla.upgrade() updates the stable build and inla.upgrade(testing = TRUE) updates the testing build. The download page recommends R 4.4 or later.
Choosing the INLA version for your R version
If you are stuck on an older R, install a version built for it with remotes::install_version(). For R 4.5 the download page gives this command, and the data table below lists the INLA version the page names for each R release from 4.1 to 4.5:
remotes::install_version("INLA", version = "25.04.29", repos = c(getOption("repos"), INLA = "https://inla.r-inla-download.org/R/testing"), dep = TRUE)
From INLA version 23.08.18 the package depends on fmesher, which you can install from CRAN with install.packages("fmesher").
How to fit a model in R-INLA step by step
The example below follows the surgical-mortality hospital model in Paula Moraga’s Spatial Statistics for Data Science, which fits a binomial model with a random effect per hospital. Adapt the variable names to your own data.
- Install the package as above and load it with
library(INLA). - Put your data in a data frame with one row per observation. The response, the number of trials (for binomial data) and any grouping variable are columns.
- Write the model formula. Fixed effects are written as in any R formula; each random or structured effect goes inside
f(), whose first argument is the index variable and whose second is the model name. The book’s example isformula = r ~ f(hospital, model = "iid", hyper = prior.prec), wherehypercarries the prior on the precision hyperparameter. - Call
inla()with the formula, the data and the likelihood family. The book’s call isres = inla(formula, data = Surg, family = "binomial", Ntrials = n, control.predictor = list(compute = TRUE), control.compute = list(dic = TRUE, return.marginals.predictor = TRUE)). - Inspect the result with
summary(res), then pull out the marginal distributions you need, as described in the next section.
The control.compute argument decides which extra quantities are computed: in the example it requests the deviance information criterion (DIC) and the marginals of the linear predictor. control.predictor = list(compute = TRUE) asks for the fitted values.
Three details of the example are worth understanding before you reuse it. First, the family argument sets the likelihood; the example uses "binomial" because the response is a count of events out of a number of trials, which is why Ntrials is supplied. Second, the model name inside f() chooses the structure of the random effect: the example uses "iid", meaning independent effects per hospital, whereas the tutorials on the R-INLA site use other model names for spatial structures. Third, anything you want back from the fit, such as DIC or marginals of the predictor, has to be requested through the control.* arguments, so decide what you need to report before you run the model.
How to read the R-INLA output
summary(res) is organised in blocks, and the book’s reading of each is as follows.
- Fixed effects. One row per fixed effect with its mean, standard deviation, quantiles and mode, plus
kld, the symmetric Kullback-Leibler divergence between the Gaussian and Laplace approximations of that posterior marginal. - Random effects and hyperparameters. Summaries for the model components declared with
f()and for their hyperparameters, such as precisions. - Model-fit lines. The deviance information criterion, the effective number of parameters and the marginal log-likelihood, available because the example requested
dic = TRUE.
Posterior marginals are stored as named lists whose elements are two-column matrices: the first column holds the value, the second the posterior density at that value. R-INLA ships helper functions for working with these marginals, inla.smarginal, inla.qmarginal, inla.pmarginal and inla.emarginal, so so the raw matrices are usually not handled directly. Report the marginal summaries you used and the priors you chose, since the priors in an INLA model are specified explicitly in the formula.
What to record for reproducibility
Because the INLA build you can install depends on your R release, a methods section should state both the R version and the INLA version used, along with the likelihood family, the model names passed to f() and the priors. Anyone replicating the analysis can then use the version-specific install command above to obtain the same build, instead of whatever the stable repository serves on the day they run it. The data table below the article lists the pairings the download page names, which you can use to check that your combination is one the project documents.
Troubleshooting R-INLA
- The install fails or the package will not load on an older R. Use the version-specific
remotes::install_version()command for your R release (see the data table below). - A dependency is missing after install. From INLA 23.08.18, install
fmesher. The download page also notes that the Bioconductor packagesgraphandRgraphvizare installed throughBiocManager. - Windows reinstall problems. The download page says you may need to uninstall INLA before reinstalling it.
- A binary does not run on your Linux system. The download page offers alternative Linux builds through
inla.binary.install(). - You need to move to a newer build. Run
inla.upgrade()for stable orinla.upgrade(testing = TRUE)for testing.
For modelling questions rather than installation ones, the project’s Support and Issues section on its site is the place to look.
Free alternatives to R-INLA
Two R packages come up most often next to R-INLA, and they relate to it differently: one builds on it, one is a separate approach. Details are from each package’s CRAN page, checked 2026-11-18.
| Package | Relationship to R-INLA | What its CRAN page says | CRAN version |
|---|---|---|---|
| inlabru | Built on INLA | “Facilitates spatial and general latent Gaussian modelling using integrated nested Laplace approximation via the INLA package”; INLA is a suggested package (version 23.01.31 or later); requires R 4.1.0 or later | 2.15.0 (published 2026-07-28) |
| brms | Separate approach, uses Stan | “Fit Bayesian generalized (non-)linear multivariate multilevel models using ‘Stan’ for full Bayesian inference” | 2.23.0 (published 2025-09-09) |
If your model is one of the multilevel types brms covers, the Stan-based route is a direct alternative; see the CASRAI guide to generalized linear mixed models for the surrounding concepts, and free statistical software for a wider survey. If you are new to R itself, start with how to use RStudio.
Sources
- R-INLA: download and install, official project site, checked 2026-11-18.
- R-INLA project home page, checked 2026-11-18.
- R-INLA examples and tutorials, checked 2026-11-18.
- Moraga, Spatial Statistics for Data Science: the INLA approach, checked 2026-11-18.
- inlabru on CRAN, checked 2026-11-18.
- brms on CRAN, checked 2026-11-18.
Data: INLA version named on the R-INLA download page for each R release
Version-specific installation targets for the INLA R package, compiled from the official R-INLA download page: the R release and the INLA version the page names for it.
Period covered: 2022/2025.
| R release | INLA version named on the download page |
|---|---|
| R 4.5 | 25.04.29 |
| R 4.4 | 24.05.10 |
| R 4.3 | 23.05.30 |
| R 4.2 | 22.05.07 |
| R 4.1 | 22.05.03 |
Sources
- R-INLA: download and install (accessed 2026-11-18)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







