Ad Code

R Script for Clustering


## for binary (jaccard) categorical variable clustering

install the package proxy

distance matrix
d = dist(tayeeb, method = "jaccard")

Export the matrix file
write.csv(as.matrix(distn), file = "dist.csv")

Install the package cluster
data = read.table(file.choose(), header = TRUE))

d = dist(tayeeb, method = "binary")


## for regular clustering

data <- na.omit(data)      # listwise deletion of missing
data <- scale(data)        # standardize variables

# Ward Hierarchical Clustering
d <- dist(data, method = "euclidean")   # distance matrix
fit <- hclust(d, method = "ward") 

plot(fit)                 # display dendogram

groups <- cutree(fit, k = 5)   # cut tree into 5 clusters

# draw dendogram with red borders around the 5 clusters 
rect.hclust(fit, k = 5, border = "red")

Post a Comment

0 Comments

Close Menu