synthpops.ltcfs module

Modeling Seattle Metro Long Term Care Facilities

generate_ltcfs(n, with_facilities, datadir, country_location, state_location, location, use_default, smooth_ages, window_length)[source]

Generate residents living in long term care facilities and their ages.

Parameters:
  • n (int) – The number of people to create.
  • with_facilities (bool) – If True, create long term care facilities, currently only available for locations in the US.
  • datadir (string) – The file path to the data directory.
  • country_location (string) – name of the country the location is in
  • state_location (string) – name of the state the location is in
  • location – name of the location
  • use_default (bool) – If True, try to first use the other parameters to find data specific to the location under study; otherwise, return default data drawing from default_location, default_state, default_country.
  • smooth_ages (bool) – If True, use smoothed out age distribution.
  • window_length (int) – length of window over which to average or smooth out age distribution
Returns:

The number of people expected to live outside long term care facilities, age_brackets, age_by_brackets dictionary, age distribution adjusted for long term care facility residents already sampled, and facilities with people living in them.

assign_facility_staff(datadir, location, state_location, country_location, ltcf_staff_age_min, ltcf_staff_age_max, facilities, workers_by_age_to_assign_count, potential_worker_uids_by_age, potential_worker_uids, facilities_by_uids, age_by_uid, use_default=False)[source]

Assign Long Term Care Facility staff to the generated facilities with residents.

Parameters:
  • datadir (string) – The file path to the data directory.
  • location – name of the location
  • state_location (string) – name of the state the location is in
  • country_location (string) – name of the country the location is in
  • ltcf_staff_age_min (int) – Long term care facility staff minimum age.
  • ltcf_staff_age_max (int) – Long term care facility staff maximum age.
  • facilities (list) – A list of lists where each sublist is a facility with the resident ages
  • workers_by_age_to_assign_count (dict) – A dictionary mapping age to the count of employed individuals of that age.
  • potential_worker_uids (dict) – dictionary of potential workers mapping their id to their age
  • facilities – A list of lists where each sublist is a facility with the resident IDs
  • age_by_uid (dict) – dictionary mapping id to age for all individuals in the population
  • use_default (bool) – If True, try to first use the other parameters to find data specific to the location under study; otherwise, return default data drawing from default_location, default_state, default_country.
Returns:

A list of lists with the facility staff IDs for each facility.

Return type:

list

remove_ltcf_residents_from_potential_workers(facilities_by_uids, potential_worker_uids, potential_worker_uids_by_age, workers_by_age_to_assign_count, age_by_uid)[source]

Remove facilities residents from potential workers

ltcf_resample_age(exp_age_distr, a)[source]

Resampling younger ages to better match data

Parameters:
  • exp_age_distr (dict) – age distribution
  • age (int) – age as an integer
Returns:

Resampled age as an integer.

Notes

This is not always necessary, but is mostly used to smooth out sharp edges in the age distribution when spsamp.resample_age() produces too many of one year and under produces the surrounding ages. For example, new borns (0 years old) may be over produced, and 1 year olds under produced, so this function can be customized to correct for that. It is currently customized to model well the age distribution for Seattle, Washington.

generate_larger_households_method_1(size, hh_sizes, hha_by_size_counts, hha_brackets, cm_age_brackets, cm_age_by_brackets, contact_matrices, single_year_age_distr)[source]

Generate ages of those living in households of greater than one individual. Reference individual is sampled conditional on the household size. All other household members have their ages sampled conditional on the reference person’s age and the age mixing contact matrix in households for the population under study.

Parameters:
  • size (int) – The household size.
  • hh_sizes (array) – The count of household size s at index s-1.
  • hha_by_size_counts (matrix) – A matrix in which each row contains the age distribution of the reference person for household size s at index s-1.
  • hha_brackets (dict) – The age brackets for the heads of household.
  • cm_age_brackets (dict) – The dictionary mapping age bracket keys to age bracket range matching the household contact matrix.
  • cm_age_by_brackets (dict) – The dictionary mapping age to the age bracket range it falls within matching the household contact matrix.
  • contact_matrices (dict) – A dictionary of the age-specific contact matrix for different physical contact settings.
  • single_year_age_distr (dict) – The age distribution.
Returns:

An array of households for size size where each household is a row and the values in the row are the ages of the household members. The first age in the row is the age of the reference individual.

generate_all_households_method_1(N, hh_sizes, hha_by_size_counts, hha_brackets, cm_age_brackets, cm_age_by_brackets, contact_matrices, single_year_age_distr)[source]

Generate the ages of those living in households together. First create households of people living alone, then larger households. For households larger than 1, a reference individual’s age is sampled conditional on the household size, while all other household members have their ages sampled conditional on the reference person’s age and the age mixing contact matrix in households for the population under study.

