Re: [R] Optimal knot locations for splines

2008-05-01 Thread Mike Dugas
Thanks for the help. I tried out the one promising lead, curfit.free.knot, and it doesn't work for linear or quadratic splines. The documentation says it should, but when I specify a linear spline, it returns a cubic. On 5/1/08, Spencer Graves <[EMAIL PROTECTED]> wrote: > > RSiteSearch('fr

[R] Optimal knot locations for splines

2008-05-01 Thread Mike Dugas
Suppose I have two variables, x and y. For a fixed number of knots, I want to create a spline transformation of x such that a loss function is minimized. Presumably, this loss function would be least squares, i.e. sum (f(x)-y)^2. The spline transformations would be linear, quadratic or cubic. I

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
The code I wrote does this using predict() which is useful for modeling approaches like GAMs. Mike On Wed, Apr 23, 2008 at 8:47 PM, hadley wickham <[EMAIL PROTECTED]> wrote: > On Wed, Apr 23, 2008 at 7:31 PM, Mike Dugas <[EMAIL PROTECTED]> wrote: > > Thanks for the help. Th

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

2008-04-23 Thread Mike Dugas
t 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

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

2008-04-23 Thread Mike Dugas
, 1112, byrow=T) a[2,] <- apply(b,2,FUN=function(x) {mean(predict(lm1,cbind(m[,-match("x1",names(m))],x1=x))) }) plot(a[1,],a[2,],xlab="x1",ylab="Response",type="l",main="Partial Dependence Plot") Mike Dugas [[alternative HTML version

[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