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 IDgbd_round_id (
int
) – the GBD round IDdecomp_step_id (
int
) – the decomp step IDcsmr_cause_id ((int) cause to pull CSMR from) –
crosswalk_version_id (
int
) – crosswalk version to usecountry_covariate_id (
List
[int
]) – list of covariate IDsconn_def (
str
) – connection definition from .odbc file (e.g. ‘epi’) to connect to the IHME databaseslocation_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 rounddrill_location_start (
Optional
[int
]) – which location ID to drill from as the parentdrill_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
-
self.
integrand_map
¶ dictionary mapping from GBD measure IDs to DisMod IDs
- Type
Dict[int, int]
-
self.
asdr
¶ all-cause mortality input object
-
self.
csmr
¶ cause-specific mortality input object from cause csmr_cause_id
-
self.
data
¶ crosswalk version data from IHME database
-
self.
covariate_data
¶ list of covariate data objects that contains the raw covariate data mapped to IDs
-
self.
location_dag
¶ DAG of locations to be used
-
self.
population
¶ population object that is used for covariate weighting
-
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)
-
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 modelmortality_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
- Returns
List[CovariateSpec] list of the covariate specs with the correct reference values and max diff.
-
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()