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
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.10.15-1 built 2022-10-15 03:21:55 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.6.0

License

GPL (>= 2)

Maintainer

Finn Lindgren

Last Published

October 24th, 2022

Functions in inlabru (2.6.0)

Poisson1_1D

1-Dimensional Homogeneous Poisson example.
bru

Convenient model fitting using (iterated) INLA
bru_call_options

Additional bru options
Poisson2_1D

1-Dimensional NonHomogeneous Poisson example.
bincount

1D LGCP bin count simulation and comparison with data
add_mappers

Add component input/latent mappers
bru_compute_linearisation

Compute inlabru model linearisation information
Poisson3_1D

1-Dimensional NonHomogeneous Poisson example.
bru_fill_missing

Fill in missing values in Spatial grids
bru_env_get

Get access to the internal environment
bru_like_inla_family

Utility functions for bru likelihood objects
bru_make_stack

Build an inla data stack from linearisation information
bru_mapper

Constructors for bru_mapper objects
bru_mapper_methods

Methods for bru_mapper objects
bru_model

Create an inlabru model object from model components
bru_int_polygon

Integration points for polygons inside an inla.mesh
bru_int_polygon_old

Integration points for polygons inside an inla.mesh
bru_get_mapper

Extract mapper information from INLA model component objects
summary.bru_info

Methods for bru_info objects
bru_log_reset

inlabru log message methods
component_list

Methods for inlabru component lists
bru_options

Create or update an options objects
component_eval

Evaluate component values in predictor expressions
code.components

Convert components to R code
bru_standardise_names

Standardise inla hyperparameter names
component

Latent model component construction
bru_forward_transformation

Transformation tools
comp_lin_eval

Construct component linearisations
bru_safe_inla

Load INLA safely for examples and tests
[.comp_simple_list

Subsetting of comp_simple_list objects, retaining class
devel.cvmeasure

Variance and correlations measures for prediction components
eval_spatial

Evaluate spatial covariates
bru_summarise

Summarise and annotate data
evaluate_effect_single_state

Evaluate a component effect
evaluate_comp_lin

Compute all component linearisations
evaluate_comp_simple

Compute simplified component mappings
evaluate_index

Compute all index values
cprod

Cross product of integration points
deltaIC

Summarise DIC and WAIC from lgcp objects.
fm_wkt_is_geocent

Handling CRS/WKT
extract_property

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

Expand labels
fm_as

Coercion methods to and from meshes
evaluate_predictor

Evaluate component effects or expressions
evaluate_model

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

Compute all component inputs
fm_has_PROJ6

PROJ6 detection
fm_get_crs

Generic method for extracting crs objects
fm_CRS

Create a coordinate reference system object
fm_CRS_as_list

Show expanded CRS arguments
fm_identical_CRS

Check if two CRS objects are identical
fm_spTransform

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

Geom for SpatialLines objects
gg.SpatialGridDataFrame

Geom for SpatialGridDataFrame objects
generate

Generate samples from fitted bru models
fm_sp_get_crs

Extract CRS information
gg.inla.mesh

Geom for inla.mesh objects
gg.matrix

Geom for matrix
gg.RasterLayer

Geom for RasterLayer objects
gg

ggplot2 geomes for inlabru related objects
glplot

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

Visualize SpatialLines using RGL
gm

ggplot geom for spatial data
gg.data.frame

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

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

Geom for SpatialPolygons objects
gg.SpatialPoints

Geom for SpatialPoints objects
glplot.SpatialPoints

Visualize SpatialPoints using RGL
glplot.inla.mesh

Visualize SpatialPoints using RGL
int.polygon

Integration points for polygons inside an inla.mesh
index_eval

Obtain indices
integration_weight_aggregation

Aggregate integration weights onto mesh nodes
import.shrimp

Shrimp data import
gmap

Plot a map using extend of a spatial object
inla.stack.mjoin

Join stacks intended to be run with different likelihoods
inla_subset_eval

Obtain inla index subset information
input_eval

Obtain component inputs
int

Weighted summation (integration) of data frame subsets
import.mexdolphin

Mexdolphin data import
import.gorillas

Gorilla data import
gg.SpatialPixelsDataFrame

Geom for SpatialPixelsDataFrame objects
globe

Plot a globe using rgl
gg.prediction

Geom for predictions
import.mrsea

MRSea data import
import.seals

Seal pup edata import
gg.SpatialPixels

Geom for SpatialPixels objects
ipoints

Generate integration points
gorillas

Gorilla nesting sites
iinla

Iterated INLA
intersection_mesh

Construct the intersection mesh of a mesh and a polygon
parse_inclusion

Parse inclusion of component labels in a predictor expression
point2count

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

Create a plot sample.
like

Likelihood construction for usage with bru()
plot.bru

Plot method for posterior marginals estimated by bru
lgcp

Log Gaussian Cox process (LGCP) inference using INLA
local_testthat

Unit test helpers
is.inside

Query if a point is inside the mesh boundary
spde.posterior

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

Split lines at mesh edges
seals

Seal pups
shrimp

Blue and red shrimp in the Western Mediterranean Sea
pixels

Generate SpatialPixels covering an inla.mesh
sline

Convert data frame to SpatialLinesDataFrame
spatial.to.ppp

Convert SpatialPoints and boundary polygon to spatstat ppp object
make_stable_integration_points

Basic robust integration weights for mesh/polygon intersections
spoly

Convert a data.frame of boundary points into a SpatialPolgonsDataFrame
predict.bru

Prediction from fitted bru model
summary_bru

Deprecated functions in inlabru
predict.inla

Prediction from fitted inla model
toygroups

Simulated 1D animal group locations and group sizes
st_check_dim

Check for "XYZ", "XYM" and "XYZM" sfg classes
inlabru

inlabru
materncov.bands

Matern correlation or covariance function approximate credible bands.
vertices

Vertices
fm_wkt_as_wkt_tree

Internal WKT handling
tsplit.inla.mesh

Split triangles of a mesh into four triangles
vertices.inla.mesh

Extract vertex locations from an inla.mesh
mexdolphin

Pan-tropical spotted dolphins in the Gulf of Mexico
sample.lgcp

Sample from an inhomogeneous Poisson process
summary.bru

Summary for an inlabru fit
mrsea

Marine renewables strategic environmental assessment
mesh_triangle_integration

Integration scheme for mesh triangle interiors
plot.prediction

Plot prediction using ggplot2
stransform

Coordinate transformation for spatial objects
multiplot

Multiple ggplots on a page.
row_kron

Row-wise Kronecker products
refine.inla.mesh

Refine an inla.mesh object
robins_subset

robins_subset
st_check_polygon

Check sfg polygon satisfies standards for POLYGON simple features
summary.bru_options

Print inlabru options
summary.component

Summarise components
st_signed_area

Calculate signed area for polygon