Measurement Inputs

Measurement inputs collects all of the things from Input Components and has a bunch of helper functions to format and combine them in accordance with the model settings for dismod.

class cascade_at.inputs.measurement_inputs.MeasurementInputs(model_version_id, gbd_round_id, decomp_step_id, conn_def, country_covariate_id, csmr_cause_id, crosswalk_version_id, location_set_version_id=None, drill_location_start=None, drill_location_end=None)[source]

Bases: object

The class that constructs all of the measurement inputs. Pulls ASDR, CSMR, crosswalk versions, and country covariates, and puts them into one data frame that then formats itself for the dismod database. Performs covariate value interpolation if age and year ranges don’t match up with GBD age and year ranges.

Parameters
  • model_version_id (int) – the model version ID

  • gbd_round_id (int) – the GBD round ID

  • decomp_step_id (int) – the decomp step ID

  • csmr_cause_id ((int) cause to pull CSMR from) –

  • crosswalk_version_id (int) – crosswalk version to use

  • country_covariate_id (List[int]) – list of covariate IDs

  • conn_def (str) – connection definition from .odbc file (e.g. ‘epi’) to connect to the IHME databases

  • location_set_version_id (Optional[int]) – can be None, if it’s none, get the best location_set_version_id for estimation hierarchy of this GBD round

  • drill_location_start (Optional[int]) – which location ID to drill from as the parent

  • drill_location_end (Optional[List[int]]) – which immediate children of the drill_location_start parent to include in the drill

self.decomp_step

the decomp step in string form

Type

str

self.demographics

a demographics object that specifies the age group, sex, location, and year IDs to grab

Type

cascade_at.inputs.demographics.Demographics

self.integrand_map

dictionary mapping from GBD measure IDs to DisMod IDs

Type

Dict[int, int]

self.asdr

all-cause mortality input object

Type

cascade_at.inputs.asdr.ASDR

self.csmr

cause-specific mortality input object from cause csmr_cause_id

Type

cascade_at.inputs.csmr.CSMR

self.data

crosswalk version data from IHME database

Type

cascade_at.inputs.data.CrosswalkVersion

self.covariate_data

list of covariate data objects that contains the raw covariate data mapped to IDs

Type

List[cascade_at.inputs.covariate_data.CovariateData]

self.location_dag

DAG of locations to be used

Type

cascade_at.inputs.locations.LocationDAG

self.population

population object that is used for covariate weighting

Type

(cascade_at.inputs.population.Population)

self.data_eta

applied to each measure

Type

(Dict[str, float]): dictionary of eta value to be

self.density

applied to each measure

Type

(Dict[str, str]): dictionary of density to be

self.nu

to each measure

Type

(Dict[str, float]): dictionary of nu value to be applied

self.dismod_data

to be used in the dismod database

Type

(pd.DataFrame) resulting dismod data formatted

Examples

>>> from cascade_at.settings.base_case import BASE_CASE
>>> from cascade_at.settings.settings import load_settings
>>>
>>> settings = load_settings(BASE_CASE)
>>> covariate_id = [i.country_covariate_id for i in settings.country_covariate]
>>>
>>> i = MeasurementInputs(
>>>    model_version_id=settings.model.model_version_id,
>>>    gbd_round_id=settings.gbd_round_id,
>>>    decomp_step_id=settings.model.decomp_step_id,
>>>    csmr_cause_id = settings.model.add_csmr_cause,
>>>    crosswalk_version_id=settings.model.crosswalk_version_id,
>>>    country_covariate_id=covariate_id,
>>>    conn_def='epi',
>>>    location_set_version_id=settings.location_set_version_id
>>> )
>>> i.get_raw_inputs()
>>> i.configure_inputs_for_dismod(settings)
get_raw_inputs()[source]

Get the raw inputs that need to be used in the modeling.

configure_inputs_for_dismod(settings, mortality_year_reduction=5)[source]

Modifies the inputs for DisMod based on model-specific settings.

Parameters
  • settings (SettingsConfig) – Settings for the model

  • mortality_year_reduction (int) – number of years to decimate csmr and asdr

prune_mortality_data(parent_location_id)[source]

Remove mortality data for descendants that are not children of parent_location_id from the configured dismod data before it gets filled into the dismod database.

Return type

DataFrame

add_covariates_to_data(df)[source]

Add on covariates to a data frame that has age_group_id, year_id or time-age upper / lower, and location_id and sex_id. Adds both country-level and study-level covariates.

Return type

DataFrame

to_gbd_avgint(parent_location_id, sex_id)[source]

Converts the demographics of the model to the avgint table.

Return type

DataFrame

interpolate_country_covariate_values(df, cov_dict)[source]

Interpolates the covariate values onto the data so that the non-standard ages and years match up to meaningful covariate values.

transform_country_covariates(df)[source]

Transforms the covariate data with the transformation ID. :param df: (pd.DataFrame) :return: self

calculate_country_covariate_reference_values(parent_location_id, sex_id)[source]

Gets the country covariate reference value for a covariate ID and a parent location ID. Also gets the maximum difference between the reference value and covariate values observed.

Run this when you’re going to make a DisMod AT database for a specific parent location and sex ID.

Param

(int)

Parameters
  • parent_location_id (int) – (int)

  • sex_id (int) – (int)

Return type

CovariateSpecs

Returns

List[CovariateSpec] list of the covariate specs with the correct reference values and max diff.

reset_index(drop, inplace)[source]
class cascade_at.inputs.measurement_inputs.MeasurementInputsFromSettings(settings)[source]

Bases: cascade_at.inputs.measurement_inputs.MeasurementInputs

Wrapper for MeasurementInputs that takes a settings object rather than the individual arguments. For convenience.

Examples

>>> from cascade_at.settings.base_case import BASE_CASE
>>> from cascade_at.settings.settings import load_settings
>>> settings = load_settings(BASE_CASE)
>>> i = MeasurementInputs(settings)
>>> i.get_raw_inputs()
>>> i.configure_inputs_for_dismod()