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

A summary_bru 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)').
#> 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.011785 0.05161039   1.908654 2.011785   2.114911 2.011785
#> Intercept 5.027391 0.03648887   4.954476 5.027392   5.100301 5.027392
#>                    kld
#> x         5.770393e-06
#> Intercept 5.770593e-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.011785 0.05160873   1.908657 2.011785   2.114908 2.011785
#> Intercept 5.027391 0.03648769   4.954478 5.027392   5.100299 5.027392
#>                    kld
#> x         5.774865e-06
#> Intercept 5.775064e-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.995826 0.005045054   1.985745 1.995826   2.005907 1.995826
#> Intercept 5.000532 0.026246222   4.948085 5.000532   5.052976 5.000532
#>                    kld
#> z         5.775289e-06
#> Intercept 5.775184e-06
# }