[adegenet-commits] r592 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 29 12:58:17 CEST 2010


Author: jombart
Date: 2010-03-29 12:58:16 +0200 (Mon, 29 Mar 2010)
New Revision: 592

Added:
   pkg/R/Hs.R
   pkg/man/Hs.Rd
Modified:
   pkg/ChangeLog
Log:
Added Hs function.


Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2010-03-26 10:59:30 UTC (rev 591)
+++ pkg/ChangeLog	2010-03-29 10:58:16 UTC (rev 592)
@@ -1,3 +1,14 @@
+			CHANGES IN ADEGENET VERSION 1.3-0
+
+
+NEW FEATURES
+
+	o Hs computes the theoretical heterozygosity by populations for
+	genpop object
+	
+
+
+	
 			CHANGES IN ADEGENET VERSION 1.2-3
 
 

Added: pkg/R/Hs.R
===================================================================
--- pkg/R/Hs.R	                        (rev 0)
+++ pkg/R/Hs.R	2010-03-29 10:58:16 UTC (rev 592)
@@ -0,0 +1,18 @@
+############################
+# Hs (expected heterozygosity)
+############################
+Hs <- function(x, truenames=TRUE) {
+
+    ## checks
+    if(!is.genpop(x)) stop("x is not a valid genpop object")
+    if(x at type=="PA") stop("not implemented for presence/absence markers")
+
+    ## main computations
+    x.byloc <- seploc(x, truenames=truenames)
+    lX <- lapply(x.byloc, function(e) makefreq(e, quiet=TRUE, truenames=truenames)$tab)
+    lres <- lapply(lX, function(X) 1- apply(X^2,1,sum))
+
+    res <- apply(as.matrix(data.frame(lres)),1,mean)
+
+    return(res)
+} # end Hs

Added: pkg/man/Hs.Rd
===================================================================
--- pkg/man/Hs.Rd	                        (rev 0)
+++ pkg/man/Hs.Rd	2010-03-29 10:58:16 UTC (rev 592)
@@ -0,0 +1,32 @@
+\encoding{UTF-8}
+\name{Hs}
+\alias{Hs}
+\title{Expected heterozygosity}
+\description{This function computes the expected heterozygosity per
+  population from \linkS4class{genpop} objects. This is possible for
+  codominant markers (\code{@type="codom"}). For haploid data, Hs still
+  provides a measure of within-population genetic diversity. 
+}
+\usage{
+Hs(x, truenames=TRUE)
+}
+\arguments{
+  \item{x}{an object of class \linkS4class{genpop}.}
+  \item{truenames}{a logical indicating whether true labels (as opposed
+    to generic labels) should be used to name the output.}
+}
+\details{
+  Let \emph{m(k)} be the number of alleles of locus \emph{k}, with a
+  total of \emph{K} loci. We note \eqn{f_i} the allele frequency of
+  allele \emph{i} in a given population. Then, \eqn{Hs} is given for a
+  given population by:\cr
+
+  \eqn{\frac{1}{K} \sum_{k=1}^K (1 - \sum_{i=1}^{m(k)} f_i^2)} \cr
+}
+\value{A vector of Hs values (one value per population).}
+\author{ Thibaut Jombart \email{t.jombart at imperial.ac.uk} }
+\examples{
+data(nancycats)
+Hs(genind2genpop(nancycats))
+}
+\keyword{multivariate}
\ No newline at end of file



More information about the adegenet-commits mailing list