Last active
January 7, 2022 00:59
-
-
Save jonkrohn/afbe11cea35efe03301d7c26fab5ec5c to your computer and use it in GitHub Desktop.
productivity-as-function-of-coffee.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "productivity-as-function-of-coffee.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyNl5ALjypxSjhVj5EWuSq1p", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/jonkrohn/afbe11cea35efe03301d7c26fab5ec5c/productivity-as-function-of-coffee.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "HVT5OvWpXLU7" | |
}, | |
"source": [ | |
"# Daily Productivity as a Function of Coffee Intake" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "3AFDGaxCRPNW" | |
}, | |
"source": [ | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"import seaborn as sns\n", | |
"import scipy.stats as st" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "RMorJbhEXv6I" | |
}, | |
"source": [ | |
"The data are from my daily habit-tracking spreadsheet. Each integer represents the number of \"pomodoros\" (25-minute blocks of uninterrupted, deeply focused work) completed on a given workday. (See [here](https://www.superdatascience.com/podcast/the-pomodoro-technique) for my introduction to the pomodoro productivity technique.)\n", | |
"\n", | |
"The `coffee` data are from the final two workweeks (Mon Aug 2 to Fri Aug 20) before I began weaning myself off of my two-cup-per-day coffee habit.\n", | |
"\n", | |
"The `no_coffee` data are from the first two workweeks since I weaned myself of coffee (Mon Sep 13 to Fri Sep 24). " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "UhH-26y-SAgA" | |
}, | |
"source": [ | |
"coffee = np.array([14, 14, 12, 11, 4, 12, 8, 12, 9, 13])\n", | |
"no_coffee = np.array([14, 15, 19, 15, 12, 13, 16, 17, 19, 14])" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "LNz49rgfSrWd", | |
"outputId": "ee33d3bf-2dc8-4aa1-c680-9034c6a50693" | |
}, | |
"source": [ | |
"coffee.mean()" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"10.9" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 3 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "hpymNXZBSt-O", | |
"outputId": "d470eaaf-312a-4d75-98c3-27392c615995" | |
}, | |
"source": [ | |
"no_coffee.mean()" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"15.4" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 4 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "HNV8jTy6Ter3" | |
}, | |
"source": [ | |
"coffee_df = pd.DataFrame(list(zip(coffee, np.repeat('Coffee', len(coffee)))), columns=['Pomodoros', 'Condition'])\n", | |
"no_coffee_df = pd.DataFrame(list(zip(no_coffee, np.repeat('No Coffee', len(no_coffee)))), columns=['Pomodoros', 'Condition'])\n", | |
"combined_df = pd.concat([coffee_df, no_coffee_df])" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 279 | |
}, | |
"id": "U45MD987WnMu", | |
"outputId": "10d2a530-d5fc-41c4-e01b-a9089c776587" | |
}, | |
"source": [ | |
"_ = sns.boxplot(x='Condition', y='Pomodoros', data=combined_df)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAVV0lEQVR4nO3dfZRddX3v8feHRDCAcIVM0RsKUceHKorV8V61rcWKNL1t1VJbZdUawTbVtW6I1qLWa6V2rarLh9bcuK4tKhKqxSWILXIVxQekrU+dgBiiqBGREh8Yw1VEEEj43j/Ojh1iJnMmyT57Zvb7tdZZc/bv7IfvmZz1yW/2+e3fTlUhSeqPg7ouQJI0Wga/JPWMwS9JPWPwS1LPGPyS1DNLuy5gGMuXL6+VK1d2XYYkLSibNm36flWN7d6+IIJ/5cqVTE5Odl2GJC0oSb61p3ZP9UhSzxj8ktQzBr8k9YzBL0k9Y/BLUs8Y/JLUMwa/JPXMghjHL6ldGzZsYOvWrZ3WsG3bNgBWrFjRaR0A4+PjrF27tusyWmPwS5oX7rjjjq5L6A2DX9K86N2uW7cOgPXr13dcyeLnOX5J6hmDX5J6xuCXpJ4x+CWpZwx+SeoZg1+Sesbgl6SeMfglqWdaC/4k5ya5Ocm109oem+RzSb6YZDLJf2vr+JKkPWuzx38esGq3tjcCr62qxwKvaZYlSSPUWvBX1ZXALbs3A0c0z48Evt3W8SVJezbquXpeAnw0y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/mUdrm4+bmpOZ7UCoNffbBrNsi5uHPa852M5vuwXccc1fHUUwa/+uBAzWZ6HbAyyUOa5dNmWO9HwP320P7VZvvxZvkPGfyVIY2Uwa9Frzkt8zvAyc1wzi3A64F/BL7EYDbTTzLLbKZV9RMGd3v6v82XuzPN8vg+4KzmS9yH7Lb96cCFSTYD9wB/N8M+pNY4O6ck9Yw9fknqGYNfknrG4JeknjH4JalnDH5J6hmDX5J6xuCXpJ75/yVuUF9WS94iAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<Figure size 432x288 with 1 Axes>" | |
] | |
}, | |
"metadata": { | |
"needs_background": "light" | |
} | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "XSD8RgiiSvi2", | |
"outputId": "68eb9c95-90e4-4eaa-e475-ccbf5217ca84" | |
}, | |
"source": [ | |
"st.ttest_ind(coffee, no_coffee, equal_var=False)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"Ttest_indResult(statistic=-3.6433299160125303, pvalue=0.002041972256638596)" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 7 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "REFMSwFjaL4x" | |
}, | |
"source": [ | |
"Over this period, I was significantly more productive on days where I didn't drink coffee ($\\mu_n =$ 15.4 pomodoros = 6.4 hours of deeply focused work) than on days where I did ($\\mu_c =$ 10.9 pomodoros = 4.5 hours of deeply focused work), $t = 3.6, p < .01$." | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment