add_method#

class add_method(year=None, method=None, method_pars=None, copy_from=None, split_shares=None, verbose=True, **kwargs)[source]#

Bases: Intervention

Intervention to add a new contraceptive method to the simulation at a specified time.

Parameters:
  • year (float) – The year at which to activate the new method

  • method (Method, optional) – A Method object defining the new contraceptive method. If None, the method will be copied from the source method (specified by copy_from).

  • method_pars (dict, optional) – Dictionary of parameters to update the method attributes. If provided, these values will override corresponding attributes in the method object (whether it was provided directly or copied from source). If None, defaults to empty dict.

  • copy_from (str) – Name of the existing method to copy switching probabilities from. Also used as the source method when method=None.

  • split_shares (float, optional) – If provided, % who would have chosen the ‘copy_from’ method and now choose the new method

  • verbose (bool) – Whether to print messages when method is activated (default True)

Examples:

# Using a Method object directly
new_method = fp.Method(name='new_impl', label='New Implant', efficacy=0.999,
                       dur_use=ss.lognorm_ex(ss.years(3), ss.years(0.5)), modern=True)
intv = fp.add_method(year=2010, method=new_method, copy_from='impl')

# Copying from source method (method=None, method_pars=None)
# Creates a copy of 'impl' with name 'impl_copy'
intv = fp.add_method(year=2010, copy_from='impl')

# Copying from source and overriding properties
intv = fp.add_method(year=2010, method_pars={'name': 'new_inj', 'efficacy': 0.995},
                    copy_from='inj')

# Using method object and overriding properties with method_pars
base_method = fp.Method(name='new_method', efficacy=0.90)
intv = fp.add_method(year=2010, method=base_method,
                    method_pars={'efficacy': 0.998}, copy_from='impl')

Attributes

auto_state_list

List of "automatic" states with boolean type (ss.BoolState) that were added via define_states()

dt

Get the current module timestep

has_product

Check if the intervention has a product

now

Shortcut to self.t.now()

state_dict

Return a flat dictionary (objdict) of all states

state_list

Return a flat list of all states (ss.Arr objects)

ti

Get the current module timestep

timevec

Shortcut to self.t.timevec

Methods

init_pre(sim)[source]#

Initialize the intervention before the simulation starts. This registers the new method but does not activate it yet.

step()[source]#

At the specified year, copy switching probabilities to make the method available.

finalize()[source]#

Report summary statistics about the new method usage.