Skip to content

Commit

Permalink
First Harris results
Browse files Browse the repository at this point in the history
  • Loading branch information
technocrat committed Aug 7, 2024
1 parent 9b37dde commit 1229c4b
Show file tree
Hide file tree
Showing 31 changed files with 986 additions and 496 deletions.
Binary file added _assets/img/models/AZ_jul2.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_jul2.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_jul2.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_jul2.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_jul2.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_jul2.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_jul2.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_jul2_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/GA_jul2_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/MI_jul2_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/NC_jul2_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/NV_jul2_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/PA_jul2_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/WI_jul2_p_sample.bson
Binary file not shown.
Binary file added _assets/objs/jul2_polls.bson
Binary file not shown.
Binary file added _assets/objs/jul_polls.bson
Binary file not shown.
105 changes: 52 additions & 53 deletions _assets/scripts/insert_jul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,102 +7,101 @@ using Statistics
using StatsPlots
using Turing

# const DESIGN_ERROR = .

@enum Month mar apr may jul jul aug sep oct nov
@enum Month mar apr may jul jul2 aug sep oct nov

@enum Pollster begin
ag
aj
am
bi
bi
bl
bl
cb
cb
cn
cn
bi2
bi3
bl2
bl3
cb2
cb3
cn2
cn3
ea
ec
ec
ec2
ec3
ep
eu
fm
fm
fo
fo
hi
hi
fm2
fm3
fo2
fo3
hi2
hi3
hp
ia
ma
ma
mi
mi
ma2
ma3
mi2
mi3
mq
mr
mr
mr2
mr3
ns
pp
ny
qi
qi
qi2
qi3
rr
si
si
sp
sp
su
su
si2
si3
sp2
sp3
su2
su3
tr
wa
wa
wa2
wa3
ws
wsl
wss
yg
end


@enum State PA GA NC MI AZ WI NV

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


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

months[jul][AZ][bl] = [Poll(45,48,781)]
months[jul][AZ][ec] = [Poll(40,50,1000)]
months[jul][AZ][bl2] = [Poll(45,48,781)]
months[jul][AZ][ec2] = [Poll(40,50,1000)]
months[jul][AZ][ia] = [Poll(44,49,800)]
months[jul][AZ][pp] = [Poll(43,51,596)]
months[jul][AZ][yg] = [Poll(37,44,900)]
months[jul][GA][bl] = [Poll(41,43,790)]
months[jul][GA][ec] = [Poll(48,41,1000)]
months[jul][GA][ia] = [Poll(42/,48,800)]
months[jul][GA][bl2] = [Poll(41,43,790)]
months[jul][GA][ec2] = [Poll(48,41,1000)]
months[jul][GA][ia] = [Poll(42,48,800)]
months[jul][GA][yg] = [Poll(40,44,1000)]
months[jul][MI][bl] = [Poll(45,39,694)]
months[jul][MI][ec] = [Poll(42,45,1000)]
months[jul][MI][bl2] = [Poll(45,39,694)]
months[jul][MI][ec2] = [Poll(42,45,1000)]
months[jul][MI][ep] = [Poll(36,42,600)]
months[jul][MI][tr] = [Poll(43,45,1059)]
months[jul][MI][yg] = [Poll(40,42,1000)]
months[jul][NC][bl] = [Poll(42,40,696)]
months[jul][NC][ec] = [Poll(41,48,1000)]
months[jul][NC][bl2] = [Poll(42,40,696)]
months[jul][NC][ec2] = [Poll(41,48,1000)]
months[jul][NC][yg] = [Poll(40,44,1000)]
months[jul][NV][bl] = [Poll(39,45,452)]
months[jul][NV][ec] = [Poll(40,56,1000)]
months[jul][NV][bl2] = [Poll(39,45,452)]
months[jul][NV][ec2] = [Poll(40,56,1000)]
months[jul][NV][ia] = [Poll(42,49,800)]
months[jul][NV][yg] = [Poll(42,46,800)]
months[jul][PA][bl] = [Poll(44,51,794)]
months[jul][PA][bl2] = [Poll(44,51,794)]
months[jul][PA][ia] = [Poll(45,49,800)]
months[jul][PA][yg] = [Poll(40,43,1000)]
months[jul][PA][ec] = [Poll(43,48,1000)]
months[jul][PA][ec2] = [Poll(43,48,1000)]
months[jul][PA][ny] = [Poll(43,47,1000)]
months[jul][WI][bl] = [Poll(47,44,695)]
months[jul][WI][ec] = [Poll(43,48,1000)]
months[jul][WI][bl2] = [Poll(47,44,695)]
months[jul][WI][ec2] = [Poll(43,48,1000)]
months[jul][WI][ia] = [Poll(47,47,546)]
months[jul][WI][ns] = [Poll(44,46,600)]
months[jul][WI][yg] = [Poll(39,43,900)]
Expand Down
99 changes: 99 additions & 0 deletions _assets/scripts/insert_jul2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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 aug sep oct nov

