Diversity index: Difference between revisions
Jump to navigation
Jump to 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 <- c(rep(0, length(wj)), rep(1, length(wj)), rep(2, length(wj)), rep(999, length(wj))) | |||
wj <- rep(wj, times = 4) | |||
qDa <- ifelse(q == 1, exp(sum(wj * log(divj))), (sum(wj * divj^(1-q)))^1/(1 - q)) | |||
minqDj <- tapply(qDa, q, min) | |||
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", " | 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
Moderator:Jouni (see all) |
This page is a stub. You may improve it into a full page. |
Upload data
|
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>