Draws the survival predicted by predict_survival() or average_survival(): the
probability of surviving to each time of the record, as the posterior median with
its credible interval. The result is a ggplot object, to be refined by the user
with further ggplot2 layers, scales, labels and themes.
Usage
plot_survival(
x,
temperature = FALSE,
facet = TRUE,
colour_by = NULL,
interval = is.null(colour_by),
time_unit = NULL
)Arguments
- x
A list, the output of
predict_survival()oraverage_survival().- temperature
A single logical value, whether to draw the record of temperature, and of any co-stressor that changes along it, in panels above the survival curve. Defaults to
FALSE.- facet
A single logical value or the character string
"all".TRUE(the default) gives a panel per setting ofnewdata, cut down to quartile values when there are many;"all"a panel for every setting;FALSEno panels, with a colour per setting.- colour_by
An optional character string naming a numeric covariate of
newdata, to colour the curves by.- interval
A single logical value, whether to draw the credible interval. Defaults to
TRUE, and toFALSEwithcolour_by.- time_unit
An optional character string giving the time unit for the axis label, e.g.
"min". The fit does not record the unit of its times, so none is shown unless given.
Details
By default each setting of newdata has its own panel, following the same rule
as in plot_tdt(). There are two ways to draw the settings together in one
panel. With facet = FALSE each setting has its own colour, from teal to deep
purple in the order of newdata, and an entry in the legend, which suits a few
settings or a covariate that is not numeric; with more than eight settings the
colours are too close to tell apart, and a message says to use panels or
colour_by. With colour_by, the curves of every value of one
numeric covariate are coloured on a continuous scale from teal for its lowest
value to deep purple for its highest, and the intervals are left out by default,
since they overlap.
With temperature = TRUE the record of temperature is drawn above the survival
curve on the same time axis, so that a drop in survival can be read against the
temperatures that caused it. A co-stressor the record follows through time is
drawn in a panel of its own between the two, named by its column, when it
changes along the record; one that stays constant is left out.
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))
# a two-day record read every hour, with a daily cycle
hours <- 0:48
record <- data.frame(time = hours * 60, day = pmin(hours %/% 24, 1),
temp = 24 + 3 * sin(2 * pi * (hours - 9) / 24))
pred <- predict_survival(fit, record, newdata = data.frame(mass = c(8, 12)))
plot_survival(pred, time_unit = "min")
plot_survival(pred, temperature = TRUE, time_unit = "min")
# both masses in one panel, the record drawn once
plot_survival(pred, temperature = TRUE, facet = FALSE, time_unit = "min")
} # }
