forked from thegraphnetwork/epigraphhub_py
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import numpy as np | ||
import pandas as pd | ||
import scipy.stats as st | ||
|
||
|
||
def prevalence(pop_size: int, positives: int, a: float = 1, b: float = 1) -> object: | ||
""" | ||
Returns the Bayesian posterior prevalence of a disease for a point in time. | ||
It assumes number of cases follow a binomial distribution with probability described as a beta(a,b) distribution | ||
Args: | ||
pop_size: population size | ||
positives: number of positives | ||
a: prior beta parameter alpha | ||
b: prior beta parameter beta | ||
Returns: | ||
object: Returns a scipy stats frozen beta distribution that represents the posterior probability of the prevalence | ||
""" | ||
a, b = 1, 1 # prior beta parameters | ||
pa = a + positives | ||
pb = b + pop_size - positives | ||
return st.beta(pa, pb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
Tests for epistats module | ||
""" | ||
import pytest | ||
import scipy.stats as st | ||
|
||
from epigraphhub.analysis.epistats import prevalence | ||
|
||
|
||
@pytest.mark.parametrize(("a", "b"), [(1, 1), (2, 2)]) | ||
def test_prevalence(a, b): | ||
p = prevalence(1000, 300, a, b) | ||
assert isinstance(p, st._distn_infrastructure.rv_frozen) | ||
assert p.mean() == pytest.approx(0.3, 0.1) | ||
assert p.std() > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.