Skip to content

Commit

Permalink
make chao estimators robust to singletons only
Browse files Browse the repository at this point in the history
  • Loading branch information
andim committed May 21, 2024
1 parent abd1297 commit 52bb131
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pyrepseq/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def convert_to_array(array: Union[Iterable, DataFrame]) -> ndarray:
def chao1(counts):
"""Estimate richness from sampled counts."""

if counts[1] == 0:
if (len(counts)==1) or (counts[1] == 0):
return np.sum(counts) + (counts[0]* (counts[0] - 1)) / 2

return np.sum(counts) + counts[0] ** 2 / (2 * counts[1])
Expand All @@ -170,6 +170,8 @@ def var_chao1(counts):
"""Variance estimator for Chao1 richness."""

f1 = counts[0]
if (len(counts)==1) or (counts[1] == 0):
return np.inf
f2 = counts[1]
ratio = f1 / f2
return f2 * ((ratio / 4) ** 4 + ratio**3 + (ratio / 2) ** 2)
Expand Down

0 comments on commit 52bb131

Please sign in to comment.