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
# excel windows and mac (see `as.Date()`) | |
# julian/gregorian; new style/old style | |
# mayan calendar | |
# armenian | |
# assyrian | |
# baha'i | |
# benghali | |
# berber | |
# buddhist | |
# burmese |
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
get_all_estimates <- function(data, x, y, power = 1L) { | |
xvar <- x | |
assign(xvar, data[[xvar]]) | |
yvar <- y | |
assign(yvar, data[[yvar]]) | |
data <- data[, !names(data) %in% c(xvar, yvar), drop = FALSE] | |
datalist <- list() |
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 to identify what changed where | |
which_changed <- function(x, y = x) { | |
# argument validation | |
stopifnot(inherits(x, "data.frame")) | |
stopifnot(inherits(y, "data.frame")) | |
stopifnot(identical(dim(x), dim(y))) | |
y <- y[, names(x)] | |
# compare objects |
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(FUN, arg) { | |
f <- formals(FUN) | |
if (!length(f)) { | |
stop("No formal arguments in ", as.character(deparse(substitute(FUN)))) | |
} | |
f2 <- f[-1] | |
FUN2 <- function() { | |
arglist <- c(arg, as.list(match.call())[-1]) | |
do.call(FUN, arglist) | |
} |
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("utils") | |
library("ggplot2") | |
library("ggrepel") | |
dat <- read.csv("data.csv", stringsAsFactors = FALSE) | |
dat[["total"]] <- dat[["democrat"]] + dat[["republican"]] | |
dat[["abbreviation"]] <- sapply(dat[["state"]], function(x) state.abb[grep(x,tolower(state.name))[1]]) | |
ggplot(dat, aes(x = democrat, y = republican, colour = total)) + | |
geom_point() + geom_abline(slope = 1, intercept = 0, colour = "gray") + |
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
Figure 4* | |
barplots* | |
codebook.pdf |
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
# uses dev version of 'waffle' | |
# devtools::install_github("leeper/waffle@patch-1") | |
library("waffle") | |
library("extrafont") | |
# population | |
set.seed(1) | |
N <- 900L | |
p <- c("Small Group 1" = 30, "Big Group 1" = 420, "Small Group 2" = 30,"Big Group 2" = 420) | |
glyph <- c("male", "female")[sample(1:2, N, 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
shrugp <- function(p) { | |
out <- symnum(p, cutpoints = c(0, 0.001, 0.01, 0.05, 0.10, 1.00), | |
symbols = c("(ツ)", "¯\\(ツ)/¯", "¯\\_(ツ)_/¯", "¯\\___(ツ)___/¯", "¯\\____(ツ)____/¯")) | |
as.character(out) | |
} | |
pvals <- c(0.09, 0.03, 0.002, 0.000001) | |
shrugp(pvals) | |
## [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
# ttable: a grammar of tables | |
# https://gist.github.com/leeper/f9cfbe6bd185763762e126a4d8d7c286 | |
# aggregate/summarize | |
# arrange | |
# annotation (metadata features) | |
# theme |
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("rtruncnorm") | |
library("prediction") | |
library("margins") | |
set.seed(14850) | |
n <- 300 | |
error <- 4 | |
ex <- data.frame( | |
d = rbinom(n,1,.5), | |
x = rnorm(n), | |
e = rnorm(n,0,error)) |