-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.R
executable file
·52 lines (42 loc) · 1.44 KB
/
simulation.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
rng <- function(size) {
# generate random number
kTimes <- 100
set.seed(0712)
x <- c(replicate(n=kTimes, expr=rlnorm(size), simplify=F),
replicate(n=kTimes, expr=rgamma(size, 3, 1), simplify=F),
replicate(n=kTimes, expr=runif(size), simplify=F),
replicate(n=kTimes, expr=rt(size, 3), simplify=F))
a <- do.call(rbind, x)
row.names(a) <- c(sapply(list("Log-normal", "Gamma", "Uniform", "t"),
rep, times=kTimes))
write.csv(a, paste("data/data", size, ".csv", sep=""))
return(x)
}
simulation <- function (size) {
require(moments)
require(nortest)
require(energy)
source("energy_test.R") # set replicate to 99 times for efficiency
test <- c("shapiro.test", "ad.test", "energy.test", "cvm.test",
"lillie.test", "pearson.test", "sf.test", "jarque.test")
x <- rng(size)
# load johnson source functions
source('johnson_transform.R')
res <- data.frame()
cat(paste("Currently simulation for sample size:", size, "\n"))
pb <- txtProgressBar(min = 0, max = length(x), style=3)
for (i in 1:length(x)) {
res <- rbind(res, johnsonTransform(x[[i]], test))
setTxtProgressBar(pb, i)
}
dist <- rep(c("Log-normal", "Gamma", "Uniform", "t"), times=length(test))
res <- cbind(size, dist, res)
return(res)
}
size <- c(10, 15, 20, 25, 30, 40, 50, 100, 200, 300, 400,
500, 1000, 1500, 2000, 5000)
res <- data.frame()
for (i in 1:length(size)) {
d <- cbind(size=size[i], simulation(size[i]))
res <- rbind(res, d)
}