Skip to contents

Plot survival 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 survival into a tidy data frame to enable custom plots to be constructed with ggplot2. See the case study vignette for some examples.


  newdata = NULL,
  t = NULL,
  tmax = NULL,
  km = NULL,
  niter = NULL,
  newdata0 = NULL,
  wane_period = NULL,
  wane_nt = 10,
  ci = NULL,
  xlab = "Time",
  ylab = "Survival",
  line_size = 1.5,
  ci_alpha = 0.2,
  show_knots = FALSE



A fitted model object as returned by survextrap


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.


Vector of times at which to compute the estimates.


Maximum time at which to compute the estimates. If t is supplied, then this is ignored. If t is not supplied, then t is set to a set of 100 equally spaced time points from 0 to tmax. If both tmax and t are not supplied, then tmax is set to the maximum follow up time in the data.


If TRUE then a Kaplan-Meier curve of the observed data is plotted, using the results of survival::survfit() on the formula originally used for the survextrap fit. By default, this is only done when there are no covariates or one factor covariate.

The Kaplan-Meier estimates are returned in the km component of the fitted model object returned by survextrap, for use in hand-crafted plots like these.


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).


Data frame of covariate values defining the "untreated" group for use in treatment waning models. See Survmspline_wane.


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 from newdata0). Optional - if this is not supplied, then no waning is assumed.


Number of intervals defining the piecewise constant approximation to the hazard during the waning period.


If TRUE then credible intervals are drawn. Defaults to drawing the intervals if the plot shows the curve for only one covariate value.


X-axis label


Y-axis label


Passed to geom_line


Transparency for the credible interval ribbons


Show the locations of the spline knots as vertical lines


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.