diff --git a/_assets/objs/2024vote.csv b/_assets/objs/2024vote.csv index f8850c7..e97147e 100644 --- a/_assets/objs/2024vote.csv +++ b/_assets/objs/2024vote.csv @@ -1,57 +1,57 @@ -st,biden_pop,trump_pop,margin,biden_col,trump_col -AK,153778,189951,-36173,0,3 -AL,849624,1441170,-591546,0,9 -AR,423932,760647,-336715,0,6 -AZ,1672143,1661686,10457,11,0 -CA,11110639,6006518,5104121,54,0 -CO,1804352,1364607,439745,10,0 -CT,1080831,714717,366114,7,0 -DC,317323,18586,298737,3,0 -DE,296268,200603,95665,3,0 -FL,5297045,5668731,-371686,0,30 -GA,2473633,2461854,11779,16,0 -HI,366130,196864,169266,4,0 -IA,759061,897672,-138611,0,6 -ID,287021,554119,-267098,0,4 -IL,3471915,2446891,1025024,19,0 -IN,1242498,1729857,-487359,0,11 -KS,570323,771406,-201083,0,6 -KY,772474,1326646,-554172,0,8 -LA,856034,1255776,-399742,0,8 -MA,2382202,1167202,1215000,11,0 -MD,1985023,976414,1008609,10,0 -ME,435072,360737,74335,1,0 -ME1,266376,164045,102331,1,0 -ME2,168696,196692,-27996,0,2 -MI,2804040,2649852,154188,15,0 -MN,1717077,1484065,233012,10,0 -MO,1253014,1718736,-465722,0,10 -MS,539398,756764,-217366,0,6 -MT,244786,343602,-98816,0,4 -NC,2684292,2758775,-74483,0,16 -ND,115042,235751,-120709,0,3 -NE,374583,556846,-182263,0,1 -NE1,132261,180290,-48029,0,1 -NE2,176468,154377,22091,1,0 -NE3,65854,222179,-156325,0,2 -NH,424937,365660,59277,4,0 -NJ,2608400,1883313,725087,14,0 -NM,501614,401894,99720,5,0 -NV,703486,669890,33596,6,0 -NY,5244886,3251997,1992889,28,0 -OH,2679165,3154834,-475669,0,17 -OK,503890,1020280,-516390,0,7 -OR,1340383,958448,381935,8,0 -PA,3458229,3377674,80555,19,0 -RI,307486,199922,107564,4,0 -SC,1091541,1385103,-293562,0,9 -SD,150471,261043,-110572,0,3 -TN,1143711,1852475,-708764,0,11 -TX,5259126,5890347,-631221,0,40 -UT,560282,865140,-304858,0,6 -VA,2413568,1962430,451138,13,0 -VT,242820,112704,130116,3,0 -WA,2369612,1584651,784961,12,0 -WI,1630866,1610184,20682,10,0 -WV,235984,545382,-309398,0,4 -WY,73491,193559,-120068,0,3 +st,biden_pop,trump_pop,margin,biden_col,trump_col,total_pop,pct,slice +AK,153778,189951,-36173,0,3,343729,0.4473815127615069,-0.052618487238493106 +AL,849624,1441170,-591546,0,9,2290794,0.3708862516664528,-0.12911374833354722 +AR,423932,760647,-336715,0,6,1184579,0.3578756672201685,-0.1421243327798315 +AZ,1672143,1661686,10457,11,0,3333829,0.5015683167912931,0.0015683167912931006 +CA,11110639,6006518,5104121,54,0,17117157,0.6490937134011214,0.14909371340112143 +CO,1804352,1364607,439745,10,0,3168959,0.5693831949230015,0.06938319492300149 +CT,1080831,714717,366114,7,0,1795548,0.6019504908807785,0.10195049088077845 +DC,317323,18586,298737,3,0,335909,0.9446695384761944,0.4446695384761944 +DE,296268,200603,95665,3,0,496871,0.5962674416498447,0.09626744164984469 +FL,5297045,5668731,-371686,0,30,10965776,0.48305245337858443,-0.016947546621415566 +GA,2473633,2461854,11779,16,0,4935487,0.5011932966290864,0.0011932966290864044 +HI,366130,196864,169266,4,0,562994,0.6503266464651488,0.15032664646514882 +IA,759061,897672,-138611,0,6,1656733,0.4581673691536295,-0.04183263084637051 +ID,287021,554119,-267098,0,4,841140,0.3412285707492213,-0.1587714292507787 +IL,3471915,2446891,1025024,19,0,5918806,0.5865904373280693,0.08659043732806926 +IN,1242498,1729857,-487359,0,11,2972355,0.4180180362036163,-0.08198196379638367 +KS,570323,771406,-201083,0,6,1341729,0.4250657174436865,-0.07493428255631351 +KY,772474,1326646,-554172,0,8,2099120,0.36799897099737033,-0.13200102900262967 +LA,856034,1255776,-399742,0,8,2111810,0.4053555954370895,-0.09464440456291051 +MA,2382202,1167202,1215000,11,0,3549404,0.6711554954014815,0.17115549540148145 +MD,1985023,976414,1008609,10,0,2961437,0.6702904704709234,0.17029047047092338 +ME,435072,360737,74335,2,0,795809,0.5467040458200397,0.04670404582003973 +ME1,266376,164045,102331,1,0,430421,0.618873149776614,0.118873149776614 +ME2,168696,196692,-27996,0,1,365388,0.4616900390817432,-0.03830996091825678 +MI,2804040,2649852,154188,15,0,5453892,0.5141355934440947,0.014135593444094652 +MN,1717077,1484065,233012,10,0,3201142,0.5363951364856667,0.036395136485666724 +MO,1253014,1718736,-465722,0,10,2971750,0.4216417935559855,-0.07835820644401448 +MS,539398,756764,-217366,0,6,1296162,0.4161501417261114,-0.08384985827388858 +MT,244786,343602,-98816,0,4,588388,0.41602819907951893,-0.08397180092048107 +NC,2684292,2758775,-74483,0,16,5443067,0.49315799346214184,-0.0068420065378581585 +ND,115042,235751,-120709,0,3,350793,0.3279483912164724,-0.1720516087835276 +NE,374583,556846,-182263,0,1,931429,0.40215947753398273,-0.09784052246601727 +NE1,132261,180290,-48029,0,1,312551,0.4231661392860685,-0.0768338607139315 +NE2,176468,154377,22091,1,0,330845,0.5333857244328916,0.03338572443289156 +NE3,65854,222179,-156325,0,2,288033,0.22863352463085826,-0.2713664753691417 +NH,424937,365660,59277,4,0,790597,0.5374887584951625,0.03748875849516253 +NJ,2608400,1883313,725087,14,0,4491713,0.5807138612818762,0.08071386128187619 +NM,501614,401894,99720,5,0,903508,0.5551849015171975,0.05518490151719746 +NV,703486,669890,33596,6,0,1373376,0.512231173400438,0.012231173400438 +NY,5244886,3251997,1992889,28,0,8496883,0.6172717689533915,0.11727176895339153 +OH,2679165,3154834,-475669,0,17,5833999,0.45923302352297285,-0.04076697647702715 +OK,503890,1020280,-516390,0,7,1524170,0.3305996050309349,-0.16940039496906512 +OR,1340383,958448,381935,8,0,2298831,0.5830715698544173,0.08307156985441733 +PA,3458229,3377674,80555,19,0,6835903,0.5058920525934906,0.005892052593490571 +RI,307486,199922,107564,4,0,507408,0.6059935988395926,0.10599359883959258 +SC,1091541,1385103,-293562,0,9,2476644,0.44073391250417904,-0.05926608749582096 +SD,150471,261043,-110572,0,3,411514,0.365652201383185,-0.134347798616815 +TN,1143711,1852475,-708764,0,11,2996186,0.38172229627933646,-0.11827770372066354 +TX,5259126,5890347,-631221,0,40,11149473,0.4716927876322047,-0.02830721236779532 +UT,560282,865140,-304858,0,6,1425422,0.39306394878148365,-0.10693605121851635 +VA,2413568,1962430,451138,13,0,4375998,0.551546869993999,0.051546869993999045 +VT,242820,112704,130116,3,0,355524,0.6829918655280656,0.18299186552806557 +WA,2369612,1584651,784961,12,0,3954263,0.599255031847907,0.09925503184790696 +WI,1630866,1610184,20682,10,0,3241050,0.5031906326653399,0.003190632665339921 +WV,235984,545382,-309398,0,4,781366,0.3020146768607797,-0.1979853231392203 +WY,73491,193559,-120068,0,3,267050,0.27519565624414905,-0.22480434375585095 diff --git a/_assets/scripts/constants.jl b/_assets/scripts/constants.jl index 05b1cfe..0910c80 100644 --- a/_assets/scripts/constants.jl +++ b/_assets/scripts/constants.jl @@ -45,7 +45,7 @@ const TIE = 269 # biden won 6 of the 7 swing states # trump won NC -const BLUE = 225 +const BLUE = 226 const RED = 220 # Create a color scale with discrete colors for each value diff --git a/_assets/scripts/_dat.jl b/_assets/scripts/debris/_dat.jl similarity index 100% rename from _assets/scripts/_dat.jl rename to _assets/scripts/debris/_dat.jl diff --git a/_assets/scripts/aggreg.jl b/_assets/scripts/debris/aggreg.jl similarity index 100% rename from _assets/scripts/aggreg.jl rename to _assets/scripts/debris/aggreg.jl diff --git a/_assets/scripts/all_votes.jl b/_assets/scripts/debris/all_votes.jl similarity index 95% rename from _assets/scripts/all_votes.jl rename to _assets/scripts/debris/all_votes.jl index 25de615..7da706e 100644 --- a/_assets/scripts/all_votes.jl +++ b/_assets/scripts/debris/all_votes.jl @@ -1,4 +1,4 @@ -# find popular votes for all candidates in swing STATES + find popular votes for all candidates in swing STATES # for purpose of applying a finite population correction factor # BUT only in the event of a sample so large as to represent # MORE than 5% of the population; this possibly could be diff --git a/_assets/scripts/alt_swing.jl b/_assets/scripts/debris/alt_swing.jl similarity index 100% rename from _assets/scripts/alt_swing.jl rename to _assets/scripts/debris/alt_swing.jl diff --git a/_assets/scripts/apr_dat.jl b/_assets/scripts/debris/apr_dat.jl similarity index 100% rename from _assets/scripts/apr_dat.jl rename to _assets/scripts/debris/apr_dat.jl diff --git a/_assets/scripts/bayes.jl b/_assets/scripts/debris/bayes.jl similarity index 100% rename from _assets/scripts/bayes.jl rename to _assets/scripts/debris/bayes.jl diff --git a/_assets/scripts/bayes2.jl b/_assets/scripts/debris/bayes2.jl similarity index 98% rename from _assets/scripts/bayes2.jl rename to _assets/scripts/debris/bayes2.jl index da39489..b5ef1ff 100644 --- a/_assets/scripts/bayes2.jl +++ b/_assets/scripts/debris/bayes2.jl @@ -88,8 +88,6 @@ function add_poll!(month::Month, state::State, pollster::Pollster, poll::Poll) push!(months[month][state][pollster], normalized_poll) end -add_poll!(mar, AZ, bl2, Poll(42., 49., 788)) - add_poll!(mar, AZ, bl2, Poll(42., 49., 788)) add_poll!(mar, AZ, ec2, Poll(44., 48., 1000)) add_poll!(mar, AZ, ws2, Poll(44., 47., 600)) diff --git a/_assets/scripts/bayes_head.jl b/_assets/scripts/debris/bayes_head.jl similarity index 100% rename from _assets/scripts/bayes_head.jl rename to _assets/scripts/debris/bayes_head.jl diff --git a/_assets/scripts/bayes_main.jl b/_assets/scripts/debris/bayes_main.jl similarity index 100% rename from _assets/scripts/bayes_main.jl rename to _assets/scripts/debris/bayes_main.jl diff --git a/_assets/scripts/blank_dat.csv b/_assets/scripts/debris/blank_dat.csv similarity index 100% rename from _assets/scripts/blank_dat.csv rename to _assets/scripts/debris/blank_dat.csv diff --git a/_assets/scripts/count_bayes.jl b/_assets/scripts/debris/count_bayes.jl similarity index 100% rename from _assets/scripts/count_bayes.jl rename to _assets/scripts/debris/count_bayes.jl diff --git a/_assets/scripts/election_priors.jl b/_assets/scripts/debris/election_priors.jl similarity index 100% rename from _assets/scripts/election_priors.jl rename to _assets/scripts/debris/election_priors.jl diff --git a/_assets/scripts/fetch_gist.jl b/_assets/scripts/debris/fetch_gist.jl similarity index 100% rename from _assets/scripts/fetch_gist.jl rename to _assets/scripts/debris/fetch_gist.jl diff --git a/_assets/scripts/debris/func.jl b/_assets/scripts/debris/func.jl index d6ffaf2..731b400 100644 --- a/_assets/scripts/debris/func.jl +++ b/_assets/scripts/debris/func.jl @@ -1,82 +1,56 @@ +""" + without_states(lost::Vector{String}) -> DataFrame -function find_combinations(target::Int64) - less_than_target = Set() - equal_to_target = Set() - greater_than_target = Set() - for i in 1:length(swing_col) - for combination in combinations(collect(keys(swing_col)), i) - sum_values = sum(swing_col[state] for state in combination) - if sum_values < target - push!(less_than_target, combination) - elseif sum_values == target - push!(equal_to_target, combination) - else - push!(greater_than_target, combination) - end - end - end - return ( - less_than_target = collect(less_than_target), - equal_to_target = collect(equal_to_target), - greater_than_target = collect(greater_than_target) - ) +Find and return rows from the `outcomes` DataFrame where the `combo` column does not contain any of the states specified in the `lost` vector and where the result is "Harris". + +# Arguments +- `lost::Vector{String}`: A vector of strings where each string represents a state to be excluded from the `combo` column. + +# Returns +- `DataFrame`: A DataFrame containing rows that meet the criteria. + +# Examples +```julia +without_states(["PA", "NC"]) +header = ["Scenario", "Electoral Votes", "Harris Total", "Trump Total", "Result"] +pretty_table(without_states["PA"]; backend = Val(:html), header = header, standalone = false) +""" +function without_states(lost::Vector{String}) + filter(row -> all(!occursin(state, row.combo) for state in lost) && row.result == "Harris", outcomes) end #------------------------------------------------------------------ +""" + metahelp() -function electoral_map(data,kindof) - if kindof == "pop" - pastel = greens - titular = titlecase(kindof *"ular") - else - pastel = purples - titular = "Electoral" - end +shows MetaFrame structure and give example - color_scale = [ - (0.0, pastel[1]), - (0.2, pastel[2]), - (0.4, pastel[3]), - (0.6, pastel[4]), - (0.8, pastel[5]), - (1.0, pastel[6]) - ] - # Create the data for the choropleth map - data = choropleth( - locationmode = "USA-states", - locations = states, - z = data, - colorscale = color_scale, - colorbar = attr( - title = titular * "Votes", - #tickvals = unique(input), - #ticktext = string.(unique(input)) - ), - zmin = minimum(input), - zmax = maximum(input) - ) - - # Create the layout for the map - layout = Layout( - title = titular * " Vote by Swing State", - geo = attr( - scope = "usa", - projection_type = "albers usa", - showlakes = true, - lakecolor = "rgb(255, 255, 255)" - ) - ) -# Create the plot - plot(data, layout) +mutable struct MetaFrame + meta::Dict{Symbol, Any} + data::DataFrame end +# Example usage +df = DataFrame(name=["John", "Jane"], age=[28, 34]) +meta_info = Dict(:source => "Survey Data", :year => 2021) + +df = MetaFrame(meta_info, df) + +meta_info = Dict( + :source => "Census Bureau, Current Population Survey, November 2022", + :title => "Table 4c. Reported Voting and Registration of the Total Voting-Age Population, by Age, for States: November 2022", + :url => "https://www.census.gov/data/tables/time-series/demo/voting-and-registration/p20-586.html", + :title => "Table 4c. Reported Voting and Registration of the Total Voting-Age Population, by Age, for States: November 2022") +""" +function metahelp() + println("Display with ?metahelp") +end #------------------------------------------------------------------ -# Function to determine the result based on the value of `biden` -function determine_result(biden_value) - if biden_value == 269 - return "tie" - elseif biden_value < 269 - return "Trump" - else - return "Harris" - end + +function radix(df::DataFrame) + for col in names(df) + if eltype(df[:, col]) == Int64 + df[:, col] = format.(df[:, col], commas=true) + end + end end + diff --git a/_assets/scripts/gaming.jl b/_assets/scripts/debris/gaming.jl similarity index 100% rename from _assets/scripts/gaming.jl rename to _assets/scripts/debris/gaming.jl diff --git a/_assets/scripts/gentab.jl b/_assets/scripts/debris/gentab.jl similarity index 100% rename from _assets/scripts/gentab.jl rename to _assets/scripts/debris/gentab.jl diff --git a/_assets/scripts/hypo.jl b/_assets/scripts/debris/hypo.jl similarity index 100% rename from _assets/scripts/hypo.jl rename to _assets/scripts/debris/hypo.jl diff --git a/_assets/scripts/insert_apr.jl b/_assets/scripts/debris/insert_apr.jl similarity index 100% rename from _assets/scripts/insert_apr.jl rename to _assets/scripts/debris/insert_apr.jl diff --git a/_assets/scripts/insert_mar.jl b/_assets/scripts/debris/insert_mar.jl similarity index 100% rename from _assets/scripts/insert_mar.jl rename to _assets/scripts/debris/insert_mar.jl diff --git a/_assets/scripts/insert_may.jl b/_assets/scripts/debris/insert_may.jl similarity index 100% rename from _assets/scripts/insert_may.jl rename to _assets/scripts/debris/insert_may.jl diff --git a/_assets/scripts/intake.jl b/_assets/scripts/debris/intake.jl similarity index 100% rename from _assets/scripts/intake.jl rename to _assets/scripts/debris/intake.jl diff --git a/_assets/scripts/mar_dat.jl b/_assets/scripts/debris/mar_dat.jl similarity index 100% rename from _assets/scripts/mar_dat.jl rename to _assets/scripts/debris/mar_dat.jl diff --git a/_assets/scripts/mar_poll.jl b/_assets/scripts/debris/mar_poll.jl similarity index 100% rename from _assets/scripts/mar_poll.jl rename to _assets/scripts/debris/mar_poll.jl diff --git a/_assets/scripts/mar_poll_foot.jl b/_assets/scripts/debris/mar_poll_foot.jl similarity index 100% rename from _assets/scripts/mar_poll_foot.jl rename to _assets/scripts/debris/mar_poll_foot.jl diff --git a/_assets/scripts/mar_poll_head.jl b/_assets/scripts/debris/mar_poll_head.jl similarity index 100% rename from _assets/scripts/mar_poll_head.jl rename to _assets/scripts/debris/mar_poll_head.jl diff --git a/_assets/scripts/mar_polls.bson b/_assets/scripts/debris/mar_polls.bson similarity index 100% rename from _assets/scripts/mar_polls.bson rename to _assets/scripts/debris/mar_polls.bson diff --git a/_assets/scripts/metrics.jl b/_assets/scripts/debris/metrics.jl similarity index 100% rename from _assets/scripts/metrics.jl rename to _assets/scripts/debris/metrics.jl diff --git a/_assets/scripts/models.jl b/_assets/scripts/debris/models.jl similarity index 100% rename from _assets/scripts/models.jl rename to _assets/scripts/debris/models.jl diff --git a/_assets/scripts/moe.jl b/_assets/scripts/debris/moe.jl similarity index 100% rename from _assets/scripts/moe.jl rename to _assets/scripts/debris/moe.jl diff --git a/_assets/scripts/naive_prior.jl b/_assets/scripts/debris/naive_prior.jl similarity index 100% rename from _assets/scripts/naive_prior.jl rename to _assets/scripts/debris/naive_prior.jl diff --git a/_assets/scripts/poll_arg.jl b/_assets/scripts/debris/poll_arg.jl similarity index 100% rename from _assets/scripts/poll_arg.jl rename to _assets/scripts/debris/poll_arg.jl diff --git a/_assets/scripts/prep.jl b/_assets/scripts/debris/prep.jl similarity index 100% rename from _assets/scripts/prep.jl rename to _assets/scripts/debris/prep.jl diff --git a/_assets/scripts/ribbon.jl b/_assets/scripts/debris/ribbon.jl similarity index 100% rename from _assets/scripts/ribbon.jl rename to _assets/scripts/debris/ribbon.jl diff --git a/_assets/scripts/scratch.jl b/_assets/scripts/debris/scratch.jl similarity index 100% rename from _assets/scripts/scratch.jl rename to _assets/scripts/debris/scratch.jl diff --git a/_assets/scripts/spread/bi2.jl b/_assets/scripts/debris/spread/bi2.jl similarity index 100% rename from _assets/scripts/spread/bi2.jl rename to _assets/scripts/debris/spread/bi2.jl diff --git a/_assets/scripts/spread/bi3.jl b/_assets/scripts/debris/spread/bi3.jl similarity index 100% rename from _assets/scripts/spread/bi3.jl rename to _assets/scripts/debris/spread/bi3.jl diff --git a/_assets/scripts/spread/bl2.jl b/_assets/scripts/debris/spread/bl2.jl similarity index 100% rename from _assets/scripts/spread/bl2.jl rename to _assets/scripts/debris/spread/bl2.jl diff --git a/_assets/scripts/spread/bl3.jl b/_assets/scripts/debris/spread/bl3.jl similarity index 100% rename from _assets/scripts/spread/bl3.jl rename to _assets/scripts/debris/spread/bl3.jl diff --git a/_assets/scripts/spread/cn2.jl b/_assets/scripts/debris/spread/cn2.jl similarity index 100% rename from _assets/scripts/spread/cn2.jl rename to _assets/scripts/debris/spread/cn2.jl diff --git a/_assets/scripts/spread/cn3.jl b/_assets/scripts/debris/spread/cn3.jl similarity index 100% rename from _assets/scripts/spread/cn3.jl rename to _assets/scripts/debris/spread/cn3.jl diff --git a/_assets/scripts/spread/ec2.jl b/_assets/scripts/debris/spread/ec2.jl similarity index 100% rename from _assets/scripts/spread/ec2.jl rename to _assets/scripts/debris/spread/ec2.jl diff --git a/_assets/scripts/spread/ec3.jl b/_assets/scripts/debris/spread/ec3.jl similarity index 100% rename from _assets/scripts/spread/ec3.jl rename to _assets/scripts/debris/spread/ec3.jl diff --git a/_assets/scripts/spread/hi2.jl b/_assets/scripts/debris/spread/hi2.jl similarity index 100% rename from _assets/scripts/spread/hi2.jl rename to _assets/scripts/debris/spread/hi2.jl diff --git a/_assets/scripts/spread/hi3.jl b/_assets/scripts/debris/spread/hi3.jl similarity index 100% rename from _assets/scripts/spread/hi3.jl rename to _assets/scripts/debris/spread/hi3.jl diff --git a/_assets/scripts/spread/ma2.jl b/_assets/scripts/debris/spread/ma2.jl similarity index 100% rename from _assets/scripts/spread/ma2.jl rename to _assets/scripts/debris/spread/ma2.jl diff --git a/_assets/scripts/spread/ma3.jl b/_assets/scripts/debris/spread/ma3.jl similarity index 100% rename from _assets/scripts/spread/ma3.jl rename to _assets/scripts/debris/spread/ma3.jl diff --git a/_assets/scripts/spread/mar_polls.bson b/_assets/scripts/debris/spread/mar_polls.bson similarity index 100% rename from _assets/scripts/spread/mar_polls.bson rename to _assets/scripts/debris/spread/mar_polls.bson diff --git a/_assets/scripts/spread/moe.jl b/_assets/scripts/debris/spread/moe.jl similarity index 100% rename from _assets/scripts/spread/moe.jl rename to _assets/scripts/debris/spread/moe.jl diff --git a/_assets/scripts/spread/qi2.jl b/_assets/scripts/debris/spread/qi2.jl similarity index 100% rename from _assets/scripts/spread/qi2.jl rename to _assets/scripts/debris/spread/qi2.jl diff --git a/_assets/scripts/spread/qi3.jl b/_assets/scripts/debris/spread/qi3.jl similarity index 100% rename from _assets/scripts/spread/qi3.jl rename to _assets/scripts/debris/spread/qi3.jl diff --git a/_assets/scripts/spread/rota b/_assets/scripts/debris/spread/rota similarity index 100% rename from _assets/scripts/spread/rota rename to _assets/scripts/debris/spread/rota diff --git a/_assets/scripts/spread/sp2.jl b/_assets/scripts/debris/spread/sp2.jl similarity index 100% rename from _assets/scripts/spread/sp2.jl rename to _assets/scripts/debris/spread/sp2.jl diff --git a/_assets/scripts/spread/sp3.jl b/_assets/scripts/debris/spread/sp3.jl similarity index 100% rename from _assets/scripts/spread/sp3.jl rename to _assets/scripts/debris/spread/sp3.jl diff --git a/_assets/scripts/spread/spread.jl b/_assets/scripts/debris/spread/spread.jl similarity index 100% rename from _assets/scripts/spread/spread.jl rename to _assets/scripts/debris/spread/spread.jl diff --git a/_assets/scripts/spread/su2.jl b/_assets/scripts/debris/spread/su2.jl similarity index 100% rename from _assets/scripts/spread/su2.jl rename to _assets/scripts/debris/spread/su2.jl diff --git a/_assets/scripts/spread/su3.jl b/_assets/scripts/debris/spread/su3.jl similarity index 100% rename from _assets/scripts/spread/su3.jl rename to _assets/scripts/debris/spread/su3.jl diff --git a/_assets/scripts/spread/ws2.jl b/_assets/scripts/debris/spread/ws2.jl similarity index 100% rename from _assets/scripts/spread/ws2.jl rename to _assets/scripts/debris/spread/ws2.jl diff --git a/_assets/scripts/spread/ws3l.jl b/_assets/scripts/debris/spread/ws3l.jl similarity index 100% rename from _assets/scripts/spread/ws3l.jl rename to _assets/scripts/debris/spread/ws3l.jl diff --git a/_assets/scripts/spread/ws3s.jl b/_assets/scripts/debris/spread/ws3s.jl similarity index 100% rename from _assets/scripts/spread/ws3s.jl rename to _assets/scripts/debris/spread/ws3s.jl diff --git a/_assets/scripts/state_level.jl b/_assets/scripts/debris/state_level.jl similarity index 100% rename from _assets/scripts/state_level.jl rename to _assets/scripts/debris/state_level.jl diff --git a/_assets/scripts/tabsstates.jl b/_assets/scripts/debris/tabsstates.jl similarity index 100% rename from _assets/scripts/tabsstates.jl rename to _assets/scripts/debris/tabsstates.jl diff --git a/_assets/scripts/vote2022.jl b/_assets/scripts/debris/vote20223.jl similarity index 100% rename from _assets/scripts/vote2022.jl rename to _assets/scripts/debris/vote20223.jl diff --git a/_assets/scripts/whatif.jl b/_assets/scripts/debris/whatif.jl similarity index 100% rename from _assets/scripts/whatif.jl rename to _assets/scripts/debris/whatif.jl diff --git a/_assets/scripts/func.jl b/_assets/scripts/func.jl deleted file mode 100644 index 731b400..0000000 --- a/_assets/scripts/func.jl +++ /dev/null @@ -1,56 +0,0 @@ -""" - without_states(lost::Vector{String}) -> DataFrame - -Find and return rows from the `outcomes` DataFrame where the `combo` column does not contain any of the states specified in the `lost` vector and where the result is "Harris". - -# Arguments -- `lost::Vector{String}`: A vector of strings where each string represents a state to be excluded from the `combo` column. - -# Returns -- `DataFrame`: A DataFrame containing rows that meet the criteria. - -# Examples -```julia -without_states(["PA", "NC"]) -header = ["Scenario", "Electoral Votes", "Harris Total", "Trump Total", "Result"] -pretty_table(without_states["PA"]; backend = Val(:html), header = header, standalone = false) -""" -function without_states(lost::Vector{String}) - filter(row -> all(!occursin(state, row.combo) for state in lost) && row.result == "Harris", outcomes) -end -#------------------------------------------------------------------ -""" - metahelp() - -shows MetaFrame structure and give example - -mutable struct MetaFrame - meta::Dict{Symbol, Any} - data::DataFrame -end - -# Example usage -df = DataFrame(name=["John", "Jane"], age=[28, 34]) -meta_info = Dict(:source => "Survey Data", :year => 2021) - -df = MetaFrame(meta_info, df) - -meta_info = Dict( - :source => "Census Bureau, Current Population Survey, November 2022", - :title => "Table 4c. Reported Voting and Registration of the Total Voting-Age Population, by Age, for States: November 2022", - :url => "https://www.census.gov/data/tables/time-series/demo/voting-and-registration/p20-586.html", - :title => "Table 4c. Reported Voting and Registration of the Total Voting-Age Population, by Age, for States: November 2022") -""" -function metahelp() - println("Display with ?metahelp") -end -#------------------------------------------------------------------ - -function radix(df::DataFrame) - for col in names(df) - if eltype(df[:, col]) == Int64 - df[:, col] = format.(df[:, col], commas=true) - end - end -end - diff --git a/_assets/scripts/insert_jun.jl b/_assets/scripts/insert_jun.jl index 2a50bb0..3a5962f 100644 --- a/_assets/scripts/insert_jun.jl +++ b/_assets/scripts/insert_jun.jl @@ -7,99 +7,108 @@ using Statistics using StatsPlots using Turing -# const DESIGN_ERROR = 0.012 +# const DESIGN_ERROR = . -@enum Month mar apr may jun jul aug sep oct nov +@enum Month mar apr may jul jul aug sep oct nov @enum Pollster begin - ag2 - aj2 - am2 - bi2 - bi3 - bl2 - bl3 - cb2 - cb3 - cn2 - cn3 - ea2 - ec2 - ec3 - ep2 - eu2 - fm2 - fm3 - fo2 - fo3 - hi2 - hi3 - hp2 - ma2 - ma3 - mi2 - mi3 - mq2 - mr2 - mr3 - ny2 - qi2 - qi3 - rr2 - si2 - si3 - sp2 - sp3 - su2 - su3 - wa2 - wa3 - ws2 - ws3l - ws3s + ag + aj + am + bi + bi + bl + bl + cb + cb + cn + cn + ea + ec + ec + ep + eu + fm + fm + fo + fo + hi + hi + hp + ia + ma + ma + mi + mi + mq + mr + mr + ns + pp + ny + qi + qi + rr + si + si + sp + sp + su + su + tr + wa + wa + ws + wsl + wss + yg end @enum State PA GA NC MI AZ WI NV struct Poll - biden_support::Float64 - trump_support::Float64 + biden_support::Float + trump_support::Float sample_size::Int end -# -@load "../objs/may_polls.bson" months -months[jun][AZ][ag2] = [Poll(42,48, 600)] -months[jun][AZ][ec2] = [Poll(43,47,1000)] -months[jun][AZ][fo2] = [Poll(46,51,1095)] -months[jun][AZ][rr2] = [Poll(47,40, 750)] -months[jun][GA][aj2] = [Poll(38,43,1000)] -months[jun][GA][ec2] = [Poll(41,45,1000)] -months[jun][GA][qi2] = [Poll(44,40,1203)] -months[jun][MI][ec2] = [Poll(43,46,1000)] -months[jun][NC][eu2] = [Poll(43,48,1332)] -months[jun][NV][ec2] = [Poll(43,46,1000)] -months[jun][NV][fo2] = [Poll(45,50,1069)] -months[jun][PA][ec2] = [Poll(45,47,1000)] -months[jun][WI][ec2] = [Poll(44,47,1000)] -months[may][AZ][am2] = [Poll(42,48, 600)] -months[may][AZ][ec2] = [Poll(43,47,1000)] -months[may][AZ][rr2] = [Poll(42,47, 750)] -months[may][GA][aj2] = [Poll(38,43,1000)] -months[may][GA][ec2] = [Poll(41,45, 604)] -months[may][MI][ec2] = [Poll(49,51,1000)] -months[may][MI][ep2] = [Poll(45,49, 600)] -months[may][MI][mi2] = [Poll(45,46, 697)] -months[may][NC][ea2] = [Poll(43,48,1332)] -months[may][NV][ec2] = [Poll(39,41,1000)] -months[may][NV][fo2] = [Poll(45,50,1000)] -months[may][PA][ec2] = [Poll(45,47,1000)] -months[may][WI][ec2] = [Poll(42,44,1000)] -months[may][WI][mq2] = [Poll(50,50, 811)] +@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][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][yg] = [Poll(40,44,1000)] +months[jul][MI][bl] = [Poll(45,39,694)] +months[jul][MI][ec] = [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][yg] = [Poll(40,44,1000)] +months[jul][NV][bl] = [Poll(39,45,452)] +months[jul][NV][ec] = [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][ia] = [Poll(45,49,800)] +months[jul][PA][yg] = [Poll(40,43,1000)] +months[jul][PA][ec] = [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][ia] = [Poll(47,47,546)] +months[jul][WI][ns] = [Poll(44,46,600)] +months[jul][WI][yg] = [Poll(39,43,900)] # needs to be done manually rather than with include() -#@save "../objs/jun_polls.bson" months +#@save "../objs/jul_polls.bson" months diff --git a/_assets/scripts/national_map.jl b/_assets/scripts/national_map.jl index 85d29d9..b404d01 100644 --- a/_assets/scripts/national_map.jl +++ b/_assets/scripts/national_map.jl @@ -87,7 +87,7 @@ votes = Dict( "KS" => 6, "KY" => 8, "LA" => 8, - "ME2" => 2, + "ME2" => 1, "MO" => 10, "MS" => 6, "MT" => 4, @@ -116,7 +116,7 @@ votes = Dict( "IL" => 19, "MA" => 11, "MD" => 10, - "ME" => 1, + "ME" => 2, "ME1" => 1, "MI" => 15, "MN" => 10, @@ -192,4 +192,4 @@ function electoral_map_with_colors(data, state_colors) PlotlyJS.savefig(fig, "/Users/ro/projects/SwingWatch/_assets/img/maps/base.png") end -electoral_map_with_colors(data, STATE_COLORS) \ No newline at end of file +electoral_map_with_colors(data, STATE_COLORS) diff --git a/changes.md b/changes.md index ddbcf4d..7756865 100644 --- a/changes.md +++ b/changes.md @@ -2,7 +2,7 @@ title = "Electoral College Changes for 2024" +++ -As the result of the 2020 Census, 17 states lost or gain an electoral vote, except that Texas gained two. +As the result of the 2020 Census, 13 states lost or gained an electoral vote, except that Texas gained two. ~~~ @@ -37,14 +37,6 @@ As the result of the 2020 Census, 17 states lost or gain an electoral vote, exce - - - - - - - - @@ -79,13 +71,6 @@ As the result of the 2020 Census, 17 states lost or gain an electoral vote, exce - - - - - - - @@ -100,20 +85,6 @@ As the result of the 2020 Census, 17 states lost or gain an electoral vote, exce - - - - - - - - - - - - - - diff --git a/index.md b/index.md index 8448abf..7bf103e 100644 --- a/index.md +++ b/index.md @@ -8,6 +8,10 @@ As of July 22, 2024, Vice President Harris will replace President Harris as the 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. +## Allocation of electoral college votes corrected\ + +Harris starts with the 226 (not 225) votes won in 2020, using the revised 2024 electoral college vote allocations. + ## Overall assessment for polling through June ### Stringent view diff --git a/poll_org.jl b/poll_org.jl index 1ac4612..8b1add2 100644 --- a/poll_org.jl +++ b/poll_org.jl @@ -1,6 +1,6 @@ # these static types assure that only legal values can be accepted @enum Month mar apr may jun jul aug sep oct nov -# 2 indicates polls using a Biden-Trump matchup +# 2 indicates polls using a Harris-Trump matchup # 3 indicates polls including RJK Jr if he has qualified for the ballot @enum Pollster bi2 bi3 bl2 bl3 cn2 cn3 ec2 ec3 hi2 hi3 ma2 ma3 moe qi2 qi3 sp2 sp3 su2 su3 ws2 ws3l ws3s # the swing states @@ -8,7 +8,7 @@ struct PollData - biden_support::Union{Float64, Missing} + harris_support::Union{Float64, Missing} trump_support::Union{Float64, Missing} sample_size::Union{Int, Missing} end @@ -121,7 +121,7 @@ end Generate a template for entering poll data into the `master_polls` object. -The template includes the appropriate `master_polls.data` syntax with placeholders for the `biden_support`, `trump_support`, and `sample_size` values in a single `PollData` entry. +The template includes the appropriate `master_polls.data` syntax with placeholders for the `harris_support`, `trump_support`, and `sample_size` values in a single `PollData` entry. # Arguments - `pollster::Pollster`: The pollster enum value for which the data is being entered. @@ -173,4 +173,4 @@ function generate_templates(month::Month) end InteractiveUtils.clipboard(templates) println("Templates copied to clipboard.") -end \ No newline at end of file +end diff --git a/sources.md b/sources.md index 8ebb3d3..fbb9e14 100644 --- a/sources.md +++ b/sources.md @@ -42,11 +42,15 @@ df = CSV.read(IOBuffer(csv_data), DataFrame) - [Bloomberg/Morning Consult: conducted April](https://pro-assets.morningconsult.com/wp-uploads/2024/04/Bloomberg_2024-Election-Tracking-Wave-7.pdf) - [Bloomberg/Morning Consult: conducted May](https://pro-assets.morningconsult.com/wp-uploads/2024/05/Bloomberg-Election-Tracking-Wave-8-Toplines-Crosstabs.pdf) - [Bloomberg/Morning Consult: conducted March](https://pro-assets.morningconsult.com/wp-uploads/2024/03/Bloomberg_2024-Election-Tracking-Wave-6.pdf) + - [Bloomberg/Morning Consult: conducted July pre-July](https://pro-assets.morningconsult.com/wp-uploads/2024/07/Bloomberg-Election-Tracking-Wave-9-Toplines-Crosstabs.pdf) - [Emerson College: conducted June](https://docs.google.com/spreadsheets/d/1vGeTKW3MRDR5dXHM2IjM8ORz7HOyP5Le/edit?gid=532631346#gid=532631346) - [Emerson College: conducted April](https://emersoncollegepolling.com/trump-holds-edge-over-biden-in-seven-key-swing-state-polls/) - [Emerson College: conducted March](https://emersoncollegepolling.com/category/state-poll/) + - [Emerson College: conducted July pre-Harris](https://docs.google.com/spreadsheets/d/1zJrIOcXtzIRkaa34BDkxoVe9HY3stwFc/edit?gid=1704598980#gid=1704598980) - [New York Times/Sienna: conducted May](https://www.nytimes.com/interactive/2024/05/13/us/elections/times-siena-poll-registered-voter-crosstabs.html) - [Wall Street Journal: conducted March ]((https://s.wsj.net/public/resources/documents/WSJ_Swing_States_Partial_March_2024.pdf)) + - [YouGov: conducted July pre-Harris](https://ygo-assets-websites-editorial-emea.yougov.net/documents/Times_SAY24_20240712_state_poll_results.pdf) + --- @@ -60,8 +64,12 @@ df = CSV.read(IOBuffer(csv_data), DataFrame) - [American Greatness: conducted June](https://cdn.amgreatness.com/app/uploads/2024/06/AZ-June-Toplines.pdf) - [Emerson College: conducted June](https://docs.google.com/spreadsheets/d/1vGeTKW3MRDR5dXHM2IjM8ORz7HOyP5Le/edit?gid=532631346#gid=532631346) - [Rasmussen Reports: conducted June](https://www.rasmussenreports.com/public_content/politics/public_surveys/crosstabs_2_arizona_june_2024) + - [Public Policy Polling conducted July pre-Harris](https://www.nytimes.com/interactive/2024/us/politics/presidential-candidates-third-party-independent.html) + - [Insider Advantage: conducted July pre-Harris](https://insideradvantage.com/top-line-cross-tabs-for-insideradvantage-az-nv-and-pa-july-15-16-surveys/) + * Georgia - [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) + - [Insider Advantage: conducted July pre-Harris](https://insideradvantage.com/top-line-tabs-for-insideradvantage-fox5-atlanta-survey/) * 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) @@ -70,8 +78,10 @@ df = CSV.read(IOBuffer(csv_data), DataFrame) - [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) - [Atlantic Journal Constitution: completed June](https://www.ajc.com/news/am-atl-poll-trump-edging-biden/2SN4MIOROZA4DFOFDNXE2CFCJU/) - [Quinnipiac University: conducted March](https://poll.qu.edu/poll-release?releaseid=3893) - - [Quinnipiac University: conducted June](https://poll.qu.edu/images/polling/ga/ga06052024_ggwb04.pdf) + - [Quinnipiac University: conducted June](https://poll.qu.edu/images/polling/ga/ga06052024_ggwb04.pdf) - [Fox News: conducted June](https://static.foxnews.com/foxnews.com/content/uploads/2024/06/Fox_June-1-4-2024_NEVADA_Topline_June-6-Release.pdf) + - [EPIC-MRA: conducted in July, pre-Harris](https://ssl2002.webhosting.comcast.net/epic-mra/press/Stwd_Survey_July2024_Media_Freq.pdf) + - [Trafalger: conducted July pre-Harris](https://www.thetrafalgargroup.org/wp-content/uploads/2024/07/MI-Gen-Pres-Poll-Report-0718.pdf) * 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) @@ -84,6 +94,7 @@ df = CSV.read(IOBuffer(csv_data), DataFrame) - [Quinnipiac: conducted April](https://poll.qu.edu/images/polling/nc/nc04102024_ncaa99.pdf) - [WRAL: conducted March](https://wwwcache.wral.com/asset/news/state/nccapitol/2024/03/12/21325738/3247050-Poll_Report_-_PollPrint-DMID1-628w54pob.pdf) - [ECU: conducted June](https://surveyresearch-ecu.reportablenews.com/pr/trump-leads-biden-by-5-points-in-north-carolina-gubernatorial-election-remains-close-with-stein-up-1-on-robinson-trump-guilty-verdict-has-little-impact-on-nc-voter-intentions-for-november) + - [Insider Advantage: conducted July pre-Harris](https://insideradvantage.com/top-line-cross-tabs-for-insideradvantage-az-nv-and-pa-july-15-16-surveys/) * Wisconsin - [CBS: conducted April](https://www.scribd.com/document/727319278/Cbsnews-20240428-WI-SUN) - [Fox News: conducted April](https://static.foxnews.com/foxnews.com/content/uploads/2024/04/b002d3b3-Fox_April-11-16-2024_WISCONSIN_Topline_April-18-Release.pdf) diff --git a/why7.md b/why7.md index 0fe7110..5170f98 100644 --- a/why7.md +++ b/why7.md @@ -12,7 +12,7 @@ title = "Seven Swing States" ~~~ -In the 2020 election, there were 49 states (including the District of Columnia and the sub-state districts in each of Maine and Nebraska) won by a margin of greater than 3.2%. Only **seven states** were decided by a margin of less than 3.2%. *Assuming* that each candidate retains all states won in the 2020 election except for the swing states, President Harris begins with 225 electoral votes, and former President Trump begins with 220 electoral votes[^1] using the 2024 Electoral College allocation. The scenario table following shows the result of a Harris win of each of the possible combinations of outcomes in those states. +In the 2020 election, there were 49 states (including the District of Columnia and the sub-state districts in each of Maine and Nebraska) won by a margin of greater than 3.2%. Only **seven states** were decided by a margin of less than 3.2%. *Assuming* that each candidate retains all states won in the 2020 election except for the swing states, Vicr President Harris begins with the 226 electoral votes won by President Biden, excluding the swing states, and former President Trump begins with 221 electoral votes[^1] using the 2024 Electoral College allocation. The scenario table following shows the result of a Harris win of each of the possible combinations of outcomes in those states. These are the states that are widely discussed as swing states for 2024. * **PA** 19 votes (down from 20 in the 2020 election) @@ -25,7 +25,7 @@ These are the states that are widely discussed as swing states for 2024. President Biden won all of the swing states in 2020 except for North Carolina. -Assuming that the remaining states and districts will be non-competitive and have the same electoral outcome, the starting point is 28 red states and districts with 220 electoral votes and 28 blue states and districts with 225 electoral votes. **President Harris begins with an advantage of five electoral votes.** +Assuming that the remaining states and districts will be non-competitive and have the same electoral outcome, the starting point is 28 red states and districts with 220 electoral votes and 28 blue states and districts with 226 electoral votes. **Vice President Harris begins with an advantage of six electoral votes.** The seven swing states have **93 votes** among them. Depending on the outcomes of their elections either President Harris or former President Trump could have more than 269 electoral votes **with 45 or more of the 93 electoral votes in the swing states.** Or they could each have 269 electoral votes, which puts the decision to the House of Representatives, voting by state delegation. @@ -35,6 +35,8 @@ The seven swing states have **93 votes** among them. Depending on the outcomes o ~~~ +### Rest of page under revision + * Former President **Trump wins in 57** of the possible outcomes * Vice President **Harris wins in 70** of the possible outcomes * There is **one possible tie** (if Harris wins only WI, MI and PA)
-1 Harris
ME12-1Harris
MI 15 161 Trump
ME2211Trump
MT 41 Trump
NE12-1Trump
NE3211Trump
OH 17