{{ message }}

Instantly share code, notes, and snippets.

# Fabian Dablander fdabl

Last active Mar 31, 2019
Implements three ways to do Bayesian variable selection. For context, see https://fdabl.github.io/r/Spike-and-Slab.html
View variable-selection-comparison.R
 library('doParallel') registerDoParallel(cores = 4) #' Spike-and-Slab Regression using Gibbs Sampling for p > 1 predictors #' #' @param y: vector of responses #' @param X: matrix of predictor values #' @param nr_samples: indicates number of samples drawn #' @param a1: parameter a1 of Gamma prior on variance sigma2e
Last active Dec 5, 2018
Visualizes three dimensional Dirichlet distributions
View dirichlet-triangle.R
 # devtools::install_github("dkahle/dirichlet") library('TeX') library('ggplot2') library('gridExtra') library('dirichlet') plot_dirichlet <- function(alphas = c(.5, .5, .5), add_points = FALSE) { f <- function(v) ddirichlet(v, alphas) mesh <- simplex_mesh(.0025) %>% as.data.frame %>% tbl_df
Last active Jul 30, 2018
View ci.R
 bfx <- function(x, tstat, n, mu, gamma, k, v = n - 2) { num <- integrate(function(delta) { dt(tstat, df = v, ncp = sqrt(n)*delta)/gamma * dnorm((delta - mu)/gamma) }, -Inf, Inf)\$value dt(tstat, df = v, ncp = sqrt(n)*x) / num } lo <- uniroot(function(x) bfx(x, .5, 10, 0, .3) - 1, interval = c(-1, 0))\$root
Created Oct 17, 2016
View dynamite.R
 # for https://www.facebook.com/efpsa.jeps/posts/1278843852167100 library('ggplot2') library('gridExtra') set.seed(1774) # generate data A = c(rnorm(20, 20, 4), rnorm(20, 40, 4)) # mixture distribution B = rt(30, 1) + 30 # from a heavy-tailed distribution (Cauchy) C = c(25, 35, 33) # just three data points
Created May 22, 2016
View bayesian_p2_ANOVA.Rmd
 --- title: "Bayesian effect size for ANOVA designs" author: "Fabian Dablander, Maarten Marsman" date: "May 22, 2016" output: html_document --- ## 1) Example: One-way design Download the data from [https://osf.io/zcipy/](https://osf.io/zcipy/), save it under "example1.sav" in the current directory.
Created Feb 22, 2016
View unsupervised.jl
 function PCA(X) ## Y = PX # required: #- P such that #- we get rid of 2nd order correlation, Cov(Y) = D [some diagonal matrix] # method: #- project onto an orthogonal space spanned by the #- eigenvectors with variances equal to the eigenvalues
Last active Jan 4, 2016
View scrape_emails.R
 library('rvest') library('stringr') fachschaft = 'http://wiki.psyfako.org/index.php?title=Liste_der_Psychologie_Fachschaften' emails = read_html(fachschaft) %>% html_nodes('p, a, span') %>% html_text(.) %>% str_replace('\\[at\\]', '@') %>% str_replace('\\(at\\)', '@') %>% str_replace('\\[ät\\]', '@') %>% str_replace('\\[dot\\]', '.') %>%
Created Dec 21, 2015
View shiny_regression.R
 shinyApp( options = list(width = '25%', height = '25%'), ui = shinyUI(fluidPage( sidebarLayout( sidebarPanel( sliderInput('e', label = 'e', min = 0, max = 100, value = 10, step = 1), sliderInput('N', label = 'N', min = 10, max = 500, value = 100, step = 1), numericInput('seed', label = 'random seed', value = 1774), numericInput('lambda', label = 'penalty (lambda)', value = 0), textInput('true', label = 'true function f(x)', value = 'x^2'),
Created Nov 18, 2015
View bayes_lasso.R
 library('runjags') lasso.bayes <- function(y, X, n.iter = 10000) { ms <- ' model { sigma ~ dunif(0, 100) tau <- pow(sigma, -2) lambda ~ dunif(0, 10)
Last active Nov 19, 2015
View bayesplot.R
 # c('practicality', 'difficulty', 'some color, dunno') papers <- rbind( # paper we discuss c(5, 3, 1), # Lindley (1993) c(8, 0, 1), # Kruschke (2010) c(4, 3, 1), # Wagenmakers (2007) c(5, 2, 1), # Dienes (2011) c(3, 7, 1), # Vandekerckhove, Matzke, Wagenmakers (2015) c(4, 8, 1), # Rouder & Morey (2012)