gen01pat {lazy.tools}R Documentation

Generate all possible 0-1 patterns of given length, or binary partition index matrix

Description

Generate all possible 0-1 patterns of given length, or binary partition index matrix

Usage

gen01pat(nitems, sort = 0, partition = 0, print = 0)

Arguments

nitems

The length of the pattern

sort

= 1 to sort the result from the left
= -1 to sort the result from the right
= 2 to sort the result by rowSums and from the left
= -2 to sort the result by rowSums and from the right

partition

= 1 to generate binary partition index matrix

print

= 1 to print the result

Details

Schatzoff et al method is used.
nitems must be less than log(.Machine$integer.max)/log(2).

Essentially the same as
cprod( rep(list(0:1),nitems) )
but gen01pat is much faster.

Value

2^nitems x nitems matrix \ or when partition=1 is given \ 2^{nitems-1}-1 x nitems matrix

References

Schatzoff, M., Tsao, R. and Fienberg, S. (1968) Efficient Calculation of All Possible Regressions. Technometrics. Vol. 10, No. 4, pp. 769-779

Examples

gen01pat( 4 )
gen01pat( 4, partition=1, sort=-2 )

pindex=gen01pat( 4, partition=1 )
left=apply(pindex,1,function(x) letters[1:4][as.logical(x)])
right=lapply(left,function(x){setdiff(letters[1:4],x)})
res=mapply( function(x,y){list(left=x,right=y)}, left,right, SIMPLIFY=FALSE)
Print(res)



[Package lazy.tools version 0.1.6 ]