CalibComponent#
- class CalibComponent(name, expected, extract_fn, conform, nll_fn, weight=1)[source]#
Bases:
prettyobj
A class to compare a single channel of observed data with output from a simulation. The Calibration class can use several CalibComponent objects to form an overall understanding of how will a given simulation reflects observed data.
- Parameters:
name (str) – the name of this component. Importantly, if extract_fn is None, the code will attempt to use the name, like “hiv.prevalence” to automatically extract data from the simulation.
data (df) – pandas Series containing calibration data. The index should be the time in either floating point years or datetime.
mode (str/func) – To handle misaligned timepoints between observed data and simulation output, it’s important to know if the data are incident (like new cases) or prevalent (like the number infected). If ‘prevalent’, simulation outputs will be interpolated to observed timepoints. If ‘incident’, outputs will be interpolated to cumulative incidence.
Methods
- static nll_beta(expected, actual)[source]#
For the beta-binomial negative log-likelihood, we begin with a Beta(1,1) prior and subsequently observe actual[‘x’] successes (positives) in actual[‘n’] trials (total observations). The result is a Beta(actual[‘x’]+1, actual[‘n’]-actual[‘x’]+1) posterior. We then compare this to the real data, which has expected[‘x’] successes (positives) in expected[‘n’] trials (total observations). To do so, we use a beta-binomial likelihood: p(x|n, x, a, b) = (n choose x) B(x+a, n-x+b) / B(a, b) where
x=expected[‘x’] n=expected[‘n’] a=actual[‘x’]+1 b=actual[‘n’]-actual[‘x’]+1
and B is the beta function, B(x, y) = Gamma(x)Gamma(y)/Gamma(x+y)
We compute the log of p(x|n, x, a, b), noting that gammaln is the log of the gamma function
- static nll_gamma(expected, actual)[source]#
Also called negative binomial, but parameterized differently The gamma-poisson likelihood is a Poisson likelihood with a gamma-distributed rate parameter
- static linear_interp(expected, actual)[source]#
Simply interpolate Use for prevalent data like prevalence