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
| fakeData <- function() { | |
| n <- 2000 | |
| n.groups <- 100 | |
| x1 <<- rnorm(n); x2 <<- rnorm(n); x3 <<- rnorm(n) | |
| X <- cbind(1, x1, x2, x3) | |
| beta0 <<- runif(ncol(X), -1, 1) | |
| group <<- rep(1:n.groups, length.out = n) |
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(readr) # for reading data | |
| library(ggplot2) # for graphics | |
| library(dplyr) # for data manipulation | |
| library(gridExtra) # for arranging plots in grids | |
| library(texreg) # for printing output | |
| library(arm) # for rescale() function | |
| # 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
| # some code to randomly pair classmates | |
| # set seed | |
| set.seed(413876) | |
| # a vector of students | |
| students <- c("a", "b", "c", "d") | |
| # create random pairs | |
| n_students <- length(students) |
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(ggplot2) | |
| library(MASS) | |
| library(logistf) | |
| set.seed(12345678) | |
| ############ FAKE DATA ############ | |
| rho <- 0.0 | |
| k <- 3 | |
| sigma <- matrix(rho, k, k); diag(sigma) <- 5 |
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
| calc_switches <- function(x) { | |
| n <- length(x) | |
| x0 <- x[1:(n - 1)] | |
| x1 <- x[2:n] | |
| switches <- sum(x0 != x1) | |
| return(switches) | |
| } | |
| calc_streak <- function(x) { |
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(magrittr) | |
| library(googlesheets) | |
| library(lubridate) | |
| library(dplyr) | |
| library(stringr) | |
| library(tidyr) | |
| library(ggplot2) | |
| library(maps) |
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
| # this code uses the googlesheets package, which you may need to install using install.packages("googlesheets") | |
| # load packages | |
| library(googlesheets) # used to load the google sheet data | |
| library(ggplot2) # used to create graphics | |
| # register google sheet | |
| sheet <- gs_key("1_bGZNmVkT2NBxJd-vQdqmy75UgFtIJ-E0m6mK7eRXyk") |
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
| # Computing Assignment 1 Code | |
| ### Question 1 | |
| x <- c(3, 4, 2, 6, 1) # create a numeric vector | |
| ### Question 2 | |
| 3*x # multiply the numeric vector by three |
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
| # Computing Assignment 2 Code | |
| # set working directory | |
| setwd("~/Dropbox/classes/pols-209") | |
| ### Task 1 | |
| # load packages | |
| library(tibble) # for 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
| # set working directory | |
| setwd("~/Dropbox/classes/pols-209") | |
| # load packages | |
| library(ggplot2) # for creating figures | |
| library(tibble) # for glimpse() | |
| # load data | |
| leg <- readRDS("data/state-legislators.rds") # data are in the data subfolder |