Section 1: Installing the R package bigDM

Author

Aritz Adin

Published

Aug 13, 2024

Manual for installing the bigDM package

The R package bigDM implements several spatial and spatio-temporal scalable disease mapping models for high-dimensional count data using the integrated nested Laplace approximation (INLA) technique for approximate Bayesian inference in latent Gaussian models (Orozco-Acosta et al., 2021; Orozco-Acosta et al., 2023; and Vicente et al., 2023).

Prerequisites

Before installing bigDM, ensure that you have the following prerequisites:

  • R: Make sure you have R installed on your system. You can download and install it from CRAN.

  • RStudio (optional): For a better development experience, you might want to use RStudio, which can be downloaded from RStudio’s official website.

  • Rtools: R version 4.0 and newer for Windows requires Rtools to build R packages containing C, C++, or Fortran code from source. Installing Rtools for Windows

  • R-INLA package: Model fitting and inference is fully Bayesian using the well-known INLA technique through the R-INLA package.

    To install the latest stable version:

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

    IMPORTANT NOTES:

    • At least the stable version of INLA 22.11.22 (or newer) must be installed for the correct use of the bigDM package.

    • Visit the R-INLA website for further details about how to install the package on MacOS and for information on version compatibilities.

Installation

  1. Install from CRAN

    install.packages("bigDM", dependencies=TRUE) 
  2. Install from GitHub (development version)

    # Install devtools package from CRAN repository
    install.packages("devtools")
    
    # Load devtools library
    library(devtools)
    
    # In some Linux OS, it might be necessary to first install the following packages
    install.packages(c("cpp11","proxy","progress","tzdb","vroom"))
    
    # Install bigDM from GitHub repository
    install_github("spatialstatisticsupna/bigDM")

Verifying the installation

Load the package and check its documentation:

library(bigDM)
packageVersion("bigDM")
[1] '0.5.5'
help("bigDM-package")

Run a test function:

library(sf)
library(tmap)
library(RColorBrewer)

tmap4 <- packageVersion("tmap") >= "3.99"


## 1) Load simulated colorectal cancer mortality data 
data("Carto_SpainMUN")
str(Carto_SpainMUN)
Classes 'sf' and 'data.frame':  7907 obs. of  9 variables:
 $ ID       : chr  "01001" "01002" "01003" "01004" ...
 $ name     : chr  "Alegria-Dulantzi" "Amurrio" "Aramaio" "Artziniega" ...
 $ area     : Units: [m^2] num  19913794 96145595 73338806 27506468 10559721 ...
 $ perimeter: Units: [m] num  34372 63352 41430 22605 17847 ...
 $ obs      : int  2 28 6 3 0 2 5 2 3 2 ...
 $ exp      : num  3.024 20.846 3.753 3.209 0.482 ...
 $ SMR      : num  0.661 1.343 1.599 0.935 0 ...
 $ region   : chr  "Pais Vasco" "Pais Vasco" "Pais Vasco" "Pais Vasco" ...
 $ geometry :sfc_MULTIPOLYGON of length 7907; first list element: List of 2
  ..$ :List of 1
  .. ..$ : num [1:16, 1:2] 538259 537564 537255 537085 536961 ...
  ..$ :List of 1
  .. ..$ : num [1:37, 1:2] 541230 540800 540369 540107 540191 ...
  ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA
  ..- attr(*, "names")= chr [1:8] "ID" "name" "area" "perimeter" ...
## 2) Divide the spatial domain into provinces
carto.list <- divide_carto(Carto_SpainMUN, ID.group="region")
carto.NAV <- carto.list$Navarra
head(carto.NAV)
Simple feature collection with 6 features and 8 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 569467 ymin: 4641035 xmax: 650989 ymax: 4757037
Projected CRS: ETRS89 / UTM zone 30N
     ID                       name           area     perimeter obs       exp
1 31001                    Abaigar  5001487 [m^2]  9753.257 [m]   0 0.2774141
2 31002                       <NA> 23128602 [m^2] 29094.768 [m]   3 1.8362324
3 31003 Abaurregaina/Abaurrea Alta 21415016 [m^2] 31404.991 [m]   0 0.7061570
4 31004                       <NA> 11023417 [m^2] 33333.132 [m]   0 0.2080274
5 31005                     Aberin 21087109 [m^2] 25121.171 [m]   1 0.9738344
6 31006                    Ablitas 77509242 [m^2] 43699.550 [m]   5 6.7425962
        SMR  region                       geometry
1 0.0000000 Navarra MULTIPOLYGON (((572068 4721...
2 1.6337802 Navarra MULTIPOLYGON (((576006.4 47...
3 0.0000000 Navarra MULTIPOLYGON (((644264 4747...
4 0.0000000 Navarra MULTIPOLYGON (((643374 4750...
5 1.0268687 Navarra MULTIPOLYGON (((578396 4720...
6 0.7415541 Navarra MULTIPOLYGON (((611630 4647...
## 3) Plot a map with the SMRs
paleta <- brewer.pal(8,"RdYlGn")[8:1]
values <- c(-Inf,0.77,0.83,0.91,1,1.10,1.20,1.30,Inf)

tmap_mode("view")

if(tmap4){
  tm_shape(carto.NAV) + 
    tm_polygons(fill="SMR", id="name", popup.vars=c("ID","obs","exp","SMR"),
                fill.scale=tm_scale(values=paleta, breaks=values, interval.closure="left"),
                fill.legend=tm_legend("SMR", show=TRUE, reverse=TRUE,
                                      position=tm_pos_in("right","top"))) + 
    tm_title("Colorectal cancer")
}else{
  tm_shape(carto.NAV) + 
    tm_polygons(col="SMR", id="name", palette=paleta,
                popup.vars=c("ID","obs","exp","SMR"),
                legend.show=T, legend.reverse=T,
                style="fixed", breaks=values, interval.closure="left") + 
    tm_layout(main.title="Colorectal cancer", main.title.position="center",
              legend.outside=T, legend.outside.position="right", legend.frame=F)
}