[R] what happens when I store linear models in an array?

Jonathan Daily biomathjdaily at gmail.com
Wed May 4 16:03:48 CEST 2011


It looks like your call:

lms.ASP[1,1] <- list(surf105.lm.ASP)

makes a list of length 1 containing the lm object and puts that list
into element [1,1] of your array. That is why you will need the extra
indexing call of [[1]] Andrew Robinson suggested.

On Wed, May 4, 2011 at 9:02 AM, Andrew Robinson
<A.Robinson at ms.unimelb.edu.au> wrote:
> Hi Andrew,
>
> try
>
> fitted(lms.ASP[1,1][[1]])
>
> Cheers
>
> Andrew
>
> On Wed, May 04, 2011 at 01:49:45PM +0200, Andrew D. Steen wrote:
>> I've got a bunch of similar datasets, all of which I've fit to linear
>> models.  I'd like to easily create arrays of a specific parameter from each
>> linear model (e.g., all of the intercepts in one array).  I figured I'd put
>> the model objects into an array, and then (somehow) I could easily create
>> corresponding arrays of intercepts or residuals or whatever, but I can't the
>> parameters back out.
>>
>>
>>
>> Right now I've stored the model objects in a 2-D array:
>> > lms.ASP <- array(list(), c(3,4))
>>
>>
>>
>> Then I fill the array element-by-element:
>> > surf105.lm. ASP <- lm(ASP ~ time)
>> > lms.ASP[1,1] <- list(surf105.lm.ASP)
>>
>>
>>
>> Something is successfully being stored in the array:
>> > test <- lms.tx.ASP[1,1]
>> > test
>> [[1]]
>> Call:
>> lm(formula = ASP ~ time)
>> Coefficients:
>>      (Intercept)  elapsed.time..hr
>>      0.430732          0.004073
>>
>>
>>
>> But I can't seem to call extraction functions on the linear models:
>> > fitted(lms.ASP[1,1])
>> NULL
>>
>>
>>
>> It seems like something less than the actual linear model object is being
>> stored in the array, but I don't understand what's happening, or how to
>> easily batch-extract parameters of linear models.  Any advice?
>>
>>
>>
>>
>>
>> ____________________________________
>>
>> Andrew D. Steen, Ph.D.
>>
>> Center for Geomicrobiology, Aarhus University
>>
>> Ny Munkegade 114
>> DK-8000 Aarhus C
>> Denmark
>> Tel: +45 8942 3241
>> Fax: +45 8942 2722
>>
>> andrew.steen at biology.au.dk
>>
>>
>>
>>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>
> --
> Andrew Robinson
> Program Manager, ACERA
> Department of Mathematics and Statistics            Tel: +61-3-8344-6410
> University of Melbourne, VIC 3010 Australia               (prefer email)
> http://www.ms.unimelb.edu.au/~andrewpr              Fax: +61-3-8344-4599
> http://www.acera.unimelb.edu.au/
>
> Forest Analytics with R (Springer, 2011)
> http://www.ms.unimelb.edu.au/FAwR/
> Introduction to Scientific Programming and Simulation using R (CRC, 2009):
> http://www.ms.unimelb.edu.au/spuRs/
>
> ______________________________________________
> 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.
>



-- 
===============================================
Jon Daily
Technician
===============================================
#!/usr/bin/env outside
# It's great, trust me.



More information about the R-help mailing list