[R] Collection of lm()s

From: Chip Barnaby <cbarnaby_at_wrightsoft.com>
Date: Mon, 12 May 2008 09:43:00 -0400


I would like to create a subscriptable collection (presumably a list) of lm() models.

I have a data frame DX containing 6 groups of data. The general idea is (NOT RUN) ...

for (i in 1:6)

{       DXS = subset( DX, <whatever>);
         LMX[ i] = lm( <formula>, data = DXS);

Now access model results by subscript ... e.g. coefficients( LMX[ 2]). Or would it be [[ 2]]?

I have experimented with various schemes, attempting to "pre-allocate" a list etc. without success.

Also, I assume that lm() does not make a copy of input data? That is, if I want "predict( LMX[ i])", I would have to retain a copy the associated DXS subsets?

TIA, Chip Barnaby

Chip Barnaby                   cbarnaby_at_wrightsoft.com
Vice President of Research
Wrightsoft Corp.               781-862-8719 x118 voice
131 Hartwell Ave               781-861-2058 fax
Lexington, MA 02421         www.wrightsoft.com

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 12 May 2008 - 13:52:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 12 May 2008 - 14:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive