library("clustrd")
# Example 1 - Continuous case (Short-term macroeconomic scenario)
data("macro", package = "clustrd")
# Reduced K-means with 3 clusters and 2 dimensions (varimax rotation)
outRKM <- cluspca(macro, 3, 2, method = "RKM", rotation = "varimax", seed = 1234)
summary(outRKM)
# Biplot
plot(outRKM)
# Scatterplot of object points
plot(outRKM, what = c(TRUE, FALSE))
# Correlation circle of the variables
lbl <- c("Gross Dom. Prod.", "Lead. Indicator", "Unempl. Rate", "Interest Rate",
"Trade Balance", "Net Nat. Savings")
plot(outRKM, what = c(FALSE, TRUE), attlabs = lbl)
# Biplot and Parallel plot showing cluster means
plot(outRKM, cludesc = TRUE)
outRKM <- cluspca(macro, 3, 2, method = "RKM", rotation = "varimax", seed = 1234)
# Example 2 - Categorical case (Contraceptive Choice in Indonesia)
data("cmc", package = "clustrd")
# Wife's age and number of children are categorized into three groups based on
# quartiles
cmc$W_AGE <- ordered(cut(cmc$W_AGE, c(16, 26, 39, 49), include.lowest = TRUE))
levels(cmc$W_AGE) <- c("16-26", "27-39", "40-49")
cmc$NCHILD <- ordered(cut(cmc$NCHILD, c(0, 1, 4, 17), right = FALSE))
levels(cmc$NCHILD) <- c("0", "1-4", "5 and above")
# Cluster correspondence analysis with 3 clusters and 2 dimensions (10 random
# starts)
outclusCA <- clusmca(cmc, 3, 2, nstart = 10, seed = 1234)
summary(outclusCA)
# Biplot and cluster description barplots showing the largest standardized
# residuals per attribute for each cluster together with subplots with the full
# residuals distribution
plot(outclusCA, cludesc = TRUE, topstdres = 20, subplot = TRUE)
# Tuning MCA K-means: selection of the appropriate number of clusters (from 3 to
# 10) and dimensions (from 2 to 9) Cluster quality criterion: average Silhouette
# width, Gower's distance on the original data (it takes a while...)
bestMCAk <- tuneclus(cmc, 3:10, 2:9, method = "MCAk", criterion = "asw", dst = "full",
nstart = 10, seed = 1234)
bestMCAk