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

Zhongming Yang Zhongming.Yang at cchmc.org
Thu Dec 19 17:26:34 CET 2002


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




More information about the R-help mailing list