Skip to content

Instantly share code, notes, and snippets.

View mrkrause's full-sized avatar

Matthew Krause mrkrause

View GitHub Profile
using Plot
function calculate(a::Number, b::Number, c::Number)
# Placeholder for a more complicated model, obviously
t = 0:0.01:5
return @. -5*max(t-a, 0) * sin(2π*b*t + c)
end
function myplot(a::Number, b::Number, c::Number; kwargs...)
results = calculate(a, b, c)
@mrkrause
mrkrause / bar_raising.jl
Last active July 9, 2021 19:51
Trivial simulation to see if "bar raising" exponentially increases # of interviews
using Statistics
using Plots
function generate_candidates(;n=1)
return 100 .+ (15 .* randn(n, 1))
end
N_HIRES = 100
N_REPS = 1000
@mrkrause
mrkrause / penguins_size.Csv
Created February 5, 2021 01:58
Palmer's Penguin sizes in the *other* CSV format.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
species🤡island🤡culmen_length_mm🤡culmen_depth_mm🤡flipper_length_mm🤡body_mass_g🤡sex
Adelie🤡Torgersen🤡39.1🤡18.7🤡181.0🤡3750.0🤡MALE
Adelie🤡Torgersen🤡39.5🤡17.4🤡186.0🤡3800.0🤡FEMALE
Adelie🤡Torgersen🤡40.3🤡18.0🤡195.0🤡3250.0🤡FEMALE
Adelie🤡Torgersen🤡🤡🤡🤡🤡
Adelie🤡Torgersen🤡36.7🤡19.3🤡193.0🤡3450.0🤡FEMALE
Adelie🤡Torgersen🤡39.3🤡20.6🤡190.0🤡3650.0🤡MALE
Adelie🤡Torgersen🤡38.9🤡17.8🤡181.0🤡3625.0🤡FEMALE
Adelie🤡Torgersen🤡39.2🤡19.6🤡195.0🤡4675.0🤡MALE
Adelie🤡Torgersen🤡34.1🤡18.1🤡193.0🤡3475.0🤡
@mrkrause
mrkrause / small_sample_sd.jl
Created December 5, 2020 19:14
Demonstrate bias when estimating standard deviation from small samples
using Plots
using StatsBase
using Printf
import StatsBase.mode
"""
Find the location of a (unimodal) histogram's mode
"""
function mode(histo::Histogram)
modeloc = findmax(histo.weights)
@mrkrause
mrkrause / ppc.m
Created November 13, 2019 06:04
Pairwise phase consistency
function ppc0 = ppc(phases, varargin)
%% PPC Compute pairwise phase consistency (PPC0 of Vinck et al, 2010)
% INPUT:
% - phases: Vector of phases (radians, single-precision)
% OUTPUT:
% - ppc0: pairwise phase consistency of the phases in `phases`.
% OPTIONS:
% - UseParallel: When to use the parallel pool: 'always', 'never', or 'auto'
% If auto, the parallel pool is used whenever there are at least
% `ParallelThreshold` items in vector and a pool is available or
@mrkrause
mrkrause / naturecomms.py
Created October 17, 2019 19:32
Crawl NPG journals to figure out how long it takes a Matters Arising to be accepted.
import requests
from bs4 import BeautifulSoup
from collections import namedtuple
from datetime import datetime
from typing import List, Sequence
# Tiny little class for holding publication history
ArticleHistory = namedtuple('ArticleHistory', ['received', 'accepted', 'published', 'doi', 'title', 'journal'])
ArticleHistory.__new__.__defaults__ = (None,)*6
NREP = 30000;
N = 1000;
K = 5;
p_random = nan(NREP, 1);
p_cluster = nan(NREP, 1);
parfor rep=1:NREP
data = randn(N, 1);
random_group = mod(randperm(N), K);