Compute the hazard ratio at a series of time points, estimated from
a `survextrap`

model. Intended for use with
non-proportional hazards models
(`survextrap(...,nonprop=TRUE)`

). In proportional hazards
models (which `survextrap`

fits by default) the hazard
ratio is constant with time.

## Usage

```
hazard_ratio(
x,
newdata = NULL,
t = NULL,
tmax = NULL,
niter = NULL,
summ_fns = NULL,
sample = FALSE
)
```

## Arguments

- x
A fitted model object as returned by

`survextrap`

- newdata
A data frame with two rows. The hazard ratio will be defined as hazard(second row) divided by hazard(first row). If the only covariate in the model is a factor with two levels, then

`newdata`

defaults to a data frame containing the levels of this factor, so that the hazard ratio for the second level versus the first level is computed. For any other models,`newdata`

must be supplied explicitly.- 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.