Skip to contents

Takes a fitted bru object produced by bru() or lgcp() and creates various summaries from it.

Usage

# S3 method for class 'bru'
summary(object, verbose = FALSE, ...)

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

Arguments

object

An object obtained from a bru() or lgcp() call

verbose

logical; If TRUE, include more details of the component definitions. If FALSE, only show basic component definition information. Default: FALSE

...

arguments passed on to component summary functions, see summary.component().

x

An object to be printed

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
}
#>               mean         sd 0.025quant 0.5quant 0.975quant     mode
#> x         2.018071 0.05146952   1.915222 2.018072   2.120916 2.018072
#> Intercept 5.039293 0.03638927   4.966577 5.039293   5.112004 5.039293
#>                    kld
#> x         5.773314e-06
#> Intercept 5.773514e-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         2.018071 0.05147431   1.915212 2.018072   2.120926 2.018072
#> Intercept 5.039293 0.03639266   4.966570 5.039293   5.112011 5.039293
#>                    kld
#> x         5.768118e-06
#> Intercept 5.768317e-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.989229 0.008101315   1.973041 1.989229   2.005417 1.989229
#> Intercept 4.927372 0.041868892   4.843706 4.927373   5.011032 4.927373
#>                    kld
#> z         5.805443e-06
#> Intercept 5.805201e-06
# }