Bayesian multilevel A/B testing
Contents
Bayesian multilevel A/B testing#
Introduction#
In this example, I used synthetic data to tune a model to estimate the magnitude of response to a yes/no manipulation. The response is binary (True/False). Other potential examples of a binary response:
Click
Disease outbreak
Financial transaction
Why use synthetic data and not prediction on real data? To explore potential features of data that could make the model give misleading results, even those features underrepresented in the curent dataset.
Problem summary#
Binary response variable (spike/no spike at any given time)
One source of variability to estimate
Stimulation
Several sources of spurious variability to explain away
Time
Subject
Trial
Neuron
Goals#
To estimate the effects of stimulation
To understand the limits of what variability we can explain away
Thought process#
I conceptualized that neurons vary in slopes and intercepts, while subjects vary in their slopes only. On the basis of this hypothesis, I generated Poisson data with the following rules:
Emissions are poisson-distubuted and have a time component
Subjects have varying strengths of effects of experimental condition
There are three subjects with five neurons each. Some invervention is applied (pharmaceutical, stimulation, etc) that affects how often neurons are activated.
Neuron 4 of mouse 0 has the least effect
Neuron 0 mouse 2 has the most effect
Slow neurons are affected the most across all mice
Exploratory plots inform the model#
Make up some data
import altair as alt
from IPython.core.display import Image, display
from bayes_window import generate_fake_spikes, fake_spikes_explore, BayesRegression
df, df_monster, index_cols, firing_rates = generate_fake_spikes(n_trials=20,
n_neurons=6,
n_mice=3,
dur=5,
mouse_response_slope=40,
overall_stim_response_strength=5)
# Make plots:
charts = fake_spikes_explore(df=df, df_monster=df_monster, index_cols=index_cols)
# Render plots:
charts[-2].properties(title=['Emissions are poisson-distubuted and have a distinct time component',
'Try pinching/scrolling and panning with your touchpad/mouse!']).interactive().display()
charts[-3].properties(title=['Subjects have varying strengths of effects of experimental condition',
'Hoverable, try it!']).interactive().display()