Diversity index: Difference between revisions
Jump to navigation
Jump to search
(→Answer) |
(→Answer) |
||
Line 24: | Line 24: | ||
true <- function(pi, q){ | true <- function(pi, q){ | ||
pi <- pi/sum(pi) | |||
qD <- rep(NA, length(q)) | qD <- rep(NA, length(q)) | ||
for(i in 1:length(q)){ | for(i in 1:length(q)){ | ||
Line 33: | Line 34: | ||
return(qD) | return(qD) | ||
} | } | ||
truelist <- function(pi){ | truelist <- function(pi){ | ||
return(true(pi, c(0, 1, 2, 999))) | return(true(pi, c(0, 1, 2, 999))) | ||
} | } | ||
truelist(c(0.2, 0.2, 0.1, 0.4, 0.1)) | |||
true2 <- function(divj, wj){ | true2 <- function(divj, wj){ | ||
Line 59: | Line 53: | ||
# diversity <- function(amount = rep(1,length(species)), species = 1:length(amount), transect = 1){ | # diversity <- function(amount = rep(1,length(species)), species = 1:length(amount), transect = 1){ | ||
pij <- as.data.frame(as.table(tapply(amount, data.frame(Transect = transect, Species = species), sum))) | pij <- as.data.frame(as.table(tapply(amount, data.frame(Transect = transect, Species = species), sum))) | ||
Line 82: | Line 71: | ||
head(out) | head(out) | ||
out <- tapply(out$pij, out$Transect, truelist) | out <- tapply(out$pij, out$Transect, truelist) | ||
# truelist WORKS NOW! | |||
head(out) | head(out) | ||
qDj <- data.frame(Zero = 1:nrow(wj), One = NA, Two = NA, Infi = NA) | qDj <- data.frame(Zero = 1:nrow(wj), One = NA, Two = NA, Infi = NA) | ||
Line 90: | Line 82: | ||
true2(qDj, wj$wj) | true2(qDj, wj$wj) | ||
out <- data.frame(Name = c("True diversity with q=0", "True diversity with q=1", | out <- data.frame(Name = c("True diversity with q=0", "True diversity with q=1", | ||
Line 104: | Line 94: | ||
print(xtable(out), type = 'html') | print(xtable(out), type = 'html') | ||
</rcode> | </rcode> |
Revision as of 12:26, 8 January 2012
[show] |
---|
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
Example to use function
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>