ggplot_inla_residuals: Plot residuals of observed vs predicted values for INLA model...

View source: R/plot_inla_residuals.R

ggplot_inla_residualsR Documentation

Plot residuals of observed vs predicted values for INLA model using ggplot2

Description

Plot residuals of observed vs predicted values for INLA model using ggplot2

Usage

ggplot_inla_residuals(inla.model, observed, CI = FALSE, binwidth = NULL)

Arguments

inla.model

An inla object

observed

The observed values

CI

Add credible intervals to the fitted values?

binwidth

The size of the bins used for the histogram. If NULL ggplot guesses for you.

Examples

## Not run: 
 library(INLA)
 data(Epil)
 observed <- Epil[1:30, 'y']
 Epil <- rbind(Epil, Epil[1:30, ])
 Epil[1:30, 'y'] <- NA
 ## make centered covariates
 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, link = 1))
 p <- ggplot_inla_residuals(result, observed)
 
 # Subplots can be altered afterwards
 p[[1]] <- p[[1]] + theme_grey()
 cowplot::plot_grid(plotlist = p)

 data(Seeds)
 l <- nrow(Seeds)
 Seeds <- rbind(Seeds, Seeds)
 Seeds$r[1:l] <- NA


 formula = r ~ x1 * x2 + f(plate, model = "iid")
 mod.seeds = inla(formula, data=Seeds, family = "binomial", Ntrials = n, 
                  control.predictor = list(compute = TRUE, link = 1))
 ggplot_inla_residuals(mod.seeds, na.omit(Seeds$r / Seeds$n))

## End(Not run)

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