---
title: "Cost-Effectiveness Analysis for Clinical Trials with CEACT"
author: "Imad EL BADISY"
output:
  pdf_document:
    toc: true
    number_sections: true
bibliography: references.bib
header-includes:
  - \usepackage{float}
vignette: >
  %\VignetteIndexEntry{Trial-Based Cost-Effectiveness Analysis with CEACT}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6.5,
  fig.height = 4.2,
  fig.pos = "H",
  dpi = 120
)
library(CEACT)
```

# Overview

CEACT implements cost-effectiveness analyses for two-arm clinical trials: observed incremental summaries, non-parametric bootstrap
uncertainty, cost-effectiveness planes, cost-effectiveness acceptability curves
(CEACs), net monetary benefit, and deterministic sensitivity analysis.

The package follows standard practice in trial-based economic evaluation, where patient-level costs and effects are observed alongside treatment allocation [@glick2014economic; @drummond2015methods]. 

Let $C_i$ denote cost, $E_i$ denote effect, and $A_i \in \{0,1\}$ denote treatment assignment, with $A_i=0$ for the
reference group and $A_i=1$ for treatment.

# Core Quantities

Mean costs and effects by arm are

\[
\bar{C}_a = \frac{1}{n_a}\sum_{i:A_i=a} C_i,
\qquad
\bar{E}_a = \frac{1}{n_a}\sum_{i:A_i=a} E_i.
\]

Incremental cost and incremental effect are

\[
\Delta C = \bar{C}_1 - \bar{C}_0,
\qquad
\Delta E = \bar{E}_1 - \bar{E}_0.
\]

When $\Delta E \ne 0$, the incremental cost-effectiveness ratio is

\[
ICER = \frac{\Delta C}{\Delta E}.
\]

Because ratios can be unstable when $\Delta E$ is near zero, CEACT also uses net monetary benefit at willingness-to-pay threshold $k$ [@stinnett1998net]:

\[
INMB(k) = k\Delta E - \Delta C.
\]

Treatment is cost-effective at threshold $k$ when $INMB(k)>0$. The CEAC is the probability of this event over an uncertainty distribution:

\[
CEAC(k) = Pr\{k\Delta E - \Delta C > 0\}.
\]

CEACT estimates this probability from non-parametric bootstrap replicates [@efron1993introduction], preserving treatment-arm sample sizes by stratified resampling. CEACs and planes are widely used to communicate decision uncertainty in cost-effectiveness studies [@fenwick2001representing; @briggs2002thinking].

# Real Trial-Based CEA Example

The example below first uses the `trial_cea` dataset included with CEACT package. This patient-level dataset contains treatment assignment, total costs, and QALYs for 500 trial participants and is suitable for demonstrating the package workflow.

```{r data}
data("trial_cea")
trial <- trial_cea

head(trial)
```

```{r observed}
observed <- cea(cost + qaly ~ group, data = trial, ref = "control")
summary(observed)
```

The observed treatment arm produces more QALYs with a small increase in mean cost. The ICER is the additional cost per additional QALY.

# Bootstrap Uncertainty

```{r bootstrap}
set.seed(42)
boot_res <- boot_icer(cost + qaly ~ group, data = trial, ref = "control",
                      R = 1000, ci.type = "perc")
summary(boot_res)
```

The bootstrap distribution summarizes sampling uncertainty in $\Delta C$, $\Delta E$, and the ICER. For publication-quality analyses, the number of
replications should generally be increased beyond this vignette if computation time allows [@willan2006statistical].

```{r plane, fig.cap="Cost-effectiveness plane from stratified non-parametric bootstrap replicates. The red line is the willingness-to-pay threshold."}
plot_ceplane(boot_res, k = 20000)
```

Most simulated replicates lie in the north-east quadrant, indicating higher cost and higher effect for treatment. Replicates below the threshold line are
cost-effective at that threshold.

# Net Monetary Benefit and CEAC

```{r ceac-table}
ceac_tbl <- compute_nmb_ceac(
  boot_res,
  wtp_range = seq(0, 50000, 5000)
)

ceac_tbl
```

```{r ceac-plot, fig.cap="Cost-effectiveness acceptability curve. The curve gives the bootstrap probability that treatment is cost-effective at each willingness-to-pay threshold."}
plot_ceac(ceac_tbl)
```

The CEAC rises as the willingness-to-pay threshold increases because the treatment's positive incremental effect receives more decision value. The curve
should be interpreted as decision uncertainty, not as the expected size of the health benefit.

# Deterministic Sensitivity Analysis

```{r dsa}
dsa_effect <- dsa_icer(
  cost + qaly ~ group,
  data = trial,
  param = "qaly",
  range = seq(0.50, 0.70, 0.025),
  ref = "control",
  metric = "INMB",
  k = 20000
)

dsa_effect
```

```{r tornado, fig.cap="One-way deterministic sensitivity analysis varying treatment-arm effect.", fig.height=3.6}
plot_tornado(dsa_effect, metric = "INMB")
```

This one-way analysis shows how the incremental net monetary benefit changes as the assumed treatment-arm effect changes. Such analyses are useful for checking which assumptions drive conclusions, but they do not replace probabilistic uncertainty analysis.

# Reproducibility Checklist

- Define the reference and treatment arms before analysis.

- Report $\Delta C$, $\Delta E$, ICER, and INMB at relevant thresholds.

- Use bootstrap or model-based uncertainty methods for CEACs.

- Interpret ICERs alongside the cost-effectiveness plane and net benefit.

- Report the willingness-to-pay thresholds used for decision interpretation.


# References
