Skip to content
Prev 26412 / 398502 Next

Can I build an array of regrssion model?

On Wed, Dec 18, 2002 at 03:51:47PM -0500, Zhongming Yang wrote:
Why not smooth regression, or non-linear regression?
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.
#change cuts to a matrix of values, col 1 is the lower
#bound, col 2 is the upper bound for your segments.

cuts <- cbind(c(1,cuts[1:(length(cuts)-1)], cuts)

#make an empty list
mod.list <- list()
#fill that list with models
for(ii in 1:dim(cuts)[1]) { 
	start <- cuts[ii,1]
	end <- cuts[ii,2]
	mod.list[[ii]] <- lm(rawData[[2]][start,end] ~ rawData[[1]][start,end])
}

#to extract coefficients
lapply(mod.list,coef)

#to extract coefficients, and confidence intervals
lapply(mod.list,function(x,...){ coef(summary(x))} )

#to reproduce your ablines
lapply(mod.list,abline,col="red")

etc

Cheers

Jason
Message-ID: <20021219110816.A12597@camille.indigoindustrial.co.nz>
In-Reply-To: <se0099cf.046@mailx.chmcc.org>; from Zhongming.Yang@cchmc.org on Wed, Dec 18, 2002 at 03:51:47PM -0500