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
#' Function for creating nonparamentric multiple change point plots with | |
#' estimates from the ecp package. | |
#' | |
#' @param data A data frame with the covariates and time variable. | |
#' @param Vars A character vector listing the names of the variates from | |
#' \code{data} to include in the nonparametric multiple change point analysis. | |
#' @param TimeVar A character string naming the time variable in \code{data}. | |
#' Must be in a format handled by POSIX, e.g. YYYY-MM-DD. | |
#' @param sig.lvl The level at which to sequentially test if a proposed change | |
#' point is statistically significant. |
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
##################### | |
# R function for downloading plain-text data from GitHub | |
# Christopher Gandrud | |
# 7 January 2013 | |
##################### | |
# source_GitHubData is directly based on source_url from the Hadley Wickham's devtools package | |
source_GitHubData <-function(url, sep = ",", header = TRUE) | |
{ |
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
# Create lag and difference variables for a grouped time series (grouped by a variable called "country") | |
# | |
# @param df a data frame containing the variable to lag and lead | |
# @param x a column name in `df` to lag and lead | |
# @param lag integer period to lag and difference | |
# | |
# @importFrom tsibble difference | |
# @importFrom dplyr %>% lag | |
create_lags_diffs <- function(df, x, lag = 1) { |
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(xfun) | |
pkg_attach2("tidyverse", "poweRlaw", "furrr") | |
plan(multiprocess) | |
# Simulate from a discrete power law | |
# @param counter numeric, to enable mapping | |
# @param n integer, number of draws | |
# @param xmin numeric, minimum value subject to power law | |
# @param alpha, scaling parameter |
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
Y | X | Z | A | |
---|---|---|---|---|
1.41349020936189 | Signup | 3.76363446527701 | 0 | |
-1.19511457323204 | No Signup | -3.81402465182499 | 1 | |
1.87668885146666 | Signup | 0.712012451131932 | 1 | |
1.8385401566156 | No Signup | -0.774724331043617 | 1 | |
3.02728268507929 | Signup | 3.25513469702395 | 1 | |
2.88424256922274 | Signup | -0.863068694934284 | 1 | |
-0.387965283366912 | No Signup | -2.59568803608236 | 0 | |
0.577546833602056 | Signup | -0.277480406497884 | 0 | |
2.72670763084368 | Signup | 0.181542158647839 | 1 |
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
######################################################## | |
# Set up RStudio and JAGS on an Amazon EC2 instance | |
# Using Ubuntu 64-bit | |
# Christopher Gandrud | |
# 16 December 2014 | |
# Partially from http://blog.yhathq.com/posts/r-in-the-cloud-part-1.html | |
# See yhat for EC2 instance set up | |
######################################################## | |
# In your terminal navigate to key pair |
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(pacman) | |
p_load(MASS, tidyverse) | |
# set seed | |
set.seed(4321) | |
# set simulation paramters | |
n <- 100 # sample size |
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(pacman) | |
p_load(MASS, tidyverse) | |
# set seed | |
set.seed(8764) | |
# set simulation paramters | |
n <- 100 # sample size |
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
set.seed(19743) | |
library(tidyverse) | |
library(ggrepel) | |
library(forcats) | |
tau <- function(x) { | |
x^2 | |
} |
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
#################### | |
# Create relogit predicted probabilities using Zelig and ggplot2 | |
# Two Sword Lengths: Losers' Consent and Violence in National Legislatures (Working Paper 2012) | |
# Christopher Gandrud | |
# Updated 26 April 2012 | |
################### | |
## Load required packages | |
library(RCurl) | |
library(Zelig) |