Arguments
- object
- verbose
logical; If
TRUE
, include more details of the component definitions. IfFALSE
, 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.018953 0.03834359 1.942333 2.018953 2.095570 2.018953
#> Intercept 4.999423 0.02710914 4.945252 4.999424 5.053592 4.999424
#> kld
#> x 5.78046e-06
#> Intercept 5.78057e-06
if (bru_safe_inla()) {
# 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
}
#> mean sd 0.025quant 0.5quant 0.975quant mode
#> x 2.018953 0.03835369 1.942313 2.018953 2.095591 2.018953
#> Intercept 4.999423 0.02711629 4.945238 4.999424 5.053606 4.999424
#> kld
#> x 5.763993e-06
#> Intercept 5.764104e-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()) {
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
}
#> mean sd 0.025quant 0.5quant 0.975quant mode
#> z 2.007557 0.005410037 1.996746 2.007557 2.018367 2.007557
#> Intercept 4.975093 0.028477102 4.918188 4.975093 5.031995 4.975093
#> kld
#> z 5.687257e-06
#> Intercept 5.687165e-06
# }