Skip to content

Instantly share code, notes, and snippets.

View johnmyleswhite's full-sized avatar

John Myles White johnmyleswhite

View GitHub Profile
@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."
@johnmyleswhite
johnmyleswhite / mean.md
Last active August 29, 2015 13:55
Counterexamples in Statistics

The sample mean is never exactly equal to the true mean when the true mean is irrational

Let D be any distribution over the integers. Suppose that the first moment exists for D and is an irrational number.

In this case, the sample mean is never exactly equal to the true mean because the sample mean is always a rational number.

This is simple to prove: the sample mean is always a sum of integers divided by the number of samples, which is always an integer.

@johnmyleswhite
johnmyleswhite / mutate.R
Created February 3, 2014 23:45
Scope reification in R
foo <- function(frame_number)
{
assign("frame_number", -1, envir = sys.frame(frame_number))
}
bar <- function()
{
frame_number <- sys.nframe()
print(frame_number)
foo(frame_number)
a <- 1
b <- 2
ftw <- function()
{
vars <- ls(envir = .GlobalEnv)
rm(list = vars, envir = .GlobalEnv)
}
ftw()
@johnmyleswhite
johnmyleswhite / abstract.md
Created February 11, 2014 22:49
Abstract for UC Davis Talk

Julia and Statistical Computing

Julia is a new language for technical computing. The language is designed to solve the "two language problem", in which scientists prototype code in a higher-level language like R and then rewrite parts (or all) of their code in a lower-level language like C. Julia strives to expose a set of basic abstractions that allow programmers to transition easily between quick-and-dirty prototype code and production-quality code.

@johnmyleswhite
johnmyleswhite / poissonmf.jl
Last active August 29, 2015 13:57
Poisson matrix factorization: a naive implementation using dense arrays
using Distributions
const Ψ = digamma
# RNG
function generate(
a::Real,
b::Real,
c::Real,
d::Real,
@johnmyleswhite
johnmyleswhite / README.md
Last active August 29, 2015 13:57
Bernoulli matrix factorization

BinaryMF

Attempt to factor a binary matrix, $D$, under the assumption that entries are IID Bernoulli draws, conditional on the value of a link-transformed linear predictor, $\mathbb{E}[D_{i, j}] = I(\mu + a_i + b_j + X_{i}^{T} Y_{j})$, where $I$ is the inverse logit link function.

Because of non-identifiability problems, we use a consistent $\mathcal{N}(0, \sigma^2)$ prior over all parameters in the model

@johnmyleswhite
johnmyleswhite / 01-bitdiddle.jl
Last active August 29, 2015 14:03
Function Evaluation in Julia and R: Example 1.5 from SICP
# Ben Bitdiddle's demonstration that Julia uses applicative-order evaluation
p() = p()
# p (generic function with 1 method)
test(x, y) = x == 0 ? 0 : y
# test (generic function with 1 method)
@johnmyleswhite
johnmyleswhite / factor_mult.R
Last active August 29, 2015 14:05
Factor arithmetic
> x <- 1
> f <- factor(x)
> f[1] * f[1]
[1] NA
Warning message:
In Ops.factor(f[1], f[1]) : * not meaningful for factors
> p <- f[1] * f[1]
Warning message:
In Ops.factor(f[1], f[1]) : * not meaningful for factors
> class(p)
@johnmyleswhite
johnmyleswhite / loss.jl
Created August 25, 2014 15:35
Worst case loss of precision when converting 64-bit integers into 64-bit floating point numbers
julia> i = uint(0) - uint(1)
0xffffffffffffffff
julia> b = float64(i)
1.8446744073709552e19
julia> j = 0
0
julia> while float64(i) == b