Learn R Programming

inlabru (version 2.1.9)

generate.inla: Sampling based on bru posteriors

Description

Takes a fitted inla object produced by INLA::inla() and produces samples given a new set of values for the model covariates or the original values used for the model fit. The samples can be based on any R expression that is valid given these values/covariates and the joint posterior of the estimated random effects.

Usage

# S3 method for inla
generate(object, ...)

Arguments

object

An inla object obtained by calling INLA::inla().

...

additional arguments passed on togenerate.bru.

Value

List of generated samples

See Also

predict.inla

Other sample generators: generate.bru, generate

Examples

Run this code
# NOT RUN {
# Some features use the INLA package.
if (require("INLA", quietly = TRUE)) {

# Generate some data

input.df <- data.frame(x=cos(1:10))
input.df <- within(input.df, y <- 5 + 2*cos(1:10) + rnorm(10, mean=0, sd=0.1))

# Fit a Gaussian likelihood model

formula = y ~ x
fit <- inla(formula, "gaussian", data = input.df, control.compute=list(config = TRUE))

# Generate samples from the posterior distribution of exp(x), where x is the fixed effect.

xpost = generate(fit, NULL, ~ exp(x), n.samples = 2)
xpost
plot(xpost[[1]])

}
# }

Run the code above in your browser using DataLab