Skip to main content

Command Palette

Search for a command to run...

Installing INLA in R on Windows

Updated
2 min read
W

Hello,

I'm passionate about transforming raw data into actionable insights, driven by a lifelong fascination with numbers. As a data analyst, I enjoy uncovering meaningful patterns and collaborating with like-minded individuals.

I'm also a strong advocate for mental health and use data to contribute to this important cause. My background in the medical field enhances my analytical approach, bridging the gap between healthcare and data analysis.

Working with Bayesian spatial models in R often brings its own set of challenges, especially when installing specialized packages like INLA. Recently, while preparing to model hotspots, I ran into exactly this issue on Windows. Here’s how I solved it and what INLA can do for your epidemiology projects.

The Challenge: Installing INLA on Windows

Started by trying the standard install command:

install.packages("INLA",
                 repos = "https://inla.r-inla-download.org/R/stable", dep = TRUE)

At first, everything looked fine. But then hit a roadblock:

  • R tried to install the latest source version of INLA.

  • Windows computers don’t have a compiler by default, so building from source failed.

  • Error messages like:

ERROR: installing binary package failed

were appearing. This is common on Windows without Rtools.

The Solution: Installing the Binary Version

The fix was simple once I knew the trick. Force R to install the binary version of INLA. This avoids compilation entirely and works perfectly for most projects.

install.packages("INLA",
                 repos = "https://inla.r-inla-download.org/R/stable",
                 type = "binary")
  • Works quickly

  • Reliable

  • Compatible with Windows

After this, INLA installed smoothly into our R library and was ready to use.

Checking the Installation

It is good practice to test that the package works:

library(INLA)

# Fit a tiny Poisson model as a test
data("kidney")
formula <- Count ~ 1 + f(Indiv, model="iid")
result <- inla(formula, family="poisson", data=kidney)

summary(result)

If you see the summary without errors, INLA is ready.

What INLA Does

INLA (Integrated Nested Laplace Approximation) is a powerful tool for Bayesian modeling, especially in spatial and spatiotemporal epidemiology. Common uses include:

  • Estimating disease incidence with spatial and temporal variation

  • Modeling environmental and socio-demographic predictors of disease

  • Accounting for uncertainty in small or sparse datasets

  • Producing posterior probability maps of disease risk

Other Useful Libraries

Alongside INLA, used several R packages to manage data and visualize results:

Package Purpose
sf Handling spatial data (points, polygons, shapefiles)
raster / terra Environmental rasters like temperature, vegetation, elevation
ggplot2 Visualizing risk maps and model results
dplyr / data.table Cleaning and manipulating data
tmap Thematic maps for spatial data visualization
spdep Spatial dependencies and neighborhood structures