Last active
October 9, 2015 14:53
-
-
Save mikelove/0fb34f56ac051ea2076b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d <- expand.grid(n=c(3,5,10,20), type=c("normal","t")) | |
d <- d[rep(seq_len(nrow(d)),each=nrep),] | |
simulate <- function(n, type) { | |
if (type == "normal") { | |
dat <- rnorm(n) | |
} else { | |
dat <- rt(n, df=3) | |
} | |
dat | |
meanerr <- abs(mean(dat) - 0) | |
medianerr <- abs(median(dat) - 0) | |
c(mean=meanerr, median=medianerr) | |
} | |
library(plyr) | |
# mdply does everything: takes columns of d as multivariate input | |
# to simulate() and then adds the output as columns to d | |
d2 <- mdply(d, simulate) | |
d2$n <- factor(d2$n) | |
library(reshape) | |
m <- melt(d2, id.vars=c("n","type")) | |
library(ggplot2) | |
ggplot(m, aes(x=n, y=value, col=variable)) + geom_boxplot() + | |
facet_wrap(~ type) + ylim(0,2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment