Re: [R] Can I get rid of this for loop using apply?

2008-04-24 Thread hadley wickham
> Great suggestions. I tested the code on an example and the run time was > reduced from 1 min 12 sec to 3 sec. Also, I like the suggestion to look at > the quantiles. I will see what insight it provides in terms of detecting > masked interactions. Well that's a decent speed up :) > I have a c

Re: [R] Can I get rid of this for loop using apply?

2008-04-24 Thread Mike Dugas
Great suggestions. I tested the code on an example and the run time was reduced from 1 min 12 sec to 3 sec. Also, I like the suggestion to look at the quantiles. I will see what insight it provides in terms of detecting masked interactions. I have a couple questions about your code. First, why

Re: [R] Can I get rid of this for loop using apply?

2008-04-23 Thread Mike Dugas
Sure, I am creating a partial dependence plot (reference Friedman's stochastic gradient paper from, I want to say, 2001). The idea is to find the relationship between one of the predictors, say x1, and y by creating the following plot: take a random sample of actual data points, hold other predict

Re: [R] Can I get rid of this for loop using apply?

2008-04-23 Thread Mike Dugas
Thanks for the help. That explains why my time testing showed no difference. Is there any way to speed up the program? It is unbearably slow if I increase the number of loops. Mike On Wed, Apr 23, 2008 at 6:23 PM, hadley wickham <[EMAIL PROTECTED]> wrote: > On Wed, Apr 23, 2008 at 4:23 PM, M

Re: [R] Can I get rid of this for loop using apply?

2008-04-23 Thread hadley wickham
On Wed, Apr 23, 2008 at 7:31 PM, Mike Dugas <[EMAIL PROTECTED]> wrote: > Thanks for the help. That explains why my time testing showed no > difference. Is there any way to speed up the program? It is unbearably > slow if I increase the number of loops. Could you explain exactly what you're tryi

Re: [R] Can I get rid of this for loop using apply?

2008-04-23 Thread hadley wickham
On Wed, Apr 23, 2008 at 4:23 PM, Mike Dugas <[EMAIL PROTECTED]> wrote: > The answer to my post is yes (which I just figured out). > Switching from for to apply isn't going to speed up your code. If you carefully read the source code of apply, you'll see the guts of the work is done by: for (i i

[R] Can I get rid of this for loop using apply?

2008-04-23 Thread Mike Dugas
The answer to my post is yes (which I just figured out). Solution: #super small version of R code for pd plot using apply a <- rbind(c(0:)*(max(m$x1)-min(m$x1))/ + min(m$x1),c(0:)*0-9) b <- matrix(rep(c(0:)*(max(m$x1)-min(m$x1))/ + min(m$x1), nrow(m)), nrow(m), 1112, b

[R] Can I get rid of this for loop using apply?

2008-04-23 Thread Mike Dugas
Hey all, The code below creates a partial dependence plot for the variable x1 in the linear model y ~ x1 + x1^2 + x2. I have noticed that the for loop in the code takes a long time to run if the size of the data is increased. Is there a way to change the for loop into an apply statement? The tr