Test for unjustified disparate impact in R
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R
man
tests
vignettes
.Rbuildignore
.gitignore
.travis.yml
DESCRIPTION
LICENSE
NAMESPACE
README.Rmd
README.md
codecov.yml
undi.Rproj

README.md

undi

Travis-CI Build Status Coverage Status

Installation

You can install undi from github with:

# install.packages("devtools")
devtools::install_github("jongbinjung/undi")

Example

library(undi)
library(tidyverse)
inv_logit <- stats::binomial()$linkinv

N <- 2000
set.seed(1)
data <- tibble(id = rep(1:N)) %>%
  mutate(
  m = rnorm(N, 0, 1),
  x = factor(rep(c("red", "blue"), N / 2)),
  x = fct_relevel(x, "red"),
  z = rnorm(N, m, 2),
  c = rnorm(N, m, 2),
  e1 = rnorm(N, 0, 0.05),
  e2 = rnorm(N, 0, 0.05),
  risk = 1 + 0.05 * (x == "blue") + 0.25 * z + c + e1,
  a = inv_logit(risk + e2) > .5,
  y = inv_logit(risk) > .5
  )
example_policy <-
  policy(a ~ x + z + c, 
         data, 
         outcome = "y", 
         cv.folds = 2, 
         distribution = "bernoulli")

# Initial RAD computation
compute_rad(example_policy)
#>    term estimate std.error statistic p.value controls
#> 1 xblue   0.3236    0.2392     1.353  0.1763   risk__

# Sensitivity with uniform parameters
sensitivity(example_policy, 
            q = .45, 
            dp = log(1.8), 
            d0 = log(2), 
            d1 = log(1.5))
#>    term estimate std.error statistic p.value controls
#> 3 xblue  0.02014  0.004904     4.106 4.1e-05   risk__

# Sensitivity with parameters assigned to levels of the grouping variable
sensitivity(example_policy, 
            q = c(.45, .55), 
            dp = c(-log(1.2), log(1.5)), 
            d0 = c(-log(3), log(3)), 
            d1 = c(0, log(1.8))
  )
#>    term estimate std.error statistic p.value controls
#> 3 xblue  0.01237  0.005585     2.215 0.02681   risk__