Skip to content

Instantly share code, notes, and snippets.

View NickCH-K's full-sized avatar

NickCH-K

View GitHub Profile
@NickCH-K
NickCH-K / selected_reporting_graph.R
Last active February 5, 2020 19:55
Selected Reporting Graph
library(tidyverse)
library(broom)
library(gridExtra)
reg_return <- function(N) {
# Choose effect size
fx <- .05
df <- tibble(x = runif(N) > .5) %>%
@NickCH-K
NickCH-K / factorPull
Created December 17, 2019 01:58
factorPull to get factor coefficients or interactions out of an R regression and store them in data
# The package for this function isn't quite ready yet, but you may find it handy nonetheless!
# Eventually this will be part of a package.
#' factorPull
#'
#' This function takes any estimated regression compatible with \code{broom::tidy()} that contains a factor variable, or a factor variable interacted with something else. It will pull out those coefficients and line them up with the original data so you can store them as a variable.
#'
#' If multiple coefficients related to the factor are dropped from the model, be sure to check the result.
#'
#' @param model A model object compatible with \code{broom::tidy()}.
@NickCH-K
NickCH-K / animated_SD_wide
Created December 12, 2019 00:46
Animated supply and demand graph
library(tidyverse)
library(Hmisc)
library(gganimate)
library(tweenr)
curve_intersect <- function(c1x, c1y, c2x, c2y, empirical=TRUE, domain=NULL) {
curve1 <- data.frame(x = c1x, y = c1y)
curve2 <- data.frame(x = c2x, y = c2y)
if (!empirical & missing(domain)) {