Skip to content

Commit

Permalink
Merge branch 'rates_module'
Browse files Browse the repository at this point in the history
  • Loading branch information
fccoelho committed Jan 24, 2022
2 parents afcba9b + 5a4466f commit 0ec696e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
23 changes: 23 additions & 0 deletions epigraphhub/analysis/epistats.py
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)
15 changes: 15 additions & 0 deletions tests/test_analysys/test_epistats.py
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
22 changes: 11 additions & 11 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from epigraphhub.connection import Tunnel, get_engine


def test_tunnel():
t = Tunnel()
t.open_tunnel("epigraph", "")
assert t.__repr__().startswith("Port")


@pytest.mark.parametrize(("db",), [("epigraphhub",), ("sandbox",)])
def test_engine(db):
e = get_engine(db=db)
e.connect()
#
# def test_tunnel():
# t = Tunnel()
# t.open_tunnel("epigraph", "")
# assert t.__repr__().startswith("Port")
#
#
# @pytest.mark.parametrize(("db",), [("epigraphhub",), ("sandbox",)])
# def test_engine(db):
# e = get_engine(db=db)
# e.connect()
23 changes: 0 additions & 23 deletions tests/test_example/test_hello.py

This file was deleted.

0 comments on commit 0ec696e

Please sign in to comment.