Skip to contents

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

Usage

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

# S3 method for 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 summary_bru2 object

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 '1:1'.
#> No num.threads change needed.
#> 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)').
#>               mean         sd 0.025quant 0.5quant 0.975quant     mode
#> x         2.018472 0.04665123   1.925281 2.018473   2.111659 2.018473
#> Intercept 5.017068 0.03298271   4.951181 5.017069   5.082951 5.017070
#>                    kld
#> x         8.494767e-06
#> Intercept 8.494980e-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.018472 0.04665574   1.925272 2.018473   2.111668 2.018473
#> Intercept 5.017068 0.03298589   4.951174 5.017069   5.082957 5.017070
#>                    kld
#> x         8.484897e-06
#> Intercept 8.485112e-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         1.999145 0.006461788   1.986238 1.999145   2.012053 1.999146
#> Intercept 5.014824 0.033728354   4.947448 5.014825   5.082197 5.014826
#>                    kld
#> z         8.485246e-06
#> Intercept 8.485029e-06
# }