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(countrycode) | |
library(tidyverse) | |
library(rio) | |
holder <- list() | |
### (0) PartyFacts lookup | |
pf <- read.csv("data/partyfacts-external-parties.csv") | |
### (1) Manifesto Project |
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
### Let's generate some data with a step function | |
library(mgcv) | |
set.seed(1116) | |
nDays <- 200 | |
day <- 1:nDays | |
y <- rnorm(200, 1, 0.25) + I(day > 100) * -0.5 | |
y <- ifelse(y < 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
library(sp) | |
library(raster) | |
library(viridis) | |
library(rgdal) | |
library(rnaturalearth) | |
### need two things, presumably | |
### - a polygon mask | |
### - a population raster |
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) | |
### Pivot the table so we have four columns | |
### L/R, GAL/TAN, issue area, and value | |
dat <- read.csv("surridge1.csv") %>% | |
pivot_longer(cols = -c(Column1, Column2), | |
names_to = "Area") | |
### Tidy up the factor levels and order | |
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(brms) | |
library(mice) | |
library(tictoc) | |
### Set a nice long number of iters so we can be sure it's not the | |
### overhead of spinning up cores, passing data, etc., | |
nIters <- 1e5 | |
thin <- nIters / 1000 | |
# Load data |
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
### Start by plotting stuff | |
library(tidyverse) | |
library(hrbrthemes) | |
## Download data from https://docs.google.com/spreadsheets/d/1inaI17l9Q-XADRNE_toXLp65sKu4_x4bXUFjZ3qjB2o/edit?usp=sharing | |
dat <- read.csv("wherever_i_saved_the_google_docs.csv") | |
### Estimate a simple model which we'll use when graphing | |
mod <- glm(I(Funded == "Yes") ~ Rank2 + ConWinner1, | |
family = binomial, |
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(rdrobust) | |
library(hrbrthemes) | |
library(cowplot) | |
library(Cairo) | |
dat <- readRDS("tidy_data.rds") | |
dat <- dat %>% | |
mutate(count_satisfied.20 = round(pct_satisfied.20 * response.20), |
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
{ | |
"class": "Survey", | |
"id": 609340, | |
"internal_title": "Learning under lockdown survey", | |
"l10n": "en_GB", | |
"runs": [ | |
{ | |
"class": "SurveyRun", | |
"alert_frequency": 0, | |
"alert_last_update": 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
dat <- read.csv("https://www.dropbox.com/s/e3p6xvjq6desua8/am_i_going_crazy.csv?dl=1") | |
holder <- list() | |
for (i in 1:20) { | |
holder[[i]] <- lm(lasso ~ ols, data = dat) | |
} | |
### For me, | |
lapply(holder, coef) | |
### gives the following. Note the intercepts in runs 1, 5 and 8 are radically different |
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) | |
### | |
nGrp <- 250 | |
grp_ideal_points <- rnorm(nGrp, 0, 1) | |
grp_sd <- 1 | |
ind_sd <- 1 | |
party_pos <- -1 | |
joinfunc1 <- function(ind_pos, party_pos) { | |
## Probability joining party |