Learn R Programming

⚠️There's a newer version (2.11.1) of this package.Take me there.

inlabru

The goal of inlabru is to facilitate spatial modeling using integrated nested Laplace approximation via the R-INLA package. Additionally, extends the GAM-like model class to more general nonlinear predictor expressions, and implements a log Gaussian Cox process likelihood for modeling univariate and spatial point processes based on ecological survey data. Model components are specified with general inputs and mapping methods to the latent variables, and the predictors are specified via general R expressions, with separate expressions for each observation likelihood model in multi-likelihood models. A prediction method based on fast Monte Carlo sampling allows posterior prediction of general expressions of the latent variables. See Fabian E. Bachl, Finn Lindgren, David L. Borchers, and Janine B. Illian (2019), inlabru: an R package for Bayesian spatial modelling from ecological survey data, Methods in Ecology and Evolution, British Ecological Society, 10, 760–766, doi:10.1111/2041-210X.13168, and citation("inlabru").

The inlabru.org website has links to old tutorials with code examples for versions up to 2.1.13. For later versions, updated versions of these tutorials, as well as new examples, can be found at https://inlabru-org.github.io/inlabru/articles/

Installation

You can install the current CRAN version of inlabru:

install.packages("inlabru")

You can install the latest bugfix release of inlabru from GitHub with:

# install.packages("remotes")
remotes::install_github("inlabru-org/inlabru", ref = "stable")

You can install the development version of inlabru from GitHub with

# install.packages("remotes")
remotes::install_github("inlabru-org/inlabru", ref = "devel")

or track the development version builds via inlabru-org.r-universe.dev:

# 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")

Example

This is a basic example which shows you how fit a simple spatial Log Gaussian Cox Process (LGCP) and predicts its intensity:

# Load libraries
library(inlabru)
library(INLA)
#> Loading required package: Matrix
#> This is INLA_23.06.15 built 2023-06-15 06:01:53 UTC.
#>  - See www.r-inla.org/contact-us for how to get help.
library(ggplot2)
bru_safe_sp(force = TRUE) # Ensures sp works without rgdal installed

# Load the data
data(gorillas, package = "inlabru")

# Construct latent model components
matern <- inla.spde2.pcmatern(gorillas$mesh,
  prior.sigma = c(0.1, 0.01),
  prior.range = c(0.01, 0.01)
)
cmp <- ~ mySmooth(coordinates, model = matern) + Intercept(1)
# Fit LGCP model
# This particular bru/like combination has a shortcut function lgcp() as well
fit <- bru(
  components = cmp,
  like(
    formula = coordinates ~ .,
    family = "cp",
    data = gorillas$nests,
    samplers = gorillas$boundary,
    domain = list(coordinates = gorillas$mesh)
  ),
  options = list(control.inla = list(int.strategy = "eb"))
)
#> Please note that rgdal will be retired during October 2023,
#> plan transition to sf/stars/terra functions using GDAL and PROJ
#> at your earliest convenience.
#> See https://r-spatial.org/r/2023/05/15/evolution4.html and https://github.com/r-spatial/evolution
#> rgdal: version: 1.6-7, (SVN revision 1203)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 3.4.1, released 2021/12/27
#> Path to GDAL shared files: /usr/share/gdal
#> GDAL binary built with GEOS: TRUE 
#> Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821]
#> Path to PROJ shared files: /home/flindgre/.local/share/proj:/usr/share/proj
#> PROJ CDN enabled: FALSE
#> Linking to sp version:1.6-1
#> To mute warnings of possible GDAL/OSR exportToProj4() degradation,
#> use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.

# Predict Gorilla nest intensity
lambda <- predict(
  fit,
  fm_pixels(gorillas$mesh, mask = gorillas$boundary, format = "sp"),
  ~ exp(mySmooth + Intercept)
)

# Plot the result
ggplot() +
  gg(lambda) +
  gg(gorillas$nests, color = "red", size = 0.2) +
  coord_equal() +
  ggtitle("Nest intensity per km squared")

Copy Link

Version

Install

install.packages('inlabru')

Monthly Downloads

