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
### Load libraries | |
library(tidyverse) | |
library(haven) ## for Stata import | |
library(readxl) | |
library(marginaleffects) ## for easy predictions and contrasts | |
library(nnet) ## for nnet::multinom | |
library(furrr) ## to perform computations in parallel | |
### Set fewer workers if you have fewer cores | |
plan(multisession, workers = 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
### PURPOSE OF THIS CODE: estimate a large model in bam and speed-test | |
### predictions using mgcv::predict.bam and | |
### marginaleffects::predictions with and without discretization and | |
### parallelization | |
### ################################################################## | |
### load libraries | |
### ################################################################## | |
library(mgcv) | |
library(marginaleffects) |
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(rstan) | |
library(cmdstanr) | |
dat <- read.delim("data_attractiveness_juge_results.csv") | |
### Set subject IDs using the same factor levels | |
subject_levels <- unique(c(dat$ID_left, | |
dat$ID_right)) | |
dat <- dat |> |
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(haven) | |
### Replace your file location here | |
bes <- read_dta("~/Dropbox/bes_data/BES2019_W25_v25.0.dta") | |
### What was turnout like in the panel? | |
bes |> | |
filter(!is.na(localTurnoutRetro)) |> | |
group_by(localTurnoutRetro) |> |
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) | |
### Write a function to download the data from the IPU | |
dl_data <- function(y, m) { | |
url <- paste0("https://data.ipu.org/api/women-ranking.csv?load-entity-refs=taxonomy_term%2Cfield_collection_item&max-depth=2&langcode=en&month=", | |
m, | |
"&year=", | |
y) | |
download.file(url, destfile = paste0("ipu_", y, m, ".csv")) | |
} |
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
### Load the necessary libraries | |
library(sf) | |
library(tidyverse) | |
### Read in the shapefile | |
### Downloaded from https://geoportal.statistics.gov.uk/datasets/ons::local-authority-districts-december-2022-boundaries-uk-bfc/explore?location=55.215430%2C-3.316939%2C6.61 | |
lad_shp <- st_read("LAD_DEC_2022_UK_BFC.shp") | |
### Read in the list of coordinates | |
### |
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(vdemdata) | |
library(tidyverse) | |
library(ggflags) | |
library(countrycode) | |
library(hrbrthemes) | |
### Get the V-Dem data in | |
data("vdem") | |
dat <- vdem |> | |
distinct(country_name, country_text_id, year, | |
v2x_polyarchy, v2x_polyarchy_sd) |> |
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(hrbrthemes) | |
### This section reads in the data -- scroll down for the code that | |
### generates the figures and the graphics | |
tibble::tribble( | |
~aye_vote, ~ONSConstID, ~Constituency, ~MP, ~Party, ~ConstyOpposition, ~ConstyOpposition_sd, | |
1, "E14000530", "Aldershot", "Leo Docherty", "Conservative", 1.67320394423204, 0.0170138236227471, |
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
### Purpose of this code: plot the proportion of people in each CSES | |
### wave 5 study who can place themselves on a left-right scale. | |
### You will need to have downloaded the CSES 5 data somewhere | |
library(tidyverse) | |
library(ggtext) | |
library(RColorBrewer) | |
library(countrycode) | |
library(hrbrthemes) |
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(hrbrthemes) | |
library(ggtext) | |
dat <- read.csv("view_cabinet.csv") | |
dat <- dat %>% | |
group_by(country_name_short, | |
country_id, | |
election_date, |
NewerOlder