% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gen01pat.R
\name{gen01pat}
\alias{gen01pat}
\title{Generate all possible 0-1 patterns of given length,
or binary partition index matrix}
\usage{
gen01pat(nitems, sort = 0, partition = 0, print = 0)
}
\arguments{
\item{nitems}{The length of the pattern}

\item{sort}{=  1 to sort the result from the left \cr
= -1 to sort the result from the right \cr
=  2 to sort the result by rowSums and from the left \cr
= -2 to sort the result by rowSums and from the right \cr}

\item{partition}{= 1 to generate binary partition index matrix}

\item{print}{= 1 to print the result}
}
\value{
\code{2^nitems x nitems} matrix \\
or when \code{partition=1} is given \\
\code{2^{nitems-1}-1 x nitems} matrix
}
\description{
Generate all possible 0-1 patterns of given length,
or binary partition index matrix
}
\details{
Schatzoff et al method is used. \cr
nitems must be less than log(.Machine$integer.max)/log(2). \cr
\cr
Essentially the same  as \cr
  cprod( rep(list(0:1),nitems) ) \cr
but gen01pat is much faster.
}
\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)


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