After searching the forum, I did not find similair questions. If you find one, please let me know. I would really appreciate.
I need to generate 1000 means of sample points from truncated gamma distriution with 1000 different shapes and scales values in R.
My followingg code works but very slow. How to improve the performance ?
library(distr)
library(distrEx)
library(truncdist)
set.seed(RANDOM.SEED)
shape.list <- runif(1000, max = 10, min = 0.01)
scale.list <- runif(1000, max = 100000, min = 100000)
mean.list <- list()
std.dev.list <- list()
for (i in seq(1000)) # very slow
{
sample.points <- rtrunc(100000, spec="gamma", a = lb.arg, b = ub.arg,
shape = shape.list[[i]], scale = scale.list[[i]])
sample.mean <- mean(sample.points)
mean.list <- append(mean.list, sample.mean)
sample.std.dev <- sd(sample.points)
std.dev.list <- append(std.dev.list, sample.std.dev)
}
The for loop is very slow and takes very long time.
Any better soluions would be appreciated. Thanks !