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',
  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
options("rgdal_show_exportToProj4_warnings"="none")
library(inlabru)
#> Loading required package: sp
library(INLA)
#> Loading required package: Matrix
#> Loading required package: foreach
#> Loading required package: parallel
#> This is INLA_22.09.02 built 2022-09-02 19:28:51 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.5.3

License

GPL (>= 2)

Maintainer

Finn Lindgren

Last Published

September 5th, 2022

Functions in inlabru (2.5.3)

code.components

Convert components to R code
component_eval

Evaluate component values in predictor expressions
bru_options

Create or update an options objects
bru_summarise

Summarise and annotate data
fm_sp_get_crs

Extract CRS information
devel.cvmeasure

Variance and correlations measures for prediction components
bru_forward_transformation

Transformation tools
cprod

Cross product of integration points
evaluate_A

Compute all A-matrices
generate

Generate samples from fitted bru models
deltaIC

Summarise DIC and WAIC from lgcp objects.
fm_CRS_as_list

Show expanded CRS arguments
gg.SpatialPolygons

Geom for SpatialPolygons objects
fm_CRS

Create a coordinate reference system object
gg.SpatialGridDataFrame

Geom for SpatialGridDataFrame objects
component_list

Methods for inlabru component lists
component

Latent model component construction
gg.SpatialPoints

Geom for SpatialPoints objects
gg.SpatialLines

Geom for SpatialLines objects
glplot.inla.mesh

Visualize SpatialPoints using RGL
glplot.SpatialPoints

Visualize SpatialPoints using RGL
evaluate_model

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

Evaluate component effects or expressions
fm_wkt_is_geocent

Handling CRS/WKT
summary_bru

Deprecated functions in inlabru
evaluate_effect_single

Evaluate a component effect
bru_safe_inla

Load INLA safely for examples and tests
glplot

Render Spatial* and inla.mesh objects using RGL
gg.matrix

Geom for matrix
evaluate_index

Compute all index values
fm_spTransform

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

Standardise inla hyperparameter names
gg.inla.mesh

Geom for inla.mesh objects
gg.data.frame

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

Geom for inla.mesh.1d objects
inlabru

inlabru
like

Likelihood construction for usage with bru()
fm_identical_CRS

Chack if two CRS objects are identical
local_testthat

Unit test helpers
import.seals

Seal pup edata import
mrsea

Marine renewables strategic environmental assessment
import.gorillas

Gorilla data import
import.mrsea

MRSea data import
make_stable_integration_points

Basic robust integration weights for mesh/polygon intersections
import.mexdolphin

Mexdolphin data import
fm_has_PROJ6

PROJ6 detection
multiplot

Multiple ggplots on a page.
gg.RasterLayer

Geom for RasterLayer objects
gg.SpatialPixels

Geom for SpatialPixels objects
gorillas

Gorilla nesting sites
gg.SpatialPixelsDataFrame

Geom for SpatialPixelsDataFrame objects
expand_labels

Expand labels
gg

ggplot2 geomes for inlabru related objects
materncov.bands

Matern correlation or covariance function approximate credible bands.
iinla

Iterated INLA
extract_property

Extract a summary property from all results of an inla result
sline

Convert data frame to SpatialLinesDataFrame
glplot.SpatialLines

Visualize SpatialLines using RGL
lgcp

Log Gaussian Cox process (LGCP) inference using INLA
spatial.to.ppp

Convert SpatialPoints and boundary polygon to spatstat ppp object
is.inside

Query if a point is inside the mesh boundary
gm

ggplot geom for spatial data
globe

Plot a globe using rgl
gmap

Plot a map using extend of a spatial object
gg.prediction

Geom for predictions
refine.inla.mesh

Refine an inla.mesh object
robins_subset

robins_subset
toygroups

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

Summarise components
spde.posterior

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

Generate SpatialPixels covering an inla.mesh
row_kron

Row-wise Kronecker products
parse_inclusion

Parse inclusion of component labels in a predictor expression
sample.lgcp

Sample from an inhomogeneous Poisson process
import.shrimp

Shrimp data import
index_eval

Obtain indices
mexdolphin

Pan-tropical spotted dolphins in the Gulf of Mexico
predict.bru

Prediction from fitted bru model
spoly

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

Coordinate transformation for spatial objects
ipoints

Generate integration points
split_lines

Split lines at mesh edges
inla_subset_eval

Obtain inla index subset information
mesh_triangle_integration

Integration scheme for mesh triangle interiors
intersection_mesh

Construct the intersection mesh of a mesh and a polygon
plotsample

Create a plot sample.
inla.stack.mjoin

Join stacks intended to be run with different likelihoods
predict.inla

Prediction from fitted inla model
input_eval

Obtain covariate values
point2count

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

Aggregate integration weights onto mesh nodes
int

Weighted summation (integration) of data frame subsets
int.polygon

Integration points for polygons inside an inla.mesh
summary.bru_options

Print inlabru options
summary.bru

Summary for an inlabru fit
vertices

Vertices
vertices.inla.mesh

Extract vertex locations from an inla.mesh
fm_wkt_as_wkt_tree

Internal WKT handling
plot.bru

Plot method for posterior marginals estimated by bru
plot.prediction

Plot prediction using ggplot2
seals

Seal pups
tsplit.inla.mesh

Split triangles of a mesh into four triangles
shrimp

Blue and red shrimp in the Western Mediterranean Sea
bincount

1D LGCP bin count simulation and comparison with data
amatrix_eval

Construct A-matrix
bru

Convenient model fitting using (iterated) INLA
bru_call_options

Additional bru options
Poisson3_1D

1-Dimensional NonHomogeneous Poisson example.
add_mappers

Add component input/latent mappers
bru_env_get

Get access to the internal environment
bru_compute_linearisation

Compute inlabru model linearisation information
Poisson1_1D

1-Dimensional Homogeneous Poisson example.
Poisson2_1D

1-Dimensional NonHomogeneous Poisson example.
bru_model

Create an inlabru model object from model components
bru_fill_missing

Fill in missing values in Spatial grids
bru_make_stack

Build an inla data stack from linearisation information
bru_log_reset

inlabru log message methods
bru_int_polygon

Integration points for polygons inside an inla.mesh
bru_int_polygon_old

Integration points for polygons inside an inla.mesh
summary.bru_info

Methods for bru_info objects
bru_mapper

Methods for bru_mapper objects
bru_mapper_methods

Implementation methods for mapper objects