Skip to content

Instantly share code, notes, and snippets.

View even4void's full-sized avatar

chl even4void

View GitHub Profile
@even4void
even4void / levelplot_annot.R
Created February 16, 2011 21:47
Lattice annotation
x <- seq(0,10)
y <- seq(0,10)
df <- expand.grid(x=x, y=y)
df$z <- rnorm(nrow(df), mean=5)
library(lattice)
levelplot(z ~ x+y, data=df,
panel=function(x, y, ...) {
panel.levelplot(x, y, ...)
panel.abline(v=1)
@even4void
even4void / CVJC.bib
Created March 10, 2011 19:38
Articles proposed for CrossValidated Journal Club
@article{arlot2010survey,
Author = {Arlot, S. and Celisse, A.},
Journal = {Statistics Surveys},
Pages = {40--79},
Title = {A survey of cross-validation procedures for model selection},
Volume = {4},
Year = {2010}}
@article{feinerer2008text,
Author = {Feinerer, I. and Hornik, K. and Meyer, D.},
@even4void
even4void / table2plot.R
Created March 13, 2011 19:59
A fake example for mixing text and graphic
display.cell <- function(x, bgcol="#DAE6F2", ...) {
opar <- par(bg=bgcol, mar=rep(0,4))
plot(c(0,1), c(0,1), type="n", axes=FALSE, xlab="", ylab="")
text(.5, .5, as.character(x), ...)
lines(c(-0.1,1.1), c(0,0))
par(opar)
}
format.digits <- function(x) as.character(paste("$", as.character(x), sep=" "))
library(mixOmics)
library(RColorbrewer)
X <- replicate(6, rnorm(50))
X.row.mds <- cmdscale(dist(X), k=1)
X.col.mds <- cmdscale(dist(t(X)), k=1)
cim(cor(X)[order(X.col.mds),order(X.col.mds)], col=rev(brewer.pal(8, "RdBu")))
cim(cor(t(X))[order(X.row.mds),order(X.row.mds)], col=rev(brewer.pal(8, "RdBu")))
cim(X, col=rev(brewer.pal(8, "RdBu"))
@even4void
even4void / sweave_ggplot.Rnw
Created March 22, 2011 23:12
How to include ggplot graphics within Sweave
% compile with
% R CMD Sweave sweave_ggplot.Rnw
% pdflatex sweave_ggplot.tex
\documentclass[t,ucs,12pt,xcolor=dvipsnames]{beamer}
\usepackage{fancyvrb}
\title{A sample Sweave demo}
\author{Author name}
\date{}
@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}}
@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 / 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 / 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)
#! /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