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(INLA)
#> Loading required package: Matrix
#> This is INLA_23.12.17 built 2023-12-17 16:59:33 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"))
)
#> Warning in inla.model.properties.generic(inla.trim.family(model), mm[names(mm) == : Model 'scopy' in section 'latent' is marked as 'experimental'; changes may appear at any time.
#>   Use this model with extra care!!! Further warnings are disabled.
#> Warning in system("timedatectl", intern = TRUE): running command 'timedatectl'
#> had status 1

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

Copy Link

Version

Install

install.packages('inlabru')

Monthly Downloads

1,741

Version

2.10.1

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Finn Lindgren

Last Published

December 21st, 2023

Functions in inlabru (2.10.1)

bru_make_stack

Build an inla data stack from linearisation information
bru_mapper

Constructors for bru_mapper objects
bru_mapper_matrix

Mapper for matrix multiplication
bru_mapper_mesh_B

Mapper for basis conversion
summary.bru_mapper

mapper object summaries
bru_mapper_taylor

Mapper for linear Taylor approximations
bru_compute_linearisation

Compute inlabru model linearisation information
evaluate_effect_single_state

Evaluate a component effect
bru_convergence_plot

Plot inlabru convergence diagnostics
evaluate_index

Compute all index values
bru_log_message

Add a log message
bru_log_new

Create a bru_log object
bru_mapper_aggregate

Mapper for aggregation
bru_mapper_collect

Mapper for concatenated variables
bru_mapper_logsumexp

Mapper for log-sum-exp aggregation
bru_mapper_marginal

Mapper for marginal distribution transformation
gg.inla.mesh

Geom for inla.mesh objects
gg.matrix

Geom for matrix
component_eval

Evaluate component values in predictor expressions
glplot

Render objects using RGL
component_list

Methods for inlabru component lists
gm

ggplot geom for spatial data
lgcp

Log Gaussian Cox process (LGCP) inference using INLA
like

Observation model construction for usage with bru()
mexdolphin

Pan-tropical spotted dolphins in the Gulf of Mexico
cprod

(Blockwise) cross product of integration points
deltaIC

Summarise DIC and WAIC from lgcp objects.
mexdolphin_sf

Pan-tropical spotted dolphins in the Gulf of Mexico
gg.RasterLayer

Geom for RasterLayer objects
gg

ggplot2 geomes for inlabru related objects
sline

Convert data frame to SpatialLinesDataFrame
spatial.to.ppp

Convert SpatialPoints and boundary polygon to spatstat ppp object
summary.component

Summarise components
gg.data.frame

Geom for data.frame
toygroups

Simulated 1D animal group locations and group sizes
gg.inla.mesh.1d

Geom for inla.mesh.1d objects
gorillas_sf

Gorilla nesting sites in sf format
iinla

Iterated INLA
inla_subset_eval

Obtain inla index subset information
inlabru-deprecated

Deprecated functions in inlabru
pixels

Generate SpatialPixels covering an inla.mesh
plot.bru

Plot method for posterior marginals estimated by bru
seals

Seal pups
shrimp

Blue and red shrimp in the Western Mediterranean Sea
summary.bru

Summary for an inlabru fit
Poisson3_1D

1-Dimensional NonHomogeneous Poisson example.
add_mappers

Add component input/latent mappers
summary.bru_options

Print inlabru options
bru_int_polygon

Integration points for polygons inside an inla.mesh
bincount

1D LGCP bin count simulation and comparison with data
bru_like_inla_family

Utility functions for bru likelihood objects
bru_log_offset

Position methods for bru_log objects
bm_list

Methods for mapper lists
bru_log_reset

Clear log contents
bru_mapper_scale

Mapper for element-wise scaling
bru_log

Access methods for bru_log objects
Poisson1_1D

1-Dimensional Homogeneous Poisson example.
Poisson2_1D

1-Dimensional NonHomogeneous Poisson example.
bru_mapper_shift

