Skip to content

Instantly share code, notes, and snippets.

View even4void's full-sized avatar

chl even4void

View GitHub Profile
@even4void
even4void / .emacs
Last active August 21, 2021 08:47
Basic setup to use Gmail from Emacs using a combination of mu, mu4e and offlineimap
(require 'offlineimap)
(add-to-list 'load-path "~/.emacs.d/lib/mu4e")
(require 'mu4e)
(require 'mu4e-maildirs-extension)
(mu4e-maildirs-extension)
(setq mu4e-drafts-folder "/drafts"
mu4e-sent-folder "/sent"
mu4e-trash-folder "/trash")
(setq mu4e-maildir-shortcuts
@even4void
even4void / twins_power.r
Created May 28, 2013 02:43
Power and sample size for univariate ACE model.
## ESTIMATE SAMPLE SIZE NEEDED to achieve a given power in univariate twin studies.
##
## Input:
## pmz: sampling fraction MZ/DZ
## tmz: intraclass correlation for MZ twins
## tdz: intraclass correlation for DZ twins
## alpha: level I risk level
## beta: level II risk level (power = 1 - beta)
##
## Output:
@even4void
even4void / raneff.r
Last active June 1, 2017 04:30
Illustration of within-unit vs. random-effect model predictions.
library(lme4)
data(sleepstudy)
## Fit individual regression lines for each subject
dfrm <- coef(lmList(Reaction ~ Days | Subject, sleepstudy))
## Estimate parameters of a random intercept and random intercept and slope model
m1 <- lmer(Reaction ~ Days + (1 | Subject), data=sleepstudy)
m2 <- lmer(Reaction ~ Days + (Days | Subject), data=sleepstudy)
@even4void
even4void / Makefile
Created October 25, 2012 18:35
A sample demo of R Markdown with pandoc
RMDFILE=demo-rmd-pandoc
PANDOC=~/.cabal/bin/pandoc
all:
Rscript -e "require(knitr); require(markdown); knit('$(RMDFILE).rmd', '$(RMDFILE).md'); purl('$(RMDFILE).rmd')"
${PANDOC} --mathjax --toc -B header.html -A footer.html --bibliography refs.bib --css markdown.css -s $(RMDFILE).md -o $(RMDFILE).html
# Compute % agreement between any two columns in a data.frame
dfrm <- data.frame(replicate(18, sample(letters[1:3], 30, replace=TRUE)))
agree <- function(df, i, j) {
tab <- table(df[,c(i,j)])
sum(diag(tab))/sum(tab)
}
# Solution 1
vagree <- Vectorize(agree, vectorize.args=list("i","j"))
#! /usr/bin/env sh
# Post-process Stata do -> log file.
# We should ensure that we use the correct stata program
# (e.g., might be stata, stata-mp, etc.). I'll put this here
# for later update.
STATA="$(which stata)"
# Process command line options
@even4void
even4void / sample.R
Created December 6, 2011 08:46
reproducible example in R
# simulate some data
set.seed(88)
n <- 30
x <- runif(n)
y <- 1.2 + 0.8*x + rnorm(n)
g <- sample(letters[1:2], n, replace=TRUE)
my.df <- data.frame(x=x, y=y, grp=factor(g))
# show data structure
dput(my.df)
@even4void
even4void / power.R
Created August 11, 2011 10:05
A simple animated demonstration of Power Analysis
mha <- 1 # mean under the alternative
es <- 2 # observed effect (deviation from mean under H0)
x <- seq(-6, 6, length=1000)
dh0 <- dnorm(x, 0, 1)
show.it <- function(es, mha, verbose=FALSE) {
dh1 <- dnorm(x, mha, 1)
plot.new()
plot.window(xlim=range(x), ylim=c(0,.6))
@even4void
even4void / tufte_bxp.R
Created August 5, 2011 23:26
Tufte's boxplot
tufte.boxplot <- function(x, g) {
k <- nlevels(g)
crit.val <- tapply(x, g, median)
plot(1:k, crit.val, ylim=c(min(x)*1.1, max(x)*1.1), pch=19,
xlab=deparse(substitute(g)), ylab=deparse(substitute(x)))
for (i in 1:k) {
tmp <- boxplot.stats(x[as.numeric(g)==i])
segments(i, tmp$stats[1], i, tmp$stats[2])
segments(i, tmp$stats[4], i, tmp$stats[5])
points(rep(i, length(tmp$out)), tmp$out, cex=.8)
@even4void
even4void / dsm5.bib
Created July 26, 2011 14:00
Some references on DSM-V
@article{Narrow2009,
Author = {Narrow, W.E. and Kuhl, E.A. and Regier, D.A.},
Journal = {World Psychiatry},
Month = {Jun},
Number = {2},
Pages = {88-89},
Title = {{DSM-V} perspectives on disentangling disability from
clinical significance},
Volume = {8},
Year = {2009}}