Learn R Programming

whatifbandit (version 0.3.0)

create_new_cols: Create Necessary Columns for Multi-Arm Bandit Trial

Description

Initializes partially empty columns in data to initialize them for the simulation. These are initialized as NA except for observations with period_number = 1, whose values are copied from the provided columns, and used as the starting point for the simulation.

Usage

create_new_cols(data, data_cols, block_cols, blocking, perfect_assignment)

Value

Updated tibble/data.table with 6 new columns:

  • mab_success: New variable to hold new success from Multi-arm bandit procedure, NA until assigned.

  • mab_condition: New variable to hold new treatment condition from Multi-arm bandit procedure, NA until assigned.

  • impute_req: Binary indicator for imputation requirement, NA until assigned.

  • new_success_date: New variable to hold the new success date under Multi-arm bandit procedure, NA until assigned.

  • block: New variable indicating the variables to block by for assignment.

  • treatment_block: New variable combining block with original treatment condition.

Arguments

data

A data.frame, data.table, or tibble containing input data from the trial. This should be the results of a traditional Randomized Controlled Trial (RCT). Any data.frames will be converted to tibbles internally.

data_cols

A named character vector containing the names of columns in data as strings:

  • id_col: Column in data; contains unique ID as a key.

  • success_col: Column in data; binary successes from the original experiment.

  • condition_col: Column in data; original treatment condition for each observation.

  • date_col: Column in data; contains original date of event/trial. Only necessary when assigning by "Date". Must be of type Date, not a character string.

  • month_col: Column in data; contains month of treatment. Only necessary when time_unit = "Month", and when periods should be determined directly by the calendar months instead of month based time periods. This column can be a string/factor variable with the month names or numeric with the month number. It can easily be created from your date_col via lubridate::month(data[[date_col]]) or format(data[[date_col]], "%m").

  • success_date_col: Column in data; contains original dates each success occurred. Only necessary when perfect_assignment = FALSE. Must be of type Date, not a character string.

  • assignment_date_col: Column in data; contains original dates treatments were assigned to observations. Only necessary when perfect_assignment = FALSE. Used to simulate imperfect information on the part of researchers conducting an adaptive trial. Must be of type Date, not a character string.

block_cols

A character vector of variables to block by. This vector should not be named.

blocking

Logical; whether or not to use treatment blocking. Treatment blocking is used to ensure an even-enough distribution of treatment conditions across blocks. For example, blocking by gender would mean the randomized assignment should split treatments evenly not just throughout the sample (so for 4 arms, 25-25-25-25), but also within each block, so 25% of men would receive each treatment and 25% of women the same.

perfect_assignment

Logical; if TRUE, assumes perfect information for treatment assignment (i.e., all outcomes are observed regardless of the date). If FALSE, hides outcomes not yet theoretically observed, based on the dates treatments would have been assigned for each wave. This is useful when simulating batch-based assignment where treatments were assigned on a given day whether or not all the information from a prior batch was available and you have exact dates treatments were assigned.