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
| # set wd | |
| setwd("~/Dropbox/classes/pols-209") | |
| # load packages | |
| library(dplyr) | |
| library(ggplot2) | |
| # load data |
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
| # set wd | |
| setwd("~/Dropbox/classes/pols-209") | |
| # load packages | |
| library(dplyr) | |
| library(ggplot2) | |
| # load data | |
| nominate <- readRDS("data/nominate.rds") # read data set |
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
| # data loading and tidying | |
| ########################## | |
| # Note: we haven't talked about how to do this, and I don't expect you to | |
| # understand the code below. | |
| library(dplyr) # useful function for cleaning up data | |
| library(lubridate) # useful for working with dates and durations | |
| library(magrittr) # useful for data manipulation | |
| library(googlesheets) # used to load the google sheet data | |
| sheet <- gs_key("19aZA5_xnMiNfrpJpVur1FxNWGxUe3l-LlJ8vPp7_uBc") # register google sheet | |
| runs <- gs_read(sheet) # load sheet |
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
| # data loading and tidying | |
| ########################## | |
| # Note: we haven't talked about how to do this, and I don't expect you to | |
| # understand the code below. | |
| library(dplyr) # useful function for cleaning up data | |
| library(lubridate) # useful for working with dates and durations | |
| library(magrittr) # useful for data manipulation | |
| library(tidyr) # to gather the data | |
| library(googlesheets) # used to load the google sheet data | |
| sheet <- gs_key("11pXvnrDfygcaMp6iI-30BasveKYLZ4Ce9Z0-cuuKLww") # register google sheet |
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
| # note: for this code to work, you need to have devtools, dplyr, and | |
| # ggplot2 install, as well as the data sets in your data folder. | |
| # set working directory **CHANGE THIS** | |
| setwd("~/Dropbox/classes/pols-209") | |
| # load packages | |
| library(dplyr) |
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
| # box model | |
| box <- c(0, 1) # the box | |
| N <- 10 # the number of draws to take from the box | |
| n_reps <- 10000 # the number of times to take and sum N draws from the box | |
| # create a function to take and sum N draws from the box n_reps times | |
| box_model <- function(box, N, n_reps) { | |
| sums <- numeric(n_reps) |
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) | |
| # change these values | |
| n_1s <- 10 # number of 1s in the box | |
| n_0s <- 10 # number of 0s in the box | |
| sample_size <- 25 # number of times to draw from the box (w/ replacement) | |
| # number of times to repeat the study |
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
| # remember to set working directory! | |
| # load packages | |
| library(ggplot2) | |
| library(dplyr) | |
| # load data | |
| d <- readRDS("data/state-legislators.rds") |
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
| # data loading and tidying | |
| ########################## | |
| # Note: we haven't talked about how to do this, and I don't expect you to | |
| # understand the code below. But trust me that it grabs the data you submitted | |
| # in the forms and loads it as a data frame. | |
| library(googlesheets) # used to load the google sheet data | |
| sheet <- gs_key("1mJVzIpolvJ5XPROMCXg1A5iU_mlWXwHBlXQwG5t_QVk") # register google sheet | |
| bodies <- gs_read(sheet) # load sheet | |
| saveRDS(bodies, "data/bodies.rds") # save the former google sheet as a .rds | |
| rm(sheet, bodies) # remove the sheet to have a clean workspace |