commit f115fd20397803b8cdf118a45520f418dfdfd78c
parent 0b6b80accb27d5a30cf8598661b4c3f504b114c0
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Sun, 14 Apr 2024 11:35:24 -0400
add more poll math
Diffstat:
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/main.go b/main.go
@@ -294,17 +294,26 @@ func sampleFromState(state State) VotesForEachParty {
std_poll := math.Sqrt((normalized_trump_share * normalized_biden_share) / joint_trump_biden_sample_size)
p_trump_more_votes := getProbabilityAboveX(0.5, normalized_trump_share, std_poll)
-
fmt.Printf("\n\tPoll: %+v", recent_biden_trump_poll)
- fmt.Printf("\n\t\tChance of R win: %f", p_trump_more_votes)
+ fmt.Printf("\n\t\tPoll says chance of R win: %f", p_trump_more_votes)
// Update general tally
num_biden_votes += poll_biden_votes
num_trump_votes += poll_trump_votes
}
- // total_sample_size := num_biden_votes + num_trump_votes
+ total_sample_size := num_biden_votes + num_trump_votes
+ if total_sample_size != 0.0 {
+ aggregate_trump_share := num_trump_votes / (num_trump_votes + num_biden_votes)
+ aggregate_biden_share := num_biden_votes / (num_trump_votes + num_biden_votes)
+
+ std_all_polls := math.Sqrt((aggregate_trump_share * aggregate_biden_share) / total_sample_size)
+
+ p_trump_more_votes := getProbabilityAboveX(0.5, aggregate_trump_share, std_all_polls)
+ fmt.Printf("\n\tAggregating all polls naïvely says chance of R win: %f", p_trump_more_votes)
+
+ }
- fmt.Println("")
+ fmt.Printf("\n\tHistorical base rate: %f", p_republican)
if r.Float64() < p_republican {
return VotesForEachParty{Democrats: 0, Republicans: state.Votes}
} else {
@@ -322,7 +331,7 @@ func simulateElection(states []State) int {
republican_seats += election_sample.Republicans
}
- fmt.Printf(" (%d) ", republican_seats)
+ fmt.Printf("\n\n\n (%d) ", republican_seats)
if republican_seats >= 270 {
return 1
} else {