Difference between revisions of "Diversity index"

From Testiwiki
Jump to: navigation, search
m (Answer)
(may work?)
Line 12: Line 12:
 
'''Actual function ''diversity'''''
 
'''Actual function ''diversity'''''
  
<rcode name="answer"
+
<rcode name="answer">
include="page:OpasnetBaseUtils|name:generic">
 
  
 
####### qD calculates true diversity for abundance pi with exponent q.
 
####### qD calculates true diversity for abundance pi with exponent q.
  
qD <- function(pi, q){
+
qD <- function(pi, q = q){
 
pi <- pi/sum(pi)
 
pi <- pi/sum(pi)
 
out <- rep(NA, length(q))
 
out <- rep(NA, length(q))
Line 31: Line 30:
 
}
 
}
  
##### qD4tapply is the same as the qD but using only a single parameter, because that is what is required for tapply.
+
##### qD4tapply is the same as the qD but using only a single parameter, #because that is what is required for tapply.
  
qD4tapply <- function(pi){
+
#qD4tapply <- function(pi, q = wikiq){
return(qD(pi, q))
+
# return(qD(pi, q))
}
+
#}
  
 
###### qDa calculates alpha diversity using gamma diversities of each transect.
 
###### qDa calculates alpha diversity using gamma diversities of each transect.
Line 72: Line 71:
 
out <- merge(pij, wj)
 
out <- merge(pij, wj)
  
out <- tapply(out$pij, out$Transect, qD4tapply)
+
out <- tapply(out$pij, out$Transect, qD)
 +
 
 
qDj <- rep(NA, nrow(wj)*length(q))
 
qDj <- rep(NA, nrow(wj)*length(q))
  
Line 98: Line 98:
  
 
cat("Functions loaded.\n")
 
cat("Functions loaded.\n")
 +
 +
wikidata <- '5/54/Tigre-data.csv'
 +
q <- c(0,1,2,999)
 +
 +
library(OpasnetBaseUtils)
 +
library(xtable)
 +
data <- opasnet.csv(wikidata, wiki = "opasnet_en", sep = ",")
 +
data <- data[data$Species != 1, ]
 +
 +
species <- data$Species
 +
amount <- data$Individuals
 +
transect <- data$Transect
 +
 +
 +
out <- diversity(amount, species, transect, q)
 +
print(xtable(out), type = 'html')
  
 
</rcode>
 
</rcode>
Line 119: Line 135:
 
<rcode include="page:OpasnetBaseUtils|name:generic|page:Diversity_index|name:answer" variables="
 
<rcode include="page:OpasnetBaseUtils|name:generic|page:Diversity_index|name:answer" variables="
 
name:wikidata|description:Select your data|type:selection|options:'5/54/Tigre-data.csv';Tigre|default:'5/54/Tigre-data.csv'|
 
name:wikidata|description:Select your data|type:selection|options:'5/54/Tigre-data.csv';Tigre|default:'5/54/Tigre-data.csv'|
name:wikiq|description:Which q values you want to calculate.|type:checkbox|options:0;0;1;1;2;2;3;3;999;∞|default:0;1;2;999
+
name:q|description:Which q values you want to calculate.|type:checkbox|options:0;0;1;1;2;2;3;3;999;∞|default:0;1;2;999
 
">
 
">
 
library(OpasnetBaseUtils)
 
library(OpasnetBaseUtils)
Line 130: Line 146:
 
transect <- data$Transect
 
transect <- data$Transect
  
out <- diversity(amount, species, transect, wikiq)
+
out <- diversity(amount, species, transect, q)
 
print(xtable(out), type = 'html')
 
print(xtable(out), type = 'html')
  

Revision as of 21:47, 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>