diff --git a/_assets/img/models/AZ_2020.png b/_assets/img/models/AZ_2020.png index 5138b87..047fed4 100644 Binary files a/_assets/img/models/AZ_2020.png and b/_assets/img/models/AZ_2020.png differ diff --git a/_assets/img/models/AZ_apr.png b/_assets/img/models/AZ_apr.png index 814391e..9b644f9 100644 Binary files a/_assets/img/models/AZ_apr.png and b/_assets/img/models/AZ_apr.png differ diff --git a/_assets/img/models/AZ_mar.png b/_assets/img/models/AZ_mar.png index a0a786c..c5b085e 100644 Binary files a/_assets/img/models/AZ_mar.png and b/_assets/img/models/AZ_mar.png differ diff --git a/_assets/img/models/AZ_may.png b/_assets/img/models/AZ_may.png new file mode 100644 index 0000000..993b119 Binary files /dev/null and b/_assets/img/models/AZ_may.png differ diff --git a/_assets/img/models/GA_2020.png b/_assets/img/models/GA_2020.png index 8969f65..388e653 100644 Binary files a/_assets/img/models/GA_2020.png and b/_assets/img/models/GA_2020.png differ diff --git a/_assets/img/models/GA_apr.png b/_assets/img/models/GA_apr.png index b5750f0..ea6b66a 100644 Binary files a/_assets/img/models/GA_apr.png and b/_assets/img/models/GA_apr.png differ diff --git a/_assets/img/models/GA_mar.png b/_assets/img/models/GA_mar.png index 51cef58..c08fd5c 100644 Binary files a/_assets/img/models/GA_mar.png and b/_assets/img/models/GA_mar.png differ diff --git a/_assets/img/models/MI_2020.png b/_assets/img/models/MI_2020.png index 53b5af0..994710b 100644 Binary files a/_assets/img/models/MI_2020.png and b/_assets/img/models/MI_2020.png differ diff --git a/_assets/img/models/MI_apr.png b/_assets/img/models/MI_apr.png index 96685db..3f44722 100644 Binary files a/_assets/img/models/MI_apr.png and b/_assets/img/models/MI_apr.png differ diff --git a/_assets/img/models/MI_mar.png b/_assets/img/models/MI_mar.png index 1b2f278..7c4bc83 100644 Binary files a/_assets/img/models/MI_mar.png and b/_assets/img/models/MI_mar.png differ diff --git a/_assets/img/models/MI_may.png b/_assets/img/models/MI_may.png new file mode 100644 index 0000000..8a029e9 Binary files /dev/null and b/_assets/img/models/MI_may.png differ diff --git a/_assets/img/models/NC_2020.png b/_assets/img/models/NC_2020.png index 3121c0c..c91e207 100644 Binary files a/_assets/img/models/NC_2020.png and b/_assets/img/models/NC_2020.png differ diff --git a/_assets/img/models/NC_apr.png b/_assets/img/models/NC_apr.png index 11c9b38..74f2664 100644 Binary files a/_assets/img/models/NC_apr.png and b/_assets/img/models/NC_apr.png differ diff --git a/_assets/img/models/NC_mar.png b/_assets/img/models/NC_mar.png index 2c3215f..52cdafb 100644 Binary files a/_assets/img/models/NC_mar.png and b/_assets/img/models/NC_mar.png differ diff --git a/_assets/img/models/NC_may.png b/_assets/img/models/NC_may.png new file mode 100644 index 0000000..02293f5 Binary files /dev/null and b/_assets/img/models/NC_may.png differ diff --git a/_assets/img/models/NV_2020.png b/_assets/img/models/NV_2020.png index a0be53e..bf55a9f 100644 Binary files a/_assets/img/models/NV_2020.png and b/_assets/img/models/NV_2020.png differ diff --git a/_assets/img/models/NV_mar.png b/_assets/img/models/NV_mar.png index 9f71c58..c1c70ba 100644 Binary files a/_assets/img/models/NV_mar.png and b/_assets/img/models/NV_mar.png differ diff --git a/_assets/img/models/NV_may.png b/_assets/img/models/NV_may.png new file mode 100644 index 0000000..ce711f2 Binary files /dev/null and b/_assets/img/models/NV_may.png differ diff --git a/_assets/img/models/PA_2020.png b/_assets/img/models/PA_2020.png index 9564030..f013ccf 100644 Binary files a/_assets/img/models/PA_2020.png and b/_assets/img/models/PA_2020.png differ diff --git a/_assets/img/models/PA_apr.png b/_assets/img/models/PA_apr.png index ccc05cb..6312b19 100644 Binary files a/_assets/img/models/PA_apr.png and b/_assets/img/models/PA_apr.png differ diff --git a/_assets/img/models/PA_mar.png b/_assets/img/models/PA_mar.png index 50a6035..d293af9 100644 Binary files a/_assets/img/models/PA_mar.png and b/_assets/img/models/PA_mar.png differ diff --git a/_assets/img/models/PA_may.png b/_assets/img/models/PA_may.png new file mode 100644 index 0000000..f4b64bb Binary files /dev/null and b/_assets/img/models/PA_may.png differ diff --git a/_assets/img/models/WI_2020.png b/_assets/img/models/WI_2020.png index 4956c94..c7acfc0 100644 Binary files a/_assets/img/models/WI_2020.png and b/_assets/img/models/WI_2020.png differ diff --git a/_assets/img/models/WI_apr.png b/_assets/img/models/WI_apr.png index e04d243..0147abb 100644 Binary files a/_assets/img/models/WI_apr.png and b/_assets/img/models/WI_apr.png differ diff --git a/_assets/img/models/WI_mar.png b/_assets/img/models/WI_mar.png index d2c675e..94e821f 100644 Binary files a/_assets/img/models/WI_mar.png and b/_assets/img/models/WI_mar.png differ diff --git a/_assets/img/models/WI_may.png b/_assets/img/models/WI_may.png new file mode 100644 index 0000000..e4b67a3 Binary files /dev/null and b/_assets/img/models/WI_may.png differ diff --git a/_assets/meta_cohort_2020.bson b/_assets/meta_cohort_2020.bson deleted file mode 100644 index cb90ef8..0000000 Binary files a/_assets/meta_cohort_2020.bson and /dev/null differ diff --git a/_assets/meta_cohort_2022.bson b/_assets/meta_cohort_2022.bson deleted file mode 100644 index 627a91d..0000000 Binary files a/_assets/meta_cohort_2022.bson and /dev/null differ diff --git a/_assets/objs/AZ_2020_p_sample.bson b/_assets/objs/AZ_2020_p_sample.bson index d03065a..a6259ac 100644 Binary files a/_assets/objs/AZ_2020_p_sample.bson and b/_assets/objs/AZ_2020_p_sample.bson differ diff --git a/_assets/objs/AZ_apr_p_sample.bson b/_assets/objs/AZ_apr_p_sample.bson index 57aa2c7..c60c96e 100644 Binary files a/_assets/objs/AZ_apr_p_sample.bson and b/_assets/objs/AZ_apr_p_sample.bson differ diff --git a/_assets/objs/AZ_mar_p_sample.bson b/_assets/objs/AZ_mar_p_sample.bson index 27860a2..bfe3ce4 100644 Binary files a/_assets/objs/AZ_mar_p_sample.bson and b/_assets/objs/AZ_mar_p_sample.bson differ diff --git a/_assets/objs/AZ_may_p_sample.bson b/_assets/objs/AZ_may_p_sample.bson new file mode 100644 index 0000000..d2f62d5 Binary files /dev/null and b/_assets/objs/AZ_may_p_sample.bson differ diff --git a/_assets/objs/GA_2020_p_sample.bson b/_assets/objs/GA_2020_p_sample.bson index 5e3074e..8b555a3 100644 Binary files a/_assets/objs/GA_2020_p_sample.bson and b/_assets/objs/GA_2020_p_sample.bson differ diff --git a/_assets/objs/GA_apr_p_sample.bson b/_assets/objs/GA_apr_p_sample.bson index eddde2a..86b0c65 100644 Binary files a/_assets/objs/GA_apr_p_sample.bson and b/_assets/objs/GA_apr_p_sample.bson differ diff --git a/_assets/objs/GA_mar_p_sample.bson b/_assets/objs/GA_mar_p_sample.bson index e89cff4..9eb1e60 100644 Binary files a/_assets/objs/GA_mar_p_sample.bson and b/_assets/objs/GA_mar_p_sample.bson differ diff --git a/_assets/objs/MI_2020_p_sample.bson b/_assets/objs/MI_2020_p_sample.bson index 7b901a5..8a7d394 100644 Binary files a/_assets/objs/MI_2020_p_sample.bson and b/_assets/objs/MI_2020_p_sample.bson differ diff --git a/_assets/objs/MI_apr_p_sample.bson b/_assets/objs/MI_apr_p_sample.bson index 8094a5e..f2efc2d 100644 Binary files a/_assets/objs/MI_apr_p_sample.bson and b/_assets/objs/MI_apr_p_sample.bson differ diff --git a/_assets/objs/MI_mar_p_sample.bson b/_assets/objs/MI_mar_p_sample.bson index 6a4d8bd..1b6b7eb 100644 Binary files a/_assets/objs/MI_mar_p_sample.bson and b/_assets/objs/MI_mar_p_sample.bson differ diff --git a/_assets/objs/MI_may_p_sample.bson b/_assets/objs/MI_may_p_sample.bson new file mode 100644 index 0000000..3b38f9e Binary files /dev/null and b/_assets/objs/MI_may_p_sample.bson differ diff --git a/_assets/objs/NC_2020_p_sample.bson b/_assets/objs/NC_2020_p_sample.bson index 93ec133..e2abe7a 100644 Binary files a/_assets/objs/NC_2020_p_sample.bson and b/_assets/objs/NC_2020_p_sample.bson differ diff --git a/_assets/objs/NC_apr_p_sample.bson b/_assets/objs/NC_apr_p_sample.bson index 76afdaf..5c0136b 100644 Binary files a/_assets/objs/NC_apr_p_sample.bson and b/_assets/objs/NC_apr_p_sample.bson differ diff --git a/_assets/objs/NC_mar_p_sample.bson b/_assets/objs/NC_mar_p_sample.bson index 7ff9533..b06cc40 100644 Binary files a/_assets/objs/NC_mar_p_sample.bson and b/_assets/objs/NC_mar_p_sample.bson differ diff --git a/_assets/objs/NC_may_p_sample.bson b/_assets/objs/NC_may_p_sample.bson new file mode 100644 index 0000000..adb6791 Binary files /dev/null and b/_assets/objs/NC_may_p_sample.bson differ diff --git a/_assets/objs/NV_2020_p_sample.bson b/_assets/objs/NV_2020_p_sample.bson index 5ec3c37..877b6e5 100644 Binary files a/_assets/objs/NV_2020_p_sample.bson and b/_assets/objs/NV_2020_p_sample.bson differ diff --git a/_assets/objs/NV_mar_p_sample.bson b/_assets/objs/NV_mar_p_sample.bson index d35fc54..c588910 100644 Binary files a/_assets/objs/NV_mar_p_sample.bson and b/_assets/objs/NV_mar_p_sample.bson differ diff --git a/_assets/objs/NV_may_p_sample.bson b/_assets/objs/NV_may_p_sample.bson new file mode 100644 index 0000000..601b0ae Binary files /dev/null and b/_assets/objs/NV_may_p_sample.bson differ diff --git a/_assets/objs/PA_2020_p_sample.bson b/_assets/objs/PA_2020_p_sample.bson index 68374b6..f2621bf 100644 Binary files a/_assets/objs/PA_2020_p_sample.bson and b/_assets/objs/PA_2020_p_sample.bson differ diff --git a/_assets/objs/PA_apr_p_sample.bson b/_assets/objs/PA_apr_p_sample.bson index 1033259..9b5714e 100644 Binary files a/_assets/objs/PA_apr_p_sample.bson and b/_assets/objs/PA_apr_p_sample.bson differ diff --git a/_assets/objs/PA_mar_p_sample.bson b/_assets/objs/PA_mar_p_sample.bson index b5ee252..34eb1de 100644 Binary files a/_assets/objs/PA_mar_p_sample.bson and b/_assets/objs/PA_mar_p_sample.bson differ diff --git a/_assets/objs/PA_may_p_sample.bson b/_assets/objs/PA_may_p_sample.bson new file mode 100644 index 0000000..a85a1c7 Binary files /dev/null and b/_assets/objs/PA_may_p_sample.bson differ diff --git a/_assets/objs/WI_2020_p_sample.bson b/_assets/objs/WI_2020_p_sample.bson index c92d56e..a47a6bb 100644 Binary files a/_assets/objs/WI_2020_p_sample.bson and b/_assets/objs/WI_2020_p_sample.bson differ diff --git a/_assets/objs/WI_apr_p_sample.bson b/_assets/objs/WI_apr_p_sample.bson index 0e81749..edcbb81 100644 Binary files a/_assets/objs/WI_apr_p_sample.bson and b/_assets/objs/WI_apr_p_sample.bson differ diff --git a/_assets/objs/WI_mar_p_sample.bson b/_assets/objs/WI_mar_p_sample.bson index 50d8c38..c892bef 100644 Binary files a/_assets/objs/WI_mar_p_sample.bson and b/_assets/objs/WI_mar_p_sample.bson differ diff --git a/_assets/objs/WI_may_p_sample.bson b/_assets/objs/WI_may_p_sample.bson new file mode 100644 index 0000000..d9bb3fd Binary files /dev/null and b/_assets/objs/WI_may_p_sample.bson differ diff --git a/_assets/election_priors.csv b/_assets/objs/election_priors similarity index 85% rename from _assets/election_priors.csv rename to _assets/objs/election_priors index 413f82e..6378d59 100644 --- a/_assets/election_priors.csv +++ b/_assets/objs/election_priors @@ -1,4 +1,4 @@ -st,biden_pop,tot +st,num_wins,num_votes AZ,1672143,3333829 GA,2473633,4935487 MI,2804040,5453892 diff --git a/_assets/objs/may_polls.bson b/_assets/objs/may_polls.bson new file mode 100644 index 0000000..71bedd3 Binary files /dev/null and b/_assets/objs/may_polls.bson differ diff --git a/_assets/scripts/election_priors.jl b/_assets/scripts/election_priors.jl index c064f2a..9f656eb 100644 --- a/_assets/scripts/election_priors.jl +++ b/_assets/scripts/election_priors.jl @@ -8,4 +8,4 @@ election_priors = election_priors[:,[1,2,3]] election_priors.tot = election_priors.biden_pop .+ election_priors.trump_pop election_priors = election_priors[:,[:st,:biden_pop,:tot]] rename!(election_priors,["st","num_wins","num_votes"]) -# CSV.write("../objs/election_priors.jl",election_priors) \ No newline at end of file +# CSV.write("../objs/election_priors",election_priors) \ No newline at end of file diff --git a/_assets/scripts/first_posterior.jl b/_assets/scripts/first_posterior.jl index c5227b5..653ac28 100644 --- a/_assets/scripts/first_posterior.jl +++ b/_assets/scripts/first_posterior.jl @@ -2,43 +2,43 @@ include("first_posterior_forepart.jl") # Set the number of votes and wins last_election = CSV.read("../objs/election_priors.csv", DataFrame) - -ST = last_election[1, :st] -num_wins = last_election[1, :num_wins] -num_votes = last_election[1, :num_votes] +#------------------------------------------------------------------ +# row indexed to state in alpha order; repeat for each of 1:7 +#------------------------------------------------------------------ +ST = last_election[4, :st] +num_wins = last_election[4, :num_wins] +num_votes = last_election[4, :num_votes] margins = CSV.read("../objs/margins.csv", DataFrame) margin = first(margins[margins.st .== ST, :pct]) -chain = sample(election_model(num_votes, num_wins), sampler, num_samples, init_params=init_params) - -p_intv = quantile(chain[:p], [0.025, 0.975]) -p_mean = summarystats(chain)[1, :mean] -p_mcse = summarystats(chain)[1, :mcse] -p_rhat = summarystats(chain)[1, :rhat] -p_df = DataFrame(median = median(chain[:p]), - mean = mean(chain[:p]), - mode = mode(chain[:p]), - q025 = p_intv[1], - q975 = p_intv[2], - mcse = summarystats(chain)[1, :mcse], - rhat = summarystats(chain)[1, :rhat]) - -# Extract the :p parameter from the chain object -p_samples = chain[:p] - -# Flatten the p_samples array into a 1D vector -p_vec = vec(p_samples) - -# Compute the density estimate +chain = sample(election_model(num_votes, num_wins), sampler, + num_samples, init_params=init_params) + +p_intv = quantile(chain[:p], [0.025, 0.975]) +p_mean = summarystats(chain)[1, :mean] +p_mcse = summarystats(chain)[1, :mcse] +p_rhat = summarystats(chain)[1, :rhat] +p_df = DataFrame(median = median(chain[:p]), + mean = mean(chain[:p]), + mode = mode(chain[:p]), + q025 = p_intv[1], + q975 = p_intv[2], + mcse = summarystats(chain)[1, :mcse], + rhat = summarystats(chain)[1, :rhat]) + +p_samples = chain[:p] +p_vec = vec(p_samples) kde_result = kde(p_vec) include("first_posterior_aftpart.jl") -# Display posterior density plot + posterior_interval = p_intv -fig = draw_density() -deep = deepcopy(chain) +fig = draw_density() +deep = deepcopy(chain) + @save ("../objs/$ST" * "_2020_p_sample.bson") deep save(("../img/models/$ST" * "_2020.png"), fig) + out = Vector(p_df[1,:]) out = round.(out,digits = 4) p_df[1,:] = out diff --git a/_assets/scripts/first_posterior_aftpart.jl b/_assets/scripts/first_posterior_aftpart.jl index d5181a2..baaac9b 100644 --- a/_assets/scripts/first_posterior_aftpart.jl +++ b/_assets/scripts/first_posterior_aftpart.jl @@ -31,7 +31,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 wins in $ST from 2020 election before polling") + ax = Axis(fig[1, 1], xlabel = "Likelihood of Biden win", ylabel = "Number of draws", title = "Model: Biden results in $ST from 2020 election before polling") # Plot the full density curve lines!(ax, kde_result.x, kde_result.density, color = "#a3b35c", linewidth = 3, strokewidth = 4, strokecolor = GREENBAR, label = "Draws") diff --git a/_assets/scripts/first_posterior_forepart.jl b/_assets/scripts/first_posterior_forepart.jl index ea3f06a..db0b031 100644 --- a/_assets/scripts/first_posterior_forepart.jl +++ b/_assets/scripts/first_posterior_forepart.jl @@ -23,20 +23,16 @@ const LORANGE = "rgb(225, 170, 110)" # Define the model @model function election_model(num_votes::Int64, num_wins::Int64) # Prior: Beta(2, 2) equivalent to a close race going in - p ~ Beta(2, 2) - - # Likelihood: Binomial(num_votes, p) + p ~ Beta(2,2) + # Likelihood num_wins ~ Binomial(num_votes, p) end -# Set up the sampler sampler = NUTS(0.65) - -# Specify the number of samples and chains num_samples = 10000 num_chains = 4 -# Sample from the posterior + init_params = [Dict(:p => 0.5)] Month_names = Dict( diff --git a/_assets/scripts/insert_may.jl b/_assets/scripts/insert_may.jl index e211c77..cf0e15f 100644 --- a/_assets/scripts/insert_may.jl +++ b/_assets/scripts/insert_may.jl @@ -7,7 +7,7 @@ using Statistics using StatsPlots using Turing -const DESIGN_ERROR = 0.012 +# const DESIGN_ERROR = 0.012 @enum Month mar apr may jun jul aug sep oct nov @@ -28,14 +28,18 @@ const DESIGN_ERROR = 0.012 fo3 hi2 hi3 + hp2 ma2 ma3 mi2 mi3 mr2 mr3 + ny2 qi2 qi3 + si2 + si3 sp2 sp3 su2 @@ -58,28 +62,30 @@ end @load "../objs/apr_polls.bson" months -""" -months[may][AZ][bl2] = [Poll(43,49, 801)] -months[may][AZ][ec2] = [Poll(44,48,1000)] -months[may][GA][bl2] = [Poll(45,47, 802)] -months[may][GA][ec2] = [Poll(44,47,1000)] -months[may][GA][fo2] = [Poll(45,51,1128)] -months[may][MI][bi2] = [Poll(43,51, 708)] -months[may][MI][ec2] = [Poll(44,45,1000)] -months[may][MI][fo2] = [Poll(46,49,1106)] -months[may][MI][mr2] = [Poll(46,42, 600)] -months[may][NC][ec2] = [Poll(42,47,1000)] -months[may][NC][bl2] = [Poll(41,51, 703)] -months[may][NC][ma2] = [Poll(43,49, 645)] -months[may][NC][qi2] = [Poll(46,48,1401)] -months[may][NV][ec2] = [Poll(44,45,1000)] -months[may][PA][bi2] = [Poll(46,47, 803)] -months[may][PA][ec2] = [Poll(45,47,1000)] -months[may][WI][bl2] = [Poll(44,48, 703)] -months[may][WI][ec2] = [Poll(45,47,1000)] -""" +months[may][AZ][bl2] = [Poll(44,49, 795)] +months[may][GA][bl2] = [Poll(44,47, 795)] +months[may][MI][bl3] = [Poll(40,44, 704)] +months[may][NC][bl2] = [Poll(42,49, 704)] +months[may][WI][bl2] = [Poll(46,47, 693)] +months[may][NV][bl2] = [Poll(47,47, 459)] +months[may][PA][bl2] = [Poll(46,48, 812)] +months[may][AZ][ec2] = [Poll(42,49, 626)] +months[may][GA][ec2] = [Poll(39,49, 604)] +months[may][MI][ec2] = [Poll(36,38, 616)] +months[may][NV][ec2] = [Poll(38,50, 614)] +months[may][PA][ec2] = [Poll(44,47,1023)] +months[may][WI][ec2] = [Poll(47,45, 614)] +months[may][NC][hp2] = [Poll(43,48,1002)] months[may][WI][qi2] = [Poll(50,44,1497)] +months[may][AZ][si2] = [Poll(42,49, 626)] +months[may][GA][si2] = [Poll(39,49, 604)] +months[may][MI][si3] = [Poll(36,38, 616)] +months[may][NV][si2] = [Poll(38,50, 614)] +months[may][PA][si2] = [Poll(44,47,1023)] +months[may][WI][si2] = [Poll(47,45, 614)] -# @save "../objs/may_polls.bson" months + +# needs to be done manually rather than with include() +#@save "../objs/may_polls.bson" months diff --git a/_assets/scripts/mar_poll.jl b/_assets/scripts/mar_poll.jl new file mode 100644 index 0000000..017ce40 --- /dev/null +++ b/_assets/scripts/mar_poll.jl @@ -0,0 +1,20 @@ +@enum State PA GA NC MI AZ WI NV +@enum Month mar apr may jun jul aug sep oct + + +STATE = State +prior_month = "mar" +mon = mar +MON = "mar" +Mon = "mar" +st = "NV" +ST = NV + +include("mar_poll_head.jl") +prior_poll = BSON.load("../objs/"*"$st"*"_2020_p_sample.bson") +@load "../objs/"*"$MON"*"_Polls.bson" months + +current_month = remove_empties(months[mon]) + +include("polls_foot.jl") + diff --git a/_assets/scripts/mar_poll_foot.jl b/_assets/scripts/mar_poll_foot.jl new file mode 100644 index 0000000..76a92aa --- /dev/null +++ b/_assets/scripts/mar_poll_foot.jl @@ -0,0 +1,72 @@ + +@model function poll_model(num_votes::Int64, num_wins::Int64, prior_dist::Distribution) + # Define the prior using the informed prior distribution + p ~ prior_dist + # Define the likelihood with additional uncertainty + num_wins ~ Binomial(num_votes, p) +end + +processed_polls = Dict(state => + Dict(pollster => + process_polls(polls) for (pollster, polls) in pollsters) + for (state, pollsters) in current_month) + +processed_polls_totals = Dict(state => + Dict("num_wins" => + sum(first(values(polls)) for polls in values(pollsters)), + "num_votes" => + sum(last(values(polls)) for polls in values(pollsters))) + for (state, pollsters) in processed_polls) + +num_wins = processed_polls_totals[ST]["num_wins"] +num_votes = processed_polls_totals[ST]["num_votes"] + +poll_posterior = prior_poll + +posterior_mean = mean(poll_posterior[:deep][:p]) +posterior_var = var(poll_posterior[:deep][:p]) +prior_alpha = posterior_mean * + (posterior_mean * (1 - posterior_mean) / posterior_var - 1) +prior_beta = (1 - posterior_mean) * (posterior_mean * + (1 - posterior_mean) / posterior_var - 1) +prior_dist = Beta(prior_alpha, prior_beta) + +model = poll_model(num_votes, num_wins, prior_dist) +sampler = NUTS(0.65) +num_samples = 10000 +num_chains = 4 +init_params = [Dict(:p => 0.5)] +chain = sample(poll_model(num_votes, num_wins, prior_dist), + sampler, num_samples, init_params=init_params) + +p_intv = quantile(chain[:p], [0.025, 0.975]) +p_mean = summarystats(chain)[1,:mean] +p_mcse = summarystats(chain)[1,:mcse] +p_rhat = summarystats(chain)[1,:rhat] +p_df = DataFrame(median = median(chain[:p]), + mean = mean(chain[:p]), + mode = mode(chain[:p]), + q025 = p_intv[1], + q975 = p_intv[2], + mcse = summarystats(chain)[1,:mcse], + rhat = summarystats(chain)[1,:rhat]) + +p_samples = chain[:p] +p_vec = vec(p_samples) +kde_result = kde(p_vec) + +posterior_interval = p_intv +fig = draw_density() +save(("../img/models/"*"$st"*"_"*"$mon"*".png"), fig) + +deep = deepcopy(chain) +@save "../objs/"*"$st"*"_"*"$mon"*"_p_sample.bson" deep + +out = Vector(p_df[1,:]) +out = round.(out,digits = 4) +p_df[1,:] = out +pretty_table(p_df,backend=Val(:html),show_subheader = false) +chain +summarystats(chain) +autocor(chain) +hpd(chain) \ No newline at end of file diff --git a/_assets/scripts/mar_poll_head.jl b/_assets/scripts/mar_poll_head.jl new file mode 100644 index 0000000..adb16b9 --- /dev/null +++ b/_assets/scripts/mar_poll_head.jl @@ -0,0 +1,215 @@ +using BSON: @load, @save +using BSON +using Colors +using Combinatorics +using CSV +using DataFrames +using Distributions +using Format +using HTTP +using GLMakie +using KernelDensity +using LinearAlgebra +using MCMCChains +using Missings +using PlotlyJS +using Plots +using PrettyTables +using Printf +using Serialization +using Statistics +using StatsPlots +using Turing +#------------------------------------------------------------------ + + +# @enum State PA GA NC MI AZ WI NV +# STATE = State +@enum Pollster begin + bi2 + bi3 + bl2 + bl3 + cb2 + cb3 + cn2 + cn3 + ec2 + ec3 + fm2 + fm3 + fo2 + fo3 + hi2 + hi3 + ma2 + ma3 + mi2 + mi3 + mr2 + mr3 + qi2 + qi3 + si2 + si3 + sp2 + sp3 + su2 + su3 + wa2 + wa3 + ws2 + ws3l + ws3s +end +#------------------------------------------------------------------ +const states = ["NV", "WI", "AZ", "GA", "MI", "PA", "NC"] +const FLAGRED = "rgb(178, 34, 52)" +const FLAGBLUE = "rgb( 60, 59, 110)" +const PURPLE = "rgb(119, 47, 81)" +const GREENBAR = "rgb( 47, 119, 78)" +const LORANGE = "rgb(225, 170, 110)" +#------------------------------------------------------------------ +mutable struct MetaFrame + meta::Dict{Symbol, Any} + data::DataFrame +end +#------------------------------------------------------------------ +struct Poll + biden_support::Float64 + trump_support::Float64 + sample_size::Int +end +#------------------------------------------------------------------ +Month_names = Dict( + "mar" => "March", + "apr" => "April", + "may" => "May", + "jun" => "June", + "aug" => "August", + "sep" => "September", + "oct" => "October") +#------------------------------------------------------------------ +margins = CSV.read("../objs/margins.csv", DataFrame) +margin = first(margins[margins.st .== st, :pct]) +#------------------------------------------------------------------ +""" + filter_empty_entries(dict::Dict{Pollster, Vector{Poll}}) -> Dict{Pollster, Vector{Poll}} + +Filter out entries in a dictionary where the values are empty vectors. + +# Arguments +- `dict::Dict{Pollster, Vector{Poll}}`: A dictionary where the keys are of type `Pollster` and the values are vectors of type `Poll`. + +# Returns +- `Dict{Pollster, Vector{Poll}}`: A new dictionary containing only the entries from the input dictionary where the vectors are not empty. + +# Description +The `filter_empty_entries` function iterates over each key-value pair in the provided dictionary. It constructs a new dictionary that includes only those entries where the value (a vector of `Poll` objects) is not empty. + +# Example +```julia +# Define types for the example +struct Pollster + name::String +end + +struct Poll + question::String + response::String +end + +# Create a dictionary with some empty and non-empty vectors +pollster1 = Pollster("Pollster A") +pollster2 = Pollster("Pollster B") +poll1 = Poll("Question 1", "Response 1") +poll2 = Poll("Question 2", "Response 2") + +dict = Dict( + pollster1 => [poll1, poll2], + pollster2 => [] +) + +# Filter out entries with empty vectors +filtered_dict = filter_empty_entries(dict) +println(filtered_dict) +# Output: +# Dict{Pollster, Vector{Poll}} with 1 entry: +# Pollster("Pollster A") => Poll[Poll("Question 1", "Response 1"), Poll("Question 2", "Response 2")] +""" +function remove_empties(the_month::Dict) + Dict(state => Dict(pollster => polls for (pollster, polls) in pollsters + if !isempty(polls)) for (state, pollsters) in the_month) +end +#------------------------------------------------------------------ +function process_polls(polls::Vector{Poll}) + result = Int64.(collect(collect([(p.biden_support, p.sample_size) for p in polls])[1])) + return [Int64(floor(result[1] / 100 * result[2])), result[2]] +end +#------------------------------------------------------------------ + +""" + draw_density() + +Draw a density plot of the parameter `p` with a shaded credible interval. + +# Returns +- `fig`: A `Figure` object containing the density plot. + +# Description +This function creates a density plot of the parameter `p` using the `kde_result` and `p_vec` variables, +which are assumed to be available in the current scope. The plot includes a shaded region representing +the credible interval specified by `posterior_interval`. + +The density curve is plotted in green (`#a3b35c`) with a stroke width of 8. The shaded credible interval +is filled in orange (`#e1aa6e`). + +The x-axis label is set to "p", the y-axis label is set to "Density", and the plot title is set to +"Density Plot of p for $ST", where `$ST` is a string variable assumed to be available in the current scope. + +The x-axis limits are set to the extrema of `p_vec`, and the y-axis limits are set to start from 0. + +A legend is added to the plot using `axislegend(ax)`. + +# Example +```julia +# Assume kde_result, p_vec, posterior_interval, and ST are available in the current scope +fig = draw_density() +""" +function draw_density() + # Create a new figure with specified resolution + 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]) + + # Plot the full density curve + lines!(ax, kde_result.x, kde_result.density, color = "#a3b35c", linewidth = 3, strokewidth = 4, strokecolor = GREENBAR, label = "Draws") + + # Find the indices corresponding to the posterior interval + indices = findall((posterior_interval[1] .<= kde_result.x) .& (kde_result.x .<= posterior_interval[2])) + + # Extract the x and y values within the posterior interval + x_region = kde_result.x[indices] + y_region = kde_result.density[indices] + + # Fill the specific area under the curve + band!(ax, x_region, fill(0, length(x_region)), y_region, color = (LORANGE), label = "Credible Interval") + + # Find the y-value corresponding to the specified x-value + y_value = kde_result.density[argmin(abs.(kde_result.x .- margin))] + + # Add a vertical line at the specified x-value from 0 to the y-value + vlines!(ax, [margin], [0, y_value], color = FLAGBLUE, linestyle = :dash, linewidth = 4, label = "2020 Actual") + + # Add a legend to the plot + axislegend(ax) + + # Adjust the plot limits to fit the density line + Makie.xlims!(ax, extrema(p_vec)) + Makie.ylims!(ax, 0, nothing) + + # Display the figure + fig +end +#------------------------------------------------------------------ \ No newline at end of file diff --git a/naive_prior.jl b/_assets/scripts/naive_prior.jl similarity index 100% rename from naive_prior.jl rename to _assets/scripts/naive_prior.jl diff --git a/_assets/scripts/polls.jl b/_assets/scripts/polls.jl index d4a39d4..c32bc84 100644 --- a/_assets/scripts/polls.jl +++ b/_assets/scripts/polls.jl @@ -1,13 +1,20 @@ @enum State PA GA NC MI AZ WI NV -STATE = State -mon = "apr" -st = "AZ" -ST = AZ -include("polls_head.jl") +@enum Month mar apr may jun jul aug sep oct + -@load "../objs/"*"$mon"*"_Polls.bson" months +STATE = State +prior_month = "apr" +mon = may +MON = "may" +Mon = "may" +st = "WI" +ST = WI + +include("polls_head.jl") +prior_poll = BSON.load("../objs/"*"$st"*"_"*"$prior_month"*"_p_sample.bson") +@load "../objs/"*"$MON"*"_Polls.bson" months -current_month = remove_empties(months[apr]) +current_month = remove_empties(months[mon]) include("polls_foot.jl") diff --git a/_assets/scripts/polls_foot.jl b/_assets/scripts/polls_foot.jl index 7a8733c..b090c71 100644 --- a/_assets/scripts/polls_foot.jl +++ b/_assets/scripts/polls_foot.jl @@ -1,78 +1,67 @@ -@load "../objs/"*"$mon"*"_Polls.bson" months - -processed_polls = Dict(state => Dict(pollster => process_polls(polls) for (pollster, polls) in pollsters) for (state, pollsters) in current_month) - -processed_polls_totals = Dict(state => Dict( - "num_wins" => sum(first(values(polls)) for polls in values(pollsters)), - "num_votes" => sum(last(values(polls)) for polls in values(pollsters)) -) for (state, pollsters) in processed_polls) - -num_wins = processed_polls_totals[ST]["num_wins"] -num_votes = processed_polls_totals[ST]["num_votes"] - -election_posterior = BSON.load("../objs/"*"$st"*"_2020_p_sample.bson") -posterior_mean = mean(election_posterior[:deep][:p]) -posterior_var = var(election_posterior[:deep][:p]) -prior_alpha = posterior_mean * (posterior_mean * (1 - posterior_mean) / posterior_var - 1) -prior_beta = (1 - posterior_mean) * (posterior_mean * (1 - posterior_mean) / posterior_var - 1) -prior_dist = Beta(prior_alpha, prior_beta) - -# @model function poll_model(num_votes::Int64, num_wins::Int64) -# # Define the prior using the Beta distribution -# p ~ prior_dist -# -# # Define the likelihood -# num_wins ~ Binomial(num_votes, p) -# end - -@model function poll_model(num_votes::Int64, num_wins::Int64) - # Define the prior using the Beta distribution - p ~ Beta(2, 2) +@model function poll_model(num_votes::Int64, num_wins::Int64, prior_dist::Distribution) + # Define the prior using the informed prior distribution + p ~ prior_dist # Define the likelihood with additional uncertainty - p_survey ~ Beta(2, 2) - num_wins ~ Binomial(num_votes, p * p_survey) + num_wins ~ Binomial(num_votes, p) end -# Set up the sampler -sampler = NUTS(0.65) - -# Specify the number of samples and chains -num_samples = 10000 -num_chains = 4 - -# Sample from the posterior -init_params = [Dict(:p => 0.5)] - -chain = sample(poll_model(num_votes, num_wins), sampler, num_samples, init_params=init_params) - +processed_polls = Dict(state => + Dict(pollster => + process_polls(polls) for (pollster, polls) in pollsters) + for (state, pollsters) in current_month) + +processed_polls_totals = Dict(state => + Dict("num_wins" => + sum(first(values(polls)) for polls in values(pollsters)), + "num_votes" => + sum(last(values(polls)) for polls in values(pollsters))) + for (state, pollsters) in processed_polls) + +num_wins = processed_polls_totals[ST]["num_wins"] +num_votes = processed_polls_totals[ST]["num_votes"] + +poll_posterior = prior_poll + +posterior_mean = mean(poll_posterior[:deep][:p]) +posterior_var = var(poll_posterior[:deep][:p]) +prior_alpha = posterior_mean * + (posterior_mean * (1 - posterior_mean) / posterior_var - 1) +prior_beta = (1 - posterior_mean) * (posterior_mean * + (1 - posterior_mean) / posterior_var - 1) +prior_dist = Beta(prior_alpha, prior_beta) + +model = poll_model(num_votes, num_wins, prior_dist) +sampler = NUTS(0.65) +num_samples = 10000 +num_chains = 4 +init_params = [Dict(:p => 0.5)] +chain = sample(poll_model(num_votes, num_wins, prior_dist), + sampler, num_samples, init_params=init_params) + p_intv = quantile(chain[:p], [0.025, 0.975]) -p_mean = summarystats(chain)[1, :mean] -p_mcse = summarystats(chain)[1, :mcse] -p_rhat = summarystats(chain)[1, :rhat] +p_mean = summarystats(chain)[1,:mean] +p_mcse = summarystats(chain)[1,:mcse] +p_rhat = summarystats(chain)[1,:rhat] p_df = DataFrame(median = median(chain[:p]), mean = mean(chain[:p]), mode = mode(chain[:p]), q025 = p_intv[1], q975 = p_intv[2], - mcse = summarystats(chain)[1, :mcse], - rhat = summarystats(chain)[1, :rhat]) - -# Extract the :p parameter from the chain object -p_samples = chain[:p] - -# Flatten the p_samples array into a 1D vector -p_vec = vec(p_samples) + mcse = summarystats(chain)[1,:mcse], + rhat = summarystats(chain)[1,:rhat]) -# Compute the density estimate +p_samples = chain[:p] +p_vec = vec(p_samples) kde_result = kde(p_vec) -# Display posterior density plot posterior_interval = p_intv -fig = draw_density() +fig = draw_density() +save(("../img/models/"*"$st"*"_"*"$mon"*".png"), fig) + deep = deepcopy(chain) @save ("../objs/"*"$st"*"_"*"$mon"*"_p_sample.bson") deep -save(("../img/models/"*"$st"*"_"*"$mon"*".png"), fig) + out = Vector(p_df[1,:]) out = round.(out,digits = 4) p_df[1,:] = out diff --git a/_assets/scripts/polls_head.jl b/_assets/scripts/polls_head.jl index 140a75a..adb16b9 100644 --- a/_assets/scripts/polls_head.jl +++ b/_assets/scripts/polls_head.jl @@ -21,7 +21,8 @@ using Statistics using StatsPlots using Turing #------------------------------------------------------------------ -@enum Month mar apr may jun jul aug sep oct nov + + # @enum State PA GA NC MI AZ WI NV # STATE = State @enum Pollster begin @@ -49,6 +50,8 @@ using Turing mr3 qi2 qi3 + si2 + si3 sp2 sp3 su2 @@ -178,7 +181,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 wins in $ST from 2020 election and polling through " * Month_names[mon]) + 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]) # Plot the full density curve lines!(ax, kde_result.x, kde_result.density, color = "#a3b35c", linewidth = 3, strokewidth = 4, strokecolor = GREENBAR, label = "Draws") diff --git a/_assets/scripts/state_level.jl b/_assets/scripts/state_level.jl index 7b182c9..7a0b71d 100644 --- a/_assets/scripts/state_level.jl +++ b/_assets/scripts/state_level.jl @@ -5,7 +5,7 @@ function filter_empty_entries(dict::Dict{Pollster, Vector{Poll}}) end using BSON: @save, @load -#@load "../objs/apr_polls.bson" months +@load "../objs/may_polls.bson" months MO = may ST = WI @@ -19,8 +19,7 @@ prior_probs[ST] summarystats(current_samples) # Trace plot -plot( -) +plot() # Autocorrelation autocor(current_samples) diff --git a/az.md b/az.md index cdadd17..5304e12 100644 --- a/az.md +++ b/az.md @@ -2,7 +2,7 @@ title = "Arizona" +++ - +* [May assessment](#may-assessment) * [April assessment](#april-assessment) * [March assessment](#march-assessment) * [2020 election](#2020-election) @@ -20,11 +20,12 @@ Assessments are based on three criteria. * **Stringent**—Biden wins if all of the values in the credible interval (analogous to the confidence interval) are equal to or greater than his 2020 margin. * **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. +* **Relaxed**—fewer than 2.5% of the values in the credible interval are less than 50.01% of the two candidate vote. -## April assessment +## May assessment Biden win under the *Relaxed* criterion. + ~~~ @@ -40,13 +41,44 @@ Biden win under the *Relaxed* criterion. + + + + + + + + +
0.50140.5014 0.50150.50090.5020.01.0
+ + + ~~~ +## April assessment + +Biden win under the *Relaxed* criterion. +~~~ + + + + + + + + + + + + + + - - + + + - +
medianmeanmodeq025q975mcserhat
0.5015 0.50150.5010.50210.50130.50090.502 0.01.01.0008
@@ -74,11 +106,12 @@ Biden win under the *Relaxed* criterion. 0.5015 0.5015 - 0.5015 + 0.5014 0.501 0.5021 0.0 - 1.0 + 1.0001 + @@ -104,11 +137,11 @@ Biden win under the *Relaxed* criterion. 0.5016 0.5016 - 0.5017 + 0.5016 0.501 0.5021 0.0 - 1.0006 + 1.0002 diff --git a/bucket_parts.jl b/bucket_parts.jl new file mode 100644 index 0000000..8031076 --- /dev/null +++ b/bucket_parts.jl @@ -0,0 +1,27 @@ +# @model function poll_model(num_votes::Int64, num_wins::Int64) +# # Define the prior using the Beta distribution +# p ~ prior_dist +# +# # Define the likelihood +# num_wins ~ Binomial(num_votes, p) +# end + +# +# election_posterior = BSON.load("../objs/"*"$st"*"_2020_p_sample.bson") +# posterior_mean = mean(election_posterior[:deep][:p]) +# posterior_var = var(election_posterior[:deep][:p]) +# prior_alpha = posterior_mean * +# (posterior_mean * (1 - posterior_mean) / posterior_var - 1) +# prior_beta = (1 - posterior_mean) * (posterior_mean * +# (1 - posterior_mean) / posterior_var - 1) +# prior_dist = Beta(prior_alpha, prior_beta) + +# @model function poll_model(num_votes::Int64, num_wins::Int64, prior_dist::Distribution) +# # Define the prior using the informed prior distribution +# p ~ prior_dist +# +# # Define the likelihood with adjusted survey uncertainty +# p_survey ~ Beta(8, 6) # Adjust the parameters as needed +# p_combined = (p + p_survey) / 2 +# num_wins ~ Binomial(num_votes, p) +# end \ No newline at end of file diff --git a/double.md b/double.md new file mode 100644 index 0000000..e69de29 diff --git a/ga.md b/ga.md index 62ad804..5644ca6 100644 --- a/ga.md +++ b/ga.md @@ -2,6 +2,7 @@ title = "Georgia" +++ +* [May assessment](#may-assessment) * [April assessment](#april-assessment) * [March assessment](#march-assessment) * [2020 election](#2020-election) @@ -12,7 +13,6 @@ title = "Georgia" * [Other news](#other-news) * [Terms](#terms) - In the 2020 election President Biden won 50.12% (0.5012) of the votes cast for Biden or Trump in Georgia. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 50.08% to 50.16%. Next, the results of each month's polling are factored in on a rolling basis. Assessments are based on three criteria. @@ -74,14 +74,13 @@ Biden win under the *Relaxed* criterion. - 0.5012 - 0.5012 - 0.5013 + 0.5011 + 0.5011 + 0.5011 0.5007 0.5016 0.0 - 1.0 - + 1.0 @@ -106,14 +105,13 @@ Biden win under the *Relaxed* criterion. - 0.5012 - 0.5012 - 0.5013 - 0.5008 + 0.5011 + 0.5011 + 0.501 + 0.5007 0.5016 0.0 - 1.0 - + 1.0005 diff --git a/index.md b/index.md index f9360db..6196cb2 100644 --- a/index.md +++ b/index.md @@ -16,7 +16,7 @@ Based on the criterion that the model shows Biden doing at least as well as he d Based on the criterion that the model shows Biden winning by at least 50% plus one vote of the two-candidate split, Biden would six of the seven swing states (having lost in North Carolina), Biden would take 77 electoral votes resulting in a **302-236 Electoral College victory.** -The poll results conducted in the seven swing states in March and April show presidential preference divided, but favoring Trump in more states than Biden. Each of the poll results has a greater or smaller degree of uncertainty that depends primarily on how many answers were collected. +The poll results conducted in the seven swing states in March, April and May show presidential preference divided, but favoring Trump in more states than Biden. Each of the poll results has a greater or smaller degree of uncertainty that depends primarily on how many answers were collected. Taking into account, however, the results of 2020, although there are signs of erosion in Biden's support, the performance is better than the standalone polls would suggest. The model is based on the *Bayesian analysis* described in [Methodology](/method]) It begins with the relative share of the two-candidate popular vote won by Biden in each of the swing states in 2020 adjusted by the effect of polling conducted in April. Beginning next month, the beginning point will be adjusted to reflect a cumulative model in which cumulative results will be reporting. diff --git a/mi.md b/mi.md index afccc1d..5a71b8c 100644 --- a/mi.md +++ b/mi.md @@ -2,6 +2,7 @@ title = "Michigan" +++ +* [May assessment](#may-assessment) * [April assessment](#april-assessment) * [March assessment](#march-assessment) * [2020 election](#2020-election) @@ -10,8 +11,7 @@ title = "Michigan" * [2022 demographics](#2022-demographics) * [Terms](#terms) - - # Model results +# Model results In the 2020 election President Biden won 51.41% (0.5141) of the votes cast for Biden or Trump in Michigan. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 51.36% to 51.45%. Next, the results of each month's polling are factored in on a rolling basis. @@ -21,6 +21,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. +## May assessment + +Biden win under the *Relaxed* criterion. + +~~~ + + + + + + + + + + + + + + + + + + + + + + + +
medianmeanmodeq025q975mcserhat
0.51390.51390.51390.51350.51440.01.0004
+ +~~~ + ## April assessment Biden win under the *Relaxed* criterion. @@ -52,7 +84,7 @@ Biden win under the *Relaxed* criterion. ~~~ -## March polls + ## March assessment @@ -73,13 +105,13 @@ Biden win under the *Relaxed* criterion. + 0.514 + 0.514 0.5141 - 0.5141 - 0.5141 - 0.5137 + 0.5136 0.5145 0.0 - 0.9999 + 1.0 @@ -104,11 +136,11 @@ Biden win under the *Relaxed* criterion. - 0.514 - 0.514 - 0.514 - 0.5136 - 0.5145 + 0.5141 + 0.5141 + 0.5141 + 0.5137 + 0.5146 0.0 1.0002 diff --git a/nc.md b/nc.md index 1b5d999..fced565 100644 --- a/nc.md +++ b/nc.md @@ -11,7 +11,7 @@ title = "North Carolina" * [Terms](#terms) -In the 2020 election President Biden won 49.32% (0.4942) of the votes cast for Biden or Trump in North Carolina. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 50.08% to 50.16%. Next, the results of each month's polling is factored in on a rolling basis +In the 2020 election President Biden won 49.32% (0.4942) of the votes cast for Biden or Trump in North Carolina. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 50.08% to 50.16%, . Next, the results of each month's polling is factored in on a rolling basis Assessments are based on three criteria. @@ -19,7 +19,7 @@ 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. -## April assessment +## May assessment A Biden victory is not within the credible interval under any of the scenarios. @@ -38,10 +38,10 @@ A Biden victory is not within the credible interval under any of the scenarios. - 0.4931 - 0.4931 - 0.4931 - 0.4927 + 0.493 + 0.493 + 0.4929 + 0.4926 0.4935 0.0 1.0 @@ -49,6 +49,37 @@ A Biden victory is not within the credible interval under any of the scenarios. +~~~ +## April assessment + +A Biden victory is not within the credible interval under any of the scenarios. + +~~~ + + + + + + + + + + + + + + + + + + + + + + + +
medianmeanmodeq025q975mcserhat
0.49320.49320.49330.49270.49360.01.0001
+ ~~~ @@ -72,11 +103,11 @@ A Biden victory is not within the credible interval under any of the scenarios. 0.4931 0.4931 - 0.493 - 0.4927 + 0.4929 + 0.4926 0.4935 0.0 - 1.0002 + 1.0004 diff --git a/nv.md b/nv.md index 29a0cb2..7313dcd 100644 --- a/nv.md +++ b/nv.md @@ -2,6 +2,7 @@ title = "Nevada" +++ +* [May assessment](#may-assessment) * [April assessment](#april-assessment) * [March assessment](#march-assessment) * [2020 election](#2020-election) @@ -12,7 +13,7 @@ title = "Nevada" # Model results -In the 2020 election President Biden won 51.22% (0.5122) of the votes cast for Biden or Trump in Nevada. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 51.14% to 51.31%. Next, the results of each month's polling are factored in on a rolling basis +In the 2020 election President Biden won 51.22% (0.5122) of the votes cast for Biden or Trump in Nevada. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 51.1% to 51.3%. Next, the results of each month's polling are factored in on a rolling basis Assessments are based on three criteria. @@ -20,6 +21,42 @@ 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. +## May assessment + +Biden wins under the *Relaxed criterion* +~~~ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
medianmeanmodeq025q975mcserhat
0.5120.5120.51260.51120.51290.01.0
+ + +~~~ + ## April assessment Biden wins under the *Relaxed criterion* @@ -38,13 +75,13 @@ Biden wins under the *Relaxed criterion* - 0.5122 - 0.5122 - 0.5122 - 0.5113 - 0.513 + 0.5031 + 0.5031 + 0.5032 + 0.5026 + 0.5037 0.0 - 1.0 + 1.0003 @@ -73,7 +110,7 @@ Biden wins under the *Relaxed criterion* 0.5122 0.5122 - 0.5123 + 0.512 0.5113 0.513 0.0 diff --git a/pa.md b/pa.md index 842542e..24dbe75 100644 --- a/pa.md +++ b/pa.md @@ -2,6 +2,7 @@ title = "Pennsylvania" +++ +* [May assessment](#may-assessment) * [April assessment](#april-assessment) * [March assessment](#march-assessment) * [2020 election](#2020-election) @@ -12,7 +13,7 @@ title = "Pennsylvania" # Model results -In the 2020 election President Biden won 50.59% (0.5059) of the votes cast for Biden or Trump in Pennsylvania. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 50.55% to 50.63%. Next, the results of each month's polling are factored in on a rolling basis. +In the 2020 election President Biden won 50.59% (0.5059) of the votes cast for Biden or Trump in Pennsylvania. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 50.56% to 50.63%. Next, the results 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 right of the 2020 margin it indicates that Biden is losing ground compared to the 2020 election results, taking the polls at face value. Assessments are based on three criteria. @@ -20,9 +21,9 @@ 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. -## April assessment +## May assessment -Biden wins under the *Relaxed* criterion +Biden win under the *Relaxed* criterion ~~~ @@ -38,16 +39,48 @@ Biden wins under the *Relaxed* criterion - - - - - + + + + +
0.50590.50590.50590.50550.50630.50580.50580.50580.50540.5061 0.0 1.0001
+ + +~~~ + +## April assessment + +Biden win under the *Relaxed* criterion +~~~ + + + + + + + + + + + + + + + + + + + + + + + +
medianmeanmodeq025q975mcserhat
0.50580.50580.50580.50540.50620.01.0009
~~~ @@ -77,8 +110,8 @@ Biden win under the *Relaxed* criterion. 0.5054 0.5062 0.0 - 1.0004 - + 1.0001 + diff --git a/sources.md b/sources.md index 44a5e69..a5ab616 100644 --- a/sources.md +++ b/sources.md @@ -52,23 +52,23 @@ df = CSV.read(IOBuffer(csv_data), DataFrame) *Single State* * Arizona - - [Cook Political Report: conducted May](https://www.cookpolitical.com/survey-research/2024-swing-state-project/23May2024-toplines) - [Fox News: conducted March](https://static.foxnews.com/foxnews.com/content/uploads/2024/03/Fox_March-7-11-2024_Arizona_Topline_March-13-Release.pdf) - [CBS: conducted May](https://www.scribd.com/document/733845819/cbsnews-20240519-AZ-1-SUN#1fullscreen=1) - [Nobel Predictive Insights: conducted May](https://www.scribd.com/document/733845819/cbsnews-20240519-AZ-1-SUN#1fullscreen=1) * Georgia - - [Cook Political Report; conducted May](https://www.cookpolitical.com/survey-research/2024-swing-state-project/unique-election-driven-traditional-issue) - [Fox News: conducted April](https://static.foxnews.com/foxnews.com/content/uploads/2024/04/Fox_April-11-16-2024_GEORGIA_Topline_April-18-Release-1.pdf) * Michigan - [CBS: conducted in April](https://www.scribd.com/document/727317994/Cbsnews-20240428-MI-SUN) - [Fox News: conducted April](https://static.foxnews.com/foxnews.com/content/uploads/2024/04/Fox_April-11-16-2024_MICHIGAN_Topline_April-18-Release.pdf) - [Marketing Resource Group: conducted April](https://www.realclearpolitics.com/docs/2024/michigan-poll-presidential-election-Press_Release.pdf) - [Mitchell Research and Communications: conducted March](https://www.realclearpolitics.com/docs/2024/Mitchell-MIRS_MI_Poll_Press_Release_-_Presidential_Race_12_NOON_3-20-24.pdf) + - [Mitchell Research and Communications: conducted May](https://www.realclearpolitics.com/docs/2024/Mitchell-MIRS_MI_Poll_Press_Release_-_Presidential_Race_517_PM_5-27-24.pdf) - [Quinnipiac University: conducted March](https://poll.qu.edu/poll-release?releaseid=3893) * Pennsylvania - [CBS: conducted April](https://www.scribd.com/document/727318459/Cbsnews-20240428-PA-SUN) - [Franklin & Marshall College Poll: conducted March](https://www.fandmpoll.org/franklin-marshall-poll-release-april-2024) * North Carolina + - [High Point: conduct May](https://www.highpoint.edu/src/files/2023/08/103memo.pdf) - [Marist: conducted March ](https://maristpoll.marist.edu/wp-content/uploads/2024/03/Marist-Poll_North-Carolina-NOS-and-Tables_202403181357.pdf) - [Highpoint University: conducted March](https://www.highpoint.edu/src/files/2023/08/102memo.pdf) - [Highpoint University: conducted May](https://www.highpoint.edu/src/files/2023/08/103memo.pdf) @@ -81,7 +81,7 @@ df = CSV.read(IOBuffer(csv_data), DataFrame) - [Quinnipiac conducted May](https://poll.qu.edu/images/polling/wi/wi05082024_wizz76.pdf) --- -[^3]: Results selected for analysis here are for two-way preference questions if asked, except in cases in which a third-party candidate qualified for the ballot prior to poll. For polls with only multiple choices in addition to Biden and Trump, their respective percentages of responses were recorded. In all cases those percentages were normalized to 100% to reflect the relative, not absolute, support of the two candidates. +[^3]: Results selected for analysis here are for two-way preference questions if asked, except in cases in which Robert F. Kennedy, Jr. qualified for the ballot prior to poll. For polls with only multiple choices in addition to Biden and Trump, their respective percentages of responses were recorded. In all cases those percentages were normalized to 100% to reflect the relative, not absolute, support of the two candidates. --- ## Demographics diff --git a/src/gmt.history b/src/gmt.history new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/gmt.history @@ -0,0 +1 @@ + diff --git a/why7.md b/why7.md index ef2a20e..f3e1b37 100644 --- a/why7.md +++ b/why7.md @@ -85,7 +85,7 @@ Without Biden wins in both North Carolina and Pennsylvania there are only **four ~~~ -All the possible comes (the scenario in which Biden wins none of the swing states is not shown.) +All the possible outcomes (the scenario in which Biden wins none of the swing states is not shown.) ~~~ diff --git a/wi.md b/wi.md index 8dd6076..62530c9 100644 --- a/wi.md +++ b/wi.md @@ -13,7 +13,7 @@ title = "Wisconsin" # Model results -In the 2020 election President Biden won 50.32% (0.5032) of the votes cast for Biden or Trump in Pennsylvania. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 50.27% to 50.37%. Next, the results of each month's polling are factored in on a rolling basis +In the 2020 election President Biden won 50.32% (0.5032) of the votes cast for Biden or Trump in Wisconsin. This leaves out votes for third-party candidates. Taking the actual result as a starting point, the model introduces some uncertainty into the result to create a range of outcomes for that election from 50.27% to 50.37%. Next, the results of each month's polling are factored in on a rolling basis Assessments are based on three criteria. @@ -21,6 +21,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. +## May assessment + +Biden wins under the *Relaxed* criterion. +~~~ +
+ + + + + + + + + + + + + + + + + + + + + + +
medianmeanmodeq025q975mcserhat
0.50310.50310.5030.50260.50370.01.0004
+ + +~~~ + ## April assessment Biden wins under the *Relaxed* criterion. @@ -71,13 +103,13 @@ Biden wins under the *Relaxed* criterion. - 0.5032 - 0.5032 + 0.5031 + 0.5031 0.5032 0.5026 0.5037 0.0 - 1.0 + 1.0003