Mapper for element-wise shifting
bru_used

List components used in a model
bru_used_update

Update used_component information objects
devel.cvmeasure

Variance and correlations measures for prediction components
bru_log_bookmark

Methods for bru_log bookmarks
bru

Convenient model fitting using (iterated) INLA
eval_in_data_context

Evaluate expressions in the data context
bru_call_options

Additional bru options
bru_mapper_const

Constant mapper
bru_env_get

Get access to the internal environment
bru_fill_missing

Fill in missing values in Spatial grids
extract_property

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

Extract mapper information from INLA model component objects
bru_mapper_factor

Mapper for factor variables
generate

Generate samples from fitted bru models
bru_mapper_multi

Mapper for tensor product domains
bru_mapper_generics

Generic methods for bru_mapper objects
bru_mapper_harmonics

Mapper for cos/sin functions
summary.bru_info

Methods for bru_info objects
bru_model

Create an inlabru model object from model components
gg.SpatialPolygons

Geom for SpatialPolygons objects
gg.bru_prediction

Geom for predictions
bru_options

Create or update an options objects
bru_timings_plot

Plot inlabru iteration timings
integration_weight_aggregation

Aggregate integration weights onto mesh nodes
bru_mapper.fm_mesh_1d

Mapper for fm_mesh_1d
bru_forward_transformation

Transformation tools
bru_mapper_pipe

Mapper for linking several mappers in sequence
ipoints

Generate integration points
bru_safe_inla

Load INLA safely for examples and tests
parse_inclusion

Parse inclusion of component labels in a predictor expression
make_hierarchical_mesh_basis

Make hierarchical mesh basis functions
eval_spatial

Evaluate spatial covariates
row_kron

Row-wise Kronecker products
bru_mapper.fm_mesh_2d

Mapper for fm_mesh_2d
bru_mapper_index

Mapper for indexed variables
bru_safe_sp

Check for potential sp version compatibility issues
bru_mapper_linear

Mapper for a linear effect
sample.lgcp

Sample from an inhomogeneous Poisson process
evaluate_comp_lin

Compute all component linearisations
comp_lin_eval

Construct component linearisations
gg.SpatRaster

Geom wrapper for SpatRaster objects
gg.SpatialGridDataFrame

Geom for SpatialGridDataFrame objects
bru_standardise_names

Standardise inla hyperparameter names
gg.SpatialLines

Geom for SpatialLines objects
component

Latent model component construction
bru_summarise

Summarise and annotate data
gg.SpatialPixels

Geom for SpatialPixels objects
gmap

Plot a map using extent of a spatial object
gorillas

Gorilla nesting sites
evaluate_inputs

Compute all component inputs
bru_used_vars

Extract basic variable names from expression
local_testthat

Unit test helpers
evaluate_model

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

Obtain indices
materncov.bands

Matern correlation or covariance function approximate credible bands.
code.components

Convert components to R code
mrsea

Marine renewables strategic environmental assessment
evaluate_comp_simple

Compute simplified component mappings
[.comp_simple_list

Subsetting of comp_simple_list objects, retaining class
inla.stack.mjoin

Join stacks intended to be run with different likelihoods
inlabru-package

inlabru
evaluate_predictor

Evaluate component effects or expressions
input_eval

Obtain component inputs
expand_labels

Expand labels
gg.SpatialPixelsDataFrame

Geom for SpatialPixelsDataFrame objects
multiplot

Multiple ggplots on a page.
gg.SpatialPoints

Geom for SpatialPoints objects
gg.sf

Geom helper for sf objects
globe

Visualize a globe using RGL
reexports

Objects exported from other packages
plot.bru_prediction

Plot prediction using ggplot2
robins_subset

robins_subset
plotsample

Create a plot sample.
point2count

Convert a plot sample of points into one of counts.
predict.bru

Prediction from fitted bru model
spde.posterior

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

Convert a data.frame of boundary points into a SpatialPolgonsDataFrame