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
# Creates a 3D plot to demonstrate how a combination of OLS parameters minimizes residual sum of squares | |
# set values for X | |
x <- seq(-50, 50, 1) | |
# Y as a function of X with random error | |
y <- NA | |
for (i in 1:length(x)) { | |
y[i] <- 2*x[i] + rnorm(1, 0, 5) | |
} |
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(tidyr) | |
library(dplyr) | |
library(ggplot2) | |
library(cowplot) # for aesthetic purposes | |
set.seed(555) | |
df <- | |
data.frame( | |
xrand = runif(100, min = 1, max = 10), |
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
tidy.fix <- function(mod) { | |
tidy(mod) %>% | |
mutate( | |
term = ifelse(term=="(Intercept)", "intercept", term)) | |
} |
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
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) |
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
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) |
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
######################################## | |
# 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() |
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
# ---------------------------------------------------- | |
# happy valentine's day | |
# trig code from @dmi3k (https://twitter.com/dmi3k/status/963758478375444480) | |
# ---------------------------------------------------- | |
library("tidyverse") | |
library("gganimate") | |
theme_set(theme_classic()) |
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
# ---- Heiss code ----------------------- | |
# From: https://gist.github.com/andrewheiss/5e162c836575721d1dd53ec2af38753c | |
# by Andrew Heiss | |
library("magrittr") | |
library("tidyverse") | |
library("lubridate") | |
library("broom") | |
library("scales") |
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
# ---------------------------------------------------- | |
# 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. |
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
--- | |
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} |
OlderNewer