[R] Can I build an array of regrssion model?

Thomas Lumley tlumley at u.washington.edu
Thu Dec 19 17:05:03 CET 2002


On Thu, 19 Dec 2002, Jason Turner wrote:

> On Wed, Dec 18, 2002 at 03:51:47PM -0500, Zhongming Yang wrote:
> > I am trying to use piecewise linear regression to approximate a
> > nonlinear function.
>
> Why not smooth regression, or non-linear regression?
>
> > Actually, I don't know how many linear functions I
> > need, therefore, I want build an array of regression models to automate
> > the approximation job. Could you please give me any clue?
>
> Clue 1) See above.  You might be using the wrong tool.  A smooth
> regression might be better here.  help(loess), library(gss), and
> library(sm) are your friends.
>
> Clue 2) If you really want piecewise linear, a list makes more
> sense than a vector.  R does handle vectors quite nicely, but I
> find its real strength is the way it handles complex lists with
> ease.


I don't see any problem with wanting to fit linear splines.  It's quite
easy, as well
eg
models <-  lapply( 1:8, function(n) lm(y~bs(x, n, degree=1)))

fits piecewise linear functions with 1 to 8 pieces.

	-thomas




More information about the R-help mailing list