Skip to contents

Estimates of the cumulative hazard at particular times, from a survextrap model

Usage

cumhaz(
  x,
  newdata = NULL,
  t = NULL,
  tmax = NULL,
  niter = NULL,
  summ_fns = NULL,
  sample = FALSE,
  newdata0 = NULL,
  wane_period = NULL,
  wane_nt = 10
)

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

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

summ_fns

A list of functions to use to summarise the posterior sample. This is passed to posterior::summarise_draws. By default this is list(median=median, ~quantile(.x, probs=c(0.025, 0.975))). If the list is named, then the names will be used for the columns of the output.

sample

If TRUE then the MCMC samples are returned instead of being summarised as a median and 95% credible intervals.

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

Value

A data frame (tibble) giving posterior summary statistics, or (if sample=TRUE) an array giving samples from the posterior.