autoplot.inla: Autoplot method for INLA objects

View source: R/autoplot_inla.R

autoplot.inlaR Documentation

Autoplot method for INLA objects

Description

Replicate the plots produced by plot using ggplot.

Usage

## S3 method for class 'inla'
autoplot(object, which = c(1:3, 5), priors = FALSE, CI = FALSE, ...)

Arguments

object

An inla object.

which

Vector of integers selecting which plots (1 – 4) are wanted.

priors

Logical, plot priors as well.

CI

Plot credible intervals. TRUE for 95% CI or a numeric in [0, 1]

...

other arguments passed to methods

Details

The plot types are

  1. Marginal plot for fixed effects

  2. Marginal plot for hyper parameters

  3. Marginal line plot for random effects

  4. Marginal boxplot plot for random effects (more informative then 3, but gets big with lots of levels

Examples

## Not run: 
 library(INLA)
 data(Epil)
 ##Define the model
 formula = y ~ Trt + Age + V4 +
          f(Ind, model="iid") + f(rand,model="iid")
 result = inla(formula, family="poisson", data = Epil, control.predictor = list(compute = TRUE))
 plot(result)

 p <- autoplot(result)

 # Change the theme
 p <- p + theme_bw()

 # Add a title to a subplot
 p[[2]] <- p[[2]] + ggtitle('Hyper parameters')

 # Switch plot of fixed effects posteriors to not rescale x axis
 #   If variables are on the same scale, this may provide a useful comparison
 p[[1]] <- p[[1]] + facet_wrap('var', scale = 'free_y')

# Change colours etc.
p[[1]]$layers[[1]] <- geom_line(colour = 'red', linetype = 2)

## End(Not run)

timcdlucas/INLAutils documentation built on Nov. 29, 2022, 5:41 a.m.