Incidence Calibration¶
This file is a helper file for the occurrence_calibration_data.py
file. It contains the
functions that are used to calibrate the asthma incidence equation.
leap.data_generation.incidence_calibration module¶
-
leap.data_generation.incidence_calibration.compute_contingency_tables(risk_factor_prob: list[float], odds_ratio_target: list[float], asthma_prev_calibrated: list[float], sample_size: float =
10000000000.0
) dict[str | int, leap.data_generation.utils.ContingencyTable] [source]¶ Compute the contingency tables for the risk factors and asthma prevalence.
This function computes the proportions of the population at different levels of family history and antibiotic exposure. The proportions are calculated based on the risk factors and the calibrated asthma prevalence. The function uses the
metafor
package to convert odds ratios into proportions.See [1] for more details.
- Parameters:¶
- risk_factor_prob: list[float]¶
A vector of the probabilities of the risk factor levels.
- odds_ratio_target: list[float]¶
A vector of odds ratios for the risk factors.
- asthma_prev_calibrated: list[float]¶
A vector of the calibrated asthma prevalence for each risk factor combination indexed by
λ
.- sample_size: float =
10000000000.0
¶ The total population size to use for the calculations.
- Returns:¶
A dictionary of
ContingencyTables
representing the proportions of the population for different risk factor levels / combinations. For example, if we have the following risk factors:family history:
{0, 1}
antibiotic exposure:
{0, 1, 2, 3}
then we have
2 * 4 = 8
combinations. Each combination is called arisk factor level
, and is indexed byλ
(this corresponds to the index in the risk_set table). The first combination,λ = 0
is a special case; this is where there are no risk factors.Each dictionary entry contains a
ContingencyTable
, with the following entries:a
: proportion of population labelled as asthma with risk factorsλ
b
: proportion of population labelled as no asthma with risk factorsλ
c
: proportion of population labelled as asthma with no risk factorsd
: proportion of population labelled as no asthma with no risk factors
-
leap.data_generation.incidence_calibration.compute_odds_ratio(contingency_table_past: leap.data_generation.utils.ContingencyTable, asthma_incidence_0: float, asthma_incidence_λ: float, ra_target: float =
1.0
) float [source]¶ Compute the odds ratio for risk factor combination
λ
.- Parameters:¶
- contingency_table_past: leap.data_generation.utils.ContingencyTable¶
A
ContingencyTable
object representing the proportions of the population for different risk factor levels in the past.- asthma_incidence_0: float¶
The calibrated asthma incidence for the risk factor combination with no risk factors (
λ = 0
) in the current year.- asthma_incidence_λ: float¶
The calibrated asthma incidence for the risk factor combination
λ
in the current year.- ra_target: float =
1.0
¶ The probability that an individual previously diagnosed with asthma will maintain their asthma diagnosis after reassessment in the current year. Range:
[0, 1]
.- mis_dx
A numeric value representing the misdiagnosis rate.
- dx
A numeric value representing the diagnosis rate.
- Returns:¶
The odds ratio for risk factor combination
λ
in the current year.
-
leap.data_generation.incidence_calibration.compute_odds_ratio_difference(risk_factor_prob_past: list[float] | numpy.ndarray, odds_ratio_target_past: list[float] | numpy.ndarray, asthma_prev_calibrated_past: list[float] | numpy.ndarray, asthma_inc_calibrated: list[float] | numpy.ndarray, odds_ratio_target: list[float] | numpy.ndarray, ra_target: float =
1.0
) float [source]¶ Compute difference in odds ratios between the target and the calibrated asthma incidence.
- Parameters:¶
- risk_factor_prob_past: list[float] | numpy.ndarray¶
A vector of the probabilities of the risk factor levels in the past.
- odds_ratio_target_past: list[float] | numpy.ndarray¶
A vector of odds ratios for the risk factors in the past.
- asthma_prev_calibrated_past: list[float] | numpy.ndarray¶
A vector of the calibrated asthma prevalence for each risk factor combination indexed by
λ
in the past.- asthma_inc_calibrated: list[float] | numpy.ndarray¶
A vector of the calibrated asthma incidence for each risk factor combination indexed by
λ
in the current year.- odds_ratio_target: list[float] | numpy.ndarray¶
A vector of odds ratios for the risk factors.
- ra_target: float =
1.0
¶ The probability that an individual previously diagnosed with asthma will maintain their asthma diagnosis after reassessment in the current year. Range:
[0, 1]
.- mis_dx
A numeric value representing the misdiagnosis rate.
- dx
A numeric value representing the diagnosis rate.
- Returns:¶
The sum of the difference in log odds ratios between the target and calibrated asthma incidence for each risk factor level.
- leap.data_generation.incidence_calibration.inc_correction_calculator(asthma_inc_target: float, asthma_prev_target_past: float, odds_ratio_target_past: numpy.ndarray, risk_factor_prob_past: numpy.ndarray, risk_set: pandas.core.frame.DataFrame) tuple[float, numpy.ndarray, numpy.ndarray] [source]¶
Calculate the correction for asthma incidence based on risk factors.
- Parameters:¶
- asthma_inc_target: float¶
The target incidence of asthma.
- asthma_prev_target_past: float¶
The target prevalence of asthma in the previous year.
- odds_ratio_target_past: numpy.ndarray¶
A vector of odds ratios for the risk factors in the previous year.
- risk_factor_prob_past: numpy.ndarray¶
A vector of the prevalence of the risk factors in the previous year.
- risk_set: pandas.core.frame.DataFrame¶
A data frame containing the risk factors and their corresponding odds ratios.
- Returns:¶
asthma_inc_correction
: the calibrated asthma incidence correction.asthma_inc_calibrated
: the calibrated asthma incidence.asthma_prev_calibrated_past
: the calibrated asthma prevalence for the previous year.
- Return type:¶
A tuple containing three entries