nkpartitions: Functions for listing all possible partitions or just...

Description Usage Arguments Value Author(s) Examples

Description

The function nkpartitions lists all possible partitions of n objects in to k clusters. The function nkpar only gives the number of such partitions.

Usage

1
2
nkpartitions(n, k, exact = TRUE, print = FALSE)
nkpar(n, k)

Arguments

n

Number of units/objects.

k

Number of clusters/groups.

exact

Search for partitions with exactly k or at most k clusters.

print

Print results as they are found.

Value

The matrix or number of possible partitions.

Author(s)

Chris Andrews

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
n <- 8 # If larger, the number of partitions increases dramatically,
# as does if we increase the number of clusters
net <- matrix(NA, ncol = n, nrow = n)
clu <- rep(1:2, times = c(3, 5))
tclu <- table(clu)
net[clu == 1, clu == 1] <- rnorm(n = tclu[1] * tclu[1], mean = 0, sd = 1)
net[clu == 1, clu == 2] <- rnorm(n = tclu[1] * tclu[2], mean = 4, sd = 1)
net[clu == 2, clu == 1] <- rnorm(n = tclu[2] * tclu[1], mean = 0, sd = 1)
net[clu == 2, clu == 2] <- rnorm(n = tclu[2] * tclu[2], mean = 0, sd = 1)

# Computation of criterion function with the correct partition
nkpar(n = n, k = length(tclu)) # Computing the number of partitions
all.par <- nkpartitions(n = n, k = length(tclu)) # Forming the partitions
all.par <- lapply(apply(all.par, 1, list), function(x) x[[1]])
# to make a list out of the matrix
res <- critFunC(M = net, clu = clu, approaches = "val", 
blocks = c("nul", "com"), preSpecM = 4)
plot(res) # We get the original partition

blockmodelingTest documentation built on May 2, 2019, 5:57 p.m.