Skip to content

Instantly share code, notes, and snippets.

View jwbowers's full-sized avatar
🎯
Focusing

Jake Bowers jwbowers

🎯
Focusing
View GitHub Profile
@lukeolson
lukeolson / wacolors.py
Created May 12, 2022 19:23
Wes Anderson color pallete, matplotlib
# colors from here (MIT):
# https://github.com/karthik/wesanderson/blob/master/R/colors.R
# example from here:
# https://matplotlib.org/3.5.0/gallery/color/custom_cmap.html
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
#!/usr/bin/env python3
## Uses batch testing and divide-and-conquer to optimize the number of 'test' runs
## Based on the premise that test runs are a bottleneck, as appears to be the case for COVID-19 testing
## assumptions:
## - Test is 100% accurate (incl. precision, recall)
## - Test batching doesn't increase per-test costs very much (big if)
## concerns:
@conormm
conormm / r-to-python-data-wrangling-basics.md
Last active June 26, 2024 07:56
R to Python: Data wrangling with dplyr and pandas

R to python data wrangling snippets

The dplyr package in R makes data wrangling significantly easier. The beauty of dplyr is that, by design, the options available are limited. Specifically, a set of key verbs form the core of the package. Using these verbs you can solve a wide range of data problems effectively in a shorter timeframe. Whilse transitioning to Python I have greatly missed the ease with which I can think through and solve problems using dplyr in R. The purpose of this document is to demonstrate how to execute the key dplyr verbs when manipulating data using Python (with the pandas package).

dplyr is organised around six key verbs:

anonymous
anonymous / bootstrapCIs.R
Created August 3, 2015 07:15
getCI <- function(B, muH0, sdH0, N) {
getM <- function(orgDV, idx) {
bsM <- mean(orgDV[idx]) # M*
bsS2M <- (((N-1) / N) * var(orgDV[idx])) / N # S^2*(M)
c(bsM, bsS2M)
}
DV <- rnorm(N, muH0, sdH0) # simulated data: original sample
M <- mean(DV) # M from original sample
S2M <- (((N-1)/N) * var(DV)) / N # S^2(M) from original sample
@JWiley
JWiley / parallel_boot_lm.cpp
Last active August 4, 2019 19:35
Rcpp Eigen and Parallel based parallel linear model bootstrap
// [[Rcpp::depends(RcppParallel)]]
// [[Rcpp::depends(RcppEigen)]]
#include <Rcpp.h>
#include <RcppEigen.h>
#include <RcppParallel.h>
using namespace std;
using namespace Rcpp;
using namespace RcppParallel;
@jiaxu825
jiaxu825 / pandocHeader
Last active March 14, 2024 20:42
A Pandoc YAML metadata block for compilling Markdown to pretty PDF via latex
---
title:
author:
date:
documentclass:
- scrartcl
header-includes:
- \usepackage{paralist}
- \usepackage{booktabs}
- \usepackage{numprint, xspace, paralist}
@denji
denji / homebrew-rvm.md
Last active February 6, 2024 08:52
Homebrew + RVM > Awesome

The MBP is my development machine, so I needed all of my tools installed with the ability to update them with ease. In the past, I used MacPorts to take care of my MySQL, Memcached, and Ruby installions and it worked just fine. This time around however, I wanted something new and fun. Homebrew.

Homebrew is a new package manager for OS X. Unlike Fink or MacPorts, Homebrew integrates with the core operating system, reducing the number of extra libraries to install etc. Another neat feature is the ability to write software package recipes in Ruby, awesome.

Here are some raw installation instructions (clean system). I like to keep everything under user ownership to make life more enjoyable, say no to sudo.

You will need the latest version of xcode, you can get it here. After the installation is complete, you may continue.

sudo mkdir /usr/local
@Rich-Harris
Rich-Harris / gh-pages.md
Created August 11, 2013 23:02
Automating gh-pages branch updating with changes to the master branch
@markmfredrickson
markmfredrickson / gist:6157476
Created August 5, 2013 16:52
How to look at submatrices of InfinitySparseMatrix objects
library(optmatch)
example(match_on)
#' @param x An ISM or blocked ISM
#' @param rs Names of rows to keep
#' @param cs Names of columns to keep
submatrix <- function(x, rs, cs) {
subset(x,
x@rownames %in% rs,
@jwbowers
jwbowers / bowers-nbp-functions.R
Created July 31, 2012 13:41
Helper functions for nbpMatching
## This file contains functions that I've found useful when working
## with the nbpMatching package. Context for the examples can be seen
## in Appendix E in
## http://jakebowers.org/PAPERS/WongRacialContext2012.pdf
## (forthcoming in the Journal of Politics).
## Make matrices of absolute distances
scalar.dist<-function(var){
## Utility function to make n x n abs dist matrices
## Cribbed from older versions of optmatch