Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

input_eval

Obtain covariate values


Description

Obtain covariate values

Usage

input_eval(...)

## S3 method for class 'component'
input_eval(component, data, ...)

## S3 method for class 'component_list'
input_eval(components, data, ...)

## S3 method for class 'bru_input'
input_eval(input, data, env = NULL, label = NULL, null.on.fail = FALSE, ...)

Arguments

...

Unused.

component

A component.

data

A data.frame or Spatial* object of covariates and/or point locations. If null, return the component's map.

Value

An vector or a coordinate matrix

Simple covariates and the map parameter

It is not unusual for a random effect act on a transformation of a covariate. In other frameworks this would mean that the transformed covariate would have to be calculated in advance and added to the data frame that is usually provided via the data parameter. inlabru provides the option to do this transformation automatically. For instance, one might be interested in the effect of a covariate x^2. In inla and other frameworks this would require to add a column xsquared to the input data frame and use the formula

  • formula = y ~ f(xsquared, model = "linear"),

In inlabru this can be achived using two ways of using the main parameter (map in version 2.1.13 and earlier).

  • components = y ~ psi(main = x^2, model = "linear")

  • components = y ~ psi(main = mySquareFun(x), model = "linear"),

  • components = y ~ psi(main = myOtherSquareFun, model = "linear"),

In the first example inlabru will interpret the map parameter as an expression to be evaluated within the data provided. Since x is a knonwn covariate it will know how to calculate it. The second example is an expression as well but it uses a function alled mySquareFun. This function is defined by user but has wo be accessible within the work space when setting up the compoonents. The third example provides the function myOtherSquareFun directly and not within an expression. In this case, inlabru will call the function using the data provided via the data parameter. inlabru expects that the output of this function is a data.frame with "psi" being the name of the single existing column. For instance,

myOtherSquareFun = function(data) { data = data[,"x", drop = FALSE] ; colnames(data) = "psi" ; return(data)}

Spatial Covariates

When fitting spatial models it is common to work with covariates that depend on space, e.g. sea surface temperature or elevation. Although it is straight forward to add this data to the input data frame or write a covariate function like in the previous section there is an even more convenient way in inlabru. Spatial covariates are often stored as SpatialPixelsDataFrame, SpatialPixelsDataFrame or RasterLayer objects. These can be provided directly via the map parameter if the input data is a SpatialPointsDataFrame. inlabru will automatically evaluate and/or interpolate the coariate at your data locations when using code like

  • components = y ~ psi(mySpatialPixels, model = "linear").

Coordinates

A common spatial modelling component when using inla are SPDE models. An important feature of inlabru is that it will automatically calculate the so called A-matrix which maps SPDE values at the mesh vertices to values at the data locations. For this purpose, the map parameter can be se to coordinates, which is the sp package function that extracts point coordinates from the SpatialPointsDataFrame that was provided as input to bru. The code for this would look as follows:

  • components = y ~ mySPDE(main = coordinates, model = inla.spde2.matern(...)).

Author(s)

Fabian E. Bachl bachlfab@gmail.com


inlabru

Bayesian Latent Gaussian Modelling using INLA and Extensions

v2.3.1
GPL (>= 2)
Authors
Finn Lindgren [aut, cre, cph] (<https://orcid.org/0000-0002-5833-2011>, Finn Lindgren continued development of the main code), Fabian E. Bachl [aut, cph] (Fabian Bachl wrote the main code), David L. Borchers [ctb, dtc, cph] (David Borchers wrote code for Gorilla data import and sampling, multiplot tool), Daniel Simpson [ctb, cph] (Daniel Simpson wrote the basic LGCP sampling method), Lindesay Scott-Howard [ctb, dtc, cph] (Lindesay Scott-Howard provided MRSea data import code), Seaton Andy [ctb] (Andy Seaton provided testing and bugfixes)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.