Skip to content

API reference

Reed-Frost final size distribution

Parameters:

Name Type Description Default
k int | NDArray[integer]

number of infections beyond the initial infections

required
s int

initial number of susceptibles

required
i int

initial number of infected

required
p float

probability of infection

required

Returns:

Type Description
float | NDArray[floating]

float | NDArray[np.floating]: probability mass

Source code in src/reedfrost/__init__.py
def pmf(
    k: int | NDArray[np.integer], s: int, i: int, p: float
) -> float | NDArray[np.floating]:
    """Reed-Frost final size distribution

    Args:
        k (int | NDArray[np.integer]): number of infections beyond the initial infections
        s (int): initial number of susceptibles
        i (int): initial number of infected
        p (float): probability of infection

    Returns:
        float | NDArray[np.floating]: probability mass
    """
    if isinstance(k, (int, np.integer)):
        return _pmf_s_inf(s_inf=s - k, s=s, i=i, p=p)
    elif isinstance(k, np.ndarray):
        return np.array([_pmf_s_inf(s_inf=s - kk, s=s, i=i, p=p) for kk in k])
    else:
        raise ValueError(f"Unknown type {type(k)}")

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)