# allComb: Finding All Possible Binary Partitions In psolymos/opticut: Likelihood Based Optimal Partitioning and Indicator Species Analysis

## Description

These functions are used to find all possible binary partitions. Finding all combinations require a classification vector with K > 1 strata.

## Usage

 ```1 2 3``` ```allComb(x, collapse) kComb(k) checkComb(x) ```

## Arguments

 `x` a vector for `allComb` (can be of any type but treated as factor, must have at least 2 unique values); and a numeric matrix for `checkComb`. `collapse` character, what to paste between levels. Defaults to `getOption("ocoptions")\$collapse`. `k` numeric, number of levels (strata) in a given classification (K > 1).

## Value

`kComb` returns a contrast matrix corresponding to all possible binary partitions of the factor with K levels. Complements are not counted twice, i.e. (0,0,1,1) is equivalent to (1,1,0,0). The number of such possible combinations is M = 2^(K - 1) - 1.

`allComb` takes a classification vector with at least 2 levels and returns a model matrix with binary partitions.

`checkComb` checks if combinations are unique and non-complementary (misfits are returned as attributes). Returns a logical value.

## Author(s)

Peter Solymos <[email protected]>

`opticut` for the user interface.
`rankComb` and `lorenz` for alternative partitioning algorithms.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```kComb(k = 2) kComb(k = 3) kComb(k = 4) ## finding all combinations (f <- rep(LETTERS[1:4], each=2)) (mc <- allComb(f, collapse = "_")) ## checking for complementary entries checkComb(mc) # TRUE ## adding complementary entries to the matrix mc2 <- cbind(z = 1 - mc[,1], mc[,c(1:ncol(mc), 1)]) colnames(mc2) <- 1:ncol(mc2) mc2 checkComb(mc2) # FALSE ```