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)
#> Loading required package: sp
library(INLA)
#> Loading required package: Matrix
#> Loading required package: foreach
#> Loading required package: parallel
#> This is INLA_22.11.28-1 built 2022-11-28 08:04:58 UTC.
#>  - See www.r-inla.org/contact-us for how to get help.
#>  - To enable PARDISO sparse library; see inla.pardiso()
library(ggplot2)

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

# Predict Gorilla nest intensity
lambda <- predict(
  fit,
  pixels(gorillas$mesh, mask = gorillas$boundary),
  ~ 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")

If you have an R installation with PROJ6/GDAL3, and INLA >= 20.06.18, and loading old spatial objects, you may need to apply the rgdal::rebuild_CRS() method on them before they are fully usable. The data objects in inlabru have been updated, so should not need this conversion anymore.

Copy Link

Version

Install

install.packages('inlabru')

Monthly Downloads

1,741

Version

2.7.0

License

GPL (>= 2)

Maintainer

Finn Lindgren

Last Published

December 2nd, 2022

Functions in inlabru (2.7.0)

Poisson1_1D

1-Dimensional Homogeneous Poisson example.
Poisson2_1D

1-Dimensional NonHomogeneous Poisson example.
bru_forward_transformation

Transformation tools
bru

Convenient model fitting using (iterated) INLA
bru_like_inla_family

Utility functions for bru likelihood objects
component_list

Methods for inlabru component lists
summary.bru_mapper

mapper object summaries
component_eval

Evaluate component values in predictor expressions
bru_log_reset

inlabru log message methods
code.components

Convert components to R code
bm_list

Methods for mapper lists
bru_call_options

Additional bru options
bru_model

Create an inlabru model object from model components
expand_labels

Expand labels
bru_int_polygon

Integration points for polygons inside an inla.mesh
add_mappers

Add component input/latent mappers
bru_convergence_plot

Plot inlabru convergence diagnostics
bru_compute_linearisation

Compute inlabru model linearisation information
cprod

Cross product of integration points
bru_make_stack

Build an inla data stack from linearisation information
bru_env_get

Get access to the internal environment
bru_mapper

Constructors for bru_mapper objects
deltaIC

Summarise DIC and WAIC from lgcp objects.
bru_get_mapper

Extract mapper information from INLA model component objects
bru_options

Create or update an options objects
bru_int_polygon_old

Integration points for polygons inside an inla.mesh
bru_mapper_generics

Generic methods for bru_mapper objects
bru_safe_inla

Load INLA safely for examples and tests
evaluate_model

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

Evaluate component effects or expressions
extract_property

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

Methods for bru_info objects
evaluate_comp_simple

Compute simplified component mappings
evaluate_comp_lin

Compute all component linearisations
bru_fill_missing

Fill in missing values in Spatial grids
fm_transform

Object coordinate transformation
evaluate_effect_single_state

Evaluate a component effect
bru_standardise_names

Standardise inla hyperparameter names
bru_summarise

Summarise and annotate data
bru_mapper_methods

Methods for bru_mapper objects
[.comp_simple_list

Subsetting of comp_simple_list objects, retaining class
evaluate_index

Compute all index values
generate

Generate samples from fitted bru models
gg.SpatialPoints

Geom for SpatialPoints objects
comp_lin_eval

Construct component linearisations
component

Latent model component construction
fm_has_PROJ6

PROJ6 detection
fm_identical_CRS

Check if two CRS objects are identical
fm_CRS

Create a coordinate reference system object
evaluate_inputs

Compute all component inputs
glplot

Render Spatial* and inla.mesh objects using RGL
devel.cvmeasure

Variance and correlations measures for prediction components
gg.SpatialPolygons

Geom for SpatialPolygons objects
fm_CRS_as_list

Show expanded CRS arguments
gg.RasterLayer

Geom for RasterLayer objects
gg

ggplot2 geomes for inlabru related objects
glplot.SpatialLines

Visualize SpatialLines using RGL
gg.prediction

Geom for predictions
eval_spatial

Evaluate spatial covariates
inla.stack.mjoin

Join stacks intended to be run with different likelihoods
fm_wkt_is_geocent

Handling CRS/WKT
gm

ggplot geom for spatial data
fm_as_sp_crs

Coercion methods to and from meshes
fm_crs

Obtain coordinate reference system object
fm_spTransform

Handle transformation of various inla objects according to coordinate reference systems of sp::CRS or INLA::inla.CRS class.
gmap

Plot a map using extent of a spatial object
fm_sp_get_crs

Extract CRS information
inla_subset_eval

Obtain inla index subset information
fm_evaluate

Methods for projecting to/from an inla.mesh
gorillas

Gorilla nesting sites
gg.inla.mesh.1d

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

Geom for data.frame
gg.SpatialLines

Geom for SpatialLines objects
gg.SpatialGridDataFrame

Geom for SpatialGridDataFrame objects
iinla

Iterated INLA
gg.inla.mesh

Geom for inla.mesh objects
gg.SpatialPixelsDataFrame

Geom for SpatialPixelsDataFrame objects
gg.SpatialPixels

Geom for SpatialPixels objects
mesh_triangle_integration

Integration scheme for mesh triangle interiors
glplot.SpatialPoints

Visualize SpatialPoints using RGL
globe

Plot a globe using rgl
gg.matrix

Geom for matrix
import.gorillas

Gorilla data import
import.mexdolphin

Mexdolphin data import
int.polygon

Integration points for polygons inside an inla.mesh
import.shrimp

Shrimp data import
glplot.inla.mesh

Visualize SpatialPoints using RGL
stransform

Deprecated functions in inlabru
import.mrsea

MRSea data import
integration_weight_aggregation

Aggregate integration weights onto mesh nodes
input_eval

Obtain component inputs
import.seals

Seal pup edata import
mrsea

Marine renewables strategic environmental assessment
predict.bru

Prediction from fitted bru model
multiplot

Multiple ggplots on a page.
inlabru

inlabru
predict.inla

Prediction from fitted inla model
sline

Convert data frame to SpatialLinesDataFrame
spatial.to.ppp

Convert SpatialPoints and boundary polygon to spatstat ppp object
mexdolphin

Pan-tropical spotted dolphins in the Gulf of Mexico
int

Weighted summation (integration) of data frame subsets
intersection_mesh

Construct the intersection mesh of a mesh and a polygon
ipoints

Generate integration points
fm_wkt_as_wkt_tree

Internal WKT handling
like

Likelihood construction for usage with bru()
index_eval

Obtain indices
parse_inclusion

Parse inclusion of component labels in a predictor expression
make_stable_integration_points

Basic robust integration weights for mesh/polygon intersections
materncov.bands

Matern correlation or covariance function approximate credible bands.
pixels

Generate SpatialPixels covering an inla.mesh
row_kron

Row-wise Kronecker products
plotsample

Create a plot sample.
st_check_polygon

Check sfg polygon satisfies standards for POLYGON simple features
local_testthat

Unit test helpers
is.inside

Query if a point is inside the mesh boundary
lgcp

Log Gaussian Cox process (LGCP) inference using INLA
robins_subset

robins_subset
point2count

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

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

Check for "XYZ", "XYM" and "XYZM" sfg classes
refine.inla.mesh

Refine an inla.mesh object
plot.bru

Plot method for posterior marginals estimated by bru
sample.lgcp

Sample from an inhomogeneous Poisson process
tsplit.inla.mesh

Split triangles of a mesh into four triangles
st_signed_area

Calculate signed area for polygon
toygroups

Simulated 1D animal group locations and group sizes
summary.component

Summarise components
seals

Seal pups
plot.prediction

Plot prediction using ggplot2
vertices.inla.mesh

Extract vertex locations from an inla.mesh
spde.posterior

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

Blue and red shrimp in the Western Mediterranean Sea
split_lines

Split lines at mesh edges
summary.bru

Summary for an inlabru fit
summary.bru_options

Print inlabru options
Poisson3_1D

1-Dimensional NonHomogeneous Poisson example.
bincount

1D LGCP bin count simulation and comparison with data