Skip to content

Commit

Permalink
Merge pull request #47 from EcoJulia/pielou
Browse files Browse the repository at this point in the history
Add Pielou evenness
  • Loading branch information
richardreeve authored Nov 6, 2023
2 parents d58eb7b + f31ae2d commit 617f869
Show file tree
Hide file tree
Showing 25 changed files with 246 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CompatHelper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
os:
- ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.arch }}
Expand All @@ -28,7 +28,7 @@ jobs:
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "2"
version = "3"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/doc-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Doc Preview Cleanup

on:
pull_request:
types: [closed]

jobs:
doc-preview-cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v2
with:
ref: gh-pages
- name: Delete preview and history + push changes
run: |
if [ -d "previews/PR$PRNUM" ]; then
git config user.name "richardreeve"
git config user.email "[email protected]"
git rm -rf "previews/PR$PRNUM"
git commit -m "delete preview"
git branch gh-pages-new $(echo "delete history" | git commit-tree HEAD^{tree})
git push --force origin gh-pages-new:gh-pages
fi
env:
PRNUM: ${{ github.event.number }}
3 changes: 3 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ on:
- dev
tags:
- 'v*'
pull_request:
workflow_dispatch:

jobs:
build:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
version: nightly
arch: x64
- name: Build package
uses: julia-actions/julia-buildpkg@latest
uses: julia-actions/julia-buildpkg@v1
- name: Run tests
uses: julia-actions/julia-runtest@latest
uses: julia-actions/julia-runtest@v1
2 changes: 1 addition & 1 deletion .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.R-version }}
- name: Install R packages
- name: Install ape and rdiversity
if: matrix.os == 'macOS-latest'
run: |
install.packages("ape", repos="http://cran.r-project.org")
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# NEWS

- v0.5.8
- Add in Pielou diversity measures
- Add docs for PRs
- v0.5.7
- Update compat and some doc fixes
- v0.5.6
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Diversity"
uuid = "d3d5718d-52de-57ab-b67a-eca7fd6175a4"
author = ["Richard Reeve <[email protected]>"]
version = "0.5.7"
version = "0.5.8"

