- task 1
- task 2
This file contains hidden or 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
| # simulation parameters | |
| n <- 25 | |
| pop_proportion <- 1/6 | |
| n_reps <- 100 | |
| # simulate data | |
| y <- rbinom(n_reps, n, pop_proportion) | |
| # compute sample percent, estimated SE, and 95% CI |
This file contains hidden or 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
| # evaluate model fit by predicting years, one-by-one, out-of-sample | |
| evaluate_models <- function(..., data, group, model_names) { | |
| require(dplyr, warn.conflicts = FALSE, quietly = TRUE) | |
| formulas <- list(...) | |
| # in-sample rmse | |
| eval1 <- NULL | |
| for (i in 1:length(formulas)) { | |
| f <- formulas[[i]] | |
| fit0 <- lm(f, data = data) | |
| df0 <- data.frame(model = model_names[i], |
This file contains hidden or 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
| # clear workspace | |
| rm(list = ls()) | |
| # load packages | |
| library(ggplot2) | |
| # box | |
| number_of_draws <- 5 | |
| box <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0) |
This file contains hidden or 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 packages | |
| library(tidyverse) # includes ggplot | |
| library(foreach) # for times() | |
| library(magrittr) | |
| # set up box and number of draws | |
| box <- c(1, 3, 5, 7) | |
| n_draws <- 400 | |
| events <- 1500:10000 |
This file contains hidden or 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
| # code to understand product terms and probit models | |
| # clear workspace | |
| rm(list = ls()) | |
| # load packages | |
| library(tidyverse) | |
| library(plotly) | |
| # parameters |
This file contains hidden or 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(googlesheets) | |
| library(forcats) | |
| sheet_key <- "10qrPd-2RJ2HXsEi1fIYm1QeCVXWnGWVgV8iq-Ph7CRs" | |
| sheet <- gs_key(sheet_key) # register google sheet | |
| votes_raw <- gs_read(sheet) %>% | |
| glimpse() |
This file contains hidden or 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 packages ----------------------------------------------------------- | |
| library(tidyverse) | |
| library(magrittr) | |
| library(blme) | |
| library(rstanarm); options(mc.cores = parallel::detectCores()) | |
| # also need the package `arm` installed |
This file contains hidden or 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
| # note this code is written for clarity, not speed, so be careful before setting | |
| # n_sims too large. when we feel it's correct, both loops are embarrassingly | |
| # parrellel, so we can hit the outer loop with foreach. | |
| # in the meantime, just set n_sims to 10,000 or 50,000 (and give it a minute) when | |
| # you are ready | |
| # load packages | |
| library(tidyverse) |
Makefile for latent-dissent.

