Learn R Programming

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 how fit a simple spatial Log Gaussian Cox Process (LGCP) and predicts its intensity:

# Load libraries
library(INLA)
#> Loading required package: Matrix
#> Loading required package: sp
#> This is INLA_24.06.27 built 2024-06-27 02:36:04 UTC.
#>  - See www.r-inla.org/contact-us for how to get help.
#>  - List available models/likelihoods/etc with inla.list.models()
#>  - Use inla.doc(<NAME>) to access documentation
library(inlabru)
#> Loading required package: fmesher
library(fmesher)
library(ggplot2)

# Construct latent model components
matern <- inla.spde2.pcmatern(
  gorillas_sf$mesh,
  prior.sigma = c(0.1, 0.01),
  prior.range = c(0.01, 0.01)
)
cmp <- ~ mySmooth(geometry, model = matern) + Intercept(1)
# Fit LGCP model
# This particular bru/like combination has a shortcut function lgcp() as well
fit <- bru(
  cmp,
  like(
    formula = geometry ~ .,
    family = "cp",
    data = gorillas_sf$nests,
    samplers = gorillas_sf$boundary,
    domain = list(geometry = gorillas_sf$mesh)
  ),
  options = list(control.inla = list(int.strategy = "eb"))
)

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

# Plot the result
ggplot() +
  geom_fm(data = gorillas_sf$mesh) +
  gg(lambda, geom = "tile") +
  gg(gorillas$nests, color = "red", size = 0.5, alpha = 0.5) +
  ggtitle("Nest intensity per km squared") +
  xlab("") +
  ylab("")

Copy Link

Version

Install

install.packages('inlabru')

Monthly Downloads

1,898

Version

2.11.1

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

July 1st, 2024

Functions in inlabru (2.11.1)

bru

Convenient model fitting using (iterated) INLA
bru_convergence_plot

Plot inlabru convergence diagnostics
Poisson3_1D

1-Dimensional NonHomogeneous Poisson example.
bincount

1D LGCP bin count simulation and comparison with data
bm_list

Methods for mapper lists
bru_env_get

Get access to the internal environment
bru_log

Access methods for bru_log objects
Poisson1_1D

1-Dimensional Homogeneous Poisson example.
bru_mapper_aggregate

Mapper for aggregation
add_mappers

Add component input/latent mappers
bru_mapper_collect

Mapper for concatenated variables
bru_fill_missing

Fill in missing values in Spatial grids
bru_int_polygon

Integration points for polygons inside an inla.mesh
bru_mapper_generics

Generic methods for bru_mapper objects
Poisson2_1D

1-Dimensional NonHomogeneous Poisson example.
bru_like_inla_family

Utility functions for bru likelihood objects
bru_log_offset

Position methods for bru_log objects
bru_log_bookmark

Methods for bru_log bookmarks
bru_mapper_matrix

Mapper for matrix multiplication
bru_log_reset

Clear log contents
bru_make_stack

Build an inla data stack from linearisation information
bru_mapper_mesh_B

Mapper for basis conversion
bru_get_mapper

Extract mapper information from INLA model component objects
summary.bru_info

Methods for bru_info objects
bru_mapper_scale

Mapper for element-wise scaling
bru_inla.stack.mexpand

Backwards compatibility to handle mexpand for INLA <= 24.06.02
bru_mapper_shift

Mapper for element-wise shifting
bru_standardise_names

Standardise inla hyperparameter names
bru_inla.stack.mjoin

Join stacks intended to be run with different likelihoods
bru_mapper_logsumexp

Mapper for log-sum-exp aggregation
bru_mapper_const

Constant mapper
bru_summarise

Summarise and annotate data
bru_log_message

Add a log message
bru_mapper_marginal

Mapper for marginal distribution transformation
bru_log_new

Create a bru_log object
bru_mapper

Constructors for bru_mapper objects
bru_mapper.fm_mesh_1d

Mapper for fm_mesh_1d
bru_mapper_index

