[adegenet-commits] r693 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 19 16:15:03 CEST 2010


Author: jombart
Date: 2010-10-19 16:15:03 +0200 (Tue, 19 Oct 2010)
New Revision: 693

Modified:
   pkg/R/dapc.R
Log:
A few minor changes


Modified: pkg/R/dapc.R
===================================================================
--- pkg/R/dapc.R	2010-10-19 14:02:21 UTC (rev 692)
+++ pkg/R/dapc.R	2010-10-19 14:15:03 UTC (rev 693)
@@ -381,17 +381,17 @@
 ##############
 ## optim.a.score
 ##############
-optim.a.score <- function(x, n.pca=1:ncol(x$tab), smart=TRUE, n=10, plot=FALSE,
-                         n.da=length(levels(x$grp)), ...){
+optim.a.score <- function(x, n.pca=1:ncol(x$tab), smart=TRUE, n=10, plot=TRUE,
+                         n.sim=10, n.da=length(levels(x$grp)), ...){
     ## A FEW CHECKS ##
     if(!inherits(x,"dapc")) stop("x is not a dapc object")
-    if(n.pca>ncol(x$tab)) stop("too many PCA axes retained")
+    if(max(n.pca)>ncol(x$tab)) stop("too many PCA axes retained")
     if(n.da>length(levels(x$grp))) stop("too many DA axes retained")
+    pred <- NULL
 
-
     ## AUXILIARY FUNCTION ##
     f1 <- function(ndim){
-        a.score(x, n.pca=ndim, n.da=n.da)$pop.score
+        a.score(x, n.pca=ndim, n.da=n.da, n.sim=n.sim)$pop.score
     }
 
 
@@ -418,18 +418,17 @@
     }
 
 
-
     ## MAKE FINAL OUTPUT ##
     res <- list()
     res$pop.score <- lres
     res$mean <- means
+    if(!is.null(pred)) res$pred <- pred
     res$best <- best
 
-
     ## PLOTTING (OPTIONAL) ##
     if(plot){
         if(smart){
-            boxplot(lres, at=n.pca, col="gold", xlab="Number of retained PCs", ylab="a-score", xlim=range(n.pca))
+            boxplot(lres, at=n.pca, col="gold", xlab="Number of retained PCs", ylab="a-score", xlim=range(n.pca)+c(-1,1), ylim=c(-.1,1.1))
             lines(pred, lwd=3)
             points(pred$x[best], pred$y[best], col="red", lwd=3)
             title("a-score optimisation - spline interpolation")
@@ -437,7 +436,7 @@
         } else {
             myCol <- rep("gold", length(lres))
             myCol[best] <- "red"
-            boxplot(lres, at=n.pca, col=myCol, xlab="Number of retained PCs", ylab="a-score", xlim=range(n.pca))
+            boxplot(lres, at=n.pca, col=myCol, xlab="Number of retained PCs", ylab="a-score", xlim=range(n.pca)+c(-1,1), ylim=c(-.1,1.1))
             lines(n.pca, sapply(lres, mean), lwd=3, type="b")
             myCol <- rep("black", length(lres))
             myCol[best] <- "red"
@@ -448,7 +447,7 @@
     }
 
     return(res)
-}
+} # end optim.a.score
 
 
 



More information about the adegenet-commits mailing list