-
-
Save alexander-wei/25db7389996deca9c562f699b1f48985 to your computer and use it in GitHub Desktop.
hacker news posts eda
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "4684ba29-b487-429e-8d1c-1dc2b1b05377", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"### t distributions. Red solid is the average across all time slots\n", | |
"for i in range(len(words)):\n", | |
" fig,ax = plt.subplots(1,3,figsize=(24,5), num=i); ax=ax.flatten();\n", | |
" Mean_Var_per_t = word_stats[i]\n", | |
" MEAN_, VAR_ = np.squeeze(baseline_stats[i])\n", | |
" \n", | |
" DOF_baseline = np.squeeze(baseline_sizes[i])[1]\n", | |
"\n", | |
" confidence_A = []\n", | |
" confidence_B = []\n", | |
" effect_ = []\n", | |
" delta_ = []\n", | |
" \n", | |
" VOX_SIZE = .02\n", | |
" xlow, xhigh = -.5,1.5\n", | |
" for u in Mean_Var_per_t:\n", | |
" DOF_cat = np.squeeze(word_sizes[0])[:,1].mean() // 2\n", | |
" ax[0].plot(np.arange(xlow,xhigh,VOX_SIZE), stats.t.pdf(np.arange(xlow,xhigh,VOX_SIZE),loc=u[0], scale=u[1]**.5,df=DOF_cat),':');\n", | |
" confidence_A.append(\n", | |
" sum([ stats.t.cdf(k,loc=MEAN_, scale=VAR_**.5,df=DOF_baseline) * stats.t.pdf(k,loc=u[0], scale=u[1]**.5,df=DOF_cat)\\\n", | |
" for k in np.arange(xlow,xhigh,VOX_SIZE)]) * VOX_SIZE)\n", | |
" confidence_B.append(\n", | |
" sum([(1- stats.t.cdf(k,loc=MEAN_, scale=VAR_**.5,df=DOF_baseline)) * stats.t.pdf(k,loc=u[0], scale=u[1]**.5,df=DOF_cat)\\\n", | |
" for k in np.arange(xlow,xhigh,VOX_SIZE)]) * VOX_SIZE)\n", | |
" effect_.append((u[0]-MEAN_)/(u[1]**.5))\n", | |
" delta_.append(10*(u[0]-MEAN_))\n", | |
" ax[0].plot(np.arange(xlow,xhigh,VOX_SIZE), stats.t.pdf(np.arange(xlow,xhigh,VOX_SIZE),loc=MEAN_, scale=VAR_**.5,df=DOF_baseline), 'r');\n", | |
" \n", | |
" ax[1].bar(np.arange(10), confidence_A, color='orange'); ax[1].stem(np.arange(10), effect_); ax[1].set_ylim(bottom=-.75);\n", | |
" \n", | |
" ax[2].bar(np.arange(10), confidence_A, color='orange'); ax[2].stem(np.arange(10), delta_); ax[2].set_ylim(bottom=-.75,top=ax[1].get_ylim()[1]);\n", | |
" fig.suptitle(words[i]) \n", | |
" ax[0].legend(np.arange(10))\n", | |
" ax[0].set_title(\"t distribution of comment rate per time bin\")\n", | |
" ax[1].set_title(\"confidence (bar) vs effect size (stem)\")\n", | |
" ax[2].set_title(\"confidence (bar) vs rate_(time|keyword) - rate_keyword (stem)\")\n", | |
" confidence_A = np.array(confidence_A); effect_ = np.array(effect_);" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"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.10.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment