remove histogram from readme & continue

master
NunoSempere 1 month ago
parent af061d6871
commit ad81189e99

@ -2,187 +2,20 @@
## About
This is a simple model of the US electoral college. It aims to be conceptually simple and replicable. Currently, it incorporates data from the electoral history in each state, since the 2000 election, as well as polls, if they exist.
This is a simple model of the US electoral college. It aims to be conceptually simple and replicatable. Currently, it incorporates data from the electoral history in each state, since the 2000 election, as well as states-specific polls, if they exist.
Other projects, like [538](https://en.wikipedia.org/wiki/FiveThirtyEight), [Nate Silver's substack](https://www.natesilver.net/) or [Gelman's model](https://github.com/TheEconomist/us-potus-model) are to this project as a sportscar is to a walking stick. They are much more sophisticated, and probably more accurate. However, they are also more difficult to understand and to design.
## A cool histogram
```
[ 187, 188): 0.00%
[ 188, 189): 0.01%
[ 189, 190): 0.00%
[ 190, 191): 0.00%
[ 191, 192): 0.00%
[ 192, 193): 0.01%
[ 193, 194): 0.01%
[ 194, 195): 0.01%
[ 195, 196): 0.00%
[ 196, 197): 0.00%
[ 197, 198): 0.01%
[ 198, 199): █ 0.02%
[ 199, 200): █ 0.02%
[ 200, 201): 0.01%
[ 201, 202): 0.01%
[ 202, 203): 0.02%
[ 203, 204): █ 0.03%
[ 204, 205): █ 0.03%
[ 205, 206): █ 0.03%
[ 206, 207): 0.02%
[ 207, 208): █ 0.02%
[ 208, 209): ██ 0.05%
[ 209, 210): ███ 0.06%
[ 210, 211): ██ 0.05%
[ 211, 212): █ 0.04%
[ 212, 213): ██ 0.05%
[ 213, 214): ███ 0.06%
[ 214, 215): ████ 0.09%
[ 215, 216): █████ 0.11%
[ 216, 217): ████ 0.08%
[ 217, 218): ███ 0.07%
[ 218, 219): █████ 0.10%
[ 219, 220): ██████ 0.12%
[ 220, 221): ██████ 0.13%
[ 221, 222): ██████ 0.12%
[ 222, 223): ██████ 0.13%
[ 223, 224): ███████ 0.14%
[ 224, 225): █████████ 0.17%
[ 225, 226): ██████████ 0.19%
[ 226, 227): █████████ 0.18%
[ 227, 228): █████████ 0.18%
[ 228, 229): ████████████ 0.24%
[ 229, 230): ██████████████ 0.28%
[ 230, 231): ██████████████ 0.27%
[ 231, 232): ██████████████ 0.28%
[ 232, 233): ████████████████ 0.30%
[ 233, 234): █████████████████ 0.33%
[ 234, 235): ████████████████████ 0.38%
[ 235, 236): ███████████████████ 0.36%
[ 236, 237): █████████████████ 0.33%
[ 237, 238): █████████████████ 0.33%
[ 238, 239): ████████████████████████ 0.46%
[ 239, 240): █████████████████████████████ 0.55%
[ 240, 241): ███████████████████████████ 0.52%
[ 241, 242): ████████████████████████ 0.46%
[ 242, 243): █████████████████████████ 0.48%
[ 243, 244): ████████████████████████████ 0.53%
[ 244, 245): ██████████████████████████████████████ 0.71%
[ 245, 246): ███████████████████████████████████████████ 0.81%
[ 246, 247): ████████████████████████████████████ 0.68%
[ 247, 248): ████████████████████████████████ 0.62%
[ 248, 249): █████████████████████████████████████ 0.70%
[ 249, 250): █████████████████████████████████████████████ 0.85%
[ 250, 251): ███████████████████████████████████████████████ 0.89%
[ 251, 252): ███████████████████████████████████████████████ 0.90%
[ 252, 253): █████████████████████████████████████████ 0.78%
[ 253, 254): ███████████████████████████████████████████ 0.82%
[ 254, 255): ████████████████████████████████████████████████████████ 1.05%
[ 255, 256): █████████████████████████████████████████████████████████████████ 1.24%
[ 256, 257): ██████████████████████████████████████████████████████████ 1.11%
[ 257, 258): █████████████████████████████████████████████████████ 1.00%
[ 258, 259): ████████████████████████████████████████████████████ 0.98%
[ 259, 260): ██████████████████████████████████████████████████████████████ 1.17%
[ 260, 261): ████████████████████████████████████████████████████████████████████████████ 1.43%
[ 261, 262): ████████████████████████████████████████████████████████████████████████████████ 1.50%
[ 262, 263): ███████████████████████████████████████████████████████████████████████ 1.34%
[ 263, 264): ████████████████████████████████████████████████████████████████ 1.21%
[ 264, 265): ████████████████████████████████████████████████████████████████████████ 1.36%
[ 265, 266): ████████████████████████████████████████████████████████████████████████████████ 1.51%
[ 266, 267): █████████████████████████████████████████████████████████████████████████████████████ 1.60%
[ 267, 268): ███████████████████████████████████████████████████████████████████████████ 1.42%
[ 268, 269): ██████████████████████████████████████████████████████████████████████████ 1.39%
[ 269, 270): ████████████████████████████████████████████████████████████████████████████ 1.44%
[ 270, 271): ███████████████████████████████████████████████████████████████████████████████████████████ 1.72%
[ 271, 272): █████████████████████████████████████████████████████████████████████████████████████████████ 1.76%
[ 272, 273): █████████████████████████████████████████████████████████████████████████████████████████ 1.68%
[ 273, 274): ███████████████████████████████████████████████████████████████████████████████ 1.49%
[ 274, 275): ███████████████████████████████████████████████████████████████████████████████████ 1.57%
[ 275, 276): █████████████████████████████████████████████████████████████████████████████████████████ 1.68%
[ 276, 277): ██████████████████████████████████████████████████████████████████████████████████████████████████ 1.84%
[ 277, 278): █████████████████████████████████████████████████████████████████████████████████████████████████ 1.83%
[ 278, 279): █████████████████████████████████████████████████████████████████████████████████████████ 1.67%
[ 279, 280): █████████████████████████████████████████████████████████████████████████████████████████ 1.68%
[ 280, 281): ██████████████████████████████████████████████████████████████████████████████████████████████ 1.78%
[ 281, 282): ████████████████████████████████████████████████████████████████████████████████████████████████████ 1.88%
[ 282, 283): █████████████████████████████████████████████████████████████████████████████████████ 1.61%
[ 283, 284): ███████████████████████████████████████████████████████████████████████████████████████ 1.64%
[ 284, 285): ███████████████████████████████████████████████████████████████████████████████████████ 1.64%
[ 285, 286): ██████████████████████████████████████████████████████████████████████████████████████████ 1.69%
[ 286, 287): ████████████████████████████████████████████████████████████████████████████████████████ 1.67%
[ 287, 288): █████████████████████████████████████████████████████████████████████████████████████████████████ 1.83%
[ 288, 289): ████████████████████████████████████████████████████████████████████████████ 1.44%
[ 289, 290): █████████████████████████████████████████████████████████████████████████████████ 1.52%
[ 290, 291): █████████████████████████████████████████████████████████████████████████████████████████████ 1.75%
[ 291, 292): ███████████████████████████████████████████████████████████████████████████████████████ 1.64%
[ 292, 293): ████████████████████████████████████████████████████████████████████ 1.29%
[ 293, 294): ███████████████████████████████████████████████████████████████████████ 1.35%
[ 294, 295): ████████████████████████████████████████████████████████████████████████ 1.37%
[ 295, 296): ██████████████████████████████████████████████████████████████████████████████ 1.47%
[ 296, 297): ███████████████████████████████████████████████████████████████████████████████████ 1.57%
[ 297, 298): ███████████████████████████████████████████████████████████████████ 1.26%
[ 298, 299): █████████████████████████████████████████████████ 0.92%
[ 299, 300): ██████████████████████████████████████████████████████ 1.03%
[ 300, 301): ███████████████████████████████████████████████████████████████████████ 1.34%
[ 301, 302): ████████████████████████████████████████████████████████████ 1.13%
[ 302, 303): ██████████████████████████████████████████████████ 0.94%
[ 303, 304): ████████████████████████████████████████████ 0.84%
[ 304, 305): ██████████████████████████████████████████ 0.79%
[ 305, 306): ███████████████████████████████████████████████ 0.90%
[ 306, 307): ████████████████████████████████████████████████████████████ 1.13%
[ 307, 308): ███████████████████████████████████████ 0.75%
[ 308, 309): ██████████████████████████████ 0.56%
[ 309, 310): ███████████████████████████████████ 0.67%
[ 310, 311): ████████████████████████████████████ 0.69%
[ 311, 312): ██████████████████████████████ 0.58%
[ 312, 313): ████████████████████████████████ 0.60%
[ 313, 314): ██████████████████████████ 0.50%
[ 314, 315): █████████████████████ 0.40%
[ 315, 316): ██████████████████████ 0.43%
[ 316, 317): ███████████████████████ 0.44%
[ 317, 318): ███████████████ 0.29%
[ 318, 319): ███████████████ 0.29%
[ 319, 320): ██████████████████████ 0.42%
[ 320, 321): ██████████████ 0.27%
[ 321, 322): ████████ 0.17%
[ 322, 323): █████████ 0.18%
[ 323, 324): █████████ 0.18%
[ 324, 325): ███████████ 0.21%
[ 325, 326): ████████████ 0.23%
[ 326, 327): ██████ 0.12%
[ 327, 328): ███ 0.06%
[ 328, 329): ████ 0.08%
[ 329, 330): ███████ 0.13%
[ 330, 331): ████ 0.09%
[ 331, 332): █ 0.03%
[ 332, 333): █ 0.02%
[ 333, 334): ██ 0.04%
[ 334, 335): ██ 0.06%
[ 335, 336): ███ 0.06%
[ 336, 337): █ 0.02%
[ 337, 338): 0.01%
[ 338, 339): 0.01%
[ 339, 340): █ 0.03%
[ 340, 341): 0.02%
[ 341, 342): 0.00%
[ 342, 343): 0.00%
[ 343, 344): 0.01%
[ 344, 345): 0.01%
[ 345, 346): 0.01%
[ 346, 347): 0.00%
```
Other projects, like [538](https://en.wikipedia.org/wiki/FiveThirtyEight), [Nate Silver's substack](https://www.natesilver.net/) or [Gelman's model](https://github.com/TheEconomist/us-potus-model) are to this project as a sportscar is to a walking stick. They are much more sophisticated, and probably more accurate. However, they are also more difficult to understand and to maintain.
## How to run
### Prerequisites
This model is written in go, an elegant language developed by Rob Pike, Ken Thompson and Robert Griesemer at Google. You can find installation instructions for all major platforms [here](https://go.dev/dl/). The website this
This model is written in go, an elegant language developed by Rob Pike, Ken Thompson and Robert Griesemer at Google. You can find installation instructions for all major platforms [here](https://go.dev/dl/). In addition, it uses git for distribution. You can find installation instructions for git [here](https://git-scm.com/downloads).
Once you have go and git, you install the model with
You can thus get the model with:
```
git clone [repo]
git clone https://git.nunosempere.com/NunoSempere/2024-election-modelling
cd 2024-election-modelling
go install
```
@ -242,14 +75,18 @@ What's happening here is that:
### To do
- [ ] Print states & polls separately
- [ ] Add graphs
- [ ] Share with Samotsvety
- [ ] Think about next steps
- [ ] Consider conditional probabilities
- See how other models account for the correlation
- [ ] Add uncertainty using Laplace's law of succession?
- Maybe only do this for contested states? Alabama is not going to turn Democratic?
- [ ] Exclude partisan polls => not that many of them
- [ ] Histogram distributions of electoral college votes
- [ ] Think about whether I want to monetize this
- Maybe with Vox?
- Otherwise: add MIT license & publish
- [ ] Think about whether I want to add other collaborators
- If so, add contribution sections, make available on github
### Done
@ -274,3 +111,5 @@ Consider polls:
General
- [x] Work on README
- [x] Print states & polls separately
- [x] Histogram distributions of electoral college votes

@ -407,10 +407,13 @@ func printElectoralCollegeHistogram(samples []int) {
}
}
cp := 0.0
for i, count := range histogram {
bar_length := (count * 100) / max_count // Assuming max_count bar length is 50 characters
bar_length := (count * 75) / max_count // Assuming max_count bar length is 50 characters
p := float64(count) / float64(len(samples)) * 100
fmt.Printf("[ %2d, %4d): %s %.2f%%\n", i, i+1, barString(bar_length), p)
cp += p
fmt.Printf("[ %2d, %4d): %s %.2f%% (%.0f%%)\n", i, i+1, barString(bar_length), p, cp)
}
}
@ -422,9 +425,10 @@ func main() {
return
}
n_sims := 1_000_000
n_sims := 100_000
printStates(states)
fmt.Printf("\n\n")
p_republicans := 0.0
results := make([]int, n_sims)
@ -434,10 +438,9 @@ func main() {
if republican_seats >= 270 {
p_republicans++
}
// fmt.Printf("%d - %t\n", republican_seats, republican_seats >= 270)
}
p_republicans = p_republicans / float64(n_sims)
fmt.Printf("\n\n\n%% republicans: %f\n", p_republicans)
fmt.Printf("\n%% republicans: %f\n", p_republicans)
printElectoralCollegeHistogram(results)
}

@ -1,3 +1,6 @@
run:
go run main.go
polls:
mkdir -p data/polls
# cd data/polls && wget https://projects.fivethirtyeight.com/polls/data/president_polls.csv

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save