# Example dataset with categorical, ordinal, and continuous variables
set.seed(123)
data_mix <- data.frame(
cat_var = factor(sample(letters[1:3], 100, replace = TRUE)), # Nominal categorical variable
ord_var = factor(sample(c("low", "medium", "high"), 100, replace = TRUE),
levels = c("low", "medium", "high"),
ordered = TRUE), # Ordinal variable
cont_var1 = rnorm(100), # Continuous variable 1
cont_var2 = runif(100) # Continuous variable 2
)
# Perform Mixed-Type Fuzzy Clustering
result_mix <- IBmix(X = data_mix, ncl = 3, beta = 2, nstart = 1)
# Print clustering results
print(result_mix$Cluster) # Cluster membership matrix
print(result_mix$InfoXT) # Mutual information between X and T
print(result_mix$MutualInfo) # Mutual information between Y and T
# Summary of output
summary(result_mix)
# Simulated categorical data example
set.seed(123)
data_cat <- data.frame(
Var1 = as.factor(sample(letters[1:3], 100, replace = TRUE)), # Nominal variable
Var2 = as.factor(sample(letters[4:6], 100, replace = TRUE)), # Nominal variable
Var3 = factor(sample(c("low", "medium", "high"), 100, replace = TRUE),
levels = c("low", "medium", "high"), ordered = TRUE) # Ordinal variable
)
# Perform fuzzy clustering on categorical data with standard IB
result_cat <- IBmix(X = data_cat, ncl = 3, beta = 15, lambda = -1, nstart = 2, maxiter = 200)
# Print clustering results
print(result_cat$Cluster) # Cluster membership matrix
print(result_cat$InfoXT) # Mutual information between X and T
print(result_cat$MutualInfo) # Mutual information between Y and T
plot(result_cat, type = "sizes") # Bar plot of cluster sizes (hardened assignments)
plot(result_cat, type = "info") # Information-theoretic quantities plot
# Simulated continuous data example
set.seed(123)
# Continuous data with 100 observations, 5 features
data_cont <- as.data.frame(matrix(rnorm(500), ncol = 5))
# Perform fuzzy clustering on continuous data with standard IB
result_cont <- IBmix(X = data_cont, ncl = 3, beta = 50, s = -1, nstart = 2)
# Print clustering results
print(result_cont$Cluster) # Cluster membership matrix
print(result_cont$InfoXT) # Mutual information between X and T
print(result_cont$MutualInfo) # Mutual information between Y and T
Run the code above in your browser using DataLab