Skip to content

Instantly share code, notes, and snippets.

View johnmyleswhite's full-sized avatar

John Myles White johnmyleswhite

View GitHub Profile
using Distributions
for sigma in -1:-1:-12
p = 2 * cdf(Normal(0.0, 1.0), sigma)
n = round(BigInt, big(10)^(-log10(p)))
@printf("%d\t%s\n", -sigma, n)
end
@johnmyleswhite
johnmyleswhite / normal_ops.md
Created March 24, 2016 16:25
Operations on Normal Variables

Some Operations on Standard Normal Variables

Assume that:

  • x[i] ~ Normal(0, 1) for all i
  • c is a constant

Then the following operations have analytic results:

  • x[1] + c ~ Normal(c, 1)
@johnmyleswhite
johnmyleswhite / prime_pairs_mod_b.jl
Last active March 15, 2016 14:43
Prime Number Conspiracy
@doc """
Search through all pairs of primes below n, then compute a table R[i, j] which
indicates the numbers of pairs (p, q) such that mod1(p, b) == i and
mod(q, b) + 1.
""" ->
function prime_pairs_mod_b(n, b, debug::Bool = false)
ps = primes(n)
R = zeros(Int, b, b)
for i in 1:(length(ps) - 1)
p, q = ps[i], ps[i + 1]
@johnmyleswhite
johnmyleswhite / fisher.md
Last active March 11, 2016 18:46
Fisher via Mayo

In relation to the test of significance, we may say that a phenomenon is experimentally demonstrable when we know how to conduct an experiment which will rarely fail to give us a statistically significant result.

(Fisher 1947, p. 14)

From "Don't throw out the error control baby with the bad statistics bathwater: a commentary" by Deborah G. Mayo

@johnmyleswhite
johnmyleswhite / statistical_maxims.md
Created December 1, 2015 15:25
Statistical Maxims
  • Correlation is not causation (???)
  • No causation without manipulation. (Holland)
  • All models are wrong, some are useful. (Box)
  • Statistics is the science of uncertainty. (arguably Tukey)
  • Statistics is the science of learning from experience, especially experience that arrives a little bit at a time. (Efron)
@johnmyleswhite
johnmyleswhite / useless_initialization.jl
Created October 11, 2015 00:57
Clever initialization is bad for 1D ideal point models
# Generate a closure that computes the unnormalized negative log-posterior at
# any set of parameters.
function make_nlp(
n_legislators,
n_bills,
legislators,
bills,
votes,
)
function nlp(θ)
@johnmyleswhite
johnmyleswhite / nullable_logic.md
Last active October 9, 2015 03:06
Design Doc for Nullables

Introduction

To understand the design of the new Nullable type in Julia 0.4, let's review how Julia worked in 0.3.

For the purpose of this discussion, there are only three things that matter in the Julia language: values, types and functions. 1 is a value; its type is Int; and one(x::Int) = 1 is a function that maps any value of type Int to the value 1.

For the purposes of this note, we'll make the simplifying assumption that types are simply sets of values. For example, the type Int is the set containing all of the valid Int values: it is effectively equivalent to the set of values {..., -1, 0, 1, ...}. In Julia, a type is uniquely defined by the set of values that it contains. At the same time, any value in Julia also has a unique concrete type, which is the smallest set that contains that value.

Given these three parts of the language, we want to introduce a new parametric class of values to represent the concept of nullness found in other languages. To help out type inference by pr

@johnmyleswhite
johnmyleswhite / dplyr_32bit_ints.R
Created September 9, 2015 14:37
32-bit Int woes in R
> library("dplyr")
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
@johnmyleswhite
johnmyleswhite / stats_woes.txt
Created August 28, 2015 16:03
Stats Quotes
"We are struck by the fact that in the social and behavioral sciences,
epidemiology, economics, market research, engineering, and even applied
physics, statistical methods are routinely used to justify causal inferences
from data not obtained from randomized experiments, and sample statistics are
used to predict the effects of policies, manipulations or experiments. Without
these uses the profession of statistics would be a far smaller business. It may
not strike many professional statisticians as particularly odd that the
discipline thriving from such uses assures its audience that they are
unwarranted, but it strikes us as very odd indeed."
library("dplyr")
library("ggplot2")
packageVersion("dplyr")
packageVersion("ggplot2")
foo <- iris %>% group_by(Species) %>% summarize(m = mean(Sepal.Length))
ggplot(foo, aes(x = 1, y = m)) +
stat_summary(fun.data = "mean_cl_boot", geom = "errorbar")