[R] Fitting models in a loop

Murray Jorgensen maj at stats.waikato.ac.nz
Tue Aug 1 06:08:39 CEST 2006


If I want to display a few polynomial regression fits I can do something 
like

for (i in 1:6) {
	mod <- lm(y ~ poly(x,i))
	print(summary(mod))
	}

Suppose that I don't want to over-write the fitted model objects, 
though. How do I create a list of blank fitted model objects for later 
use in a loop?

Murray Jorgensen
-- 
Dr Murray Jorgensen      http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: maj at waikato.ac.nz                                Fax 7 838 4155
Phone  +64 7 838 4773 wk    Home +64 7 825 0441    Mobile 021 1395 862



More information about the R-help mailing list