diff --git a/README.md b/README.md index f83374e..de403ee 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,21 @@ When Democrats won with Obama, they won by a lot, whereas when Republicans won w Remedy: consider the conditional probabilities? But how? Or, relax assumptions using Laplace's law? +- [ ] 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? + ## Second round: just consider polls - [x] Download and format - [x] Read -- [ ] Add date of poll +- [x] Add date of poll - [ ] Consider what the standards error should be +- [ ] Consider how to aggregate polls? + - One extreme: Just look at the most recent one + - [x] Another extreme: Aggregate very naïvely, add up all samples together? - [ ] Aggregate polls? - [ ] Exclude polls older than one month? +- [ ] Exclude partisan polls - [ ] ... - -## Third diff --git a/main.go b/main.go index 4c558b3..131fe70 100644 --- a/main.go +++ b/main.go @@ -190,7 +190,7 @@ func sampleFromState(state State) VotesForEachParty { fmt.Printf("\n\nState: %s", state.Name) fmt.Printf("\n\tVotes: %d", state.Votes) fmt.Printf("\n\tHistory: %s", state.PresidentialElectoralHistory) - fmt.Printf("\n\tPolls: %s", state.Polls) + // fmt.Printf("\n\tPolls: %s", state.Polls) switch state.Name { case "Nebraska": @@ -233,11 +233,6 @@ func sampleFromState(state State) VotesForEachParty { } } p_republican = p_republican / float64(len(state.PresidentialElectoralHistory)) - if r.Float64() < p_republican { - return VotesForEachParty{Democrats: 0, Republicans: state.Votes} - } else { - return VotesForEachParty{Democrats: state.Votes, Republicans: 0} - } /* Considering polls */ var recent_polls []Poll @@ -246,7 +241,45 @@ func sampleFromState(state State) VotesForEachParty { recent_polls = append(recent_polls, poll) } } - return VotesForEachParty{Democrats: 1, Republicans: 1} + + var recent_biden_trump_polls []Poll + for _, recent_poll := range recent_polls { + has_biden := false + has_trump := false + for candidate_name, _ := range recent_poll.PollResults { + if candidate_name == "Biden" { + has_biden = true + } else if candidate_name == "Trump" { + has_trump = true + } + } + if has_biden && has_trump { + recent_biden_trump_polls = append(recent_biden_trump_polls, recent_poll) + } + fmt.Printf("\n\tPoll: %+v", recent_poll) + } + + num_biden_votes := 0.0 + num_trump_votes := 0.0 + for _, recent_biden_trump_poll := range recent_biden_trump_polls { + biden_percentage := 0.0 + trump_percentage := 0.0 + for candidate_name, candidate_percentage := range recent_biden_trump_poll.PollResults { + if candidate_name == "Biden" { + biden_percentage = candidate_percentage + } else if candidate_name == "Trump" { + trump_percentage = candidate_percentage + } + } + num_biden_votes += biden_percentage * float64(recent_biden_trump_poll.SampleSize) + num_trump_votes += trump_percentage * float64(recent_biden_trump_poll.SampleSize) + } + + if r.Float64() < p_republican { + return VotesForEachParty{Democrats: 0, Republicans: state.Votes} + } else { + return VotesForEachParty{Democrats: state.Votes, Republicans: 0} + } } } }