[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.

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('free

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

[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

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

2008-04-23 Thread Mike Dugas
, 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 deleted]] __ R-help@r

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

2008-04-23 Thread Mike Dugas
, 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 in 1:d2) { tmp - FUN(array

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

2008-04-23 Thread Mike Dugas
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. That explains why my time testing showed