This function can be used to perturb a clustering vector in order to randomly associate certain individuals with another cluster.

lab_switching(Z, p_out = 0.1)

Arguments

Z

a clustering vector

p_out

a probability of perturbation for the clustering

Value

a perturbed clustering vector

Examples

Z <- sample(1:4,100,replace=TRUE)
p = 0.1
Z_pert <- lab_switching(Z,p)
table("Initial clustering" = Z,"Perturbed clustering" = Z_pert)
#>                   Perturbed clustering
#> Initial clustering  1  2  3  4
#>                  1 27  0  1  0
#>                  2  0 23  1  0
#>                  3  0  0 23  2
#>                  4  0  0  1 22