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

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: ggplot2
#> Loading required package: sp
library(INLA)
#> Loading required package: Matrix
#> Loading required package: foreach
#> Loading required package: parallel
#> This is INLA_21.03.14-3 built 2021-03-14 09:05:27 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
fit <- lgcp(cmp,
            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.3.1

License

GPL (>= 2)

Maintainer

Finn Lindgren

Last Published

March 22nd, 2021

Functions in inlabru (2.3.1)

bru_compute_linearisation

Compute inlabru model linearisation information
Poisson1_1D

1-Dimensional Homogeneous Poisson example.
amatrix_eval

Construct A-matrix
Poisson3_1D

1-Dimensional NonHomogeneous Poisson example.
Poisson2_1D

1-Dimensional NonHomogeneous Poisson example.
bru

Convenient model fitting using (iterated) INLA
bincount

1D LGCP bin count simulation and comparison with data
bru_call_options

Additional bru options
add_mappers

Add component input/latent mappers
bru_env_get

Get access to the internal environment
bru_log_reset

inlabru log message methods
bru_int_polygon

Integration points for polygons inside an inla.mesh
bru_make_stack

Build an inla data stack from linearisation information
summary.bru_info

Methods for bru_info objects
evaluate_effect_single

Evaluate a component effect
expand_labels

Expand labels
bru_fill_missing

Fill in missing values in Spatial grids
extract_property

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

Methods for inlabru component lists
component

Latent model component construction
evaluate_model

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

Geom for SpatialGridDataFrame objects
gg.SpatialPoints

Geom for SpatialPoints objects
evaluate_predictor

Evaluate component effects or expressions
gg.SpatialPolygons

Geom for SpatialPolygons objects
evaluate_index

Compute all index values
fm_identical_CRS

Chack 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
glplot.SpatialLines

Visualize SpatialLines using RGL
glplot

Render Spatial* and inla.mesh objects using RGL
ipoints

Generate integration points
import.mrsea

MRSea data import
is.inside

Query if a point is inside the mesh boundary
import.seals

Seal pup edata import
bru_standardise_names

Standardise inla hyperparameter names
bru_mapper_methods

Implementation methods for mapper objects
fm_CRS

Create a coordinate reference system object
bru_model

Create an inlabru model object from model components
fm_CRS_as_list

Show expanded CRS arguments
code.components

Convert components to R code
bru_options

Create or update an options objects
local_testthat

Unit test helpers
bru_safe_inla

Load INLA safely for examples and tests
gorillas

Gorilla nesting sites
gg.SpatialPixels

Geom for SpatialPixels objects
plot.bru

Plot method for posterior marginals estimated by bru
plot.prediction

Plot prediction using ggplot2
make_stable_integration_points

Basic robust integration weights for mesh/polygon intersections
gg.SpatialPixelsDataFrame

Geom for SpatialPixelsDataFrame objects
summary.bru_options

Print inlabru options
cprod

Cross product of integration points
deltaIC

Summarise DIC and WAIC from lgcp objects.
fm_sp_get_crs

Extract CRS information
summary.component

Summarise components
gg.inla.mesh

Geom for inla.mesh objects
index_eval

Obtain indices
plotsample

Create a plot sample.
gg.matrix

Geom for matrix
point2count

Convert a plot sample of points into one of counts.
gg.inla.mesh.1d

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

Geom for data.frame
gm

ggplot geom for spatial data
import.shrimp

Shrimp data import
iinla

Iterated INLA
inla.stack.mjoin

Join stacks intended to be run with different likelihoods
vertices

Vertices
split_lines

Split lines at mesh edges
vertices.inla.mesh

Extract vertex locations from an inla.mesh
spoly

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

Generate samples from fitted bru models
int

Weighted summation (integration) of data frame subsets
glplot.inla.mesh

Visualize SpatialPoints using RGL
glplot.SpatialPoints

Visualize SpatialPoints using RGL
int.polygon

Integration points for polygons inside an inla.mesh
summary_bru

Deprecated functions in inlabru
gmap

Plot a map using extend of a spatial object
multiplot

Multiple ggplots on a page.
mrsea

Marine renewables strategic environmental assessment
sample.lgcp

Sample from an inhomogeneous Poisson process
integration_weight_aggregation

Aggregate integration weights onto mesh nodes
mexdolphin

Pan-tropical spotted dolphins in the Gulf of Mexico
spde.posterior

Posteriors of SPDE hyper parameters and Matern correlation or covariance function.
spatial.to.ppp

Convert SpatialPoints and boundary polygon to spatstat ppp object
fm_wkt_as_wkt_tree

Internal WKT handling
materncov.bands

Matern correlation or covariance function approximate credible bands.
lgcp

Log Gaussian Cox process (LGCP) inference using INLA
like

intersection_mesh

Construct the intersection mesh of a mesh and a polygon
seals

Seal pups
refine.inla.mesh

Refine an inla.mesh object
bru_mapper

Methods for bru_mapper objects
row_kron

Row-wise Kronecker products
stransform

Coordinate transformation for spatial objects
summary.bru

Summary for an inlabru fit
evaluate_A

Compute all A-matrices
devel.cvmeasure

Variance and correlations measures for prediction components
fm_wkt_is_geocent

Handling CRS/WKT
fm_has_PROJ6

PROJ6 detection
globe

Plot a globe using rgl
gg

ggplot2 geomes for inlabru related objects
gg.RasterLayer

Geom for RasterLayer objects
import.gorillas

Gorilla data import
gg.prediction

Geom for predictions
import.mexdolphin

Mexdolphin data import
inlabru

inlabru
parse_inclusion

Parse inclusion of component labels in a predictor expression
input_eval

Obtain covariate values
predict.bru

Prediction from fitted bru model
shrimp

Blue and red shrimp in the Western Mediterranean Sea
pixels

Generate SpatialPixels covering an inla.mesh
predict.inla

Prediction from fitted inla model
sline

Convert data frame to SpatialLinesDataFrame
toygroups

Simulated 1D animal group locations and group sizes
tsplit.inla.mesh

Split triangles of a mesh into four triangles