synthpops.plot_tools module

This module plots the age-specific contact matrix in different settings.

synthpops.plot_tools.calculate_contact_matrix(population, density_or_frequency='density', setting_code='H')

Calculate the symmetric age-specific contact matrix from the connections for all people in the population. density_or_frequency sets the type of contact matrix calculated.

When density_or_frequency is set to ‘frequency’ each person is assumed to have a fixed amount of contact with others they are connected to in a setting so each person will split their contact amount equally among their connections. This means that if a person has links to 4 other individuals then 1/4 will be added to the matrix element matrix[age_i][age_j] for each link, where age_i is the age of the individual and age_j is the age of the contact. This follows the mass action principle such that increased density or number of people a person is in contact with leads to decreased per-link or connection contact rate.

When density_or_frequency is set to ‘density’ the amount of contact each person has with others scales with the number of people they are connected to. This means that a person with connections to 4 individuals has a higher total contact rate than a person with connection to 3 individuals. For this definition if a person has links to 4 other individuals then 1 will be added to the matrix element matrix[age_i][age_j] for each contact. This follows the ‘pseudo’mass action principle such that the per-link or connection contact rate is constant.

Parameters
  • population (dict) – A dictionary of a population with attributes.

  • density_or_frequency (str) – option for the type of contact matrix calculated.

  • setting_code (str) – name of the physial contact setting: H for households, S for schools, W for workplaces, C for community or other, and ‘lTCF’ for long term care facilities

Returns

Symmetric age specific contact matrix.

synthpops.plot_tools.plot_contact_matrix(matrix, age_count, aggregate_age_count, age_brackets, age_by_brackets_dic, setting_code='H', density_or_frequency='density', logcolors_flag=False, aggregate_flag=True, cmap='cmr.freeze_r', fontsize=16, rotation=50, title_prefix=None)

Plots the age specific contact matrix where the matrix element matrix_ij is the contact rate or frequency for the average individual in age group i with all of their contacts in age group j. Can either be density or frequency definition, as well as a single year age contact matrix or a contact matrix for aggregated age brackets.

Parameters
  • matrix (np.array) – symmetric contact matrix, element ij is the contact for an average individual in age group i with all of their contacts in age group j

  • age_count (dict) – dictionary with the count of individuals in the population for each age

  • aggregate_age_count (dict) – dictionary with the count of individuals in the population in each age bracket

  • age_brackets (dict) – dictionary mapping age bracket keys to age bracket range

  • age_by_brackets_dic (dict) – dictionary mapping age to the age bracket range it falls in

  • setting_code (str) – name of the physial contact setting: H for households, S for schools, W for workplaces, C for community or other

  • density_or_frequency (str) – If ‘density’, then each contact counts for 1/(group size -1) of a person’s contact in a group, elif ‘frequency’ then count each contact. This means that more people in a group leads to higher rates of contact/exposure.

  • logcolors_flag (bool) – If True, plot heatmap in logscale

  • aggregate_flag (book) – If True, plot the contact matrix for aggregate age brackets, else single year age contact matrix.

  • cmap (str or matplotlib colormap) – colormap

  • fontsize (int) – base font size

  • rotation (int) – rotation for x axis labels

  • title_prefix (str) – optional title prefix for the figure

Returns

A fig object.

Note

For the long term care facilities you may want the age count and the aggregate age count to only consider those who live or work in long term care facilities because otherwise this will be the whole population wide average mixing in that setting