method_switching#
- class method_switching(year=None, from_methods=None, to_method=None, switch_prob=None, age_groups=None, postpartum=None, annual=False, verbose=False, **kwargs)[source]#
Bases:
InterventionIntervention that causes women to switch from specific contraceptive methods to a target method.
This intervention modifies the switching probabilities in the contraception module’s switching matrix to induce transitions from one or more source methods to a destination method.
- Parameters:
year (float) – Year when switching intervention begins
from_methods (str/list) – Method name(s) or index(es) to switch from
to_method (str/int) – Method name or index to switch to
switch_prob (float/dict) – Probability of switching. Can be: - float: Same probability for all source methods - dict: {method_name: probability} for different rates per source
age_groups (list) – Age group names to apply switching. If None, applies to all age groups. Use None for all, or list like [‘<18’, ‘18-20’, ‘20-25’, ‘25-35’, ‘>35’]
postpartum (int/list) – Postpartum states to modify (0, 1, 6). If None, modifies all states.
annual (bool) – If True, switch_prob is annual and converted to per-timestep
verbose (bool) – Print detailed information
Example:
# 10% of injectable users switch to DMPA-SC starting in 2025 intv1 = fp.method_switching( year=2025, from_methods='inj', to_method='dmpasc', switch_prob=0.10, annual=False ) # Different rates for different methods intv2 = fp.method_switching( year=2030, from_methods=['dmpasc3', 'withdrawal', 'other_trad'], to_method='dmpasc6', switch_prob={'dmpasc3': 0.26, 'withdrawal': 0.20, 'other_trad': 0.20}, annual=False )
Attributes
auto_state_listList of "automatic" states with boolean type (ss.BoolState) that were added via define_states()
dtGet the current module timestep
has_productCheck if the intervention has a product
nowShortcut to self.t.now()
state_dictReturn a flat dictionary (objdict) of all states
state_listReturn a flat list of all states (ss.Arr objects)
tiGet the current module timestep
timevecShortcut to self.t.timevec
Methods