Skip to content

Instantly share code, notes, and snippets.

@jtleek
jtleek / gist:9665572
Last active August 29, 2015 13:57
Gist for 80/20 post on Simply Stats
# Load library
library(RSkittleBrewer)
# Differences in mean between 0 and 5
sig = seq(0,5,length=100)
# This is the sample size
ss = 20
# Calculate power from 200 replicated tests
@jtleek
jtleek / P-value histogram Med Journals
Last active August 29, 2015 14:01
Code to create p-value histograms of significant p-values in journal abstracts for JAMA, NEJM, BMJ, Lancet, and AJE 2000-2010
## See the paper by Jager and Leek and associated discussion
## for more information: http://biostatistics.oxfordjournals.org/content/15/1/1
## For the code to perform the analysis in that paper or to see how the p-values
## were collected see the repo: https://github.com/jtleek/swfdr
## The data for this gist are available here:
## https://github.com/jtleek/swfdr/blob/master/pvalueData.rda
## Load packages
library(ggplot2)
@jtleek
jtleek / any-pvalue-significant.R
Created August 19, 2015 14:22
Any p-value significant example
## Load library/set seed
set.seed(1325)
library(qvalue)
library(RSkittleBrewer)
trop = RSkittleBrewer("tropical")
## Set a target p-value
target_pval = 0.8
## Not significant if we
Blah blah blah 2
library(lubridate)
dt = "2015-11-18"
predict_function = function(dt){
dt_ymd = ymd(dt)
## Get some info
mday_dt = mday(dt_ymd)
wday_dt = wday(d_ymd)
## Download data
@jtleek
jtleek / puzzlehard_nov25_2015.delim
Last active November 25, 2015 17:08
November 25th advanced dplyr puzzle
col3 col2 col4 col1
h b t t
i w i g
k t g n
n h n i
@jtleek
jtleek / puzzle_nov25_2015.delim
Last active November 25, 2015 17:08
November 25th dplyr puzzle
col3 col2 col4 col1
h a t t
i v i g
k s g n
n g n i
@jtleek
jtleek / tday.delim
Last active November 25, 2015 17:13
Nov 25 dplyr puzzle solution
col1 col3 col2
t h a
n k s
g i v
i n g
@jtleek
jtleek / googleCite.R
Created September 3, 2013 14:07
googleCite gist
#########################################################################################
# Some functions to quantify your Google Scholar citations page.
# R functions Copyright (C) 2011 John Muschelli (jmuschel@jhsph.edu), Andrew Jaffe (ajaffe@jhsph.edu),
# Jeffrey Leek (jtleek@gmail.com), and the Simply Statistics Blog
# (http://simplystatistics.tumblr.com, http://twitter.com/simplystats)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@jtleek
jtleek / dumb-resid
Created December 7, 2016 16:16
bootstrapping residuals - the dumb way
f1 = formula(log(cost) ~ date)
lm1 = lm(f1,data=nuclear)
stat = lm1$coeff[2]
resid = lm1$residuals
fit = lm1$fitted.values
n = dim(nuclear)[1]
B = 500
stat0 = rep(0,B)