This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
bayes_update_normal = function( | |
data_mu, | |
data_se, | |
prior_mu = 0, | |
prior_se = 3){ | |
if(all(data_mu == 0)){ | |
return(c(0,0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
country | inflation (YoY Sept 2023) | Leader approval | Disapproval | Net | |
---|---|---|---|---|---|
Austria | 7.37 | 23 | 73 | -50 | |
Belgium | 2.39 | 38 | 46 | -8 | |
Brazil | 5.19 | 51 | 45 | 6 | |
Canada | 4 | 33 | 59 | -26 | |
France | 4.86 | 23 | 72 | -49 | |
Germany | 4.53 | 25 | 68 | -43 | |
Ireland | 6.41 | 39 | 52 | -13 | |
Italy | 5.44 | 44 | 51 | -7 | |
Japan | 3.2 | 23 | 63 | -40 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
end_date | pollster | n | population | pid_weighted | keep | remove | |
---|---|---|---|---|---|---|---|
2021-09-13 | survey monkey | 3985 | LV | 1 | 0.55 | 0.41 | |
2021-09-13 | trafalgar | 1082 | LV | 0 | 0.53 | 0.45 | |
2021-09-11 | emerson | 1000 | LV | 1 | 0.6 | 0.4 | |
2021-09-10 | data for progress | 2464 | LV | 1 | 0.57 | 0.43 | |
2021-09-08 | surveyusa | 930 | LV | 0 | 0.54 | 0.41 | |
2021-09-07 | suffolk | 500 | LV | 0 | 0.58 | 0.41 | |
2021-09-06 | uc berkeley | 6550 | LV | 0 | 0.6 | 0.39 | |
2021-09-04 | trafalgar | 1079 | LV | 0 | 0.53 | 0.43 | |
2021-09-01 | yougov | 1955 | LV | 1 | 0.56 | 0.44 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Description | |
#' This file runs a live election-night forecast based on The Economist's pre-election forecasting model | |
#' available at projects.economist.com/us-2020-forecast/president. | |
#' It is resampling model based on https://pkremp.github.io/update_prob.html. | |
#' This script does not input any real election results! You will have to enter your picks/constraints manually (scroll to the bottom of the script). | |
#' | |
#' Licence | |
#' This software is published by *[The Economist](https://www.economist.com)* under the [MIT licence](https://opensource.org/licenses/MIT). The data generated by *The Economist* are available under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/). | |
#' The licences include only the data and the software authored by *The Economist*, and do not cover any *Economist* content or third-party data or content made available using the software. More information about licensing, syndication and the copyright of *Economist* content can be fou |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
library(pbapply) | |
url<- 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQ56fySJKLL18Lipu1_i3ID9JE06voJEz2EXm6JW4Vh11zmndyTwejMavuNntzIWLY0RyhA1UsVEen0/pub?gid=0&single=true&output=csv' | |
all_polls <- read_csv(url) | |
# remove any polls if biden or trump blank | |
all_polls <- all_polls %>% filter(!is.na(biden),!is.na(trump))#, include == "TRUE") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(pbapply) | |
library(tidyverse) | |
mod <- read_csv('~/Downloads/output/site_data/electoral_college_simulations.csv') | |
mod <- mod %>% gather(state,vote,4:ncol(.)) | |
evs <- read_csv('data/prior/state_evs.csv') | |
mod <- mod %>% left_join(evs) | |
tp <- pblapply(1:max(mod$draw), | |
cl = 12, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(janitor) | |
library(lubridate) | |
library(zoo) | |
library(politicaldata) | |
RUN_DATE <- Sys.Date() | |
start_date <- ymd("2020-02-01") | |
election_day <- ymd('2020-11-03') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(zoo) | |
trump_approve <- read_csv("https://projects.fivethirtyeight.com/polls-page/president_approval_polls.csv") | |
trump_approve <- trump_approve %>% | |
mutate("date" = mdy(end_date)) %>% | |
dplyr::select(pollster, | |
date, | |
"approve" = yes, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(politicaldata) | |
library(lubridate) | |
library(zoo) | |
library(gghighlight) | |
today_2020_time_difference <- as.numeric(difftime(ymd('2020-11-03'),Sys.Date(),units = 'days')) | |
# wrangle ----------------------------------------------------------------- | |
# historical |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls()) #reset the environment | |
library(tidyverse) | |
library(lubridate) | |
library(mgcv) | |
exponent_weight <- function(i) { | |
exp(-0.04*i) | |
} | |
TODAY_DAY <- difftime(Sys.Date(),as.Date("2017-01-21")) |
NewerOlder