policy: Create policy object

Description Usage Arguments Value

Description

Create policy object

Usage

1
2
3
4
5
policy(formula, data, outcome, train = 0.5, risk = "resp_trt",
  model = names(models()), down_sample = 1, fit1 = NULL, pred1 = NULL,
  fit_ptreat = NULL, pred_ptreat = NULL, ptreat = NULL, resp_ctl = NULL,
  resp_trt = NULL, calibrate = FALSE, save_models = FALSE,
  recast_df = FALSE, seed = round(stats::runif(1) * 10000), ...)

Arguments

formula

a formula in the form of treatment ~ grouping_variable + other predictors where the LHS is the treatment column, first element on the RHS is the grouping variable (e.g., Race), and the remainder of the RHS specifies the predictors (features) for treatment/response models

data

data frame to use; must include all the columns specified in formula and given in the outcome parameter

outcome

name of outcome column in data

train

either (1) a value between 0 and 1 representing the proportion of data to use in training, (2) the name of a column of characters "train" and "test" within data to use in splitting the data, or (3) a logical vector of equal length as nrow(data) used to index training data

risk

One of "resp_ctl" or "resp_trt", indicating which treatment regime should be used as the risk score (default: resp_trt)

model

character of modelling method to use for risk models; run names(undi::models()) to get list of available models

down_sample

(Optional) proportion (between 0 and 1) or number (greater than 1) of rows to sample, if down sampling the data; default is 1 (i.e., use all data)

fit1

a function of the form f(formula, data, ...) used for fitting the first-stage model; overides model

pred1

a function of the form f(model, data, formula) used for generating predictions from the first-stage model; the formula argument can be ignored within the function body, but the function should still accept it; some prediction functions (e.g., glmnet) require the original formula; predictions should be on probability scale, while "risk" will always be on logit scale; overrides model

fit_ptreat

a function of the form f(formula, data, ...) used for fitting propensity (probability of treatment) models. If not specified, fit1 is used by default, with the provided formula argument.

pred_ptreat

a function of the form f(model, data, formula) used for generating propensity predictions. If not specified, pred1 is used by default.

ptreat

(Optional) default value for probability of treatment;

resp_ctl

(Optional)

resp_trt

(Optional) default value for probability of response = 1 given each treatment regime (ctl, trt); useful for cases where outcome under certain treatment regimes is deterministic (e.g., probability of finding illegal weapon if NOT frisked is 0)

calibrate

whether or not to use platt scaling to calibrate predictions

save_models

whether or not fitted models should be returned

recast_df

(Optional) whether data should be re-cast as a data.frame; this might be useful if the modeling function requires a model matrix, and data contains character columns — recasting as a data frame will convert all character columns to factors

seed

random seed to use

...

additional arguments passed to first-stage model fitting function, fit1 and fit_ptreat

Value

policy object

data

original data frame, augmented with columns fold__, ptrt__, resp_ctl__, resp_trt__, and risk__, which contain train/test fold indicators for the first stage, treatment propesinty, first stage model probability predictions under control and treatment, and appropriate risk measure on logit-scale, respectively

risk_col

either "resp_ctl" or "resp_trt", indicating which was used for "risk"

treatment

name of column from data used as treatment indicator

outcome

name of column from data used as outcome indicator

grouping

name of column from data used as grouping variable

features

additional features used in first stage model

fit1

function used to fit first stage model

pred1

function used to generate predictions from first stage model

fit_ptreat

function used to fit model for treatment propensity

pred_ptreat

function used to generate predictions for treatment propensity

m_*

if save_models = TRUE, each of the fitted models; otherwise set to NULL

call

the original call


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