[Esm-commits] r41 - pkg/ESM/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jan 14 12:15:48 CET 2011
Author: timotheepoisot
Date: 2011-01-14 12:15:47 +0100 (Fri, 14 Jan 2011)
New Revision: 41
Modified:
pkg/ESM/R/functions.r
Log:
Modified: pkg/ESM/R/functions.r
===================================================================
--- pkg/ESM/R/functions.r 2010-10-07 17:11:09 UTC (rev 40)
+++ pkg/ESM/R/functions.r 2011-01-14 11:15:47 UTC (rev 41)
@@ -9,6 +9,16 @@
return(out)
}
+Rpdi <- function(fit)
+{
+ fit <- fit[fit>0]
+ if(length(fit)==1){return(1)}
+ fit <- sort(as.vector(fit),decreasing=TRUE)
+ test <- fit[2:length(fit)]
+ out <- sum(fit[1]-test)/length(test)
+ return(out)
+}
+
rr <- function(fit)
{
N <- length(fit)
@@ -39,7 +49,7 @@
return(SSI)
}
-getspe <- function(mat,measure=pdi,normal='whole',...)
+getspe <- function(mat,measure=pdi,normal='species',...)
{
mat <- fixmat(mat)
if(normal=='species'){mat <- t(apply(mat,1,function(x)x/max(x)))}
@@ -71,43 +81,4 @@
nm[(cl[i]<m)&(m<=cl[(i+1)])] <- cl[i]
}
return(scale(nm,0,1))
-}
-
-Overlap = function(mat)
-{
- for(i in 1:nrow(mat))
- {
- mat[i,] <- mat[i,]/sum(mat[i,])
- }
- out <- matrix(0,nrow=nrow(mat),ncol=nrow(mat))
- colnames(out) <- rownames(mat)
- rownames(out) <- rownames(mat)
- for(i in 1:(nrow(mat)-1))
- {
- for(j in (i+1):nrow(mat))
- {
- out[i,j] <- 1-1/2*sum(abs(mat[i,]-mat[j,]))
- }
- }
- diag(out) <- rep(1,length(diag(out)))
- return(out)
-}
-
-getOLsp = function(OLmat,id)
-{
- byR <- OLmat[id,]
- byC <- OLmat[,id]
- OlSP <- c(byR[c((id+1):length(byR))],byC[c(1:(id-1))])
- return(OlSP)
-}
-
-getOLvec = function(net)
-{
- net <- empty(net)
- net <- net/max(net)
- OLmat <- Overlap(net)
- l <- c(1:nrow(OLmat))
- OL <- lapply(l,function(x)getOLsp(OLmat,id=x))
- if(!is.null(rownames(OLmat))){names(OL)<-rownames(OLmat)}
- return(OL)
}
\ No newline at end of file
More information about the Esm-commits
mailing list