1,741

Version

2.8.0

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Finn Lindgren

Last Published

June 20th, 2023

Functions in inlabru (2.8.0)

add_mappers

Add component input/latent mappers
bru_int_polygon

Integration points for polygons inside an inla.mesh
bru_get_mapper

Extract mapper information from INLA model component objects
bru_like_inla_family

Utility functions for bru likelihood objects
bru_mapper_generics

Generic methods for bru_mapper objects
bru_mapper

Constructors for bru_mapper objects
summary.bru_info

Methods for bru_info objects
bru_log_reset

inlabru log message methods
bru_env_get

Get access to the internal environment
bru_fill_missing

Fill in missing values in Spatial grids
bru_forward_transformation

Transformation tools
bru_safe_sp

Check for potential sp version compatibility issues
bru_safe_inla

Load INLA safely for examples and tests
bru_make_stack

Build an inla data stack from linearisation information
bru_used

List components used in a model
bru_standardise_names

Standardise inla hyperparameter names
bru_mapper_methods

Methods for bru_mapper objects
summary.bru_mapper

mapper object summaries
bru_summarise

Summarise and annotate data
bru_used_update

Update used_component information objects
deltaIC

Summarise DIC and WAIC from lgcp objects.
cprod

(Blockwise) cross product of integration points
comp_lin_eval

Construct component linearisations
eval_spatial

Evaluate spatial covariates
component_eval

Evaluate component values in predictor expressions
bru_model

Create an inlabru model object from model components
component

Latent model component construction
evaluate_comp_lin

Compute all component linearisations
component_list

Methods for inlabru component lists
evaluate_inputs

Compute all component inputs
code.components

Convert components to R code
call-stack

Call stack utility functions
evaluate_comp_simple

Compute simplified component mappings
evaluate_model

Evaluate or sample from a posterior result given a model and locations
fm_crs_wkt

Handling CRS/WKT
bru_options

Create or update an options objects
fm_CRS

Create a coordinate reference system object
extract_property

