Skip to content

Instantly share code, notes, and snippets.

@jtleek
jtleek / puzzle_nov25_2015.delim
Last active Nov 25, 2015
November 25th dplyr puzzle
View puzzle_nov25_2015.delim
col3 col2 col4 col1
h a t t
i v i g
k s g n
n g n i
View predict_function
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 / any-pvalue-significant.R
Created Aug 19, 2015
Any p-value significant example
View any-pvalue-significant.R
## 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
View google-scraper.R
## Load libraries
library(XML)
library(dplyr)
library(RCurl)
## Get the results for a specific term
scrape_term = function(search_term,npages){
base_url = "http://scholar.google.com/scholar?"
search_string = paste0("q=",paste0(strsplit(search_term," ")[[1]],collapse="+"))
dat = data.frame(NA,nrow=10*npages,ncol=3)
@jtleek
jtleek / P-value histogram Med Journals
Last active Aug 29, 2015
Code to create p-value histograms of significant p-values in journal abstracts for JAMA, NEJM, BMJ, Lancet, and AJE 2000-2010
View P-value histogram Med Journals
## 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 / gist:9665572
Last active Aug 29, 2015
Gist for 80/20 post on Simply Stats
View gist:9665572
# 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
View googleCite.R
#########################################################################################
# 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 / gist:4369771
Created Dec 24, 2012
Create a Christmas Tree in R
View gist:4369771
# Make the canvas
plot(1:10,1:10,xlim=c(-5,5),ylim=c(0,10),type="n",xlab="",ylab="",xaxt="n",yaxt="n")
# Make the branches
rect(-1,0,1,2,col="tan3",border="tan4",lwd=3)
polygon(c(-5,0,5),c(2,4,2),col="palegreen3",border="palegreen4",lwd=3)
polygon(c(-4,0,4),c(3.5,5.5,3.5),col="palegreen4",border="palegreen3",lwd=3)
polygon(c(-3,0,3),c(5,6.5,5),col="palegreen3",border="palegreen4",lwd=3)
polygon(c(-2,0,2),c(6.25,7.5,6.25),col="palegreen4",border="palegreen3",lwd=3)
@jtleek
jtleek / gist:4177366
Created Nov 30, 2012
Bonferroni Correcting Autism P-values
View gist:4177366
pvaluesPain = c(0.02, 0.06, 0.75, 0.38, 0.3, 0.07, 0.22, 0.27)
adjustedPvaluesPain = p.adjust(pvaluesPain,method="bonferroni")
adjustedPvaluesPain
sum(adjustedPvaluesPain < 0.05)
pvaluesNoPain = c(0.82, 0.98, 0.65, 0.39, 0.88, 0.95, 0.29, 0.64, 0.81)
adjustedPvaluesNoPain = p.adjust(pvaluesNoPain,method="bonferroni")
adjustedPvaluesNoPain
sum(adjustedPvaluesNoPain < 0.05)