Difference between revisions of "Diversity index"

From Testiwiki
Jump to: navigation, search
(Answer: beta diversity added)
(Answer)
Line 12: Line 12:
 
'''Actual function ''diversity'''''
 
'''Actual function ''diversity'''''
  
<rcode name="answer">
+
<rcode name="answer" include="page:Diversity_index|name:answer|page:OpasnetBaseUtils|name:generic">
 +
q.wiki <- c(0,1,2,3)
 
####NOTE! q.wiki MUST BE DEFINED OR ALPHA DIVERSITIES WILL BE CALCULATED WRONG
 
####NOTE! q.wiki MUST BE DEFINED OR ALPHA DIVERSITIES WILL BE CALCULATED WRONG
  
####### qD calculates true diversity for abundance pi with exponent q.
+
####### qD calculates true i.e. gamma diversity for abundance pi with exponent q.
  
 
qD <- function(pi, q = q.wiki){ # q.wiki is the q given by the user.
 
qD <- function(pi, q = q.wiki){ # q.wiki is the q given by the user.
Line 76: Line 77:
 
gamma <- qD(pi, q)
 
gamma <- qD(pi, q)
 
alpha <- qDa(qDj, wj$wj, q)
 
alpha <- qDa(qDj, wj$wj, q)
 +
dim(qDj) <- c(length(q), length(qDj)/length(q))
 +
 +
return(list(gamma = gamma, alpha = alpha, tr.gammas = t(qDj)))
 +
}
 +
 +
########## diversity.table makes a data table out of the results.
 +
 +
diversity.table <- function(amount = rep(1,length(species)), species = 1:length(amount), transect = 1, q = q.wiki){
 +
 +
temp <- diversity(amount, species, transect, q)
 +
gamma <- temp[["gamma"]]
 +
alpha <- temp[["alpha"]]
 
beta. <- gamma / alpha
 
beta. <- gamma / alpha
 
beta.A <- gamma - alpha
 
beta.A <- gamma - alpha
Line 132: Line 145:
 
<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:q.wiki|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.wiki|description:Which q values you want to calculate.|type:checkbox|options:0;0;0.5;0.5;1;1;2;2;3;3;6;6;999;∞|default:0;1;2;999
 
">
 
">
 
library(OpasnetBaseUtils)
 
library(OpasnetBaseUtils)
Line 143: Line 156:
 
transect <- data$Transect
 
transect <- data$Transect
  
out <- diversity(amount = amount, species = species, transect = transect, q = q.wiki)
+
print(xtable(diversity(amount, species, transect, q.wiki)[[1]]), type = 'html')
print(xtable(out), type = 'html')
+
print(xtable(diversity(amount, species, transect, q.wiki)[[2]]), type = 'html')
 +
print(xtable(diversity(amount, species, transect, q.wiki)[[3]]), type = 'html')
 +
print(xtable(diversity.table(amount, species, transect, q.wiki)), type = 'html')
  
 
</rcode>
 
</rcode>

Revision as of 17:58, 10 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

Examples

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
0.5
1
2
3
6

+ Show code

--#: Mikä ihme tässä koodissa on vikana? q.diviä ei muka löydy mutten ymmärrä miksei. Ongelma on diversity-funktiossa, joka on määritelty sivun ensimmäisessä rcodessa. --Jouni 00:36, 9 January 2012 (EET) to Teemu Rintala

--# : Ilmeisesti funktioparametrien defaulteiksi ei saa laittaa ennalta määrittelemättömiä muuttujia. Vaihdoin defaultiksi "q = 0", "q = q.div" sijaan. --Teemu R 16:23, 9 January 2012 (EET)
# : OK. Luulin, että funktion sisältä kutsuttava funktio voi saada toisen funktion sisällä olevia oletusarvoja, muttei näin välttämättä ole. Oletusarvot ovat kuitenkin tärkeitä, koska qD-funktiota käytetään tapplyssa, jossa voi antaa vain yhden parametrin ja loput tulevat oletusarvoista. Toteutin tämän niin, että käytetään q.wikiä, joka yleensä kysytään käyttäjärajapinnassa tai muuten. --Jouni 20:15, 9 January 2012 (EET)

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>