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 likelihoods is straight forward. See like for more information on how to provide additional likelihoods 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())

Arguments

components

A formula-like specification of latent components. Also used to define a default linear additive predictor. See component() for details.

...

Likelihoods, each constructed by a calling like(), or named parameters that can be passed to a single like() call. Note that all the arguments will be evaluated before calling like() in order to detect if they are like objects. This means that special arguments that need to be evaluated in the context of response_data or data (such as Ntrials) may will only work that way in direct calls to like().

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

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.

Details

  • bru_rerun Continue the optimisation from a previously computed estimate.

Author

Fabian E. Bachl bachlfab@gmail.com

Examples

# \donttest{
if (bru_safe_inla(multicore = FALSE)) {

  # 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, family = "gaussian", data = input.df)

  # Obtain summary
  fit$summary.fixed
}
#> Current num.threads is '4:1'.
#> Setting INLA option num.threads to '1:1'. Previous value '4:1'.
#> Warning: All covariate evaluations for 'Intercept' are NULL; an intercept component was likely intended.
#>   Implicit latent intercept component specification is deprecated since version 2.1.14.
#>   Use explicit notation '+ Intercept(1)' instead (or '+1' for '+ Intercept(1)').
#> Warning: The input evaluation 'Intercept' for 'Intercept' failed. Perhaps the data object doesn't contain the needed variables? Falling back to '1'.
#>               mean         sd 0.025quant 0.5quant 0.975quant     mode
#> x         2.027702 0.05210915   1.923574 2.027703   2.131825 2.027703
#> Intercept 4.959784 0.03684149   4.886164 4.959785   5.033398 4.959784
#>                    kld
#> x         5.770443e-06
#> Intercept 5.770644e-06


if (bru_safe_inla(multicore = FALSE)) {

  # Alternatively, we can use the like() function to construct the likelihood:

  lik <- like(family = "gaussian", formula = y ~ x + Intercept, data = input.df)
  fit <- bru(~ x + Intercept(1), lik)
  fit$summary.fixed
}
#> Current num.threads is '1:1'.
#> No num.threads change needed.
#>               mean         sd 0.025quant 0.5quant 0.975quant     mode
#> x         2.027702 0.05211308   1.923566 2.027703   2.131833 2.027703
#> Intercept 4.959784 0.03684427   4.886158 4.959785   5.033404 4.959784
#>                    kld
#> x         5.766616e-06
#> Intercept 5.766821e-06

# An important addition to the INLA methodology is bru's ability to use
# non-linear predictors. Such a predictor can be formulated via like()'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(multicore = FALSE)) {
  z <- 2
  input.df <- within(input.df, y <- 5 + exp(z) * x + rnorm(10, mean = 0, sd = 0.1))
  lik <- like(
    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
}
#> Current num.threads is '1:1'.
#> No num.threads change needed.
#>               mean          sd 0.025quant 0.5quant 0.975quant     mode
#> z         2.000938 0.006940227   1.987069 2.000938   2.014806 2.000938
#> Intercept 5.019976 0.036290631   4.947457 5.019976   5.092490 5.019976
#>                    kld
#> z         5.769853e-06
#> Intercept 5.769670e-06
# }