Skip to content

Instantly share code, notes, and snippets.

@jmxpearson
Last active January 24, 2017 16:29
Show Gist options
  • Save jmxpearson/077407a40aaf967eb12db41b6c851f1d to your computer and use it in GitHub Desktop.
Save jmxpearson/077407a40aaf967eb12db41b6c851f1d to your computer and use it in GitHub Desktop.
Sample power analysis for firing rate task
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Spiking power analysis\n",
"\n",
"This notebook illustrates a simple simulation-based spiking analysis\n",
"\n",
"We will assume:\n",
"\n",
"- a baseline firing period prior to each trial $\\lambda_0$\n",
"- a baseline period of $T_0$ seconds\n",
"- a stimulus presentation period on each trial $\\alpha \\lambda_0$\n",
"- a stimulus period of $T$ seconds\n",
"- a firing rate response that is more variable than Poisson; this is modeled as a trial-to-trial Gaussian noise on the log firing rate: $\\log \\lambda_i = \\log (\\alpha\\lambda) + \\epsilon$\n",
"- a paired t-test on firing rates to determine significance"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import scipy.stats as stats\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"np.random.seed(12345) # for reproducibility"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, let's go through it carefully and plot along the way:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# define some numbers\n",
"baseline = 20. # firing rate in Hz\n",
"Tbaseline = 1.\n",
"Tstim = 1.\n",
"effect = 2 # fractional change from baseline\n",
"trial_noise_std = 0.0 # trial-to-trial noise as a percentage\n",
"Ntrials = 500 # number of trials for each stimulus\n",
"Nexpt = 1000 # number of synthetic experiments to conduct\n",
"alpha = 0.05 # nominal false positive rate"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make some fake firing rates:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"baseline_rates = np.exp(np.log(baseline) * (1 + trial_noise_std * np.random.randn(Ntrials)))\n",
"stim_rates = np.exp(np.log(effect * baseline) * (1 + trial_noise_std * np.random.randn(Ntrials)))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEKCAYAAAAcgp5RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGvFJREFUeJzt3XuUVeWd5vHvA0qGiiJQhCoFLRAcg87YOHaMy2in7I5E\nzHhZnRlBM+2FjDExJmSyTEQnkYodDThpY9ZqdWIMsWTFKHHZoqttQUcrGk1AbVxeULkYLpZSEotr\nyojAb/7Yu8pjWZdzijoc6vX5rFWLfd6zL+97Xs5z9n733ucoIjAzs3QNqnQFzMysvBz0ZmaJc9Cb\nmSXOQW9mljgHvZlZ4hz0ZmaJc9BbUSSdJ+mhflrXY5Jm9Me6ull/0XWVNFvS/B6e/5qkDZK2Shop\naZukcT3Mf4uk/116rc3Kx0FvHSSdJOlJSZsl/UnSE5KOA4iIOyPitArXr07Sbkk9/r/tQ127vJlE\n0n7APwGfi4hhEdEaEQdGxJoetv21iLi2hG2XjaRfSrqm0vWwytuv0hWwfYOkA4EHgEuA3wBDgJOB\ndytZr05EFsrqdgZpcETs6qft1QIfA14uZmZJgyJidz9tu7dt9Wc7LXHeo7d2/xGIiFgQmXcj4pGI\neBFA0gWSnmifOd+zvkTSCkmtkv654LlBkv5J0kZJqyV9vac9cUkzJC2X9Lakf5N0WDd1/G3+7+Z8\nKOXTeb1+J+kGSX8CZndR1xslrZO0RdLTkk7q7cWQdATwSv5wk6RHCtp9eD79S0k3S/pXSduA+sK9\naEmflbRe0rcltUhqlnRhwTZGSnogr9cSSf9YWO9O9Wk/mpkhaS3w//LyBZLelLRJUpOkSXn5xcCX\ngO/mr9XCvPxgSfdIeivvm28UbONT+euzJV/nj3t7nWxgcNBbux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kJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x10e9b8c88>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.hist(baseline_rates, label='baseline');\n",
"plt.hist(stim_rates, label='stim');\n",
"plt.legend();\n",
"plt.title('Single trial firing rates');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and use these to generate fake spike counts:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"baseline_counts = stats.poisson.rvs(baseline_rates * Tbaseline)\n",
"stim_counts = stats.poisson.rvs(stim_rates * Tstim)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEKCAYAAAAcgp5RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHi5JREFUeJzt3XuUVeWd5vHvA4JNRVEomioFKRCiQXuMl4mxjcYyRiPa\nXnpWj6LpjkraMVE7ZIyJ4CShSCeImcTE1TFObEUJK95zAWeIoAvLayKakHhBQUAuFnIgIgoSQeE3\nf+xNeSyoy7lxqjbPZ62zOPv27vc9p3jOe96zL4oIzMwsu3pVuwJmZlZZDnozs4xz0JuZZZyD3sws\n4xz0ZmYZ56A3M8s4B73tkqQLJT1YprIekTSuHGW1U36X6yppkqQZZd7/CZJeypt+VdJnyrkPs1I4\n6PdgaUA9KWmDpL9IelzSMQARcWdEnF7l+jVI2i6pw7/TIupa1pNHIuKJiBhdzjKrRdLtkr5T7XpY\nee1V7QpYdUjaF3gAuAy4D+gLnAhsqWa92hBJKKvdFaTeEbFt91XJrOdxj37PdQgQEXFvJLZExMMR\n8QKApIskPb5j5bRnfZmkxZLWS/pJ3rJekn4oaZ2kpZKu6KgnLmmcpIWS3pD0W0nD2qnjo+m/GyS9\nLemTab2ekHSDpL8Ak3ZR1x9LWinpLUnPSDqhKy+IpFpJD0h6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b\nK1FGku4k+aGrFsgBk0h6FvcBBwErgPMiYkO16lgsSZ8CHiP5zxPp41qSs53vpee3778A00n+FnsB\n90TE9yQNJAPtyyfpJOBrEXF2VtonaQTwa5K/y72AX0TE1Ky0D0DSx4FbgT7AMuASoDcFtM8nTJmZ\nZZx/jDUzyzgHvZlZxjnozcwyzkFvZpZxDnozs4xz0JuZZZyD3sws4xz0ZmYZ9/8BC/9HZhVhUd0A\nAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x10e9c7390>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.hist(baseline_counts, label='baseline');\n",
"plt.hist(stim_counts, label='stim');\n",
"plt.legend();\n",
"plt.title('Single trial spike counts');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calculate firing rates from data:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"obs_baseline_rates = baseline_counts / Tbaseline\n",
"obs_stim_rates = stim_counts / Tstim"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-62.191816367 3.41747897325e-237\n",
"True\n"
]
}
],
"source": [
"tstat, pval = stats.ttest_rel(obs_baseline_rates, obs_stim_rates)\n",
"print(tstat, pval)\n",
"print(pval < alpha)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Now put it in a function"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def run_expt(baseline, effect, Tbaseline, Tstim, trial_noise_std, Ntrials):\n",
" # run a single synthetic experiment, return p-value for paired t-test\n",
" # of baseline vs stim spike rate\n",
" \n",
" # random rates\n",
" baseline_rates = np.exp(np.log(baseline) * (1 + trial_noise_std * np.random.randn(Ntrials)))\n",
" stim_rates = np.exp(np.log(effect * baseline) * (1 + trial_noise_std * np.random.randn(Ntrials)))\n",
" \n",
" # random counts\n",
" baseline_counts = stats.poisson.rvs(baseline_rates * Tbaseline)\n",
" stim_counts = stats.poisson.rvs(stim_rates * Tstim)\n",
" \n",
" # observed rates\n",
" obs_baseline_rates = baseline_counts / Tbaseline\n",
" obs_stim_rates = stim_counts / Tstim\n",
" \n",
" # test\n",
" return stats.ttest_rel(obs_baseline_rates, obs_stim_rates)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def calc_power(alpha, Nexpt, exptfun, *args):\n",
" # calculate power for an experiment defined by false positive rate alpha and repeated Nexpt times\n",
" # exptfun returns an object with a pvalue\n",
" # args are passed on to exptfun\n",
" \n",
" pvals = np.array([exptfun(*args).pvalue for _ in range(Nexpt)])\n",
" \n",
" return np.mean(pvals < alpha)\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Now calculate power"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.68400000000000005"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alpha = 0.05\n",
"Nexpt = 1000\n",
"baseline = 20. # firing rate in Hz\n",
"Tbaseline = 1.\n",
"Tstim = 1.\n",
"effect = 1.2 # fractional change from baseline\n",
"trial_noise_std = 0.10 # trial-to-trial noise as a percentage\n",
"Ntrials = 50 # number of trials for each stimulus\n",
"\n",
"calc_power(alpha, Nexpt, run_expt, baseline, effect, Tbaseline, Tstim, trial_noise_std, Ntrials)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [Root]",
"language": "python",
"name": "Python [Root]"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment