[adegenet-commits] r724 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 24 16:18:03 CET 2010


Author: jombart
Date: 2010-11-24 16:18:03 +0100 (Wed, 24 Nov 2010)
New Revision: 724

Modified:
   pkg/R/inbreeding.R
   pkg/man/inbreeding.Rd
Log:
Corrections to the weighting scheme.


Modified: pkg/R/inbreeding.R
===================================================================
--- pkg/R/inbreeding.R	2010-11-24 00:01:14 UTC (rev 723)
+++ pkg/R/inbreeding.R	2010-11-24 15:18:03 UTC (rev 724)
@@ -52,15 +52,25 @@
 
     ## COMPUTE FINAL RESULT ##
     num <- homotab - tabpi2
-    denom <- tabpi2 * (1 - tabpi2)
+    ## denom <- tabpi2 * (1 - tabpi2) # does not actually compute a weighted mean
+    denom <- 1 - tabpi2
     res <- num / denom
+    ## return values per locus ##
     if(res.type=="byloc") return(res)
 
-    res <- apply(res, 1, mean, na.rm=TRUE)
+    ## return mean weighted by effective nb of alleles ##
+    wtab <- 1/tabpi2
+    wtab[is.na(res)] <- NA
+    wtab <- t(apply(wtab, 1, function(e) return(e/sum(e,na.rm=TRUE))))
+    res <- wtab * res
+
+    res <- apply(res, 1, sum, na.rm=TRUE)
     if(plot){
         par(bg="grey")
         nPop <- length(unique(popx))
         myCol <- rainbow(nPop)[as.integer(pop(x))]
+        if(min(res)>0) ylim <- c(0, 1.1*max(res))
+        if(max(res)<0) ylim <- c(min(res), 0+abs(min(res))*0.1)
         plot(res, col=myCol, type="h", ylab="Inbreeding", xlab="Individuals", ...)
     }
 

Modified: pkg/man/inbreeding.Rd
===================================================================
--- pkg/man/inbreeding.Rd	2010-11-24 00:01:14 UTC (rev 723)
+++ pkg/man/inbreeding.Rd	2010-11-24 15:18:03 UTC (rev 724)
@@ -46,7 +46,7 @@
 \details{
   Let \eqn{p_i} refer to the allele frequencies in a population. Let
   \eqn{h} be an variable which equates 1 if the individual is
-  heterozygote, and 0 otherwise. For one locus, Balloux's inbreeding coefficient is
+  homozygote, and 0 otherwise. For one locus, Balloux's inbreeding coefficient is
   defined as:
 
   \eqn{  \frac{h - \sum_i p_i^2}{ \sum_i p_i^2 (1- \sum_i p_i^2)} } \cr



More information about the adegenet-commits mailing list