knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

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)

# Sensitivity with uniform parameters
sensitivity(example_policy, 
            q = .45, 
            dp = log(1.8), 
            d0 = log(2), 
            d1 = log(1.5))

# 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))
  )


jongbinjung/undi documentation built on May 8, 2019, 11:56 p.m.