Skip to contents

Assesses whether two selected clusters from an initial partition remain invariant under a second partition, up to relabeling. Invariance means that: (i) all observations from each selected cluster remain grouped together, and (ii) no additional observations are assigned to these clusters.

Usage

preserve.cl(cl, cl_phi, clusters)

Arguments

cl

Integer vector of length \(n\) giving the initial cluster assignment.

cl_phi

Integer vector of length \(n\) giving the cluster assignment after perturbation.

clusters

Integer vector of length 2 specifying the labels of the clusters in cl to be tracked.

Value

Logical. TRUE if both clusters remain invariant in cl_phi (up to label permutation), and FALSE otherwise.

See also

Other Utilities: ARI(), is.CS(), setup.model()

Examples

# Original partition
cl <- c(1, 1, 2, 2, 3, 3)

# Same selected clusters up to relabeling
cl_phi <- c(4, 4, 5, 5, 6, 6)
preserve.cl(cl, cl_phi, clusters = c(1, 2))
#> [1] TRUE

# Cluster 1 is no longer preserved
cl_phi2 <- c(4, 5, 5, 5, 6, 6)
preserve.cl(cl, cl_phi2, clusters = c(1, 2))
#> [1] FALSE