[adegenet-commits] r538 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jan 22 19:06:48 CET 2010


Author: jombart
Date: 2010-01-22 19:06:48 +0100 (Fri, 22 Jan 2010)
New Revision: 538

Modified:
   pkg/R/dapc.R
Log:
fixed a bug in variable contrib scaling.


Modified: pkg/R/dapc.R
===================================================================
--- pkg/R/dapc.R	2010-01-19 00:47:39 UTC (rev 537)
+++ pkg/R/dapc.R	2010-01-22 18:06:48 UTC (rev 538)
@@ -76,7 +76,12 @@
     ## optional: get loadings of alleles
     if(var.contrib){
         res$var.contr <- as.matrix(U) %*% as.matrix(ldaX$scaling)
-        res$var.contr <- t(apply(res$var.contr, 1, function(e) e*e / sum(e*e)))
+        f1 <- function(x){
+            temp <- sum(x*x)
+            if(temp < 1e-12) return(rep(0, length(x)))
+            return(x*x / temp)
+        }
+        res$var.contr <- t(apply(res$var.contr, 1, f1))
     }
 
     class(res) <- "dapc"



More information about the adegenet-commits mailing list