clusteration {truecluster} | R Documentation |
Functions to construct all possible groupings or calculate the number of possible groupings.
clusteration(n = NULL, k = NULL, nmax = NULL, kmax = nmax) nclusteration(n = NULL, k = NULL, nmax = NULL, kmax = nmax) ## S3 method for class 'clusteration': print(x, within = "-", between = "+", ...)
n |
number of elements |
k |
number of groups (optional) |
nmax |
maximal number of elements |
kmax |
maximal number of groups |
x |
an object of class 'clusteration' |
within |
character to seperate elements within the same grouping |
between |
charachter to seperate between groupings |
... |
ignored |
Can be used to create/calculate all groupings (using nmax
), where the number of groupings can be restricted (kmax
).
The result is a matrix (n x k) which contains in the lower.tri
Jens' triangle not unlike Pascal's triangle.
Using n
instead of nmax
will return a vector equaling the last line of the triangle,
using k
can be used to directly return the groupings/number of groupings for a single fixed number of groups.
All results are created using the triangle construction method
just calling nclusteration(n=, k=) makes use of Jensen's formula
C(n,k)=frac{1}{k!} cdot sum_{c=1}^{k}{over{k}{c} cdot k^n }
The triangle construction method uses the recursive formula
C(n,k)=C(n-1,k-1) + k cdot C(n-1,k)
where C(n,1)=1 and C(n,n)=1.
Function nclusteration
returns either a matrix[n,k] or a vector[k] or a scalar.
Function clusteration
returns either a list matrix[[n,k]] or a list vector[[k]] or a single element list vector[[1]] of list of groupings,
where groupings is a list with as many elements as groups and each group beeing represented by a vector of group member indices. A special print method prints this nicely.
The total number of possible groupings increases worse than exponential
Jens Oehlschlägel
Jensen, R.E. (1969) A dynamic programming algorithm for cluster analysis. Operations Research, 17, 1034-57.
margination
, combination
, choose
clusteration(nmax=5) clusteration(n=5) clusteration(n=5, k=3) nclusteration(nmax=5) nclusteration(n=5) nclusteration(n=5, k=3) n <- 100 k <- 5 x <- nclusteration(nmax=n) matplot(1:n, cbind((1:n)^(1:n), rowSums(x), k^(1:n), x[,k]) , log="y", type="l" , lty=1:4, xlab="n" , ylab = "combinations" , main = "number of possible groupings" ) legend(n,1 , c(expression(n^n), expression(k %in% group("{", list(1,2,...,n), "}")), substitute(k^n, list(k=k)), substitute(k==c, list(c=k)) ), lty=1:4, col=1:4, xjust=1, yjust=0)