Skip to content

Instantly share code, notes, and snippets.

View mikedecr's full-sized avatar

Mike DeCrescenzo mikedecr

View GitHub Profile
@mikedecr
mikedecr / scrape_scum_data.R
Last active April 24, 2022 23:52
Scrape SCUM scores for all Bond films from killjamesbond.com
# ----------------------------------------------------------------------------
# Scrape SCUM data from KillJamesBond.com
# by Michael DeCrescenzo (github.com/mikedecr)
# ----------------------------------------------------------------------------
# We take the following approach.
# 1. There is a table at https://www.killjamesbond.com/scum-rankings
# containing links to each film's SCUM data.
# We use this table to build an index of URLs to walk
# 2. We the define several functions to get SCUM and other metadata
---
title: '`xaringanthemer` font problem MWE'
author: Michael G. DeCrescenzo
date: |
`r format(Sys.time(), '%B %d, %Y')`
---
Specifying a different font with `base_family` works fine.
```{r}
@mikedecr
mikedecr / smartly-reinstall-R-pkgs.R
Last active November 30, 2021 20:42
When you're installing packages after a major R upgrade and you DON'T just want to get everything from CRAN.
# ----------------------------------------------------
# Installing packages for new R version.
# Michael DeCrescenzo
#
# Hi, I'm a political science PhD student looking for
# a data science/quantitative research/statistics job.
# Learn more at <mikedecr.github.io> and <github.com/mikedecr>
#
# This script deals with the following problem:
# I upgraded to new major version of R, & I want to reinstall packages.
# ---- Heiss code -----------------------
# From: https://gist.github.com/andrewheiss/5e162c836575721d1dd53ec2af38753c
# by Andrew Heiss
library("magrittr")
library("tidyverse")
library("lubridate")
library("broom")
library("scales")
@mikedecr
mikedecr / heart-gif.R
Last active February 14, 2018 15:33
make a gif of a heart using R, ggplot, and gganimate
# ----------------------------------------------------
# happy valentine's day
# trig code from @dmi3k (https://twitter.com/dmi3k/status/963758478375444480)
# ----------------------------------------------------
library("tidyverse")
library("gganimate")
theme_set(theme_classic())
@mikedecr
mikedecr / tweet_if_prime_date.R
Last active January 8, 2017 17:16
Prime Number Date Tweeter
########################################
# Script to tweet if the date is a prime number (American date)
# (((European and International date formats coming soon)))
########################################
library(lubridate) # date functions
library(matlab) # contains isprime()
@mikedecr
mikedecr / McCrary_Test.R
Last active December 5, 2016 23:53
Modifies the DCdensity() function from R's `rdd` package so it returns enough data for custom plotting
mccrary <-
function (runvar, cutpoint, bin = NULL, bw = NULL, verbose = FALSE,
plot = TRUE, ext.out = FALSE, htest = FALSE)
{
library(rdd)
runvar <- runvar[complete.cases(runvar)]
rn <- length(runvar)
rsd <- sd(runvar)
rmin <- min(runvar)
rmax <- max(runvar)
@mikedecr
mikedecr / pred_fx.r
Last active July 17, 2017 02:36
Function for generating predicted values from lm and glm model objects
fx <- function(model, design, predictor = design[,2], alpha = 0.05, reps = 10000, vc = vcov(model)){
require(mvtnorm)
require(sandwich)
# sample from MV normal
matrix.of.draws1 <- t(rmvnorm(n = reps, mean = coef(model), sigma = vc))
design <- as.matrix(design)
tidy.fix <- function(mod) {
tidy(mod) %>%
mutate(
term = ifelse(term=="(Intercept)", "intercept", term))
}
library(tidyr)
library(dplyr)
library(ggplot2)
library(cowplot) # for aesthetic purposes
set.seed(555)
df <-
data.frame(
xrand = runif(100, min = 1, max = 10),