Dear R users, I need to run 1000 simulations to find maximum likelihood estimates. I print my output as a vector. However, it is taking too long. I am running 50 simulations at a time and it is taking me 30 minutes. Once I tried to run 200 simulations at once, after 2 hours I stopped it and saw that only about 40 of them are simulated in those 2 hours. Is there any way to make my simulations faster? (I can post my code if needed, I'm just looking for general ideas here). Thank you in advance. -- View this message in context: http://r.789695.n4.nabble.com/how-to-make-simulation-faster-tp4647492.html Sent from the R help mailing list archive at Nabble.com.
On Fri, Oct 26, 2012 at 4:23 AM, stats12 <skarmv at gmail.com> wrote:> Dear R users, > > I need to run 1000 simulations to find maximum likelihood estimates. I > print my output as a vector. However, it is taking too long. I am running 50 > simulations at a time and it is taking me 30 minutes. Once I tried to run > 200 simulations at once, after 2 hours I stopped it and saw that only about > 40 of them are simulated in those 2 hours. Is there any way to make my > simulations faster? (I can post my code if needed, I'm just looking for > general ideas here). Thank you in advance. >Code would be nice: I struggle to think of an basic MLE fitting that would take ~36s per iteration and scale so badly if you are writing idiomatic R: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Finally, I note you're posting from Nabble. Please include context in your reply -- I don't believe Nabble does this automatically, so you'll need to manually include it. Most of the regular respondents on this list don't use Nabble -- it is a _mailing list_ after all -- so we don't get the forum view you do, only emails of the individual posts. Combine that with the high volume of posts, and it's quite difficult to trace a discussion if we all don't make sure to include context. RMW
use Rprof to profile your code to determine where time is being spent. This might tell you where to concentrate your effort. Sent from my iPad On Oct 25, 2012, at 23:23, stats12 <skarmv at gmail.com> wrote:> Dear R users, > > I need to run 1000 simulations to find maximum likelihood estimates. I > print my output as a vector. However, it is taking too long. I am running 50 > simulations at a time and it is taking me 30 minutes. Once I tried to run > 200 simulations at once, after 2 hours I stopped it and saw that only about > 40 of them are simulated in those 2 hours. Is there any way to make my > simulations faster? (I can post my code if needed, I'm just looking for > general ideas here). Thank you in advance. > > > > -- > View this message in context: http://r.789695.n4.nabble.com/how-to-make-simulation-faster-tp4647492.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
You can get even better improvement using the 'data.table' package:> require(data.table) > system.time({+ dt <- data.table(value = x, z = z) + r3 <- dt[ + , list(sum = sum(value)) + , keyby = z + ] + }) user system elapsed 0.14 0.00 0.14 On Thu, Oct 25, 2012 at 11:23 PM, stats12 <skarmv at gmail.com> wrote:> Dear R users, > > I need to run 1000 simulations to find maximum likelihood estimates. I > print my output as a vector. However, it is taking too long. I am running 50 > simulations at a time and it is taking me 30 minutes. Once I tried to run > 200 simulations at once, after 2 hours I stopped it and saw that only about > 40 of them are simulated in those 2 hours. Is there any way to make my > simulations faster? (I can post my code if needed, I'm just looking for > general ideas here). Thank you in advance. > > > > -- > View this message in context: http://r.789695.n4.nabble.com/how-to-make-simulation-faster-tp4647492.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.