[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ also recently revised, and may need further improvements.

## Installation

The package is registered in the `General` registry on v1.x and so can be installed with `add`. For example on Julia v1.6:
The package is registered in the `General` registry on v1.x and so can be
installed with `add`. For example on Julia v1.8:

```julia
(@v1.8) pkg> add Diversity
Resolving package versions...
Updating `~/.julia/environments/v1.8/Project.toml`
[d3d5718d] + Diversity v0.5.7
[d3d5718d] + Diversity v0.5.8
Updating `~/.julia/environments/v1.8/Manifest.toml`
[d3d5718d] + Diversity v0.5.7
[d3d5718d] + Diversity v0.5.8

(@v1.8) pkg>
```
Expand Down
55 changes: 15 additions & 40 deletions docs/diversity.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Diversity
# Diversity package

**Diversity** is a [Julia](http://www.julialang.org) package that
provides functionality for measuring alpha, beta and gamma diversity
Expand All @@ -11,7 +11,7 @@ these are all ecological diversity measures, but this will be
expanded, possibly through interfacing to BioJulia.

This package is in beta now, but is cross-validated against our R
package [boydorr/rdiversity][rdiversity-url], which is developed
package [rdiversity][rdiversity-url], which is developed
independently, so please [raise an issue][issues-url] if you find any
problems. We now use a DataFrame as the common output format for all
of the diversity calculations to provide consistency with our R
Expand All @@ -20,26 +20,21 @@ optimised for speed at the moment due to the substantial changes that
have happened to it under the hood, and the Phylogenetics submodule is
also new, and may need further improvements.

Version 0.4, which has been recently released, has significant
breaking changes to the underlying code, whuch mean it is no longer
compatible with Julia v0.5. It is periodically working with Julia
nightly and I aim to keep it that way (though other packages need to
be updated too). Older interfaces from v0.2 have been removed in v0.4.

## Install

The package is registered in the `General` registry on v1.x and so can be installed with `add`. For example on Julia v1.6:
The package is registered in the `General` registry on v1.x and so can be installed with `add`. For example on Julia v1.8:

```julia
(@v1.6) pkg> add Diversity
(@v1.8) pkg> add Diversity
Resolving package versions...
Updating `~/.julia/environments/v1.6/Project.toml`
[d3d5718d] + Diversity v0.5.5
Updating `~/.julia/environments/v1.6/Manifest.toml`
[d3d5718d] + Diversity v0.5.5
Updating `~/.julia/environments/v1.8/Project.toml`
[d3d5718d] + Diversity v0.5.8
Updating `~/.julia/environments/v1.8/Manifest.toml`
[d3d5718d] + Diversity v0.5.8

(@v1.6) pkg>
(@v1.8) pkg>
```

## Usage

### Diversity
Expand Down Expand Up @@ -69,13 +64,14 @@ using Diversity

# Example population
pop = [1 1 0; 2 0 0; 3 1 4]
pop = pop / sum(pop)
pop ./= sum(pop)

# Create Metacommunity object
meta = Metacommunity(pop)
```

#### Calculating diversity

First we need to calculate the low-level diversity component seperately, by passing a `metacommunity` object to the appropriate function; `RawAlpha()`, `NormalisedAlpha()`, `RawBeta()`, `NormalisedBeta()`, `RawRho()`, `NormalisedRho()`, or `Gamma()`.

```julia
Expand Down Expand Up @@ -107,9 +103,11 @@ metadiv(meta, 0:2)
```

Alternatively, if computational efficiency is not an issue, a single measure of diversity may be calculated directly by calling a wrapper function:

```julia
norm_sub_alpha(meta, 0:2)
```

A complete list of these functions is shown below:

* `raw_sub_alpha()` : per-subcommunity estimate of naive-community metacommunity diversity
Expand Down Expand Up @@ -139,7 +137,7 @@ generate trees to incorporate into the diversity code:
```julia-repl
julia> using Diversity, Phylo
julia> communities = [4 1; 3 2; 1 0; 0 1] / 12;
julia> communities = [4 1; 3 2; 1 0; 0 1] ./ 12;
julia> nt = rand(Nonultrametric(4))
RootedTree with 4 tips, 7 nodes and 6 branches.
Expand All @@ -156,31 +154,8 @@ julia> raw_meta_rho(metaphylo, [1, 2])
│ 2 │ Phylogenetic Branch │ RawRho │ 2 │ types │ │ metacommunity │ │ 1.52575 │
```

[docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg
[docs-latest-url]: https://richardreeve.github.io/Diversity.jl/latest

[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg
[docs-stable-url]: https://richardreeve.github.io/Diversity.jl/stable

[travis-img]: https://travis-ci.org/richardreeve/Diversity.jl.svg?branch=master
[travis-url]: https://travis-ci.org/richardreeve/Diversity.jl?branch=master

[appveyor-img]: https://ci.appveyor.com/api/projects/status/github/richardreeve/Diversity.jl?svg=true&branch=master
[appveyor-url]: https://ci.appveyor.com/project/richardreeve/diversity-jl/branch/master

[coveralls-img]: https://img.shields.io/coveralls/richardreeve/Diversity.jl.svg
[coveralls-url]: https://coveralls.io/r/richardreeve/Diversity.jl?branch=master

[codecov-img]: https://codecov.io/gh/richardreeve/Diversity.jl/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/richardreeve/Diversity.jl

[issues-url]: https://github.com/richardreeve/Diversity.jl/issues

[pkg-0.5-img]: http://pkg.julialang.org/badges/Diversity_0.5.svg
[pkg-0.5-url]: http://pkg.julialang.org/?pkg=Diversity&ver=0.5
[pkg-0.6-img]: http://pkg.julialang.org/badges/Diversity_0.6.svg
[pkg-0.6-url]: http://pkg.julialang.org/?pkg=Diversity&ver=0.6

[paper-url]: http://arxiv.org/abs/1404.6520

[rdiversity-url]: https://github.com/boydorr/rdiversity
Expand Down
42 changes: 40 additions & 2 deletions docs/src/ecology.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Diversity.Ecology

n the **Diversity.Ecology** submodule, we replicate old ecological
In the **Diversity.Ecology** submodule, we replicate old ecological
diversity measures and generalised versions of them that relate to our
general measures of alpha, beta and gamma diversity at subcommunity
and ecosystem measures. The generalisations of the richness, Shannon
Expand All @@ -18,7 +18,7 @@ julia> using Diversity.Ecology, LinearAlgebra
julia> community = [10, 20, 20];
julia> community /= sum(community);
julia> community = community ./ sum(community); # Convert counts to proportions
julia> diversity = simpson(community)
1×7 DataFrame
Expand All @@ -27,6 +27,10 @@ julia> diversity = simpson(community)
─────┼──────────────────────────────────────────────────────────────────────────────────────
1 │ Unique Simpson types subcommunity 1 0.36
julia> ecosystem = [2 2 0; 0 2 2]';
julia> ecosystem = ecosystem ./ sum(ecosystem);
julia> jaccard(ecosystem)
1×8 DataFrame
Row │ div_type measure q type_level type_name partition_level partition_name diversity
Expand All @@ -51,6 +55,40 @@ julia> generalisedjaccard(ecosystem, [0, 1, 2], Matrix(1.0I, 3, 3))
1 │ Arbitrary Z Jaccard 0 types metacommunity 0.333333
2 │ Arbitrary Z Jaccard 1 types metacommunity 0.414214
3 │ Arbitrary Z Jaccard 2 types metacommunity 0.5
julia> community = [0.7, 0.2, 0.1];
julia> pielou(community)
1×7 DataFrame
Row │ div_type measure type_level type_name partition_level partition_name diversity
│ String String String String String String Float64
─────┼──────────────────────────────────────────────────────────────────────────────────────
1 │ Unique Pielou types subcommunity 1 0.729847
julia> communitymat = [10 20 30 20 0; #5 sites/subcommunities (columns) and 6 species (rows)
10 0 50 80 10;
60 10 90 0 0;
10 10 10 10 10;
70 70 70 70 70;
10 0 0 90 0];
julia> generalisedpielou(subcommunityDiversity, communitymat)
5×7 DataFrame
Row │ div_type measure type_level type_name partition_level partition_name diversity
│ String String String String String String Float64
─────┼─────────────────────────────────────────────────────────────────────────────────────────
1 │ Arbitrary Z Pielou types subcommunity 1 0.781115
2 │ Arbitrary Z Pielou types subcommunity 2 0.745557
3 │ Arbitrary Z Pielou types subcommunity 3 0.888073
4 │ Arbitrary Z Pielou types subcommunity 4 0.864562
5 │ Arbitrary Z Pielou types subcommunity 5 0.622366
julia> generalisedpielou(metacommunityDiversity, communitymat)
1×7 DataFrame
Row │ div_type measure type_level type_name partition_level partition_name diversity
│ String String String String String String Float64
─────┼─────────────────────────────────────────────────────────────────────────────────────────
1 │ Arbitrary Z Pielou types metacommunity 0.510146
```

```@contents
Expand Down
2 changes: 1 addition & 1 deletion docs/src/hill.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ julia> using Diversity.Hill
julia> community = [10, 20, 20, 0, 3];
julia> community /= sum(community);
julia> community ./= sum(community);
julia> diversities = hillnumber(community, [0, 1, 2])
3×7 DataFrame
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ julia> # Load the package into R
julia> # Example population
pop = [1 1 0; 2 0 0; 3 1 4];
julia> pop = pop / sum(pop);
julia> pop = pop ./ sum(pop);
julia> # Create Metacommunity object
meta = Metacommunity(pop);
Expand Down
2 changes: 1 addition & 1 deletion docs/src/jost.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ julia> using Diversity.Jost
julia> ecosystem = [2 2 0; 0 2 2]';
julia> ecosystem /= sum(ecosystem);
julia> ecosystem = ecosystem ./ sum(ecosystem);
julia> diversities = jostbeta(ecosystem, [0, 1, 2])
3×8 DataFrame
Expand Down
2 changes: 1 addition & 1 deletion docs/src/phylogenetics.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ julia> using Diversity, Phylo
julia> species = ["Dog", "Cat", "Human", "Potato"];
julia> community = [4, 1, 3, 2] / 10;
julia> community = [4, 1, 3, 2] ./ 10;
julia> nt = rand(Nonultrametric(species))
RootedTree with 4 tips, 7 nodes and 6 branches.
Expand Down
2 changes: 1 addition & 1 deletion src/Diversity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export generalisedrichness, richness
export generalisedshannon, shannon
export generalisedsimpson, simpson
export generalisedjaccard, jaccard

export generalisedpielou, pielou
end # sub-module Ecology

"""
Expand Down
9 changes: 3 additions & 6 deletions src/DiversityMeasure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,9 @@ function inddiv end
df = reduce(append!, dfs)
cols = addedoutputcols(_getmeta(measure))
if length(cols) > 0
len = length(df)
data = getaddedoutput(_getmeta(measure))
for col in keys(cols)
insert!(df, length(df) + 1, data[col], col)
insertcols!(df, ncol(df) + 1, col => data[col])
end
end
return df
Expand Down Expand Up @@ -249,10 +248,9 @@ function subdiv end
df = reduce(append!, dfs)
cols = addedoutputcols(_getmeta(measure))
if length(cols) > 0
len = length(df)
data = getaddedoutput(_getmeta(measure))
for col in keys(cols)
insert!(df, length(df) + 1, data[col], col)
insertcols!(df, ncol(df) + 1, col => data[col])
end
end
return df
Expand Down Expand Up @@ -307,10 +305,9 @@ function metadiv end
diversity=raw)
cols = addedoutputcols(_getmeta(measure))
if length(cols) > 0
len = length(df)
data = getaddedoutput(_getmeta(measure))
for col in keys(cols)
insert!(df, length(df) + 1, data[col], col)
insertcols!(df, ncol(df) + 1, col => data[col])
end
end
return df
Expand Down
Loading

2 comments on commit 617f869

@richardreeve
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/94808

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.8 -m "<description of version>" 617f869f70b4bdf19adfb0e48a1a4d2e05bd0627
git push origin v0.5.8

Please sign in to comment.