Skip to contents

This method is a wrapper for INLA::inla and provides multiple enhancements.

  • Easy usage of spatial covariates and automatic construction of inla projection matrices for (spatial) SPDE models. This feature is accessible via the components parameter. Practical examples on how to use spatial data by means of the components parameter can also be found by looking at the lgcp() function's documentation.

  • Constructing multiple observation models is straightforward. See bru_obs() for more information on how to provide additional models to bru using the ... parameter list.

  • Support for non-linear predictors. See example below.

  • Log Gaussian Cox process (LGCP) inference is available by using the "cp" family or (even easier) by using the lgcp() function.

Usage

bru(components = ~Intercept(1), ..., options = list(), .envir = parent.frame())

bru_rerun(result, options = list())

# S3 method for class 'bru'
print(x, ...)

Arguments

components

Latent component definitions, either as a bru_comp_list() object, or a formula-like specification. Also used to define a default linear additive predictor. See bru_comp() for details.

...

Observation models, each constructed by a calling bru_obs(), or bru_obs_list().

Alternatively, for backwards compatibility, may be named parameters that can be passed to a single bru_obs() call. These arguments will be evaluated before calling bru_obs(), in order to detect if they already are bru_obs objects. This means that special arguments that are only available in the context of data or response_data (such as Ntrials) will only work properly in direct calls to bru_obs().

options

A bru_options options object or a list of options passed on to bru_options()

.envir

Environment for component evaluation (for when a non-formula specification is used)

result

A previous estimation object of class bru

x

A bru object to be printed

Value

bru returns an object of class "bru". A bru object inherits from INLA::inla (see the inla documentation for its properties) and adds additional information stored in the bru_info field.

Methods (by generic)

  • print(bru): Print a summary of a bru object.

Functions

  • bru_rerun(): Continue the optimisation from a previously computed estimate. The estimation options list can be given new values to override the original settings.

    To rerun with a subset of the data (e.g. for cross validation or prior sampling), use bru_set_missing() to set all or part of the response data to NA before calling bru_rerun().

Author

Fabian E. Bachl bachlfab@gmail.com

Examples

# \donttest{
if (bru_safe_inla()) {
  # Simulate some covariates x and observations y
  input.df <- data.frame(x = cos(1:10))
  input.df <- within(input.df, {
    y <- 5 + 2 * x + rnorm(10, mean = 0, sd = 0.1)
  })

  # Fit a Gaussian likelihood model
  fit <- bru(y ~ x + Intercept(1), family = "gaussian", data = input.df)

  # Obtain summary
  fit$summary.fixed
}
#> Changing INLA option num.threads from '4:1' to '1:1'.
#>               mean         sd 0.025quant 0.5quant 0.975quant     mode
#> x         1.942445 0.04114300   1.860231 1.942445   2.024656 1.942445
#> Intercept 5.007054 0.02908835   4.948928 5.007055   5.065178 5.007055
#>                    kld
#> x         5.769834e-06
#> Intercept 5.769959e-06


if (bru_safe_inla()) {
  # Alternatively, we can use the bru_obs() function to construct the likelihood:

  lik <- bru_obs(family = "gaussian",
              formula = y ~ x + Intercept,
              data = input.df)
  fit <- bru(~ x + Intercept(1), lik)
  fit$summary.fixed
}
#>               mean         sd 0.025quant 0.5quant 0.975quant     mode
#> x         1.942445 0.04114300   1.860231 1.942445   2.024656 1.942445
#> Intercept 5.007054 0.02908835   4.948928 5.007055   5.065178 5.007055
#>                    kld
#> x         5.769834e-06
#> Intercept 5.769959e-06

# An important addition to the INLA methodology is bru's ability to use
# non-linear predictors. Such a predictor can be formulated via bru_obs()'s
# \code{formula} parameter. The z(1) notation is needed to ensure that
# the z component should be interpreted as single latent variable and not
# a covariate:

if (bru_safe_inla()) {
  z <- 2
  input.df <- within(input.df, {
    y <- 5 + exp(z) * x + rnorm(10, mean = 0, sd = 0.1)
  })
  lik <- bru_obs(
    family = "gaussian", data = input.df,
    formula = y ~ exp(z) * x + Intercept
  )
  fit <- bru(~ z(1) + Intercept(1), lik)

  # Check the result (z posterior should be around 2)
  fit$summary.fixed
}
#>               mean          sd 0.025quant 0.5quant 0.975quant     mode
#> z         1.990574 0.007513642   1.975560 1.990574   2.005587 1.990574
#> Intercept 5.022316 0.038883951   4.944615 5.022317   5.100012 5.022317
#>                    kld
#> z         5.775125e-06
#> Intercept 5.774917e-06
# }