Uploaded by Srividya Kondagunta

code for s1

advertisement
library(psych)
library(factoextra)
mydata <- read.csv(file.choose())
indicators <- mydata [ ,c("I1", "I2", "I3", "I4", "I5", "I6", "I7" )]
fit <- princomp(indicators, cor=TRUE)
summary(fit)
loadings(fit)
plot(fit, type = "lines")
biplot(fit)
fit <- principal(indicators, nfactors=2, rotate = "varimax")
fit
mydata$Perf <- rowMeans(cbind(mydata$I1,mydata$ I4, mydata$I5, mydata$I6))
mydata$IQ <- rowMeans(cbind(mydata$I2, mydata$I3, mydata$I7))
mydata$zCommonality <- scale (mydata$Commonality,center=TRUE,scale=TRUE)
mydata$zActivity <- scale (mydata$Activity,center=TRUE,scale=TRUE)
mydata$zPerf <- scale (mydata$Perf,center=TRUE,scale=TRUE)
mydata$zIQ <- scale (mydata$IQ,center=TRUE,scale=TRUE)
clusterdata <- mydata [ ,c("zCommonality", "zActivity", "zPerf", "zIQ")]
fviz_nbclust(clusterdata, FUNcluster = kmeans, method = c("silhouette", "wss", "gap_stat"),
diss = NULL, k.max = 10, nboot = 100, verbose = interactive(), barfill = "steelblue", barcolor =
"steelblue", linecolor = "steelblue", print.summary = TRUE)
set.seed(123)
km.res <- kmeans(clusterdata, 6, nstart = 25)
print(km.res)
aggregate(clusterdata, by=list(cluster=km.res$cluster), mean)
dd <- cbind(clusterdata, cluster = km.res$cluster)
head(dd)
fviz_cluster(km.res, data = clusterdata)
Download