Skip to content

Commit

Permalink
Preconvention assessment
Browse files Browse the repository at this point in the history
  • Loading branch information
technocrat committed Aug 22, 2024
1 parent 1229c4b commit ecd7c69
Show file tree
Hide file tree
Showing 30 changed files with 416 additions and 96 deletions.
Binary file added _assets/img/models/AZ_aug1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _assets/img/models/GA_aug1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _assets/img/models/MI_aug1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _assets/img/models/NC_aug1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _assets/img/models/NV_aug1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _assets/img/models/PA_aug1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _assets/img/models/WI_aug1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _assets/objs/AZ_aug1_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/GA_aug1_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/MI_aug1_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/NC_aug1_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/NV_aug1_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/PA_aug1_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/WI_aug1_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/aug1_polls.bson
Binary file not shown.
98 changes: 98 additions & 0 deletions _assets/scripts/insert_aug1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using BSON: @save, @load
using CSV
using DataFrames
using LinearAlgebra
using PrettyTables
using Printf
using Serialization
using Statistics
using StatsPlots
using Turing

@enum Month mar apr may jul jul2 aug1 aug2 sep oct nov

@enum Pollster begin
ag
aj
am
bi2
bi3
bl2
bl3
cb2
cb3
cj
cn2
cn3
ea
ec2
ec3
ep
eu
fm2
fm3
fo2
fo3
hi2
hi3
hp
ia
ma2
ma3
mi2
mi3
mq
mr2
mr3
ny2
ns
pp
ny
qi2
qi3
rr
si2
si3
sp2
sp3
su2
su3
tr
wa2
wa3
ws
wsl
wss
yg
end

@enum State PA GA NC MI AZ WI NV

struct Poll
biden_support::Float64
trump_support::Float64
sample_size::Int64
end


@load "../objs/jul2_polls.bson" months

months[aug1][AZ][ny2] = [Poll(49,45,677)]
months[aug1][AZ][tr] = [Poll(47,48,1000)]
months[aug1][GA][ny2] = [Poll(44,51,661)]
months[aug1][MI][tr] = [Poll(49,47,800)]
months[aug1][NC][cj] = [Poll(47,44,600)]
months[aug1][NV][tr] = [Poll(45,49,1000)]
months[aug1][NV][ny2] = [Poll(42,45,677)]
months[aug1][PA][ec2] = [Poll(47,47,1000)]
months[aug1][PA][tr] = [Poll(44,46,1000)]
months[aug1][PA][qi2] = [Poll(48,45,1738)]
months[aug1][WI][tr] = [Poll(48,49,800)]




# needs to be done manually rather than with include()
#@save "../objs/aug1_polls.bson" months


Binary file added _assets/scripts/mandelbrot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions _assets/scripts/polls.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
@enum State PA GA NC MI AZ WI NV
@enum Month mar apr may jun jul jul2 aug sep oct
# @enum State PA GA NC MI AZ WI NV
# @enum Month mar apr may jun jul jul2 aug1 aug2 sep oct


STATE = State
prior_month = "jul"
mon = jul2
MON = "jul2"
Mon = "jul2"
st = "AZ"
ST = AZ
prior_month = "jul2"
mon = aug1
MON = "aug1"
Mon = "aug1"
st = "PA"
ST = PA

#include("polls_head.jl")
prior_poll = BSON.load("../objs/"*"$st"*"_"*"$prior_month"*"_p_sample.bson")
@load "../objs/"*"$MON"*"_polls.bson" months
margin = first(margins[margins.st .== st, :pct])

current_month = remove_empties(months[mon])
#
# include("polls_foot.jl")

include("polls_foot.jl")

6 changes: 4 additions & 2 deletions _assets/scripts/polls_head.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ using Turing
bl3
cb2
cb3
cj
cn2
cn3
ea
Expand All @@ -63,7 +64,7 @@ using Turing
mr3
ns
pp
ny
ny2
qi2
qi3
rr
Expand Down Expand Up @@ -107,7 +108,8 @@ Month_names = Dict(
"jun" => "June",
"jul" => "July",
"jul2" => "July-post",
"aug" => "August",
"aug1" => "early August",
"aug2" => "late August",
"sep" => "September",
"oct" => "October")
#------------------------------------------------------------------
Expand Down
43 changes: 32 additions & 11 deletions az.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@
title = "Arizona"
+++

