[R] slow loops in Monte Carlo Simulations

2004-09-28 Thread Nael Al Anaswah
Hi there, I am running Monte Carlo Simulations in R using ordinary while (condition) loops. Since the number of iterations is something like 100.000 and within each iteration a given subsample is extended sequentially it takes hours to run the simulation. Does anyone know if there is either

Re: [R] slow loops in Monte Carlo Simulations

2004-09-28 Thread Duncan Murdoch
On Tue, 28 Sep 2004 13:46:04 +0200, Nael Al Anaswah [EMAIL PROTECTED] wrote : Hi there, I am running Monte Carlo Simulations in R using ordinary while (condition) loops. Since the number of iterations is something like 100.000 and within each iteration a given subsample is extended

Re: [R] slow loops in Monte Carlo Simulations

2004-09-28 Thread Witold Eryk Wolski
Hi! Have you taken a look at the MCMCpack - package on cran: This package contains functions for posterior simulation for a number of statistical models. All simulation is done in compiled C++ written in the Scythe Statistical Library Version 1.0. All models return coda mcmc objects that can

Re: [R] slow loops in Monte Carlo Simulations

2004-09-28 Thread Gardar Johannesson
The key is to assign space in advance -- e.g., compare: N - 2 res - NULL system.time( for(i in 1:N) res - c(res, sample(10)) ) [1] 28.62 8.91 37.79 0.00 0.00 res - vector(list,N) system.time( for(i in 1:N) res[[i]] - sample(10) ) [1] 0.45 0.00 0.44 0.00 0.00 res - matrix(0.0, N,10)