T7 - Calibration¶
Tutorial 2 demonstrated how to run the model and plot the outputs. But it’s entirely possible that the model outputs won’t look like the data for the country that you wish to model. The default parameter values included in HPVsim are intended as points of departure to be iteratively refined via calibration. The process of model calibration involves finding the model parameters that are the most likely explanation for the observed data. This tutorial gives an introduction to the Fit object and some recipes for optimization approaches.
Click here to open an interactive version of this notebook.
Data types supported by HPVsim¶
Data on HPV and cervical disease comes in many different formats. When using HPVsim, the goal is typically to produce population-level estimates of epidemic outputs like: - age-specific incidence of cancer or high-grade lesions in one or more years; - number of cases of cancer or high-grade lesions reported in one or more years; - HPV prevalence over time; - lifetime incidence of HPV; - the distribution of genotypes in detected cases of cancer/high-grade lesions; - sexual behavior metrics like the average age at first marriage, duration of relationships, or number of lifetime partners.
After running HPVsim, estimates all of these variables are included within the results
dictionary. To plot them alongside data, the easiest method is to use the Calibration
object.
The Calibration object¶
Calibration objects contain the following ingredients: - an hpv.Sim()
instance with details of the model configuration; - two lists of parameters to vary, one for parameters that vary by genotype and one for those that don’t; - dataframes that hold the calibration targets, which are typically added as csv files; - a list of any additional results to plot; - settings that are passed to the Optuna package[LINK], an open source hyperparameter optimization framework that automates calibration
for HPVsim.
We have included Optuna as a built-in calibration option as we have found that it works reasonably well, but it is also possible to use other methods; we will discuss this a little further down.
The example below illustrates the general idea of calibration, and can be adapted for different use cases:
[1]:
# Import HPVsim
import hpvsim as hpv
# Configure a simulation with some parameters
pars = dict(n_agents=10e3, start=1980, end=2020, dt=0.25, location='nigeria')
sim = hpv.Sim(pars)
# Specify some parameters to adjust during calibration.
# The parameters in the calib_pars dictionary don't vary by genotype,
# whereas those in the genotype_pars dictionary do. Both kinds are
# given in the order [best, lower_bound, upper_bound].
calib_pars = dict(
beta=[0.05, 0.010, 0.20],
)
genotype_pars = dict(
hpv16=dict(
sev_fn=dict(k=[0.5, 0.2, 1.0]),
dur_episomal=dict(par1=[6, 4, 12])
),
hpv18=dict(
sev_fn=dict(k=[0.5, 0.2, 1.0]),
dur_episomal=dict(par1=[6, 4, 12])
)
)
# List the datafiles that contain data that we wish to compare the model to:
datafiles=['nigeria_cancer_cases.csv',
'nigeria_cancer_types.csv']
# List extra results that we don't have data on, but wish to include in the
# calibration object so we can plot them.
results_to_plot = ['cancer_incidence', 'asr_cancer_incidence']
# Create the calibration object, run it, and plot the results
calib = hpv.Calibration(
sim,
calib_pars=calib_pars,
genotype_pars=genotype_pars,
extra_sim_result_keys=results_to_plot,
datafiles=datafiles,
total_trials=3, n_workers=1
)
calib.calibrate(die=True)
calib.plot(res_to_plot=4);
HPVsim 1.2.0 (2023-05-31) — © 2023 by IDM
Loading location-specific demographic data for "nigeria"
/home/docs/checkouts/readthedocs.org/user_builds/institute-for-disease-modeling-hpvsim/envs/v1.2.0/lib/python3.9/site-packages/sciris/sc_fileio.py:172: UserWarning: Fixing known unpickling deprecation "No module named 'pandas.core.indexes.numeric'"
obj = _unpickler(filestr, **kw, **kwargs) # Unpickle the data
Initializing sim with 10000 agents
Loading location-specific data for "nigeria"
/home/docs/checkouts/readthedocs.org/user_builds/institute-for-disease-modeling-hpvsim/envs/v1.2.0/lib/python3.9/site-packages/sciris/sc_fileio.py:172: UserWarning: Fixing known unpickling deprecation "No module named 'pandas.core.indexes.numeric'"
obj = _unpickler(filestr, **kw, **kwargs) # Unpickle the data
/home/docs/checkouts/readthedocs.org/user_builds/institute-for-disease-modeling-hpvsim/envs/v1.2.0/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
[I 2023-08-10 17:37:55,184] A new study created in RDB with name: hpvsim_calibration
Could not delete study, skipping...
'Record does not exist.'
Removed existing calibration hpvsim_calibration.db
Initializing sim (resetting people) with 10000 agents
Loading location-specific data for "nigeria"
Running 1980.0 ( 0/164) (0.00 s) ———————————————————— 1%
Running 1982.5 (10/164) (0.30 s) •——————————————————— 7%
Running 1985.0 (20/164) (0.62 s) ••—————————————————— 13%
Running 1987.5 (30/164) (0.96 s) •••————————————————— 19%
Running 1990.0 (40/164) (1.33 s) •••••——————————————— 25%
Running 1992.5 (50/164) (1.72 s) ••••••—————————————— 31%
Running 1995.0 (60/164) (2.15 s) •••••••————————————— 37%
Running 1997.5 (70/164) (2.59 s) ••••••••———————————— 43%
Running 2000.0 (80/164) (3.08 s) •••••••••——————————— 49%
Running 2002.5 (90/164) (3.61 s) •••••••••••————————— 55%
Running 2005.0 (100/164) (4.17 s) ••••••••••••———————— 62%
Running 2007.5 (110/164) (4.74 s) •••••••••••••——————— 68%
Running 2010.0 (120/164) (5.38 s) ••••••••••••••—————— 74%
Running 2012.5 (130/164) (6.06 s) •••••••••••••••————— 80%
Running 2015.0 (140/164) (6.79 s) •••••••••••••••••——— 86%
Running 2017.5 (150/164) (7.52 s) ••••••••••••••••••—— 92%
Running 2020.0 (160/164) (8.33 s) •••••••••••••••••••— 98%
[I 2023-08-10 17:38:04,281] Trial 0 finished with value: 772.3504344741068 and parameters: {'hpv16_sev_fn_k': 0.9650243774222094, 'hpv16_dur_episomal_par1': 9.261222357071876, 'hpv18_sev_fn_k': 0.9783932376280178, 'hpv18_dur_episomal_par1': 6.677388286076273, 'beta': 0.14774049889110344}. Best is trial 0 with value: 772.3504344741068.
Simulation summary:
49,805,441 infections
0 dysplasias
0 pre-cins
17,938,291 cin1s
7,469,379 cin2s
6,707,286 cin3s
81,543,301 cins
1,285,001 cancers
0 cancer detections
902,158 cancer deaths
0 detected cancer deaths
42,162,956 reinfections
0 reactivations
934,452,032 number susceptible
87,443,968 number infectious
8,595,640 number with inactive infection
237,289,104 number with no cellular changes
101,780,808 number with episomal infection
718 number with transformation
8,595,640 number with cancer
96,039,600 number infected
110,376,456 number with abnormal cells
0 number with latent infection
9,469,067 number with precin
10,511,289 number with cin1
13,923,113 number with cin2
56,944,416 number with cin3
72,082,848 number with detectable dysplasia
0 number with detected cancer
0 number screened
0 number treated for precancerous lesions
0 number treated for cancer
0 number vaccinated
0 number given therapeutic vaccine
1.78 hpv incidence (/100)
0 cin1 incidence (/100,000)
0 cin2 incidence (/100,000)
0 cin3 incidence (/100,000)
0 dysplasia incidence (/100,000)
1,020 cancer incidence (/100,000)
7,448,549 births
2,425,627 other deaths
-466,881 migration
1,172 age-adjusted cervical cancer incidence (/100,000)
0 age-adjusted cervical cancer mortality
0 newly vaccinated
0 cumulative number vaccinated
0 new doses
0 cumulative doses
0 new therapeutic vaccine doses
0 newly received therapeutic vaccine
0 cumulative therapeutic vaccine doses
0 total received therapeutic vaccine
0 new screens
0 newly screened
0 new cin treatments
0 newly treated for cins
0 new cancer treatments
0 newly treated for cancer
0 cumulative screens
0 cumulative number screened
0 cumulative cin treatments
0 cumulative number treated for cins
0 cumulative cancer treatments
0 cumulative number treated for cancer
0 detected cancer incidence (/100,000)
670 cancer mortality
237,289,104 number alive
0 crude death rate
0 crude birth rate
12.28 hpv prevalence (/100)
0 pre-cin prevalence (/100,000)
0 cin1 prevalence (/100,000)
0 cin2 prevalence (/100,000)
0 cin3 prevalence (/100,000)
Initializing sim (resetting people) with 10000 agents
Loading location-specific data for "nigeria"
Running 1980.0 ( 0/164) (0.00 s) ———————————————————— 1%
Running 1982.5 (10/164) (0.30 s) •——————————————————— 7%
Running 1985.0 (20/164) (0.63 s) ••—————————————————— 13%
Running 1987.5 (30/164) (0.97 s) •••————————————————— 19%
Running 1990.0 (40/164) (1.35 s) •••••——————————————— 25%
Running 1992.5 (50/164) (1.73 s) ••••••—————————————— 31%
Running 1995.0 (60/164) (2.16 s) •••••••————————————— 37%
Running 1997.5 (70/164) (2.61 s) ••••••••———————————— 43%
Running 2000.0 (80/164) (3.10 s) •••••••••——————————— 49%
Running 2002.5 (90/164) (3.59 s) •••••••••••————————— 55%
Running 2005.0 (100/164) (4.16 s) ••••••••••••———————— 62%
Running 2007.5 (110/164) (4.71 s) •••••••••••••——————— 68%
Running 2010.0 (120/164) (5.32 s) ••••••••••••••—————— 74%
Running 2012.5 (130/164) (5.93 s) •••••••••••••••————— 80%
Running 2015.0 (140/164) (6.63 s) •••••••••••••••••——— 86%
Running 2017.5 (150/164) (7.32 s) ••••••••••••••••••—— 92%
Running 2020.0 (160/164) (8.06 s) •••••••••••••••••••— 98%
[I 2023-08-10 17:38:12,788] Trial 1 finished with value: 550.9294419894335 and parameters: {'hpv16_sev_fn_k': 0.8390450386773418, 'hpv16_dur_episomal_par1': 6.646888383669061, 'hpv18_sev_fn_k': 0.40755165717072095, 'hpv18_dur_episomal_par1': 8.811830770492158, 'beta': 0.19612220344086148}. Best is trial 1 with value: 550.9294419894335.
Simulation summary:
52,829,394 infections
0 dysplasias
0 pre-cins
16,727,273 cin1s
7,299,147 cin2s
4,974,079 cin3s
73,206,237 cins
919,397 cancers
0 cancer detections
681,646 cancer deaths
0 detected cancer deaths
44,188,503 reinfections
0 reactivations
841,743,808 number susceptible
80,964,368 number infectious
6,443,678 number with inactive infection
230,108,464 number with no cellular changes
95,897,384 number with episomal infection
1,437 number with transformation
6,443,678 number with cancer
87,408,048 number infected
102,341,064 number with abnormal cells
0 number with latent infection
9,917,992 number with precin
17,270,292 number with cin1
18,563,912 number with cin2
40,384,500 number with cin3
63,660,320 number with detectable dysplasia
0 number with detected cancer
0 number screened
0 number treated for precancerous lesions
0 number treated for cancer
0 number vaccinated
0 number given therapeutic vaccine
2.09 hpv incidence (/100)
0 cin1 incidence (/100,000)
0 cin2 incidence (/100,000)
0 cin3 incidence (/100,000)
0 dysplasia incidence (/100,000)
754 cancer incidence (/100,000)
7,434,184 births
2,742,388 other deaths
-122,107 migration
911 age-adjusted cervical cancer incidence (/100,000)
0 age-adjusted cervical cancer mortality
0 newly vaccinated
0 cumulative number vaccinated
0 new doses
0 cumulative doses
0 new therapeutic vaccine doses
0 newly received therapeutic vaccine
0 cumulative therapeutic vaccine doses
0 total received therapeutic vaccine
0 new screens
0 newly screened
0 new cin treatments
0 newly treated for cins
0 new cancer treatments
0 newly treated for cancer
0 cumulative screens
0 cumulative number screened
0 cumulative cin treatments
0 cumulative number treated for cins
0 cumulative cancer treatments
0 cumulative number treated for cancer
0 detected cancer incidence (/100,000)
531 cancer mortality
230,108,464 number alive
0 crude death rate
0 crude birth rate
11.73 hpv prevalence (/100)
0 pre-cin prevalence (/100,000)
0 cin1 prevalence (/100,000)
0 cin2 prevalence (/100,000)
0 cin3 prevalence (/100,000)
Initializing sim (resetting people) with 10000 agents
Loading location-specific data for "nigeria"
Running 1980.0 ( 0/164) (0.00 s) ———————————————————— 1%
Running 1982.5 (10/164) (0.30 s) •——————————————————— 7%
Running 1985.0 (20/164) (0.62 s) ••—————————————————— 13%
Running 1987.5 (30/164) (0.95 s) •••————————————————— 19%
Running 1990.0 (40/164) (1.30 s) •••••——————————————— 25%
Running 1992.5 (50/164) (1.68 s) ••••••—————————————— 31%
Running 1995.0 (60/164) (2.08 s) •••••••————————————— 37%
Running 1997.5 (70/164) (2.51 s) ••••••••———————————— 43%
Running 2000.0 (80/164) (2.96 s) •••••••••——————————— 49%
Running 2002.5 (90/164) (3.42 s) •••••••••••————————— 55%
Running 2005.0 (100/164) (3.93 s) ••••••••••••———————— 62%
Running 2007.5 (110/164) (4.46 s) •••••••••••••——————— 68%
Running 2010.0 (120/164) (5.02 s) ••••••••••••••—————— 74%
Running 2012.5 (130/164) (5.58 s) •••••••••••••••————— 80%
Running 2015.0 (140/164) (6.19 s) •••••••••••••••••——— 86%
Running 2017.5 (150/164) (6.84 s) ••••••••••••••••••—— 92%
Running 2020.0 (160/164) (7.52 s) •••••••••••••••••••— 98%
[I 2023-08-10 17:38:20,724] Trial 2 finished with value: 382.53227858284134 and parameters: {'hpv16_sev_fn_k': 0.8817002438189334, 'hpv16_dur_episomal_par1': 5.444310949580579, 'hpv18_sev_fn_k': 0.39672639768986584, 'hpv18_dur_episomal_par1': 7.777890619945825, 'beta': 0.1862962234320804}. Best is trial 2 with value: 382.53227858284134.
Simulation summary:
49,173,358 infections
0 dysplasias
0 pre-cins
16,309,953 cin1s
6,223,166 cin2s
4,170,326 cin3s
66,625,371 cins
641,423 cancers
0 cancer detections
539,427 cancer deaths
0 detected cancer deaths
40,496,552 reinfections
0 reactivations
776,452,224 number susceptible
70,614,688 number infectious
4,742,076 number with inactive infection
223,961,472 number with no cellular changes
87,903,664 number with episomal infection
1,437 number with transformation
4,742,076 number with cancer
75,356,768 number infected
92,645,736 number with abnormal cells
0 number with latent infection
9,448,237 number with precin
15,758,314 number with cin1
15,876,112 number with cin2
30,937,696 number with cin3
52,778,396 number with detectable dysplasia
0 number with detected cancer
0 number screened
0 number treated for precancerous lesions
0 number treated for cancer
0 number vaccinated
0 number given therapeutic vaccine
2.11 hpv incidence (/100)
0 cin1 incidence (/100,000)
0 cin2 incidence (/100,000)
0 cin3 incidence (/100,000)
0 dysplasia incidence (/100,000)
552 cancer incidence (/100,000)
7,441,367 births
2,332,251 other deaths
-380,688 migration
657 age-adjusted cervical cancer incidence (/100,000)
0 age-adjusted cervical cancer mortality
0 newly vaccinated
0 cumulative number vaccinated
0 new doses
0 cumulative doses
0 new therapeutic vaccine doses
0 newly received therapeutic vaccine
0 cumulative therapeutic vaccine doses
0 total received therapeutic vaccine
0 new screens
0 newly screened
0 new cin treatments
0 newly treated for cins
0 new cancer treatments
0 newly treated for cancer
0 cumulative screens
0 cumulative number screened
0 cumulative cin treatments
0 cumulative number treated for cins
0 cumulative cancer treatments
0 cumulative number treated for cancer
0 detected cancer incidence (/100,000)
446 cancer mortality
223,961,472 number alive
0 crude death rate
0 crude birth rate
10.51 hpv prevalence (/100)
0 pre-cin prevalence (/100,000)
0 cin1 prevalence (/100,000)
0 cin2 prevalence (/100,000)
0 cin3 prevalence (/100,000)
Loading saved results...
Removed temporary file tmp_calibration_00000.obj
Loaded trial 0
Removed temporary file tmp_calibration_00001.obj
Loaded trial 1
Removed temporary file tmp_calibration_00002.obj
Loaded trial 2
Making results structure...
Processed 3 trials; 0 failed
Deleted study hpvsim_calibration in sqlite:///hpvsim_calibration.db
Removed existing calibration hpvsim_calibration.db
This isn’t a great fit yet! In general, it will probably be necessary to run many more trials that the 3 we ran here. Moreover, careful consideration should be given to the parameters that you want to adjust during calibration. In HPVsim we have taken the approach that any parameter can be adjusted. As we learn more about which parameters make most sense to calibrate, we will add details here. We would also enourage users to share their experiences with calibration and parameter searches.
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]: