
<!-- README.md is generated from README.Rmd. Please edit that file -->

# causalWins

<!-- badges: start -->

<!-- badges: end -->

A package for estimating the causal win ratio, win proportion, and net
benefit using three distinct approaches as proposed in [Even et
al. (2025)](https://arxiv.org/abs/2501.16933): nearest neighbor
matching, distributed regression forests, and efficient influence
functions.

## Installation

You can install the development version of causalWins from
[GitHub](https://github.com/) with:

``` r
# install.packages("pak")
pak::pak("FranciscoAndrade90/causalWins")
```

## Example

This is a basic usage example:

``` r
library(causalWins)
# ---------------------------------------------------------
    # Generate data with mixed covariates
# ---------------------------------------------------------
set.seed(123)
n <- 100
base <- data.frame(
  X1 = rnorm(n, mean = 5, sd = 2), # numeric covariate 1
  X2 = rnorm(n, mean = 10, sd = 3), # numeric covariate 2
  X3 = factor(sample(c("A", "B", "C"), n, replace = TRUE)), # factor covariate
  Y1 = rnorm(n, mean = 50, sd = 10), # numeric outcome 1
  Y2 = rnorm(n, mean = 100, sd = 20), # numeric outcome 2
  arm = sample(c(0, 1), n, replace = TRUE) # binary treatment arm
)
# ---------------------------------------------------------
    # Compute win ratio with nearest neighbor pairing
# ---------------------------------------------------------
res_nn <- nn_win_ratio(
  base = base,
  treatment_name = "arm",
  outcome_names = c("Y1", "Y2")
)
#> Covariates are both categorical and numerical.
#> No custom distance was provided.
#> Performing FAMD and setting distance to 'euclidean'.
#> Specify a distance function to override this choice.
# ---------------------------------------------------------
    # Compute win ratio with Distributional Random Forests
# ---------------------------------------------------------
res_drf <- drf_win_ratio(
  base = base,
  treatment_name = "arm",
  outcome_names = c("Y1", "Y2")
)
# ---------------------------------------------------------
    # Compute win ratio with Efficient Influence Functions
# ---------------------------------------------------------
res_eif <- eif_win_ratio(
  base = base,
  treatment_name = "arm",
  outcome_names = c("Y1", "Y2")
)
#> Covariates are both categorical and numerical.
#> No custom distance was provided.
#> Performing FAMD and setting distance to 'euclidean'.
#> Specify a distance function to override this choice.
#> No 'propensity_scores' was provided. 'Probability forest' will be used instead to compute those scores.
#> Specify 'propensity_scores' to override this choice.
```
