Skip to content

Instantly share code, notes, and snippets.

View davharris's full-sized avatar

David J. Harris davharris

View GitHub Profile

There's a list of GRFP proposals you can browse here. My essays are here.

From my small sample size of submitting twice, my main advice for the proposal is: The proposal is largely a credibility game, and one of the best ways to signal credibility is to be specific and show that you've thought things through (eg in my proposal, I showed off in a parenthetical that I knew about the equipment I'd be using down to the centimeter). This is kind of silly, but my gut feeling is that it goes a surprisingly long way. My first proposal was rejected in part because I hedged my bets about what my study species would be because I didn't know where I'd end up doing my PhD. No one is going to force you to follow your proposed research exactly (or at all; my dissertation ended up being completely unrelated to what I proposed), so picking on

@davharris
davharris / inflatable-hurdles.R
Last active August 15, 2016 18:26
Shouldn't the zero-inflated negative binomial and hurdle-negative-binomial be different?
library(pscl)
y = c(86, 0, 29, 0, 16, 0, 20, 0, 0, 1, 2, 0, 0, 96, 0, 7, 0, 0,
0, 0, 25, 0, 0, 233, 0, 7, 0, 0, 67, 0, 6, 0, 0, 0, 12, 0, 0,
0, 9, 0, 12, 18, 39, 0, 59, 15, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 88, 48, 50, 26, 0, 47, 0, 0, 0, 18, 0, 60, 0, 0, 180, 0, 0,
28, 95, 13, 0, 28, 19, 32, 0, 2, 0, 0, 0, 28, 0, 0, 0, 184, 14,
0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 6, 21, 68, 0, 0, 0, 3, 9, 0,
0, 0, 1, 15, 0, 13, 26, 0, 0, 0, 0, 0, 0, 0, 0, 342, 93, 0, 3,
0, 0, 0, 94, 0, 0, 56, 56, 27, 11, 27, 7, 0, 12, 66, 0, 0, 3,
@davharris
davharris / bayes-reproducibility-density.R
Last active September 2, 2015 06:10
Code for a kernel density plot showing the Bayes Factors associated with the "Bayesian Reproducibility Project" blog post by Alex Etz.
# Start by running the code on Alex Etz's blog post
# http://alexanderetz.com/2015/08/30/the-bayesian-reproducibility-project/
# Cap the Bayes Factor at 10^12 to allow zooming in further
bfRepCapped = pmin(bfRep, 1E12)
# Kernel density estimate of the log-transformed Bayes Factors
D = density(log(bfRepCapped))
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
# Samples Generated by Stan
# stan_version_major=2
# stan_version_minor=6
# stan_version_patch=0
# init=random
# seed=1252933291
# chain_id=1
# iter=20
# warmup=10
# save_warmup=1
@davharris
davharris / abstract_ESA_2015.md
Last active August 29, 2015 14:16
ESA Abstract 2015

Estimating species interactions from observational data with Markov networks

David J. Harris, Population Biology, UC Davis, Davis, CA

Background/Question/Methods

Inferring species interactions from observational data is one of the most controversial issues in community ecology. Part of the problem is that an interaction between one pair of species can ripple through an ecological network and produce surprising indirect consequences. For example, a species could indirectly harm its mutualists by attracting their natural enemies. In this talk, I show how methods from statistical physics and machine learning can enable ecologists to make quantitative predictions about the landscape-level consequences of positive and negative species interactions. The proposed models, called Markov networks or Markov random fields, provide a rigorous and well-specified method for predicting the types of communities that would arise from any possible matrix of pairwise species interactions. Just as importantly, Mar

n = 10
delta = 0.1
sd = 1
# Calculate power with n and delta
power.t.test(n = n, delta = delta, sd = 1, type = "one.sample") # ~5% power
# Run 10,000 t.tests
p = replicate(1E4, t.test(rnorm(n, mean = delta, sd = 1))$p.value)
f = function(x){
x
}
f() # Throws error: x is missing
g = function(x){
letters[x]
}
@davharris
davharris / geiger.R
Created January 30, 2015 00:52
geiger versus multivariate normal
# Confirming that I understand how geiger's variance-covariance matrices work
library(geiger)
library(mvtnorm)
geo = get(data("geospiza"))
# Simulate one trait using geiger::sim.char
sim = t(
#Based on https://github.com/robotlolita/fuck-you
# and https://en.wikipedia.org/wiki/Transformation_of_text
screw_you = function(x){
chars = strsplit(paste0(c(" ", rev(letters), rev(LETTERS), 0, 9:1, "&_?!\".';'"), collapse = ""), "")[[1]]
flipped = strsplit(
" zʎxʍʌnʇsɹbdouɯlʞɾıɥɓɟǝpɔqɐZ⅄XMΛ∩⊥SᴚΌԀONW⅂⋊ſIH⅁ℲƎᗡƆ𐐒∀068ㄥ9ގㄣƐᘔ⇂⅋‾¿¡„,˙'؛",
"")[[1]]
split = strsplit(as.character(substitute(x)), "")[[1]]
n = 7 # Number of elements to permute
k = 1E5 # Number of permutations allowed by RNG
# Declare a character vector to store permutations
permutations = character(k)
for(i in 1:k){
# save k permutations as strings
permutations[i] = paste(sample.int(n), collapse = "-")
}