[Vegan-commits] r2530 - in pkg/ordiconsensus: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jun 18 15:56:30 CEST 2013
Author: gblanchet
Date: 2013-06-18 15:56:29 +0200 (Tue, 18 Jun 2013)
New Revision: 2530
Added:
pkg/ordiconsensus/R/SADbin.R
pkg/ordiconsensus/man/SADbin.Rd
Modified:
pkg/ordiconsensus/DESCRIPTION
pkg/ordiconsensus/NAMESPACE
pkg/ordiconsensus/man/consensusRDA.Rd
pkg/ordiconsensus/man/ordiconsensus-package.Rd
Log:
small correction and add SADbin
Modified: pkg/ordiconsensus/DESCRIPTION
===================================================================
--- pkg/ordiconsensus/DESCRIPTION 2013-06-17 13:44:09 UTC (rev 2529)
+++ pkg/ordiconsensus/DESCRIPTION 2013-06-18 13:56:29 UTC (rev 2530)
@@ -1,7 +1,7 @@
Package: ordiconsensus
Type: Package
Title: Consensus of canonical ordinations through the canonical redundancy analysis
-Version: 0.3-1
+Version: 0.3-2
Date: 2012-11-09
Author: F. Guillaume Blanchet
Maintainer: F. Guillaume Blanchet <guillaume.blanchet at helsinki.fi>
Modified: pkg/ordiconsensus/NAMESPACE
===================================================================
--- pkg/ordiconsensus/NAMESPACE 2013-06-17 13:44:09 UTC (rev 2529)
+++ pkg/ordiconsensus/NAMESPACE 2013-06-18 13:56:29 UTC (rev 2530)
@@ -1,6 +1,6 @@
### Export
-export(coeffCompare,consensusRDA,RV)
+export(coeffCompare,consensusRDA,RV,SADbin)
### Import
Added: pkg/ordiconsensus/R/SADbin.R
===================================================================
--- pkg/ordiconsensus/R/SADbin.R (rev 0)
+++ pkg/ordiconsensus/R/SADbin.R 2013-06-18 13:56:29 UTC (rev 2530)
@@ -0,0 +1,103 @@
+SADbin <-
+function(data,method=c("log","modlog","modhalflog"),base=2){
+### Function that does method 1 of binning from Gray et al. (2006)
+###
+### Arguments:
+###
+### data: species abundant data
+### method: binning method following Gray et al. (2006). Either "log", "modlog", or "modhalflog"
+### base: base of the log to be used.
+###
+### copyleft - Guillaume Blanchet - August 2008
+##################################################################
+ method<-match.arg(method)
+
+ "%w/o%" <- function(x,y) x[!x %in% y] #-- x without y
+ #CC# Find the number of class to be used
+ spmax<-max(data)
+
+ #CC# Number of bins
+ nbin<-ceiling(log(spmax+1,base=base))+1
+
+ #CC# Find the levels of abundance of species
+ lev<-as.numeric(levels(as.factor(data)))
+ nlev<-nlevels(as.factor(data))
+
+ #CC# Number of species per level
+ nsp.lev<-vector(length=nlev)
+ data.lev<-vector(length=length(data))
+
+ for(i in 1:nlev){
+ search<-which(data==lev[i])
+ nsp.lev[i]<-length(search)
+ data.lev[search]<-lev[i]
+ }
+
+ #### Find the number of species in each bins (and which species goes in which bins)
+ #CC# Starting the species which give an integer with a log_base
+ sp.div<-base^(1:(nbin-1))
+ sp.div<-c(1,sp.div)
+
+ bin.mat<-matrix(0,ncol=nbin,nrow=length(data))
+
+ bin.sp.div<-vector(length=nbin)
+ for(i in 1:nbin){
+ if(length(which(lev==sp.div[i]))!=0){
+ bin.sp.div[i]<-nsp.lev[which(lev==sp.div[i])]
+ bin.mat[which(data.lev==sp.div[i]),i]<-1
+ }
+ }
+
+ if(method=="modhalflog"){
+ bin.sp.div2<-bin.sp.div/2
+ bin.sp.div.good<-c(0,bin.sp.div2)+c(bin.sp.div2,0)
+
+ bin.mat2<-bin.mat/2
+ bin.mat<-cbind(0,bin.mat2)+cbind(bin.mat2,0)
+ }
+
+ #CC# Than with all the other ones
+ spnot.div<-data %w/o% sp.div
+ spnot.div2<-which((data %in% sp.div)==FALSE)
+
+ bin.spnot.div<-vector(mode="numeric",length=nbin)
+
+ if(method=="log" | method=="modhalflog"){
+ for(i in 1:length(spnot.div)){
+ bin.sel<-which(sp.div>spnot.div[i])[1]
+ bin.spnot.div[bin.sel]<-bin.spnot.div[bin.sel]+1
+
+ bin.mat[spnot.div2[i],bin.sel]<-1
+ }
+ }
+ else if(method=="modlog"){
+
+ for(i in 1:length(spnot.div)){
+ bin.sel<-which(sp.div>spnot.div[i])[1]-1
+ bin.spnot.div[bin.sel]<-bin.spnot.div[bin.sel]+1
+
+ bin.mat[spnot.div2[i],bin.sel]<-1
+ }
+ }else{
+ stop("method should be 'log' or 'modlog'")
+ }
+
+ #CC# Construct the resulting binning
+ if(method=="modhalflog"){
+ bin<-bin.sp.div.good[-length(bin.sp.div.good)]+bin.spnot.div
+ bin.mat<-bin.mat[,-length(bin.sp.div.good)]
+ }
+ else if(method=="log"){
+ bin<-bin.sp.div+bin.spnot.div
+ }
+ else if(method=="modlog"){
+ bin<-bin.sp.div+bin.spnot.div
+ bin<-bin[-length(bin)]
+ bin.mat<-bin.mat[,-ncol(bin.mat)]
+
+ }else{
+ stop("method should be 'log' or 'modlog'")
+ }
+
+ return(list(bin=bin,sp.bin=bin.mat))
+}
Added: pkg/ordiconsensus/man/SADbin.Rd
===================================================================
--- pkg/ordiconsensus/man/SADbin.Rd (rev 0)
+++ pkg/ordiconsensus/man/SADbin.Rd 2013-06-18 13:56:29 UTC (rev 2530)
@@ -0,0 +1,54 @@
+\name{SADbin}
+\alias{SADbin}
+\title{
+Species-abundance distribution (SAD) bins
+}
+\description{
+This function constructs bins for a species-abundance distribution. The function was designed so that every variation of bins can easily be constructed.
+}
+\usage{
+SADbin(data, method = c("log", "modlog", "modhalflog"), base = 2)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{data}{
+A vector of species abundance for the whole study area.
+}
+ \item{method}{
+A character string defining which binning method to use.
+}
+ \item{base}{
+The logarithm base used to perform the binning
+}
+}
+\details{
+All value in \code{data} are expected to be count data. An error message will be sent if the value in \code{data} are not integers.
+
+The different method of binning are defined as such :
+
+log (using a base = 2) : Bin 1 = 1, Bin 2 = 2, Bin 3 = 3-4, Bin 4 = 5-8, ...
+
+modlog (using a base = 2) : Bin 1 = 1, Bin 2 = 2-3, Bin 3 = 4-7, Bin 4 = 8-15,...
+
+modhalflog (using a base = 2) : Bin 1 = half the number of species with 1 individuals, Bin 2 = half the number of species with 2 individuals, all species with 3 individuals and half the number of species with 4 individuals, Bin 3 = 4-8, abundances that fall exactly on the boundary are divided equally between the given bin and the next lower bin, and so on.
+}
+
+\value{
+\item{bin}{A vector defining the number of species in each bin}
+\item{sp.bin}{A matrix with the species in rows and the bins in columns. This matrix describe which species is in which bin}
+}
+\references{
+Gray, J.S., A. Bjorgesaeter, and K. I. Ugland. 2006. On plotting species abundance distributions. \emph{Journal of Animal Ecology} \strong{75}:752--756.
+}
+\author{
+F. Guillaume Blanchet
+}
+
+\examples{
+
+data(mite)
+SADmite<-SADbin(colSums(mite))
+barplot(SADmite$bin,names.arg=paste("Bin",1:length(SADmite$bin)),las=2)
+
+}
+\keyword{ cluster }
Modified: pkg/ordiconsensus/man/consensusRDA.Rd
===================================================================
--- pkg/ordiconsensus/man/consensusRDA.Rd 2013-06-17 13:44:09 UTC (rev 2529)
+++ pkg/ordiconsensus/man/consensusRDA.Rd 2013-06-18 13:56:29 UTC (rev 2530)
@@ -100,8 +100,8 @@
### Consensus RDA
consRDA<-consensusRDA(ordiRes,ordiResTest,beetle,beetle.expl)
summary(consRDA)
+axisLabels<-c(paste("Axis 1 - ",round(consRDA$values[1]/sum(consRDA$values),4)*100,sep=""),paste("Axis 2 - ",round(consRDA$values[2]/sum(consRDA$values),4)*100,sep=""))
-axisLabels<-c(paste("Axis 1 - ",round(consRDA$values[1]/sum(consRDA$values),4)*100,"%",sep=""),paste("Axis 2 - ",round(consRDA$values[2]/sum(consRDA$values),4)*100,"%",sep=""))
plot(consRDA$siteConsensus[,1:2],pch=19,xlab=axisLabels[1],ylab=axisLabels[2],las=1)
abline(h=0,v=0,lty=3)
@@ -110,6 +110,7 @@
arrows(0,0,consRDA$descConsensus[,1]*0.4,consRDA$descConsensus[,2]*0.4,col="blue",length=0.1,angle=12)
text(consRDA$descConsensus[,1:2]*0.4,labels=rownames(consRDA$descConsensus),col="blue")
+
}
\keyword{ multivariate }
Modified: pkg/ordiconsensus/man/ordiconsensus-package.Rd
===================================================================
--- pkg/ordiconsensus/man/ordiconsensus-package.Rd 2013-06-17 13:44:09 UTC (rev 2529)
+++ pkg/ordiconsensus/man/ordiconsensus-package.Rd 2013-06-18 13:56:29 UTC (rev 2530)
@@ -12,7 +12,7 @@
\tabular{ll}{
Package: \tab ordiconsensus\cr
Type: \tab Package\cr
-Version: \tab 0.3-1\cr
+Version: \tab 0.3-2\cr
Date: \tab 2012-11-12\cr
License: \tab Unlimited\cr
}
More information about the Vegan-commits
mailing list