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

Liaw, Andy andy_liaw at merck.com
Thu Dec 19 18:22:03 CET 2002


Try lines(predict(mod), col="red").  (This is assuming your original x data
are sorted.)

abline(mod) draws a single straight line, using intercept and slope from a
simple linear regression model ('mod').  If mod has more than one slope (as
is the case with bs()), it won't make sense.

Andy

> -----Original Message-----
> From: Zhongming Yang [mailto:Zhongming.Yang at cchmc.org]
> Sent: Thursday, December 19, 2002 11:21 AM
> To: jasont at indigoindustrial.co.nz; tlumley at u.washington.edu
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] Can I build an array of regrssion model?
> 
> 
> Thanks,
> 
> But why I can't draw regression line with the following code:
> 
> rawData = scan("c:/zyang/mass/data/A01/1.PRN",
> what=list(numeric(),numeric()));
> len = length(rawData[[1]]);
> mod = lm(rawData[[2]]~bs(rawData[[1]],10,degree=1));
> plot(rawData[[1]],rawData[[2]],type='l', col="green", xlab="Da/z",
> ylab="m/z");
> abline(mod,col="red");
> 
> 
> 
> 
> 
> 
> 
> >>> Thomas Lumley <tlumley at u.washington.edu> 12/19/02 11:04AM >>>
> 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

------------------------------------------------------------------------------




More information about the R-help mailing list