R-beta: leaps() and subsets() functions

Thomas Lumley thomas at biostat.washington.edu
Fri Oct 10 18:37:24 CEST 1997

On Thu, 9 Oct 1997, Matthew R. Nelson wrote:

> Dear R-users,
> Is anyone successfully using leaps() and particularly subsets() 
> (contributed function) in R?  When I attempt to run them with modest 
> matrices, R promptly faults and dumps the core.  Also, how does one use 
> subsets.formula() within subsets()?

I haven't been able to cause problems like this (I'm running 0.50-a4  on
Solaris 2.5.1 and 0.50-a2 or thereabouts on Debian Linux).

What exactly happens, and do you mean "moderate"ly large or "moderate"ly
small -- I just tried the following 
	R> x<-matrix(rnorm(10000),ncol=10)
	R> subsets(x,y)->a
	R> subsets(cbind(x,x),y)->aa
with 1000 cases and 10 variables and with 20 variables with 10 exact
linear dependencies.

With 50 variables and 1000 cases I get "Error: memory exhausted" but this
can be fixed by specifying more memory at startup. With R -v20
	R> x<-matrix(rnorm(50000),ncol=50)
 	R> y<-rnorm(1000)
 	R> subsets(cbind(x,x),y,method="backward")->aa

Exhaustive search with 50 variables is not feasible, but we can
try subsets up to size 4, say.
	R> subsets(cbind(x,x),y,nvmax=4,really.big=T)->aa
This takes a long time, but doesn't crash on my system.

subsets.formula() is used automatically if the argument is a formula
	R> p<-rnorm(1000)
	R> q<-rep(0:1,500)
	R> subsets(y~p*q)->a
	R> summary(a)
	 Subset selection object
	Call: subsets.formula(y ~ p * q)
	3 Variables  (and intercept)
	    Forced in Forced out
	p       FALSE      FALSE
	q       FALSE      FALSE
	p.q     FALSE      FALSE
	1 subsets of each size up to 3
	Selection Algorithm: exhaustive
	         p   q   p.q
	1  ( 1 ) "*" " " " "
	2  ( 1 ) "*" " " "*"
	3  ( 1 ) "*" "*" "*"

As you can see it doesn't care about preserving hierarchical models - it
chooses p+p.q as the best model of size 2. 

Thomas Lumley
Biostatistics		: "Never attribute to malice what  :
Uni of Washington	:  can be adequately explained by  :
Box 357232		:  incompetence" - Hanlon's Razor  :
Seattle WA 98195-7232	:				   :

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list