list of lm() results

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

list of lm() results

Idgarad
How can I get the results of lm() into a list so I can loop through the results?

e.g.

myResults[1] <- lm(...)
myResults[2] <- lm(...)
myResults[3] <- lm(...)
...
myResults[15] <- lm(...)
myResults[16] <- lm(...)

so far every attempt I've tried doesn't work throwing a "number of
items to replace is not a multiple of replacement length" error or
simply not working.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: list of lm() results

David Winsemius

On Jul 21, 2009, at 12:27 PM, Idgarad wrote:

> How can I get the results of lm() into a list so I can loop through  
> the results?
>
> e.g.
>
> myResults[1] <- lm(...)
> myResults[2] <- lm(...)
> myResults[3] <- lm(...)
> ...
> myResults[15] <- lm(...)
> myResults[16] <- lm(...)
>
> so far every attempt I've tried doesn't work throwing a "number of
> items to replace is not a multiple of replacement length" error or
> simply not working.

?"[["

You are trying to use a vector/array  assignment operator, "[<- ",  
when you should be using a list assignment operator, "[[<-".


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: list of lm() results

Greg Snow-2
In reply to this post by Idgarad
First make sure that myResults is a list (you probably did this, but just to be sure):

> myResults <- list()

Then use doubled brackets [[]]:

> myResults[[1]] <- lm(...)
Etc.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Idgarad
> Sent: Tuesday, July 21, 2009 10:28 AM
> To: [hidden email]
> Subject: [R] list of lm() results
>
> How can I get the results of lm() into a list so I can loop through the
> results?
>
> e.g.
>
> myResults[1] <- lm(...)
> myResults[2] <- lm(...)
> myResults[3] <- lm(...)
> ...
> myResults[15] <- lm(...)
> myResults[16] <- lm(...)
>
> so far every attempt I've tried doesn't work throwing a "number of
> items to replace is not a multiple of replacement length" error or
> simply not working.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: list of lm() results

Giovanni Petris
In reply to this post by Idgarad

My guess is that you did not define the list correcly before making
any assignments to it. Try something like

> myResults <- vector("list", 16)

and then your code

> myResults[1] <- lm(...)
> myResults[2] <- lm(...)
> myResults[3] <- lm(...)
 ...
> myResults[15] <- lm(...)
> myResults[16] <- lm(...)

HTH,
Giovanni

> Date: Tue, 21 Jul 2009 11:27:52 -0500
> From: Idgarad <[hidden email]>
> Sender: [hidden email]
> Precedence: list
> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
> DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
>
> How can I get the results of lm() into a list so I can loop through the results?
>
> e.g.
>
> myResults[1] <- lm(...)
> myResults[2] <- lm(...)
> myResults[3] <- lm(...)
> ...
> myResults[15] <- lm(...)
> myResults[16] <- lm(...)
>
> so far every attempt I've tried doesn't work throwing a "number of
> items to replace is not a multiple of replacement length" error or
> simply not working.
>
> ______________________________________________
> [hidden email] 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.
>
>

--

Giovanni Petris  <[hidden email]>
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: list of lm() results

Gene Leynes
I found that it was easiest to just pull out the parts I want with an
"apply" loop.

Here I am regressing a bunch of equity returns on some index returns and
just keeping the coefficients:

EqCoefQ1 = apply(retEqQ1,2,
        function(x) summary(lm(x~retIndexQ1))$coefficients)

On Tue, Jul 21, 2009 at 4:49 PM, Giovanni Petris <[hidden email]> wrote:

>
> My guess is that you did not define the list correcly before making
> any assignments to it. Try something like
>
> > myResults <- vector("list", 16)
>
> and then your code
>
> > myResults[1] <- lm(...)
> > myResults[2] <- lm(...)
> > myResults[3] <- lm(...)
>  ...
> > myResults[15] <- lm(...)
> > myResults[16] <- lm(...)
>
> HTH,
> Giovanni
>
> > Date: Tue, 21 Jul 2009 11:27:52 -0500
> > From: Idgarad <[hidden email]>
> > Sender: [hidden email]
> > Precedence: list
> > DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com;
> s=gamma;
> > DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
> >
> > How can I get the results of lm() into a list so I can loop through the
> results?
> >
> > e.g.
> >
> > myResults[1] <- lm(...)
> > myResults[2] <- lm(...)
> > myResults[3] <- lm(...)
> > ...
> > myResults[15] <- lm(...)
> > myResults[16] <- lm(...)
> >
> > so far every attempt I've tried doesn't work throwing a "number of
> > items to replace is not a multiple of replacement length" error or
> > simply not working.
> >
> > ______________________________________________
> > [hidden email] 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.
> >
> >
>
> --
>
> Giovanni Petris  <[hidden email]>
> Associate Professor
> Department of Mathematical Sciences
> University of Arkansas - Fayetteville, AR 72701
> Ph: (479) 575-6324, 575-8630 (fax)
> http://definetti.uark.edu/~gpetris/<http://definetti.uark.edu/%7Egpetris/>
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.