Re: [R] Alternatives for explicit for() loops

2015-11-15 Thread marammagdysalem
Thanks a lot Jim and Boris for replying. Sent from my iPhone > On Nov 9, 2015, at 1:13 AM, jim holtman wrote: > > You need to take a close look at the function incomb that you are creating. > I see what appears to be a constant value > ("*(gamma((1/beta)+1))*((alpha)^(-(1/beta)))") being com

Re: [R] Alternatives for explicit for() loops

2015-11-08 Thread Boris Steipe
While I fully agree with Jim's comments, you may also need to understand the notion of time complexity in algorithm analysis. All the mentioned speed-ups are basically linear, in the sense that they accelerate a single step of your algorithm. However if your algorithm has combinatorial complexit

Re: [R] Alternatives for explicit for() loops

2015-11-08 Thread jim holtman
You need to take a close look at the function incomb that you are creating. I see what appears to be a constant value ("*( gamma((1/beta)+1))*((alpha)^(-(1/beta)))") being computed that you might only have to compute once before the function. You are also referencing many variables (m, LED, j, ..

Re: [R] Alternatives for explicit for() loops

2015-11-08 Thread Maram SAlem
Thanks all for replying. In fact I've used the the Rprof() function and found out that the incomb() function (in my code above) takes about 80% of the time, but I didn't figure out which part of the function is causing the delay. So I thought that this may be due to the for() loops. I MUST run th

Re: [R] Alternatives for explicit for() loops

2015-11-06 Thread stephen sefick
If you have multiple cores, you could try the foreach package. Jim's advice still holds, but you would be farming the work out. FWIW, Stephen On Fri, Nov 6, 2015 at 8:54 AM, jim holtman wrote: > If you have code that is running for a long time, then take a small case > that only runs for 5-10 m

Re: [R] Alternatives for explicit for() loops

2015-11-06 Thread jim holtman
If you have code that is running for a long time, then take a small case that only runs for 5-10 minutes and turn on the RProfiler so that you can see where you are spending your time. In most cases, it is probably not the 'for' loops that are causing the problem, but some function/calculation you

Re: [R] Alternatives for explicit for() loops

2015-11-04 Thread Maram SAlem
Hi Jim, Thanks a lot for replying. In fact I'm trying to run a simulation study that enables me to calculate the Bayes risk of a sampling plan selected from progressively type-II censored Weibull model. One of the steps involves evaluating the expected test time, which is a rather complicated for

Re: [R] Alternatives for explicit for() loops

2015-11-01 Thread jim holtman
Why are you recreating the incomb function within the loop instead of defining it outside the loop? Also you are referencing several variables that are global (e.g., m & j); you should be passing these in as parameters to the function. Jim Holtman Data Munger Guru What is the problem that you a

Re: [R] Alternatives for explicit for() loops

2015-11-01 Thread Duncan Murdoch
On 01/11/2015 7:31 AM, Maram SAlem wrote: > Hi All, > > I'm writing a long code that takes long time to execute. So I used the > Rprof() function and found out that the function that takes about 80% of > the time is the incomb () fucntion (below), and this is most probably > because of the many ex

[R] Alternatives for explicit for() loops

2015-11-01 Thread Maram SAlem
Hi All, I'm writing a long code that takes long time to execute. So I used the Rprof() function and found out that the function that takes about 80% of the time is the incomb () fucntion (below), and this is most probably because of the many explicit for() loops I'm using. n=18;m=4;p=0.3;alpha=0.