Skip to content

API reference

Probability mass function for final size of a Reed-Frost outbreak.

See Lefevre & Picard (1990) equation 3.10 for details.

Parameters:

Name Type Description Default
k int, or int array

number of total infections

required
n int

initial number susceptible

required
m int

initial number infected

1
p float

probability of "effective contact" (i.e., infection)

required

Returns:

Type Description
float | NDArray[float64]

float, or float array: pmf of the total infection distribution

Source code in src/reedfrost/__init__.py
def pmf(
    k: int | NDArray[np.int64], n: int, p: float, m: int = 1
) -> float | NDArray[np.float64]:
    """
    Probability mass function for final size of a Reed-Frost outbreak.

    See Lefevre & Picard (1990) equation 3.10 for details.

    Args:
        k (int, or int array): number of total infections
        n (int): initial number susceptible
        m (int): initial number infected
        p (float): probability of "effective contact" (i.e., infection)

    Returns:
        float, or float array: pmf of the total infection distribution
    """
    q = 1.0 - p

    return comb(n, k) * q ** ((n - k) * (m + k)) * _kgontcharoff(k, q, m)

Distribution of outbreak sizes of Reed-Frost outbreaks, conditioned on the outbreak being large.

See Barbour & Sergey 2004 (doi:10.1016/j.spa.2004.03.013) corollary 3.4

Parameters:

Name Type Description Default
k int, or int array

number of total infections

required
n int

initial number of susceptibles

required
lambda_ float

reproduction number

required
i_n int

initial number of susceptibles. Defaults to 1.

1

Returns:

Type Description
float | NDArray[float64]

float, or float array: pmf of the total infection distribution

Source code in src/reedfrost/__init__.py
def pmf_large(
    k: int | NDArray[np.int64], n: int, lambda_: float, i_n: int = 1
) -> float | NDArray[np.float64]:
    """Distribution of outbreak sizes of Reed-Frost outbreaks, conditioned on
    the outbreak being large.

    See Barbour & Sergey 2004 (doi:10.1016/j.spa.2004.03.013) corollary 3.4

    Args:
        k (int, or int array): number of total infections
        n (int): initial number of susceptibles
        lambda_ (float): reproduction number
        i_n (int, optional): initial number of susceptibles. Defaults to 1.

    Returns:
        float, or float array: pmf of the total infection distribution
    """
    if not lambda_ > 1.0:
        raise RuntimeWarning(
            f"Large outbreak distribution assumes lambda>1, instead saw {lambda_}"
        )
    theta = _theta_fun(i_n / n, lambda_)
    sigma = np.sqrt(theta * (1.0 - theta) / (1 - lambda_ * theta) ** 2)
    sd = np.sqrt(n) * sigma
    mean = n * (1.0 - theta)
    return scipy.stats.norm.pdf(x=k, loc=mean, scale=sd)