add more poll math
This commit is contained in:
parent
0b6b80accb
commit
f115fd2039
19
main.go
19
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)
|
||||
|
||||
fmt.Println("")
|
||||
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.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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user