Learn R Programming

whatifbandit (version 0.3.0)

get_bandit.thompson: Thompson sampling Algorithm

Description

Thompson sampling Algorithm

Usage

# S3 method for thompson
get_bandit(past_results, conditions, current_period, ndraws)

Value

A named list of length 2, where element 1 is the named numeric vector of Thompson sampling probabilities, and element 2 is a reference to the same vector. The second element is adjusted later in the simulation based on what the user has set for control_augment and random_assign_prop to reflect the probability of assignment to a given treatment at that period.

Arguments

past_results

A tibble/data.table containing summary of prior periods, with successes, number of observations, and success rates, which is created by get_past_results().

current_period

Numeric value of length 1; current period of the adaptive trial simulation.

ndraws

A numeric value; When Thompson sampling direct calculations fail, draws from a simulated posterior will be used to approximate the Thompson sampling probabilities. This is the number of simulations to use, the default is 5000 to match the default parameter bandit::best_binomial_bandit_sim(), but might need to be raised or lowered depending on performance and accuracy concerns.

Details

Thompson sampling is calculated using the bandit package but the direct calculation can fail. If this occurs, a simulation based method is used instead to estimate the posterior distribution, and the user receives a warning.