s-news
[Top] [All Lists]

Re: [S] power set of a vector - summary

To: Bin Chen <pbchen@gsbphd6.uchicago.edu>
Subject: Re: [S] power set of a vector - summary
From: Renaud Lancelot <lancelot@telecomplus.sn>
Date: Thu, 21 Oct 1999 18:40:54 +0100
Cc: S-news <s-news@wubios.wustl.edu>
References: <Pine.GSO.3.96.991020222948.22191A-100000@gsbphd6.uchicago.edu>
Sender: owner-s-news@wubios.wustl.edu
Some of you may have noticed that
> all.combos <- 
> as.logical(as.matrix(do.call("expand.grid",rep(list(c(0,1)),8))))
all.combos is a vector of logical values, which is not the expected
result.

Charles Berry would like to correct:

> combos <- as.matrix(do.call("expand.grid",rep(list(c(0,1)),8)))
> mode(combos) <- "logical"

combos is now the expected matrix of logical values.

This solution is much faster and smarter than mine !

Best,

Renaud


> On Wed, 20 Oct 1999 09:48:09 -0700 (PDT), "Charles C. Berry"
> <cberry@tajo.ucsd.edu> wrote:
> 
> Hmmm. This sounds more like a job for leaps(), but if lm() really is the
> way to
> go,
> 
> all.combos <- as.logical(
>                 as.matrix(
>                         do.call("expand.grid",rep(list(c(0,1)),8))
>                         ))
> 
> returns a matrix whose 256 rows give all possible subsets
> 
> then names(X)[all.combos[i,]] will return the names of the vraibles
> corresponding to the subset for the i^{th} row.
> 
> >
> >Hi. Is there a simple command that gives the power set of a vector
> >(that is, all its subsets)? I'm trying to run 256 variants of a least
> >squares model involving a maximum of 8 independent variables
> >(including the intercept) and then compute their posterior odds. I
> >figure if I can get all the subsets of the names of the X data.frame I
> >would be able to do this quickly, using a loop in which
> >
> >subset.of.names <-- ?? names(X) ??
> >lm(data.frame(y,X[,row(matrix(names(X)))[names(X)==subset.of.names]]))
> >...
> >
> >Thanks a lot in advance.
> >
> >- Bin Chen
> >-----------------------------------------------------------------------
> >This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
> >send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
> >message:  unsubscribe s-news
> 
> Charles C. Berry                        (858) 534-2098
>                                          Dept of Family/Preventive
> Medicine
> E mailto:cberry@tajo.ucsd.edu            UC San Diego
> http://hacuna.ucsd.edu/members/ccb.html  La Jolla, San Diego 92093-0645
> 
> 
> 
> -----------------------------------------------------------------------
> This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
> send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
> message:  unsubscribe s-news


-- 
Renaud Lancelot
ISRA-LNERV
BP 2057 Dakar-Hann
Senegal

tel     (221) 832 49 02
fax     (221) 821 18 79
email   renaud.lancelot@cirad.fr
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>