Plot hazard curves from a survextrap
model. This
function is intended as a quick check of a fitted model, so it
deliberately has limited options for customisation. The data
behind these plots can be extracted with hazard
into
a tidy data frame to enable custom plots to be constructed with
ggplot2. See the case study vignette for some examples.
Usage
plot_hazard(
x,
newdata = NULL,
t = NULL,
tmax = NULL,
niter = NULL,
newdata0 = NULL,
wane_period = NULL,
wane_nt = 10,
ci = NULL,
xlab = "Time",
ylab = "Hazard",
line_size = 1.5,
ci_alpha = 0.2,
show_knots = FALSE
)
Arguments
- x
A fitted model object as returned by
survextrap
- newdata
Data frame of covariate values to compute the output for. If there are covariates in the model and this is not supplied, the following default is used:
(a) if the only covariate is one factor variable, then the output is computed for each level of this factor.
(b) if there are multiple covariates, or any numeric covariates, then the output is computed at the mean of each numeric covariate in the original data, and at the baseline level of each factor covariate.
Note caution is required about how treatment groups (for example) are stored in your data. If these are coded as numeric (0/1), then if
newdata
is not specified only one output will be shown, which relates to the average value of this numeric variable over the data, which doesn't correspond to either of the treatment groups. To avoid this, a treatment group should be stored as a factor.- t
Vector of times at which to compute the estimates.
- tmax
Maximum time at which to compute the estimates. If
t
is supplied, then this is ignored. Ift
is not supplied, thent
is set to a set of 100 equally spaced time points from 0 totmax
. If bothtmax
andt
are not supplied, thentmax
is set to the maximum follow up time in the data.- niter
Number of MCMC iterations to use to compute credible intervals. Set to a low value to make this function quicker, at the cost of some approximation error (which may not be important for plotting or model development).
- newdata0
Data frame of covariate values defining the "untreated" group for use in treatment waning models. See
Survmspline_wane
.- wane_period
Vector of two numbers, defining the time period over which the hazard is interpolated between the hazard of the "treated" group (taken from
newdata
) and the hazard of the "untreated" group (taken fromnewdata0
). Optional - if this is not supplied, then no waning is assumed.- wane_nt
Number of intervals defining the piecewise constant approximation to the hazard during the waning period.
- ci
If
TRUE
then credible intervals are drawn. Defaults to drawing the intervals if the plot shows the curve for only one covariate value.- xlab
X-axis label
- ylab
Y-axis label
- line_size
Passed to
geom_line
- ci_alpha
Transparency for the credible interval ribbons
- show_knots
Show the locations of the spline knots as vertical lines
Details
If the model has a single factor covariate (excluding background
hazard strata), then curves are produced for each level of this
factor if newdata
requests this (or is left to its default).
Otherwise, only a single curve is produced, illustrating the
corresponding output from hazard
.