Last active
November 14, 2020 22:55
-
-
Save NaimKabir/125b66f35cc23d4da3bec3194b98906a to your computer and use it in GitHub Desktop.
This file contains hidden or 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": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Now let's simulate some per-precinct votes and collect % of Trump votes from split-ticket voters.\n", | |
"\n", | |
"This can be sampled a a bunch of weighted coinflips with the probability $p({trump})$--i.e, sampling from a binomial distribution." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# let's say we're dealing with a fixed size of split-ticket voters in each precinct\n", | |
"split_pop_size = 100 \n", | |
"split_votes = np.random.binomial(split_pop_size, p_trump, num_precincts) # simulating\n", | |
"split_trump_percentage = split_votes / split_pop_size" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.7.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment