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.08.26 built 2023-08-26 14:18:34 UTC.
#>  - See www.r-inla.org/contact-us for how to get help.
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")

Copy Link

Version

Install

install.packages('inlabru')

Monthly Downloads

1,680

Version

2.9.0

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Finn Lindgren

Last Published

August 28th, 2023

Functions in inlabru (2.9.0)

summary.bru_info

Methods for bru_info objects
bru_like_inla_family

Utility functions for bru likelihood objects
bru_log_offset

Position methods for bru_log objects
bru_model

Create an inlabru model object from model components
bru_mapper_generics

Generic methods for bru_mapper objects
bru_safe_inla

Load INLA safely for examples and tests
bru_options

Create or update an options objects
bru_log_reset

Clear log contents
summary.bru_mapper

mapper object summaries
bru_make_stack

Build an inla data stack from linearisation information
bru_mapper_methods

Methods for bru_mapper objects
bru_mapper

Constructors for bru_mapper objects
bru_safe_sp

Check for potential sp version compatibility issues
bru_used_vars

Extract basic variable names from expression
bru_summarise

Summarise and annotate data
bru_standardise_names

Standardise inla hyperparameter names
bru_forward_transformation

Transformation tools
component

Latent model component construction
comp_lin_eval

Construct component linearisations
bru_used_update

Update used_component information objects
bru_used

List components used in a model
code.components

Convert components to R code
evaluate_comp_simple

Compute simplified component mappings
devel.cvmeasure

Variance and correlations measures for prediction components
evaluate_comp_lin

Compute all component linearisations
eval_spatial

Evaluate spatial covariates
eval_in_data_context

Evaluate expressions in the data context
cprod

(Blockwise) cross product of integration points
deltaIC

Summarise DIC and WAIC from lgcp objects.
evaluate_index

Compute all index values
generate

Generate samples from fitted bru models
extract_property

Extract a summary property from all results of an inla result
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
[.comp_simple_list

Subsetting of comp_simple_list objects, retaining class
component_list

Methods for inlabru component lists
component_eval

Evaluate component values in predictor expressions
expand_labels

Expand labels
evaluate_predictor

Evaluate component effects or expressions
gg.data.frame

Geom for data.frame
gg.RasterLayer

Geom for RasterLayer objects
gg

ggplot2 geomes for inlabru related objects
gg.SpatialPolygons

Geom for SpatialPolygons objects
gg.SpatRaster

Geom wrapper for SpatRaster objects
gg.SpatialGridDataFrame

Geom for SpatialGridDataFrame objects
gg.SpatialPixels

Geom for SpatialPixels objects
gg.SpatialLines

Geom for SpatialLines objects
gg.SpatialPixelsDataFrame

Geom for SpatialPixelsDataFrame objects
gg.SpatialPoints

Geom for SpatialPoints objects
gg.sf

Geom helper for sf objects
globe

Visualize a globe using RGL
gorillas

Gorilla nesting sites
gg.bru_prediction

Geom for predictions
gmap

Plot a map using extent of a spatial object
gg.inla.mesh.1d

Geom for inla.mesh.1d objects
gorillas_sf

Gorilla nesting sites in sf format
iinla

Iterated INLA
gg.matrix

Geom for matrix
gg.inla.mesh

Geom for inla.mesh objects
glplot

Render objects using RGL
gm

ggplot geom for spatial data
integration_weight_aggregation

Aggregate integration weights onto mesh nodes
ipoints

Generate integration points
lgcp

Log Gaussian Cox process (LGCP) inference using INLA
like

Observation model construction for usage with bru()
inlabru-package

inlabru
input_eval

Obtain component inputs
mexdolphin_sf

Pan-tropical spotted dolphins in the Gulf of Mexico
inla_subset_eval

Obtain inla index subset information
pixels

Generate SpatialPixels covering an inla.mesh
mrsea

Marine renewables strategic environmental assessment
mexdolphin

Pan-tropical spotted dolphins in the Gulf of Mexico
inlabru-deprecated

Deprecated functions in inlabru
inla.stack.mjoin

Join stacks intended to be run with different likelihoods
plot.bru

Plot method for posterior marginals estimated by bru
index_eval

Obtain indices
materncov.bands

Matern correlation or covariance function approximate credible bands.
multiplot

Multiple ggplots on a page.
local_testthat

Unit test helpers
plot.bru_prediction

Plot prediction using ggplot2
plotsample

Create a plot sample.
robins_subset

robins_subset
reexports

Objects exported from other packages
sample.lgcp

Sample from an inhomogeneous Poisson process
row_kron

Row-wise Kronecker products
spatial.to.ppp

Convert SpatialPoints and boundary polygon to spatstat ppp object
spoly

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

Convert data frame to SpatialLinesDataFrame
spde.posterior

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

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

Prediction from fitted bru model
seals

Seal pups
summary.bru_options

Print inlabru options
summary.bru

Summary for an inlabru fit
shrimp

Blue and red shrimp in the Western Mediterranean Sea
make_hierarchical_mesh_basis

Make hierarchical mesh basis functions
parse_inclusion

Parse inclusion of component labels in a predictor expression
summary.component

Summarise components
toygroups

Simulated 1D animal group locations and group sizes
Poisson1_1D

1-Dimensional Homogeneous Poisson example.
bru_convergence_plot

Plot inlabru convergence diagnostics
bru_compute_linearisation

Compute inlabru model linearisation information
Poisson3_1D

1-Dimensional NonHomogeneous Poisson example.
add_mappers

Add component input/latent mappers
Poisson2_1D

1-Dimensional NonHomogeneous Poisson example.
bm_list

Methods for mapper lists
bru

Convenient model fitting using (iterated) INLA
bru_call_options

Additional bru options
bincount

1D LGCP bin count simulation and comparison with data
bru_fill_missing

Fill in missing values in Spatial grids
bru_log_bookmark

Methods for bru_log bookmarks
bru_get_mapper

Extract mapper information from INLA model component objects
bru_log_new

Create a bru_log object
bru_log_message

Add a log message
bru_log

Access methods for bru_log objects
bru_env_get

Get access to the internal environment
bru_int_polygon

Integration points for polygons inside an inla.mesh