---
title: "Cure Models with the Beta-Danish Distribution"
author: "Bilal Ahmad"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Cure Models with the Beta-Danish Distribution}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 4.5,
  warning = FALSE,
  message = FALSE
)
```

## Two cure formulations

The package implements two cure formulations on the Exponentiated Danish
kernel:

- **Mixture cure** splits the population into a susceptible fraction
  `pi(Z)` modelled by logistic regression on the incidence covariates,
  and a cured fraction `1 - pi(Z)`.
- **Promotion-time cure** derives the cure fraction from a latent
  Poisson process of clonogenic cells with intensity
  `theta(Z) = exp(Z' gamma)`; the cure fraction is `exp(-theta(Z))`.

Both are fitted via `fit_bd_cure()`.

## Quick example

Both fits below use simulated data with a known cure structure.

```{r example}
library(BetaDanish)
set.seed(2026)
n <- 250
z <- stats::rbinom(n, 1, 0.5)
pi_susc <- stats::plogis(0.3 + 0.7 * z)
cured   <- stats::rbinom(n, 1, 1 - pi_susc) == 1
T_true  <- ifelse(cured, Inf,
                  rbetadanish(n, a = 1, b = 2, c = 1.5, k = 0.4))
C   <- stats::rexp(n, 0.04)
time   <- pmin(T_true, C)
status <- ifelse(T_true <= C, 1, 0)
dat <- data.frame(time = time, status = status, z = z)
cat("Sample size:", n, " Censoring rate:", round(mean(status == 0), 2), "\n")
```

## Mixture cure model

```{r mix, error = TRUE}
fit_mix <- fit_bd_cure(
  formula_aft  = survival::Surv(time, status) ~ 1,
  formula_cure = ~ z,
  data         = dat,
  type         = "mixture",
  n_starts     = 3
)
summary(fit_mix)
```

## Promotion-time cure model

```{r prom, error = TRUE}
fit_prom <- fit_bd_cure(
  formula_aft  = survival::Surv(time, status) ~ 1,
  formula_cure = ~ z,
  data         = dat,
  type         = "promotion",
  n_starts     = 3
)
summary(fit_prom)
```

## See also

- `?fit_bd_cure` for full documentation
- `?bd_bootstrap_ci` for bootstrap confidence intervals
- `?plot.bd_cure` for Cox-Snell residual plots
