[adegenet-commits] r510 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 4 16:03:42 CET 2009


Author: jombart
Date: 2009-12-04 16:03:42 +0100 (Fri, 04 Dec 2009)
New Revision: 510

Modified:
   pkg/R/dapc.R
Log:
automatic selection of nb of clusters now possible


Modified: pkg/R/dapc.R
===================================================================
--- pkg/R/dapc.R	2009-12-04 14:49:08 UTC (rev 509)
+++ pkg/R/dapc.R	2009-12-04 15:03:42 UTC (rev 510)
@@ -6,7 +6,7 @@
 ######################
 ## find.clusters.data.frame
 ######################
-find.clusters.data.frame <- function(x, n.pca=NULL, n.clust=NULL, stat=c("BIC", "AIC", "WSS"),
+find.clusters.data.frame <- function(x, n.pca=NULL, n.clust=NULL, stat=c("BIC", "AIC", "WSS"), choose.n.clust=TRUE,
                                      max.n.clust=round(nrow(x)/10), n.iter=1e6, n.start=100, center=TRUE, scale=TRUE){
 
     ## CHECKS ##
@@ -85,11 +85,14 @@
             myTitle <- "Value of within SS\nversus number of clusters"
         }
 
-        plot(c(1,nbClust), myStat, xlab="Number of clusters", ylab=myLab, main=myTitle, type="b", col="blue")
-        abline(h=0, lty=2, col="red")
-        cat("Choose the number of clusters (>=2: ")
-        n.clust <- as.integer(readLines(n = 1))
-
+        if(choose.n.clust){
+            plot(c(1,nbClust), myStat, xlab="Number of clusters", ylab=myLab, main=myTitle, type="b", col="blue")
+            abline(h=0, lty=2, col="red")
+            cat("Choose the number of clusters (>=2: ")
+            n.clust <- as.integer(readLines(n = 1))
+        } else {
+            n.clust <- which.min(myStat)
+        }
     }
 
     ## get final groups



More information about the adegenet-commits mailing list