Skip to content

Commit

Permalink
Add in sub-module Diversity.Jost to provide support for Jost's divers…
Browse files Browse the repository at this point in the history
…ity measures.

jostD() is simply qD() from the main package or hillnumbers() from Diversity.Hill
jostbeta (or jostβ) is Jost's naive beta diversity, the gamma diversity of the ecosystem divided by the alpha diversity.
  • Loading branch information
richardreeve committed Sep 3, 2014
1 parent 8910f74 commit d3b6cce
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Diversity.jl
Expand Up @@ -21,6 +21,13 @@ export generalisedsimpson, simpson

end # sub-module Compatibility

module Jost

include("Jost.jl")
export jostD, jostbeta, jostβ

end # sub-module Jost

module Hill

include("Hill.jl")
Expand Down
31 changes: 31 additions & 0 deletions src/Jost.jl
@@ -0,0 +1,31 @@
using Diversity

## jostD - calculate naive diversity of order q of a population with
## given relative proportions
##
## Arguments:
## - proportions - relative proportions of different individuals /
## species in population
## - qs - single number or vector of orders of diversity measurement
jostD = qD


## jostbeta - calculate Jost's beta diversity of multiple sub-communities
## Calculates Jost's beta diversity of a series of columns representing
## independent community counts, for a series of orders, repesented as
## a vector of qs. This is just the naive gamma diversity divided by
## the naive alpha diversity
##
## Arguments:
## - proportions - population proportions
## - qs - vector of values of parameter q
##
## Returns:
## - array of diversities, first dimension representing sub-communities, and
## last representing values of q
function jostbeta{S <: FloatingPoint,
T <: Number}(proportions::Matrix{S}, qs::Union(T, Vector{T}))
(proportions, qs) ./ (proportions, qs)
end

jostβ = jostbeta
9 changes: 9 additions & 0 deletions test/runtests.jl
Expand Up @@ -124,6 +124,15 @@ using Diversity.Compatibility

@test_approx_eq simpson(communities) ᾱ(communities, 2) .^ -1
@test_approx_eq generalisedsimpson(communities, Ḡ, Z1) 1

# Checking Jost's diversities
using Diversity.Jost

@test jostD == qD
@test jostβ == jostbeta
@test_approx_eq jostbeta(communities, 1) (communities, 1)
@test_approx_eq jostbeta(allthesame, qs) ones(qs)

# Checking Hill numbers
using Diversity.Hill

Expand Down

0 comments on commit d3b6cce

Please sign in to comment.