Learn R Programming

inlabru (version 2.1.1)

predict.inla: Prediction from fitted inla model

Description

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

Usage

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

Arguments

object

An object obtained by calling bru or lgcp.

...

Arguments passed on to predict.bru().

Value

A prediction object.

Details

IMPORTANT: The inla object provided has to have an additional field called "formula". This is the formula used to call the inla() function and will be used to convert the inla object to a bru object. Thereafter, preict.bru() is called to perform the prediction.

Examples

Run this code
# NOT RUN {
# 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))

# Add formula to inla object

fit$formula = y ~ x

Estimate posterior statistics of exp(x), where x is the random effect.

xpost = predict(fit, NULL, ~ exp(x))
xpost
plot(xpost)

# }

Run the code above in your browser using DataLab