diff --git a/README.md b/README.md index 593af9b..22ca3cd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Nuño's simple electoral college simulator +# Simple electoral college simulator ## About @@ -6,6 +6,8 @@ This is a simple model of the US electoral college. It aims to be conceptually s 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. +Compare with: [Nuño's simple node version manager](https://github.com/NunoSempere/nsnvm), [squiggle.c](https://git.nunosempere.com/personal/squiggle.c), [Predict, Resolve & Tally](https://github.com/NunoSempere/PredictResolveTally) + ## How to run ### Prerequisites @@ -142,7 +144,7 @@ Notes on 2020: ## Roadmap -It's not clear to me what I will do with this. As a result of writting down the model, I've realized that 80/20-ing a 538 would involve more effort than what I was expecting +It's not clear to me what I will do with this. As a result of writting down the model, I've realized that 80/20-ing a 538 would involve more effort than what I was expecting. I may just add the national drift + election day error + idiosyncratic error terms and then just call it a day. ### To do diff --git a/data/results/2000.csv b/data/electoral-history/2000.csv similarity index 100% rename from data/results/2000.csv rename to data/electoral-history/2000.csv diff --git a/data/results/2004.csv b/data/electoral-history/2004.csv similarity index 100% rename from data/results/2004.csv rename to data/electoral-history/2004.csv diff --git a/data/results/2008.csv b/data/electoral-history/2008.csv similarity index 100% rename from data/results/2008.csv rename to data/electoral-history/2008.csv diff --git a/data/results/2012.csv b/data/electoral-history/2012.csv similarity index 100% rename from data/results/2012.csv rename to data/electoral-history/2012.csv diff --git a/data/results/2016.csv b/data/electoral-history/2016.csv similarity index 100% rename from data/results/2016.csv rename to data/electoral-history/2016.csv diff --git a/data/results/2020.csv b/data/electoral-history/2020.csv similarity index 100% rename from data/results/2020.csv rename to data/electoral-history/2020.csv diff --git a/data/results/src.txt b/data/electoral-history/src.txt similarity index 100% rename from data/results/src.txt rename to data/electoral-history/src.txt diff --git a/data/electoral-college-votes-2010-census.csv b/data/num-electors/electoral-college-votes-2010-census.csv similarity index 100% rename from data/electoral-college-votes-2010-census.csv rename to data/num-electors/electoral-college-votes-2010-census.csv diff --git a/data/electoral-college-votes.csv b/data/num-electors/electoral-college-votes.csv similarity index 100% rename from data/electoral-college-votes.csv rename to data/num-electors/electoral-college-votes.csv diff --git a/data/electoral-college-votes.source b/data/num-electors/electoral-college-votes.source similarity index 100% rename from data/electoral-college-votes.source rename to data/num-electors/electoral-college-votes.source diff --git a/data/poll-errors/.~lock.gallup-republicans.ods# b/data/poll-errors/.~lock.gallup-republicans.ods# new file mode 100644 index 0000000..4d7e9f1 --- /dev/null +++ b/data/poll-errors/.~lock.gallup-republicans.ods# @@ -0,0 +1 @@ +,nuno,calma,14.04.2024 19:03,file:///home/nuno/.config/libreoffice/4; \ No newline at end of file diff --git a/data/poll-errors/gallup-republicans.csv b/data/poll-errors/gallup-republicans.csv new file mode 100644 index 0000000..ee61807 --- /dev/null +++ b/data/poll-errors/gallup-republicans.csv @@ -0,0 +1,20 @@ +year,midapril,nov,final +2008,43,40,47.1 +2004,50,49,51 +2000,41,48,48.4 +1996,35,41,40.7 +1992,44,37,37.5 +1988,45,56,53 +1984,54,59,59 +1980,34,47,51 +1976,49,49,48.0 +1972,,62,62 +1968,43,43,44 +1964,,36,38.5 +1960,44,49,49.55 +1956,61,59,58 +1952,59,51,55 +1948,47,50,45.6 +1944,42,48,45.9 +1940,,48,44.8 +1936,,44,36.5 diff --git a/data/poll-errors/gallup-republicans.ods b/data/poll-errors/gallup-republicans.ods new file mode 100644 index 0000000..24719c1 Binary files /dev/null and b/data/poll-errors/gallup-republicans.ods differ diff --git a/data/poll-errors/gallup-winners.ods b/data/poll-errors/gallup-winners.ods new file mode 100644 index 0000000..13ac202 Binary files /dev/null and b/data/poll-errors/gallup-winners.ods differ diff --git a/data/poll-errors/gallup-winners.ods.~1~ b/data/poll-errors/gallup-winners.ods.~1~ new file mode 100644 index 0000000..13ac202 Binary files /dev/null and b/data/poll-errors/gallup-winners.ods.~1~ differ diff --git a/data/poll-errors/source.txt b/data/poll-errors/source.txt new file mode 100644 index 0000000..ad6176a --- /dev/null +++ b/data/poll-errors/source.txt @@ -0,0 +1,3 @@ +https://news.gallup.com/poll/110548/gallup-presidential-election-trial-heat-trends.aspx + +https://en.wikipedia.org/wiki/1996_United_States_presidential_election diff --git a/main.go b/main.go index 4618323..5f3b12d 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ func readStates() ([]State, error) { var states map[string]State = make(map[string]State) /* Electoral college votes for the 2024 election*/ - votes_file, err := os.Open("data/electoral-college-votes.csv") + votes_file, err := os.Open("data/num-electors/electoral-college-votes.csv") // votes_file, err := os.Open("data/electoral-college-votes-2010-census.csv") if err != nil { return nil, fmt.Errorf("error opening the votes file: %v", err) @@ -70,17 +70,17 @@ func readStates() ([]State, error) { /* Election results */ var years = []string{"2000", "2004", "2008", "2012", "2016", "2020"} for _, year := range years { - results_filename := fmt.Sprintf("data/results/%s.csv", year) - results_file, err := os.Open(results_filename) + electoral_history_filename := fmt.Sprintf("data/electoral-history/%s.csv", year) + electoral_history_file, err := os.Open(electoral_history_filename) if err != nil { - return nil, fmt.Errorf("error opening the results file for %s: %v", year, err) + return nil, fmt.Errorf("error opening the electoral_history file for %s: %v", year, err) } - resultsReader := csv.NewReader(results_file) - if _, err := resultsReader.Read(); err != nil { // Skip header - return nil, fmt.Errorf("error reading results header for %s: %v", year, err) + electoral_history_reader := csv.NewReader(electoral_history_file) + if _, err := electoral_history_reader.Read(); err != nil { // Skip header + return nil, fmt.Errorf("error reading electoral_history header for %s: %v", year, err) } for { - record, err := resultsReader.Read() + record, err := electoral_history_reader.Read() if err != nil { break // EOF or an error } @@ -94,7 +94,7 @@ func readStates() ([]State, error) { states[state] = data } - results_file.Close() + electoral_history_file.Close() } /* Read polls */ diff --git a/scratchpad.txt b/scratchpad.txt new file mode 100644 index 0000000..8feec5e --- /dev/null +++ b/scratchpad.txt @@ -0,0 +1,18 @@ +- Uncertainty due to drift between now and the election +- Uncertainty due to difference between last election poll and final vote share +- Better prior by incorporating more past elections +- Think about how to: + - Inject error + - Inject correlated error + +--- + +Not as good as gallup. +State uncertainty higher than national. +Should calculate republican error instead. + +Final error: +National drift + state more uncertain than national + not as good as gallup error + idosyncratic state error + +later: error correlated across states +