Skip to content

Instantly share code, notes, and snippets.

View dhicks's full-sized avatar

Dan Hicks dhicks

View GitHub Profile
---
title: "Samples can be smaller than you think"
output:
flexdashboard::flex_dashboard:
vertical_layout: scroll
runtime: shiny
---
```{r setup, include = FALSE}
library(tidyverse)
@dhicks
dhicks / elven_accuracy
Created October 16, 2023 05:16
Rolling elven accuracy using RAW vs. just rolling all three at once
library(magrittr)
## Given a vector, calculate both the mean and standard deviation
mean_sd = function(vec) {
list(mean = mean(vec),
sd = sd(vec))
}
d20 = function() sample.int(20, 1)
@dhicks
dhicks / q-and-a.R
Created October 13, 2023 16:49
Compare two approaches to managing Q&A queues
library(tidyverse)
## Parameters ----
## How many people have questions?
n_questions = 30
## How many questions will actually get answered?
max_questions = 15
## How many times to run the simulation?
N = 500
@dhicks
dhicks / mermaid.css
Created July 21, 2022 18:43
Argument map styling for Mermaid
/*-- scss:rules --*/
.mermaid svg {
max-width: 100%;
height: auto;
}
#Argument rect {
stroke:transparent;
fill:#e5e5e5!important;
}
@dhicks
dhicks / interactions.R
Created December 24, 2021 16:39
Omitted interaction terms don't cause omitted variable bias maybe?
library(tidyverse)
theme_set(theme_minimal())
library(broom)
one_sim = function(id, n = 100) {
dataf = tibble(x1 = rnorm(n, 0, 1),
x2 = rnorm(n, 0, 1),
eps = rnorm(n, 0, .1),
y = 1 + x1 + 3*x1*x2 + eps)
coef_df = lm(y ~ x1 + x2, dataf) |>
@dhicks
dhicks / vaxx-waffle.R
Created September 15, 2021 22:02
Waffle plots to illustrate the importance of base rates
library(tidyverse)
# Sys.unsetenv('GITHUB_PAT')
# remotes::install_github('https://github.com/hrbrmstr/waffle')
library(waffle)
## <https://www.npr.org/sections/goatsandsoda/2021/08/20/1029628471/highly-vaccinated-israel-is-seeing-a-dramatic-surge-in-new-covid-cases-heres-why>
## "half of Israel's seriously ill patients who are currently hospitalized were fully vaccinated at least five months ago"
# vaxx rate: 78%
@dhicks
dhicks / dependencies.Rmd
Created September 17, 2020 15:25
Create a cool table of dependencies in a bookdown book
## From <https://github.com/tidymodels/TMwR/blob/master/index.Rmd>
```{r pkg-list, echo = FALSE, results="asis"}
deps <- desc::desc_get_deps()
pkgs <- sort(deps$package[deps$type == "Imports"])
pkgs <- sessioninfo::package_info(pkgs, dependencies = FALSE)
df <- tibble::tibble(
package = pkgs$package,
version = pkgs$ondiskversion,
source = gsub("@", "\\\\@", pkgs$source)
)
## Parses a roster page saved from Canvas and allocates students to groups within discussion sections
## To use:
## 1. Navigate to the People page in a Canvas course using your browser
## 2. Right-click on the page and select "Save as"
## 3a. `Rscript parse.R path/to/roster.html`
## -OR-
## 3b. Save it to `data_folder` as `roster.html`. `Rscript parse.R` or run in RStudio.
## Setup ----
@dhicks
dhicks / sample_size_sim.R
Last active March 16, 2020 20:30
If one group is much larger than the other, does this inflate type I error rates or bias estimates?
## If one group is much larger than the other, does this
## inflate type I error rates or bias estimates?
library(tidyverse)
library(broom)
library(tictoc)
set.seed(2020-03-16)
## Parameters ----
a_n = 300
@dhicks
dhicks / fixcalibre
Created July 25, 2019 21:48
Just a little Bash wrapper around a Ghostscript call to fix an encoding error when Calibre converts epub to pdf
#!/bin/bash
## Just a little Bash wrapper for a Ghostscript call
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$2" "$1"