Skip to content

Instantly share code, notes, and snippets.

View fdabl's full-sized avatar

Fabian Dablander fdabl

View GitHub Profile
library('shiny')
# the code (with a little cleaning up) for the visualisations is from
# http://alexanderetz.com/2015/07/25/understanding-bayes-updating-priors-via-the-likelihood/
# Alex Etz runs a really nice blog -- go check it out!
shinyApp(
ui = shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
div(style = 'display: inline-block;', numericInput('a', label = h4('a'), value = 1)),
#' False Discovery Rate (FDR)
#' see also http://www.sciencedirect.com/science/article/pii/S1053811901910377
#'
#' Declared active Declared inactive
#' Active V_aa V_ai T_a
#' Inactive V_ia V_ii T_i
#' D_a D_i V
#'
#' instead of controlling the overall family wise error, we control
#' the proportion of false discoveries; that is, we want (V_aa) / (V_aa + V_ia)
library('shiny')
# read this: http://alexanderetz.com/2015/04/15/understanding-bayes-a-look-at-the-likelihood/
shinyApp(
ui = shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("p1", label = "p1",
min = 0, max = 1, value = 0.7, step = 0.01),
/*
* empirically tests the complexity of a bogosort based algorithm which
* shuffles circles until they don't overlap (for stimulus presentation)
* is a function of the circle radius, the canvas width and height
*
* call it with (first arg is radius, then width and height of canvas)
* > node test.js 10 300 500
* > node test.js 10
* etc.
*/
require(rvest)
require(dplyr)
scrape <- function(year, top) {
possible <- c(10, 25, 100)
if (!top %in% possible) stop("top must be 10, 25 or 100!")
if (!year %in% 2012:2014) stop("data available only for years 2012 - 2014")
targets <- top[1:which(possible == top)]
library('BayesFactor')
# Bayesian version of http://rynesherman.com/phack.r
# see also http://osc.centerforopenscience.org/2014/07/02/phack/
bhack <- function(n = 30, hackrate = 10, m1 = 0, m2 = 0, sd1 = 1, sd2 = 1,
max_n = 100, bf_cutoff = 3, sims = 1000, graph = TRUE) {
out <- matrix(NA, nrow = sims, ncol = 4)
for (i in 1:sims) {
hackcount <- 0
@fdabl
fdabl / chisq.jl
Last active August 29, 2015 14:12
######
# Homework on Chi² Tests / Loglinear Models on 2x2 tables
#
# instead of computing it by hand or in R, I wrote
# it in Julia, an awesome new language for technical
# computing. I discovered it yesterday, and it is
# truly intriguing. Do check it out! http://julialang.org/
######
# imports; functions in those modules are global now
library('coda')
library('BayesFactor')
set.seed(1774) # Laplace easter egg :)
contains_zero <- function(interval) {
return(interval[1] < 0 && interval[2] > 0)
}
# models from p. 146 of
# http://www.uni-tuebingen.de//uni/sii/pw/heller/statistics_III_ws14/stat5www.pdf
# c(model1, model2, model3)
aic <- c(8128.519, 8249.935, 8163.826)
llh <- c(-4039.260, -4118.967, -4074.913)
params <- c(25, 6, 7)
# compute the relative distance of each model AIC to the
# model with the minimum AIC
@fdabl
fdabl / pcurve.R
Last active August 29, 2015 14:06
library('pwr') # for power calculations
library('foreign') # for dreadful spss .sav files
library('psych') # required by phack
source('http://rynesherman.com/phack.r')
SIM <- 10000
set.seed(42)
options(warn=-1) # avoid warning by read.spss
############################################
# Simulating p-hacking