* [July assessmenbt from beginning of Harris campaign](#July-assessment-from-beginning-of-Harris-campaign)
* [July assessment through end of Biden campaign](#July-assessment-through-end-of-Biden-xcampaign)
* [June assessment](#June-assessment)
* [May assessment](#may-assessment)
* [April assessment](#april-assessment)
* [March assessment](#march-assessment)
* [2020 election](#2020-election)
* [Scenarios](#scenarios)
* [State facts](#state-facts)
* [2022 demographics](#2022-demographics)
* [Terms](#terms)
\toc


# Model results
Expand All @@ -27,6 +17,37 @@ Assessments are based on three criteria.
* **Historical**—fewer than 2.5% of the values in the credible interval are less than 2020 margin.
* **Relaxed**—fewer than 2.5% of the values in the credible interval are less than 50.01% of the two candidate vote.

## August assessment before convention

Harris wins under the *Relaxed* criterion.

~~~
<table>
<thead>
<tr class = "header headerLastRow">
<th style = "text-align: right;">median</th>
<th style = "text-align: right;">mean</th>
<th style = "text-align: right;">mode</th>
<th style = "text-align: right;">q025</th>
<th style = "text-align: right;">q975</th>
<th style = "text-align: right;">mcse</th>
<th style = "text-align: right;">rhat</th>
</tr>
</thead>
<tbody>
<tr>
<td style = "text-align: right;">0.5013</td>
<td style = "text-align: right;">0.5013</td>
<td style = "text-align: right;">0.5012</td>
<td style = "text-align: right;">0.5007</td>
<td style = "text-align: right;">0.5018</td>
<td style = "text-align: right;">0.0</td>
<td style = "text-align: right;">1.0001</td>
</tr>
</tbody>
</table>
<img src="/assets/img/models/AZ_aug1.png" style="width: 100%; display: block;">
~~~
## July assessment from beginning of Harris campaign

Harris wins under the *Relaxed* criterion.
Expand Down
42 changes: 42 additions & 0 deletions extract_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Directory containing .jl files
directory="/Users/ro/projects/SwingWatch/_assets/scripts"

# Output file to store extracted lines
output_file="output_file.txt"

# Check if the directory exists
if [ ! -d "$directory" ]; then
echo "Directory does not exist: $directory"
exit 1
fi

# Empty the output file if it already exists
> "$output_file"

# Function to extract lines from a file
extract_functions() {
local file="$1"
local in_function=0
while IFS= read -r line; do
if [[ $line =~ ^function ]]; then
in_function=1
echo "$line" >> "$output_file"
elif [[ $in_function -eq 1 && $line =~ end$ ]]; then
echo "$line" >> "$output_file"
echo "" >> "$output_file" # Add a newline for readability
in_function=0
elif [[ $in_function -eq 1 ]]; then
echo "$line" >> "$output_file"
fi
done < "$file"
}

# Export the function to be available in subshells
export -f extract_functions

# Find .jl files and process each one
find "$directory" -type f -name '*.jl' -exec bash -c 'extract_functions "$0"' {} \;

echo "Extraction complete. Output stored in: $output_file"
46 changes: 33 additions & 13 deletions ga.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@
title = "Georgia"
+++

* [July assessment from beginning of Harris campaign](#July-assessment-from-beginning-of-Harris-campaign)
* [July assessment through end of Biden campaign](#July-assessment-through-end-of-Biden-campaign)
* [June assessment](#june-assessment)
* [May assessment](#may-assessment)
* [April assessment](#april-assessment)
* [March assessment](#march-assessment)
* [2020 election](#2020-election)
* [Scenarios](#scenarios)
* [State facts](#state-facts)
* [2022 demographics](#2022-demographics)
* [Runoff rules](#runoff-rules)
* [Other news](#other-news)
* [Terms](#terms)
\toc

In the 2020 election President Harris won 50.12% (0.5012) of the Electoral Electoral Electoral Electoral Electoral Votes cast for Harris or Trump in Georgia. This leaves out Electoral Electoral Electoral Electoral Electoral Votes for third-party candidates. Taking the actual Winner as a starting point, the model introduces some uncertainty into the Winner to create a range of outcomes for that election from 50.08% to 50.16%. Next, the Winners of each month's polling are factored in on a rolling basis. When the plot shows that more of the credible interval lies to the left of the 2020 margin it indicates that Harris is losing ground compared to the 2020 election Winners, taking the polls at face value.

Expand All @@ -25,6 +13,38 @@ Assessments are based on three criteria.
* **Historical**—fewer than 2.5% of the values in the credible interval are less than 2020 margin.
* **Relaxed**—fewer than 2.5% of the values in the credible interval are less than 50.01% of the two candidate vote.

## August assessment before convention

Harris wins under the *Relaxed* criterion.

~~~
<table>
<thead>
<tr class = "header headerLastRow">
<th style = "text-align: right;">median</th>
<th style = "text-align: right;">mean</th>
<th style = "text-align: right;">mode</th>
<th style = "text-align: right;">q025</th>
<th style = "text-align: right;">q975</th>
<th style = "text-align: right;">mcse</th>
<th style = "text-align: right;">rhat</th>
</tr>
</thead>
<tbody>
<tr>
<td style = "text-align: right;">0.501</td>
<td style = "text-align: right;">0.501</td>
<td style = "text-align: right;">0.501</td>
<td style = "text-align: right;">0.5005</td>
<td style = "text-align: right;">0.5014</td>
<td style = "text-align: right;">0.0</td>
<td style = "text-align: right;">0.9999</td>
</tr>
</tbody>
</table>
<img src="/assets/img/models/GA_aug1.png" style="width: 100%; display: block;">
~~~
## July assessment from beginning of Harris campaign

Harris wins under the *Relaxed* criterion.
Expand Down
2 changes: 1 addition & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title = "Latest"

## Superseding event

Vice President Harris replaced President President as the nominee of the Democratic Party. The model has been revised to take into account the polls conducted in July prior to July 21, 2024 (when Biden withdrew) as the prior distribution, after introducing some variability to partially account for the added uncertainty introduced by the substitution
Vice President Harris replaced President Biden as the nominee of the Democratic Party. The model has been revised to take into account the polls conducted in July prior to July 21, 2024 (when Biden withdrew) as the prior distribution, after introducing some variability to partially account for the added uncertainty introduced by the substitution

For polls conducted through the end of the month, the model will be updated and every fortnight thereafter. Consideration will also be given to reassessing swing states, depending on initial results. It is expected that most Blue and Red states will remain as such, but some swing states will move.

Expand Down
47 changes: 36 additions & 11 deletions mi.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@
title = "Michigan"
+++

* [July assessment from beginning of Harris campaign](#July-assessment-from-beginning-of-Harris-campaign)
* [July assessment through end of Biden campaign](#July-assessment-through-end-of-Biden-campaign)
* [June assessment](#june-assessment)
* [May assessment](#may-assessment)
* [April assessment](#april-assessment)
* [March assessment](#march-assessment)
* [2020 election](#2020-election)
* [Scenarios](#scenarios)
* [State facts](#state-facts)
* [2022 demographics](#2022-demographics)
* [Terms](#terms)
\toc

# Model results

Expand All @@ -26,6 +16,41 @@ Assessments are based on three criteria.
* **Historical**—fewer than 2.5% of the values in the credible interval are less than 2020 margin.
* **Relaxed**—fewer than 2.5% of the values in the credible interval are less than 50.01% of the two candidate vote.

## August assessment before convention

Harris wins under the *Relaxed* criterion.

~~~
<table>
<thead>
<tr class = "header headerLastRow">
<th style = "text-align: right;">median</th>
<th style = "text-align: right;">mean</th>
<th style = "text-align: right;">mode</th>
<th style = "text-align: right;">q025</th>
<th style = "text-align: right;">q975</th>
<th style = "text-align: right;">mcse</th>
<th style = "text-align: right;">rhat</th>
</tr>
</thead>
<tbody>
<tr>
<td style = "text-align: right;">0.5139</td>
<td style = "text-align: right;">0.5139</td>
<td style = "text-align: right;">0.5136</td>
<td style = "text-align: right;">0.5134</td>
<td style = "text-align: right;">0.5143</td>
<td style = "text-align: right;">0.0</td>
<td style = "text-align: right;">1.0012</td>
</tr>
</tbody>
</table>
<img src="/assets/img/models/MI_aug1.png" style="width: 100%; display: block;">
~~~



## July assessment from beginning of Harris campaign

Harris wins under the *Relaxed criterion*
Expand Down
Loading

0 comments on commit ecd7c69

Please sign in to comment.