Extract a summary property from all results of an inla result
[.comp_simple_list

Subsetting of comp_simple_list objects, retaining class
evaluate_index

Compute all index values
evaluate_effect_single_state

Evaluate a component effect
fm_CRS_as_list

Show expanded CRS arguments
gg.SpatialLines

Geom for SpatialLines objects
fm_evaluate

Methods for projecting to/from an inla.mesh
gg.SpatialPixels

Geom for SpatialPixels objects
fm_centroids

Extract triangle centroids from an inla.mesh
eval_in_data_context

Evaluate expressions in the data context
devel.cvmeasure

Variance and correlations measures for prediction components
fm_crs_is_null

Obtain coordinate reference system object
bru_used_vars

Extract basic variable names from expression
fm_cprod

(Blockwise) cross product of integration points
evaluate_predictor

Evaluate component effects or expressions
fm_int_multi_sampler

Multi-domain sampler integration
fm_is_within

Query if points are inside a mesh
fm_pixels

Generate lattice points covering a mesh
fm_store_points

store points in different formats
fm_as_sp_crs

Coercion methods to and from meshes
fm_vertex_projection

Project integration points to mesh vertices
fm_transform

Object coordinate transformation
gg.RasterLayer

Geom for RasterLayer objects
expand_labels

Expand labels
fm_int

Multi-domain integration
gg.matrix

Geom for matrix
fm_identical_CRS

Check if two CRS objects are identical
gg.inla.mesh

Geom for inla.mesh objects
gg.inla.mesh.1d

Geom for inla.mesh.1d objects
gg.prediction

Geom for predictions
fm_int_inla_mesh

Subset integration on a mesh
gg.SpatRaster

Geom wrapper for SpatRaster objects
fm_int_inla_mesh_core

Integration scheme for mesh triangle interiors
glplot.SpatialLines

Visualize SpatialLines using RGL
fm_vertices

Extract vertex locations from an inla.mesh
gg

ggplot2 geomes for inlabru related objects
generate

Generate samples from fitted bru models
fm_contains

Check which mesh triangles are inside a polygon
gg.SpatialPolygons

Geom for SpatialPolygons objects
globe

Plot a globe using rgl
plot.prediction

Plot prediction using ggplot2
lgcp

Log Gaussian Cox process (LGCP) inference using INLA
like

Likelihood construction for usage with bru()
gg.data.frame

Geom for data.frame
import.mrsea

MRSea data import
import.mexdolphin

Mexdolphin data import
index_eval

Obtain indices
glplot.SpatialPoints

Visualize SpatialPoints using RGL
plotsample

Create a plot sample.
sample.lgcp

Sample from an inhomogeneous Poisson process
gg.SpatialGridDataFrame

Geom for SpatialGridDataFrame objects
gg.SpatialPoints

Geom for SpatialPoints objects
gg.SpatialPixelsDataFrame

Geom for SpatialPixelsDataFrame objects
iinla

Iterated INLA
import.gorillas

Gorilla data import
glplot

Render Spatial* and inla.mesh objects using RGL
glplot.inla.mesh

Visualize SpatialPoints using RGL
gm

ggplot geom for spatial data
integration_weight_aggregation

Aggregate integration weights onto mesh nodes
seals

Seal pups
inla.stack.mjoin

Join stacks intended to be run with different likelihoods
mrsea

Marine renewables strategic environmental assessment
gmap

Plot a map using extent of a spatial object
inla_subset_eval

Obtain inla index subset information
stransform

Deprecated functions in inlabru
multiplot

Multiple ggplots on a page.
inlabru-package

inlabru
intersection_mesh

Construct the intersection mesh of a mesh and a polygon
input_eval

Obtain component inputs
fm_wkt_as_wkt_tree

Internal WKT handling
summary.bru_options

Print inlabru options
robins_subset

robins_subset
row_kron

Row-wise Kronecker products
local_testthat

Unit test helpers
ipoints

Generate integration points
parse_inclusion

Parse inclusion of component labels in a predictor expression
summary.component

Summarise components
mexdolphin

Pan-tropical spotted dolphins in the Gulf of Mexico
is.inside

Query if a point is inside the mesh boundary
mesh_triangle_integration

Integration scheme for mesh triangle interiors
gorillas

Gorilla nesting sites
materncov.bands

Matern correlation or covariance function approximate credible bands.
make_hierarchical_mesh_basis

Make hierarchical mesh basis functions
pixels

Generate SpatialPixels covering an inla.mesh
plot.bru

Plot method for posterior marginals estimated by bru
predict.inla

Prediction from fitted inla model
refine.inla.mesh

Refine an inla.mesh object
shrimp

Blue and red shrimp in the Western Mediterranean Sea
spoly

Convert a data.frame of boundary points into a SpatialPolgonsDataFrame
split_lines

Split lines at mesh edges
toygroups

Simulated 1D animal group locations and group sizes
import.seals

Seal pup edata import
import.shrimp

Shrimp data import
tsplit.inla.mesh

Split triangles of a mesh into four triangles
point2count

Convert a plot sample of points into one of counts.
st_signed_area

Calculate signed area for polygon
sline

Convert data frame to SpatialLinesDataFrame
summary.bru

Summary for an inlabru fit
predict.bru

Prediction from fitted bru model
spde.posterior

Posteriors of SPDE hyper parameters and Matern correlation or covariance function.
st_check_dim

Check for "XYZ", "XYM" and "XYZM" sfg classes
spatial.to.ppp

Convert SpatialPoints and boundary polygon to spatstat ppp object
st_check_polygon

Check sfg polygon satisfies standards for POLYGON simple features
bru

Convenient model fitting using (iterated) INLA
Poisson3_1D

1-Dimensional NonHomogeneous Poisson example.
bincount

1D LGCP bin count simulation and comparison with data
Poisson1_1D

1-Dimensional Homogeneous Poisson example.
bru_compute_linearisation

Compute inlabru model linearisation information
Poisson2_1D

1-Dimensional NonHomogeneous Poisson example.
bru_call_options

Additional bru options
bru_convergence_plot

Plot inlabru convergence diagnostics
bm_list

Methods for mapper lists