Mapper for indexed variables
[.comp_simple_list

Subsetting of comp_simple_list objects, retaining class
evaluate_comp_simple

Compute simplified component mappings
gg.sf

Geom helper for sf objects
bru_mapper_factor

Mapper for factor variables
bru_mapper_multi

Mapper for tensor product domains
globe

Visualize a globe using RGL
bru_mapper_linear

Mapper for a linear effect
bru_timings

Extract timing information from fitted bru object
bru_safe_inla

Load INLA safely for examples and tests
bru_mapper.fm_mesh_2d

Mapper for fm_mesh_2d
bru_mapper_pipe

Mapper for linking several mappers in sequence
bru_forward_transformation

Transformation tools
bru_mapper_harmonics

Mapper for cos/sin functions
bru_used

List components used in a model
bru_model

Create an inlabru model object from model components
bru_options

Create or update an options objects
code.components

Convert components to R code
bru_safe_sp

Check for potential sp version compatibility issues
gg.RasterLayer

Geom for RasterLayer objects
summary.bru_mapper

mapper object summaries
bru_mapper_taylor

Mapper for linear Taylor approximations
bru_timings_plot

Plot inlabru iteration timings
bru_used_update

Update used_component information objects
like

Observation model construction for usage with bru()
component_list

Methods for inlabru component lists
bru_used_vars

Extract basic variable names from expression
local_testthat

Unit test helpers
make_hierarchical_mesh_basis

Make hierarchical mesh basis functions
plot.bru

Plot method for posterior marginals estimated by bru
component

Latent model component construction
eval_spatial

Evaluate spatial covariates
comp_lin_eval

Construct component linearisations
devel.cvmeasure

Variance and correlations measures for prediction components
seals

Seal pups
shrimp

Blue and red shrimp in the Western Mediterranean Sea
deltaIC

Summarise DIC and WAIC from lgcp objects.
gg

ggplot2 geomes for inlabru related objects
evaluate_comp_lin

Compute all component linearisations
evaluate_predictor

Evaluate component effects or expressions
eval_in_data_context

Evaluate expressions in the data context
extract_property

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

Summary for an inlabru fit
generate

Generate samples from fitted bru models
component_eval

Evaluate component values in predictor expressions
evaluate_effect_single_state

Evaluate a component effect
evaluate_inputs

Compute all component inputs
evaluate_model

Evaluate or sample from a posterior result given a model and locations
gg.SpatialPixelsDataFrame

Geom for SpatialPixelsDataFrame objects
summary.bru_options

Print inlabru options
gg.data.frame

Geom for data.frame
gg.SpatialPoints

Geom for SpatialPoints objects
expand_labels

Expand labels
gg.SpatialPolygons

Geom for SpatialPolygons objects
gg.fm_mesh_1d

Geom for fm_mesh_1d objects
gg.SpatialLines

Geom for SpatialLines objects
gorillas_sf

Gorilla nesting sites in sf format
iinla

Iterated INLA
index_eval

Obtain indices
inla_subset_eval

Obtain inla index subset information
gg.bru_prediction

Geom for predictions
glplot

Render objects using RGL
gm

ggplot geom for spatial data
gmap

Plot a map using extent of a spatial object
gg.SpatialPixels

Geom for SpatialPixels objects
evaluate_index

Compute all index values
sline

Convert data frame to SpatialLinesDataFrame
gg.SpatRaster

Geom wrapper for SpatRaster objects
spatial.to.ppp

Convert SpatialPoints and boundary polygon to spatstat ppp object
ipoints

Deprecated functions in inlabru
inlabru-package

inlabru
point2count

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

Pan-tropical spotted dolphins in the Gulf of Mexico
gorillas

Gorilla nesting sites
materncov.bands

Matern correlation or covariance function approximate credible bands.
input_eval

Obtain component inputs
predict.bru

Prediction from fitted bru model
gg.SpatialGridDataFrame

Geom for SpatialGridDataFrame objects
row_kron

Row-wise Kronecker products
plot.bru_prediction

Plot prediction using ggplot2
lgcp

Log Gaussian Cox process (LGCP) inference using INLA
sample.lgcp

Sample from an inhomogeneous Poisson process
gg.fm_mesh_2d

Geom for inla.mesh objects
multiplot

Multiple ggplots on a page.
parse_inclusion

Parse inclusion of component labels in a predictor expression
spde.posterior

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

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

Create a plot sample.
reexports

Objects exported from other packages
gg.matrix

Geom for matrix
mexdolphin_sf

Pan-tropical spotted dolphins in the Gulf of Mexico
mrsea

Marine renewables strategic environmental assessment
robins_subset

robins_subset
toypoints

Simulated 2D point process data
summary.component

Summarise components
toygroups

Simulated 1D animal group locations and group sizes
bru_compute_linearisation

Compute inlabru model linearisation information
bru_call_options

Additional bru options