Difference between revisions of "Diversity index"

From Testiwiki
Jump to: navigation, search
(Answer: most of it works)
(Answer)
Line 36: Line 36:
 
## JOTAIN KUMMAA TRUE-FUNKTIOSSA, KUN ANTAA JÄRJETTÖMIÄ TULOKSIA
 
## JOTAIN KUMMAA TRUE-FUNKTIOSSA, KUN ANTAA JÄRJETTÖMIÄ TULOKSIA
  
diversity2 <- function(pi){
+
##diversity2 <- function(pi){
out <- true(pi, c(0, 1, 2, 999))
+
##out <- true(pi, c(0, 1, 2, 999))
return(out)
+
##return(out)
}
+
##}
  
diversity2(c(0.2, 0.4, 0.1, 0.1, 0.2))
+
##diversity2(c(0.2, 0.4, 0.1, 0.1, 0.2))
  
 
truelist <- function(pi){
 
truelist <- function(pi){
Line 48: Line 48:
  
 
true2 <- function(divj, wj){
 
true2 <- function(divj, wj){
#q <- data.frame(Zero = rep(0, length(wj)), One = 1, Two = 2, Infi = 999)
+
q <- c(rep(0, length(wj)), rep(1, length(wj)), rep(2, length(wj)), rep(999, length(wj)))
if(q == 1)
+
wj <- rep(wj, times = 4)
     {qDa <- exp(sum(wj * log(divj)))}
+
     qDa <- ifelse(q == 1, exp(sum(wj * log(divj))), (sum(wj * divj^(1-q)))^1/(1 - q))
else
+
minqDj <- tapply(qDa, q, min)
    {qDa <- (sum(wj * divj^(1-q)))^1/(1 - q)}
+
qDa <- tapply(qDa, q, sum)
 +
qDa <- qDa^(1-c(0, 1, 2, 3))
 +
qDa[4] <- minqDj[4]
 
return(qDa)
 
return(qDa)
 
}
 
}
Line 74: Line 76:
 
wj <- as.data.frame(as.table(tapply(pij$pij, pij$Transect, sum)))
 
wj <- as.data.frame(as.table(tapply(pij$pij, pij$Transect, sum)))
 
head(wj)
 
head(wj)
colnames(wj) <- c("Transect", "Weight")
+
colnames(wj) <- c("Transect", "wj")
 
out <- merge(pij, wj)
 
out <- merge(pij, wj)
 +
sum(out$pij)
 +
sum(tapply(out$wj, out$Transect, max))
 
head(out)
 
head(out)
 
out <- tapply(out$pij, out$Transect, truelist)
 
out <- tapply(out$pij, out$Transect, truelist)
Line 83: Line 87:
 
qDj[i,] <- out[[i]][1:4]
 
qDj[i,] <- out[[i]][1:4]
 
}
 
}
qDj
+
qDj <- c(qDj$Zero, qDj$One, qDj$Two, qDj$Infi)
 +
 
 +
true2(qDj, wj$wj)
  
 
#NYT PITÄISI LASKEA true2 MUTTA MITEN YHDISTÄNKÄÄN div ja q?
 
#NYT PITÄISI LASKEA true2 MUTTA MITEN YHDISTÄNKÄÄN div ja q?

Revision as of 08:30, 8 January 2012



Question

How to calculate diversity indices?

Answer

Upload your data to Opasnet Base. Use the function diversity to calculate the most common indices.

Actual function diversity

+ Show code

Example to use function

Give your data in R format or leave empty for example data:

Is your data individual data or group abundancies?:

+ Show code

The data should be given in R format as a list of values in parenthesis, beginning with c:

c(3,5,3,5,2,1,3,3,4,2) or equivalently c(0.1,0.2,0.4,0.1,0.2)

where the values are either

  • identifiers of the species 1,2,3... in which the individuals belong (one entry per individual), or
  • abundancies of species, i.e. proportions of individuals belonging to each species among the whole population (one entry per species).

Rationale

Diversity indices are thoroughly described in Wikipedia.

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>