Skip to content

Instantly share code, notes, and snippets.

View jwbowers's full-sized avatar
🎯
Focusing

Jake Bowers jwbowers

🎯
Focusing
View GitHub Profile
\newcommand{\pfn}{\text{pfn}}
\newcommand{\bset}{\mathcal{B}}
\newcommand{\splitfn}{\text{splitfn}}
\newcommand{\bZ}{\bm{Z}}
\newcommand{\bS}{\bm{S}}
\newcommand{\bz}{\bm{z}}
\newcommand{\bOne}{\bm{1}}
@jwbowers
jwbowers / commit_sizes.py
Created April 18, 2024 09:55
List the percentage change in text between each commit and the previous commit. Can be more than 100.
import subprocess
import sys
import csv
# uses the GitPython module
import git
from pathlib import Path
## Notice need to install GitPython
## Recommended:
## python3 -m venv .venv
@jwbowers
jwbowers / anytreatment_vs_control.R
Created August 8, 2023 19:35
Bias in Estimating "Any Treatment" versus Control
library(tidyverse)
library(DeclareDesign)
my_designer <- function(N, tau1, tau2) {
# N - total sample size
# tau1 - difference in proportion control versus "easy" message
# tau2 - difference in proportion control versus "right" message
fixed_pop <- fabricate(
N = N,
@jwbowers
jwbowers / lm_lin_example.R
Created July 1, 2022 10:27
High_Dim_Cov_Adj
library(estimatr)
library(fabricatr)
library(DeclareDesign)
set.seed(12345)
dat <-
fabricate(
N = 50,
x = sample(1:40, N, replace = TRUE),
@jwbowers
jwbowers / pop_sampling_dd1.R
Last active April 17, 2020 17:14
A simple sampling design for declare design
## We have many group homes (like nursing homes) and few COVID tests.
## We want to test a simple random sample within each home to estimate the proportion positive with COVID (or detect
## any COVID)
## So, each place has a fixed population (N) and we will sample from this place.
## The population should be unique for combination of N and covidprob (which is just .02 in the simulations, but higher for
## testing here).
## I'd like to use the nice DeclareDesign functions like redesign() to assess
## power to detect COVID given different proportions of sampling for each population size
@jwbowers
jwbowers / pop_sampling_dd1.R
Created April 16, 2020 20:09
A simple sampling design for declare design
> pop <- declare_population(N,
+ covid=rbinom(N,size=1,prob=covidprob))
> samp <- declare_sampling(n=n)
> sim_design <- pop + samp
> set.seed(12345)
> tmp <- draw_data(redesign(sim_design,N=40,n=20,covidprob=.5))
> table(tmp$covid)
0 1
9 11
@jwbowers
jwbowers / Basic test for Declare Design
Created April 14, 2020 21:13
SimpleTestDeclareation.R
#' Wrap a basic one-way t-test so that it's usable by the tidy functions
#' @param data The data that we pass in. See discussion of tidy_estimator and handlers in declare_estimator
#' @returns A data frame that contains quantities useful for assessing the design and estimator
our_ttest <- function(data) {
require(coin)
res <- coin::oneway_test(
outcome ~ factor(Xclus),
data = data,
distribution = "asymptotic"
)
## Example of simulating data from a design with one-sided non-compliance
types <- c("Always-Taker", "Never-Taker", "Complier", "Defier")
direct_effect_of_encouragement <- 0.0
proportion_defiers <- 0.0
design <- declare_population(
N = 500,
type = sample( types, N, replace = TRUE,
prob = c(0.1, 0.1, 0.8 - proportion_defiers, proportion_defiers)
),
@jwbowers
jwbowers / ebp-cartoon2.html
Last active January 10, 2020 20:50
2 panel cartoon about evidence based policy
<!DOCTYPE html>
<meta charset="utf-8">
<!-- build:css v/cmx.css -->
<link rel="stylesheet" href="styles/cmx.css">
<link rel="stylesheet" href="styles/cmx-overlay.css">
<!-- endbuild -->
<!-- build:js v/cmx.js -->
<script data-main="scripts/main" src="scripts/vendor/require.js"></script>
<!-- endbuild -->
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
@jwbowers
jwbowers / ebp-cartoon-weak-theory.html
Last active December 1, 2019 19:51
EBP Weak Theory
<!DOCTYPE html>
<meta charset="utf-8">
<!-- build:css v/cmx.css -->
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css"/>
<script src="http://cmx.io/v/0.1/cmx.js"></script>
<!-- <link rel="stylesheet" href="styles/cmx-overlay.css"> -->
<!-- endbuild -->
<!-- build:js v/cmx.js -->
<!-- <script data-main="scripts/main" src="scripts/vendor/require.js"></script> -->
<!-- endbuild -->