Skip to contents

Draws the output of hazard_residuals(). With against = NULL, the residuals are set against the values expected of a uniform distribution, which is what they follow when the model describes the data: the points then lie along the diagonal. With against naming a column, the residuals are drawn against it, to look for a pattern the model has missed: points for a numeric variable, such as body mass, and boxes for a grouping, such as the trial or the treatment. A horizontal line marks 0.5, the middle of the residuals under the model; residuals below it are individuals that failed earlier than the model predicts. The time of failure is not a variable to draw them against (see hazard_residuals()). The result is a ggplot object, which can be refined by the user with further ggplot2 layers, scales, labels and themes.

Usage

plot_residuals(x, against = NULL)

Arguments

x

A tibble, the output of hazard_residuals().

against

An optional character string naming a column of x to draw the residuals against. NULL (the default) compares them with the uniform distribution.

Value

A ggplot object.

Examples

if (FALSE) { # \dontrun{
# a model fitted to a small ramping trial: 20 individuals warmed from 20 to 35
# degrees over 60 minutes and checked every 10, in two trials (see fit_hazard())
path   <- data.frame(path_id = "A", time = c(0, 60), temp = c(20, 35))
checks <- data.frame(path_id = "A", time = seq(0, 60, by = 10))
ind    <- data.frame(id = 1:20, path_id = "A", event = 1, mass = runif(20, 8, 12),
                     trial = rep(c("a", "b"), each = 10),
                     t_upper = sample(seq(10, 60, 10), 20, replace = TRUE))
long   <- build_hazard_data(ind, path, "interval", covariates = c("mass", "trial"),
                            checks = checks)
fit    <- fit_hazard(long, "exp", dpar_formulas = list(loga = ~ 1 + mass))

res <- hazard_residuals(fit)
plot_residuals(res)
plot_residuals(res, against = "mass")
plot_residuals(res, against = "trial")
} # }