Parameters:
  • N (int) – The number of people in the population.
  • hh_sizes (array) – The count of household size s at index s-1.
  • hha_by_size_counts (matrix) – A matrix in which each row contains the age distribution of the reference person for household size s at index s-1.
  • hha_brackets (dict) – The age brackets for the heads of household.
  • cm_age_brackets (dict) – The dictionary mapping age bracket keys to age bracket range matching the household contact matrix.
  • cm_age_by_brackets (dict) – The dictionary mapping age to the age bracket range it falls within matching the household contact matrix.
  • contact_matrices (dict) – The dictionary of the age-specific contact matrix for different physical contact settings.
  • single_year_age_distr (dict) – The age distribution.
Returns:

An array of all households where each household is a row and the values in the row are the ages of the household members. The first age in the row is the age of the reference individual. Households are randomly shuffled by size.

Note

This method is not guaranteed to model the population age distribution well automatically. The method called inside, generate_larger_households_method_1 uses the method ltcf_resample_age to fit Seattle, Washington populations with long term care facilities generated. For a method that matches the age distribution well for populations in general, please use generate_all_households_methods_2.

generate_all_households_method_2(n_nonltcf, hh_sizes, hha_by_size, hha_brackets, cm_age_brackets, cm_age_by_brackets, contact_matrices, ltcf_adjusted_age_distr)[source]

Generate the ages of those living in households together. First create households of people living alone, then larger households. For households larger than 1, a reference individual’s age is sampled conditional on the household size, while all other household members have their ages sampled conditional on the reference person’s age and the age mixing contact matrix in households for the population under study. Fix the count of ages in the population before placing individuals in households so that the age distribution of the generated population is fixed to closely match the age distribution from data on the population.

Parameters:
  • n_nonltcf (int) – The number of people in the population not living in long term care facilities.
  • hh_sizes (array) – The count of household size s at index s-1.
  • hha_by_size_counts (matrix) – A matrix in which each row contains the age distribution of the reference person for household size s at index s-1.
  • hha_brackets (dict) – The age brackets for the heads of household.
  • cm_age_brackets (dict) – The dictionary mapping age bracket keys to age bracket range matching the household contact matrix.
  • cm_age_by_brackets (dict) – The dictionary mapping age to the age bracket range it falls within matching the household contact matrix.
  • contact_matrices (dict) – The dictionary of the age-specific contact matrix for different physical contact settings.
  • ltcf_adjusted_age_distr (dict) – The age distribution.
Returns:

An array of all households where each household is a row and the values in the row are the ages of the household members. The first age in the row is the age of the reference individual. Households are randomly shuffled by size.

get_ltcf_sizes(popdict, keys_to_exclude=[])[source]

Get long term care facility sizes, including both residents and staff.

Parameters:
  • popdict (dict) – population dictionary
  • keys_to_exclude (list) – possible keys to exclude for roles in long term care facilities. See notes.
Returns:

Dictionary of the size for each long term care facility generated.

Return type:

dict

Notes

keys_to_exclude is an empty list by default, but can contain the different long term care facility roles: ‘ltcf_res’ for residents and ‘ltcf_staff’ for staff. If either role is included in the parameter keys_to_exclude, then individuals with that value equal to 1 will not be counted.

class LongTermCareFacility(ltcfid=None, resident_uids=array([], dtype=int64), staff_uids=array([], dtype=int64), **kwargs)[source]

Bases: synthpops.base.LayerGroup

A class for individual long term care facilities and methods to operate on each.

Parameters:kwargs (dict) – data dictionary of the long term care facility

Class constructor for empty long term care facility (ltcf).

Parameters:
  • **ltcfid (int) – ltcf id
  • **resident_uids (np.array) – ids of ltcf members
  • **staff_uids (np.array) – ages of ltcf members
validate()[source]

Check that information supplied to make a long term care facility is valid and update to the correct type if necessary.

member_uids

residents and staff.

Returns:ltcf member ids
Return type:np.ndarray
Type:Return ids of all ltcf members
member_ages(age_by_uid)[source]

Return ages of all ltcf members: residents and staff.

Returns:ltcf member ages
Return type:np.ndarray
resident_ages(age_by_uid)[source]
staff_ages(age_by_uid)[source]
get_ltcf(pop, ltcfid)[source]

Return ltcf with id: ltcfid.

Parameters:
  • pop (sp.Pop) – population
  • ltcfid (int) – ltcf id number
Returns:

A populated ltcf.

Return type:

sp.LongTermCareFacility

add_ltcf(pop, ltcf)[source]

Add a ltcf to the list of ltcfs.

Parameters:
  • pop (sp.Pop) – population
  • ltcf (sp.LongTermCareFacility) – ltcf with at minimum the ltcfid, resident_uids and staff_uids.
initialize_empty_ltcfs(pop, n_ltcfs=None)[source]

Array of empty ltcfs.

Parameters:
  • pop (sp.Pop) – population
  • n_ltcfs (int) – the number of ltcfs to initialize
populate_ltcfs(pop, resident_lists, staff_lists)[source]

Populate all of the ltcfs. Store each ltcf at the index corresponding to it’s ltcfid.

Parameters:
  • pop (sp.Pop) – population
  • residents_list (list) – list of lists where each sublist represents a ltcf and contains the ids of the residents
  • staff_lists (list) – list of lists where each sublist represents a ltcf and contains the ids of the staff