Difference between revisions of "Diversity index"

From Testiwiki
Jump to: navigation, search
(Answer: seems to work. A new example)
(Answer: something wrong with qD)
Line 18: Line 18:
  
 
qD <- function(pi, q){
 
qD <- function(pi, q){
 +
print(pi)
 +
print(q)
 +
print(q)
 
pi <- pi/sum(pi)
 
pi <- pi/sum(pi)
 
out <- rep(NA, length(q))
 
out <- rep(NA, length(q))
Line 83: Line 86:
 
out <- qDa(qDj, wj$wj, q)
 
out <- qDa(qDj, wj$wj, q)
 
out2 <- qD(pi, q)
 
out2 <- qD(pi, q)
q <- gsub("999", "∞", q)
+
qt <- gsub("999", "∞", q)
  
outlabel <- c(paste("Alpha diversity with q=", q, sep=""), paste("Gamma diversity with q=", q, sep=""))
+
outlabel <- c(paste("Alpha diversity with q=", qt, sep=""), paste("Gamma diversity with q=", qt, sep=""))
outsymbol <- c(paste(q, "Da", sep=""), paste(q, "D", sep=""))
+
outsymbol <- c(paste(qt, "Da", sep=""), paste(qt, "D", sep=""))
  
 
out <- data.frame(Name = c(outlabel, "Richness", "Shannon index",  
 
out <- data.frame(Name = c(outlabel, "Richness", "Shannon index",  
Line 96: Line 99:
 
return(out)
 
return(out)
 
}
 
}
 +
library(OpasnetBaseUtils)
 +
data <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
 +
diversity(amount=data, species = 1:20, transect = c(rep(1, 10), rep(2, 10)), q = c(0, 1, 2))
  
 
</rcode>
 
</rcode>
Line 101: Line 107:
 
'''Example 1 to use function
 
'''Example 1 to use function
  
<rcode include="page:Diversity_index|name:answer" variables="
+
<rcode include="page:Diversity_index|name:answer|page:OpasnetBaseUtils|name:generic" variables="
 
name:data|description:Give your data in R format or leave empty for example data|
 
name:data|description:Give your data in R format or leave empty for example data|
 
name:individual|description:Is your data individual data or group abundancies?|type:selection|options:TRUE;Individual;FALSE;Group|default:TRUE
 
name:individual|description:Is your data individual data or group abundancies?|type:selection|options:TRUE;Individual;FALSE;Group|default:TRUE
Line 108: Line 114:
 
if(is.null(data)) {data <- c(1,4,6,9,3,4,5,6,5,4,3,3,5,5,7,5,5,4,3,4,5,6,8,9,5,4,5,4,3,3,4,9,6,6,4,5,3,2,1,1,2,3,4,3,2,3,4,5,6,7,7)}
 
if(is.null(data)) {data <- c(1,4,6,9,3,4,5,6,5,4,3,3,5,5,7,5,5,4,3,4,5,6,8,9,5,4,5,4,3,3,4,9,6,6,4,5,3,2,1,1,2,3,4,3,2,3,4,5,6,7,7)}
 
data
 
data
if(individual==TRUE) out <- diversity(species = data) else out <- diversity(amount = data)
+
diversity(data)
 +
if(individual==TRUE) out <- diversity(species = data, q = 1) else out <- diversity(amount = data, q = 1)
 
print(xtable(out), type = 'html')
 
print(xtable(out), type = 'html')
 
</rcode>
 
</rcode>
Line 129: Line 136:
 
out <- diversity(amount, species, transect, q)
 
out <- diversity(amount, species, transect, q)
 
print(xtable(out), type = 'html')
 
print(xtable(out), type = 'html')
 +
  
 
</rcode>
 
</rcode>

Revision as of 18:51, 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 1 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

Example 2

Select your data:

Which q values you want to calculate.:
0
1
2
3

+ 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>