# \dontshow{
set.seed (0)
# }
##--- EXAMPLE 1 ------------------------------------------
sig <- diag(2)
cen <- rep(1,2)
x <- rbind(MASS::mvrnorm(360, cen * 0, sig),
MASS::mvrnorm(540, cen * 5, sig * 6 - 2),
MASS::mvrnorm(100, cen * 2.5, sig * 50))
## Two groups and 10\% trimming level
clus <- tclust(x, k = 2, alpha = 0.1, restr.fact = 8)
plot(clus)
plot(clus, labels = "observation")
plot(clus, labels = "cluster")
## Three groups (one of them very scattered) and 0\% trimming level
clus <- tclust(x, k = 3, alpha=0.0, restr.fact = 100)
plot(clus)
##--- EXAMPLE 2 ------------------------------------------
data(geyser2)
(clus <- tclust(geyser2, k = 3, alpha = 0.03))
plot(clus)
# \donttest{
##--- EXAMPLE 3 ------------------------------------------
data(M5data)
x <- M5data[, 1:2]
clus.a <- tclust(x, k = 3, alpha = 0.1, restr.fact = 1,
restr = "eigen", equal.weights = TRUE)
clus.b <- tclust(x, k = 3, alpha = 0.1, restr.fact = 50,
restr = "eigen", equal.weights = FALSE)
clus.c <- tclust(x, k = 3, alpha = 0.1, restr.fact = 1,
restr = "deter", equal.weights = TRUE)
clus.d <- tclust(x, k = 3, alpha = 0.1, restr.fact = 50,
restr = "deter", equal.weights = FALSE)
pa <- par(mfrow = c (2, 2))
plot(clus.a, main = "(a)")
plot(clus.b, main = "(b)")
plot(clus.c, main = "(c)")
plot(clus.d, main = "(d)")
par(pa)
##--- EXAMPLE 4 ------------------------------------------
data (swissbank)
## Two clusters and 8\% trimming level
(clus <- tclust(swissbank, k = 2, alpha = 0.08, restr.fact = 50))
## Pairs plot of the clustering solution
pairs(swissbank, col = clus$cluster + 1)
## Two coordinates
plot(swissbank[, 4], swissbank[, 6], col = clus$cluster + 1,
xlab = "Distance of the inner frame to lower border",
ylab = "Length of the diagonal")
plot(clus)
## Three clusters and 0\% trimming level
clus<- tclust(swissbank, k = 3, alpha = 0.0, restr.fact = 110)
## Pairs plot of the clustering solution
pairs(swissbank, col = clus$cluster + 1)
## Two coordinates
plot(swissbank[, 4], swissbank[, 6], col = clus$cluster + 1,
xlab = "Distance of the inner frame to lower border",
ylab = "Length of the diagonal")
plot(clus)
##--- EXAMPLE 5 ------------------------------------------
data(M5data)
x <- M5data[, 1:2]
## Classification trimmed likelihood approach
clus.a <- tclust(x, k = 3, alpha = 0.1, restr.fact = 50,
opt="HARD", restr = "eigen", equal.weights = FALSE)
## Mixture trimmed likelihood approach
clus.b <- tclust(x, k = 3, alpha = 0.1, restr.fact = 50,
opt="MIXT", restr = "eigen", equal.weights = FALSE)
## Hard 0-1 cluster assignment (all 0 if trimmed unit)
head(clus.a$posterior)
## Posterior probabilities cluster assignment for the
## mixture approach (all 0 if trimmed unit)
head(clus.b$posterior)
# }
Run the code above in your browser using DataLab