Created
May 1, 2012 09:44
-
-
Save anandnalya/2566854 to your computer and use it in GitHub Desktop.
Clustering of synthetic control data in R, see http://anandnalya.com/2012/05/01/clustering-of-synthetic-control-data-in-r/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- read.table("synthetic_control.data") | |
cat( "read", length(x[,1]), "records.\n") | |
# load clustering library | |
library(flexclust) | |
# get number of clusters from user | |
n <- as.integer( readline("Enter number of clusters: ")) | |
# run kmeans clustering on the dataset | |
cl1 <- cclust(x, n) | |
print("clustering complete") | |
# show summary of clustering | |
summary(cl1) | |
# plot the clusters | |
plot(cl1, main="Clusters") | |
readline("Press enter for cluster histogram") | |
m<-info(cl1, "size") # size of each cluster | |
hist(rep(1:n, m), breaks=0:n, xlab="Cluster No.", main="Cluster Plot") | |
readline("Press enter for a plot of distance of data points from its cluster centorid") | |
stripes(cl1) | |
print("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment