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

From: Andrew D. Steen <andrew.decker.steen_at_gmail.com>
Date: Wed, 04 May 2011 22:43:09 +0200

Thanks all, this is very helpful.
--Andrew Steen

> -----Original Message-----
> From: David Winsemius [mailto:dwinsemius_at_comcast.net]
> Sent: Wednesday, May 04, 2011 4:35 PM
> To: Andrew D. Steen
> Cc: r-help_at_r-project.org
> Subject: Re: [R] what happens when I store linear models in an array?
>
>
> On May 4, 2011, at 4:49 AM, 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])
> > NUL
> >
> > 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?
> >
>
> The problem is that the "[" function is returning a sublist from that
> array of lists, which is still a list. You wanted the contents of the
> first (and only) element of that list and Andrew Robinson offered you
> the solution.
>
> --
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT



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 Thu 05 May 2011 - 06:25:13 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 Thu 05 May 2011 - 07:00:07 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