@enum Pollster begin
ag
aj
am
bi2
bi3
bl2
bl3
cb2
cb3
cn2
cn3
ea
ec2
ec3
ep
eu
fm2
fm3
fo2
fo3
hi2
hi3
hp
ia
ma2
ma3
mi2
mi3
mq
mr2
mr3
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/jul_polls.bson" months

months[jul2][AZ][bl2] = [Poll(48,47,804)]
months[jul2][AZ][ec2] = [Poll(44,49,800)]
months[jul2][GA][bl2] = [Poll(47,47,799)]
months[jul2][GA][ec2] = [Poll(46,48,800)]
months[jul2][MI][bl2] = [Poll(53,42,706)]
months[jul2][MI][ec2] = [Poll(45,46,800)]
months[jul2][MI][fo2] = [Poll(43,45,1012)]
months[jul2][NC][bl2] = [Poll(46,48,706)]
months[jul2][NV][bl2] = [Poll(47,45,454)]
months[jul2][PA][bl2] = [Poll(46,50,804)]
months[jul2][PA][fo2] = [Poll(45,43,1034)]
months[jul2][PA][am] = [Poll(45,47,600)]
months[jul2][PA][ec2] = [Poll(46,48,850)]
months[jul2][WI][bl2] = [Poll(49,47,700)]
months[jul2][WI][ec2] = [Poll(47,47,854)]
months[jul2][WI][fo2] = [Poll(46,46,1046)]


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


6 changes: 2 additions & 4 deletions _assets/scripts/insert_jul_pre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ using Statistics
using StatsPlots
using Turing

# const DESIGN_ERROR = .

@enum Month mar apr may jun jul aug sep oct nov
@enum Month mar apr may jun jul jul2 aug sep oct nov

@enum Pollster begin
ag
Expand Down Expand Up @@ -109,6 +107,6 @@ months[jul][WI][yg] = [Poll(39,43,900)]


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


18 changes: 9 additions & 9 deletions _assets/scripts/polls.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
@enum State PA GA NC MI AZ WI NV
@enum Month mar apr may jun jul aug sep oct
@enum Month mar apr may jun jul jul2 aug sep oct


STATE = State
prior_month = "jun"
mon = jul
MON = "jul"
Mon = "jul"
st = "NV"
ST = NV
prior_month = "jul"
mon = jul2
MON = "jul2"
Mon = "jul2"
st = "AZ"
ST = AZ

include("polls_head.jl")
#include("polls_head.jl")
prior_poll = BSON.load("../objs/"*"$st"*"_"*"$prior_month"*"_p_sample.bson")
@load "../objs/"*"$MON"*"_pre_polls.bson" months
@load "../objs/"*"$MON"*"_polls.bson" months

current_month = remove_empties(months[mon])

Expand Down
11 changes: 8 additions & 3 deletions _assets/scripts/polls_head.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ using Serialization
using Statistics
using StatsPlots
using Turing




#------------------------------------------------------------------


Expand Down Expand Up @@ -93,7 +97,7 @@ end
struct Poll
biden_support::Float64
trump_support::Float64
sample_size::Int
sample_size::Int64
end
#------------------------------------------------------------------
Month_names = Dict(
Expand All @@ -102,12 +106,13 @@ Month_names = Dict(
"may" => "May",
"jun" => "June",
"jul" => "July",
"jul2" => "July-post",
"aug" => "August",
"sep" => "September",
"oct" => "October")
#------------------------------------------------------------------
margins = CSV.read("../objs/margins.csv", DataFrame)
margin = first(margins[margins.st .== st, :pct])
margin = first(margins[margins.st .== st, :pct])
#------------------------------------------------------------------
"""
filter_empty_entries(dict::Dict{Pollster, Vector{Poll}}) -> Dict{Pollster, Vector{Poll}}
Expand Down Expand Up @@ -197,7 +202,7 @@ function draw_density()
fig = Figure(size = (600, 400))

# Add an axis to the figure
ax = Axis(fig[1, 1], xlabel = "Likelihood of Biden win", ylabel = "Number of draws", title = "Model: Biden results in $ST from 2020 election and polling through " * Month_names[Mon])
ax = Axis(fig[1, 1], xlabel = "Likelihood of Harris win", ylabel = "Number of draws", title = "Model: Harris results in $ST from 2020 election and polling through " * Month_names[Mon])

# Plot the full density curve
lines!(ax, kde_result.x, kde_result.density, color = "#a3b35c", linewidth = 3, strokewidth = 4, strokecolor = GREENBAR, label = "Draws")
Expand Down
Loading

0 comments on commit 1229c4b

Please sign in to comment.