The aim of this vignette is to show how to perform probabilistic sensitivity analyses (PSA) on survival data.

The main function to use is `resample_surv()`

within `define_psa()`

.

The `resample_surv()`

function uses a random generator with the parameters of the initially defined distribution. All you need to do is specify the `n`

argument to define the number of draws, and you can control variability in this way (the higher `n`

is, the lower the variability). Under the hood, an empirical cumulative function is created with these random draws and a nonlinear model determining Least Squares estimates of the new parameters is then fitted.

```
<- define_surv_dist("gamma", shape = 2, rate = 0.1)
surv_dist <- define_psa(surv_dist ~ resample_surv(n = 500)) psa
```

You can display the distribution and its confidence interval using the `plot()`

function. This is useful to check the expected variability of your model.

```
<- define_psa(surv_dist ~ resample_surv(n = 50))
psa2 plot(surv_dist, psa = psa)
```

`plot(surv_dist, psa = psa2)`

A non-parametric bootstrap (random sampling) of the `data.frame`

is performed. At each iteration of the PSA, a new `data.frame`

is created and the model runs with this new data. To perform a PSA with real data, `resample_surv()`

must not contain any arguments.

```
<- flexsurv::flexsurvreg(survival::Surv(rectime, censrec) ~ group,
fit_cov data = bc,
dist = "exp")|>
define_surv_fit()
<- define_psa(fit_cov ~ resample_surv())
psa
plot(fit_cov, times = 1:1000, psa = psa, Nrep = 10)
```

`## No covariates provided, returning aggregate survival across all subjects.`

It is possible to carry out a PSA with all objects of class `surv_object`

, including complex objects, created using a sequence of operations. Taking the previous vignette as an example:

```
<- set_covariates(fit_cov, group = "Poor")
fitcov_poor <- set_covariates(fit_cov, group = "Medium")
fitcov_medium <- flexsurvreg(
fit_w formula = Surv(futime, fustat) ~ 1,
data = ovarian, dist = "weibull"
|>
) define_surv_fit()
|>
fit_cov set_covariates(group = "Good") |>
apply_hr(hr = 2) |>
mix(
fitcov_medium,weights = c(0.25, 0.75)
|>
) add_hazards(
fit_w|>
) join(
fitcov_poor,at = 500
|>
) plot(psa = psa, 1:1000, Nrep = 10)
```