[adegenet-commits] r512 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 4 19:03:23 CET 2009


Author: jombart
Date: 2009-12-04 19:03:22 +0100 (Fri, 04 Dec 2009)
New Revision: 512

Modified:
   pkg/R/dapc.R
Log:
Added another criterion to choose te best bumber of clusters.


Modified: pkg/R/dapc.R
===================================================================
--- pkg/R/dapc.R	2009-12-04 17:11:22 UTC (rev 511)
+++ pkg/R/dapc.R	2009-12-04 18:03:22 UTC (rev 512)
@@ -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"), choose.n.clust=TRUE,
+find.clusters.data.frame <- function(x, n.pca=NULL, n.clust=NULL, stat=c("BIC", "AIC", "WSS"), choose.n.clust=TRUE, criterion=c("min","diff")
                                      max.n.clust=round(nrow(x)/10), n.iter=1e6, n.start=100, center=TRUE, scale=TRUE){
 
     ## CHECKS ##
@@ -91,7 +91,13 @@
             cat("Choose the number of clusters (>=2: ")
             n.clust <- as.integer(readLines(n = 1))
         } else {
-            n.clust <- which.min(myStat)
+            if(criterion=="min") {
+                n.clust <- which.min(myStat)
+            }
+            if(criterion=="diff") {
+                temp <- diff(myStat)
+                n.clust <- which.max( which((temp-min(temp))< max(temp)/1e4)) )
+            }
         }
     }
 



More information about the adegenet-commits mailing list