Skip to content

Instantly share code, notes, and snippets.

/sim.R Secret

Created September 5, 2012 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d7600c292fd8dff93a4c to your computer and use it in GitHub Desktop.
Save anonymous/d7600c292fd8dff93a4c to your computer and use it in GitHub Desktop.
Comparing log vs. normal procedures on dataset
set.seed(17)
ci <- function (x, alpha=.05) {
z <- -qnorm(alpha / 2)
y <- log(x); n <- length(y); s2 <- var(y)
m <- mean(y) + s2 / 2
d <- z * sqrt(s2 / n + s2 * s2 / (2 * (n - 1)))
exp(c(mean=m, lcl=m-d, ucl=m+d))
}
ci.u <- function(x, alpha=.05) {
mean(x) + sd(x) * c(mean=0, lcl=1, ucl=-1) / sqrt(length(x)) * qnorm(alpha/2)
}
trial <- function(n=100) {
x <- sample(x, n, TRUE)
cbind(ci(x), ci.u(x))
}
x <- read.table("titan/time-minisat-2.2.0-distribution/minisat-2.2.0/times.txt")$V1
m <- mean(x)
sim <- sapply(1:5000, function(i) trial(100))
sapply(c(LNLCL=2, LCL=5, LNUCL=3, UCL=6), function(i) sum(sim[i,] > m)/dim(sim)[2])
sim <- sapply(1:5000, function(i) trial(200))
sapply(c(LNLCL=2, LCL=5, LNUCL=3, UCL=6), function(i) sum(sim[i,] > m)/dim(sim)[2])
sim <- sapply(1:5000, function(i) trial(500))
sapply(c(LNLCL=2, LCL=5, LNUCL=3, UCL=6), function(i) sum(sim[i,] > m)/dim(sim)[2])
sim <- sapply(1:5000, function(i) trial(1000))
sapply(c(LNLCL=2, LCL=5, LNUCL=3, UCL=6), function(i) sum(sim[i,] > m)/dim(sim)[2])
# output:
#
# LNLCL LCL LNUCL UCL
# 0.0554 0.0146 0.9992 0.9506
#
# LNLCL LCL LNUCL UCL
# 0.1206 0.0154 1.0000 0.9602
#
# LNLCL LCL LNUCL UCL
# 0.3844 0.0182 1.0000 0.9658
#
# LNLCL LCL LNUCL UCL
# 0.7484 0.0194 1.0000 0.9702
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment