opynfield.fit_models package

Submodules

opynfield.fit_models.fit_group_models module

opynfield.fit_models.fit_group_models.group_fit_all(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], defaults: opynfield.config.defaults_settings.Defaults, model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]], upper: dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]], lower: dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]], initial: dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]]) dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]]

This function coordinates fitting all the models for time vs y-measures within a group

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains y-measure data indexed by groups and measure name

  • defaults (Defaults) – what default settings to use

  • model_params (dict[str, dict[str, ModelSpecification]]) – dictionary that contains model settings indexed by groups and measure name

  • upper (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains upper parameter bounds indexed by groups and measure name

  • lower (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains lower parameter bounds indexed by groups and measure name

  • initial (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains p0 indexed by groups and measure name

Returns

a dictionary of the parameter fits by measure name for this group

Return type

dict[str, pd.DataFrame]

opynfield.fit_models.fit_group_models.group_fit_by_cov_measure(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], coverage_averaged_measures: list[str], model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]], mode: str, upper: dict[str, dict[str, pandas.core.frame.DataFrame]], lower: dict[str, dict[str, pandas.core.frame.DataFrame]], initial: dict[str, dict[str, pandas.core.frame.DataFrame]], group: str) dict[str, pandas.core.frame.DataFrame]

This function coordinates fitting all the models for time vs y-measures within a group

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains y-measure data indexed by groups and measure name

  • coverage_averaged_measures (list[str]) – list of all y measures to model

  • model_params (dict[str, dict[str, ModelSpecification]]) – dictionary that contains model settings indexed by groups and measure name

  • mode (str) – which coverage measure to use as the x-measure

  • upper (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains upper parameter bounds indexed by groups and measure name

  • lower (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains lower parameter bounds indexed by groups and measure name

  • initial (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains p0 indexed by groups and measure name

  • group (str) – what group to model

Returns

a dictionary of the parameter fits by measure name for this group

Return type

dict[str, pd.DataFrame]

opynfield.fit_models.fit_group_models.group_fit_by_time(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], time_averaged_measures: list[str], model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]], upper: dict[str, dict[str, pandas.core.frame.DataFrame]], lower: dict[str, dict[str, pandas.core.frame.DataFrame]], initial: dict[str, dict[str, pandas.core.frame.DataFrame]], group: str) dict[str, pandas.core.frame.DataFrame]

This function coordinates fitting all the models for time vs y-measures within a group

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains y-measure data indexed by groups and measure name

  • time_averaged_measures (list[str]) – list of all y measures to model

  • model_params (dict[str, dict[str, ModelSpecification]]) – dictionary that contains model settings indexed by groups and measure name

  • upper (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains upper parameter bounds indexed by groups and measure name

  • lower (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains lower parameter bounds indexed by groups and measure name

  • initial (dict[str, dict[str, pd.DataFrame]]) – dictionary that contains p0 indexed by groups and measure name

  • group (str) – what group to model

Returns

a dictionary of the parameter fits by measure name for this group

Return type

dict[str, pd.DataFrame]

opynfield.fit_models.fit_group_models.group_fit_measure_by_cov_measure(group_individual_measure_df: pandas.core.frame.DataFrame, group_individual_cov_df: pandas.core.frame.DataFrame, specs: opynfield.config.model_settings.ModelSpecification, uppers: pandas.core.frame.DataFrame, lowers: pandas.core.frame.DataFrame, initials: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame

This function fits the model for a single coverage-measure vs y-measure relationship

Parameters
  • group_individual_measure_df (pd.DataFrame) – dataframe that includes the needed y data

  • group_individual_cov_df (pd.DataFrame) – the dataframe that includes the needed coverage data

  • specs (ModelSpecification) – the model settings for this relationship

  • uppers (pd.DataFrame) – the upper bounds for this relationship

  • lowers (pd.DataFrame) – the lower bounds for this relationship

  • initials (pd.DataFrame) – the p0 for this relationship

Returns

the parameter fits for this relationship

Return type

pd.DataFrame

opynfield.fit_models.fit_group_models.group_fit_measure_by_time(group_individual_measure_df: pandas.core.frame.DataFrame, specs: opynfield.config.model_settings.ModelSpecification, uppers: pandas.core.frame.DataFrame, lowers: pandas.core.frame.DataFrame, initials: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame

This function fits the model for a single time vs y-measure relationship

Parameters
  • group_individual_measure_df (pd.DataFrame) – dataframe that includes the needed data

  • specs (ModelSpecification) – the model settings for this relationship

  • uppers (pd.DataFrame) – the upper bounds for this relationship

  • lowers (pd.DataFrame) – the lower bounds for this relationship

  • initials (pd.DataFrame) – the p0 for this relationship

Returns

the parameter fits for this relationship

Return type

pd.DataFrame

opynfield.fit_models.fit_individual_models module

opynfield.fit_models.fit_individual_models.find_fit_bounds(fits: dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]], user_inputs: opynfield.config.user_input.UserInput) tuple[dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]], dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]], dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]]]

This function finds the bounds to use when re-fitting the individual bounds based on the distribution of the naive fits

Parameters
  • fits (dict[str, dict[str, dict[str, pd.DataFrame]]]) – the original (naive) parameter fits

  • user_inputs (UserInput) – user settings to use

Returns

the upper bounds, lower bounds, and p0s to use, each a dictionary indexed by group, x-measure, and y-measure

Return type

tuple[dict[str, dict[str, dict[str, pd.DataFrame]]], dict[str, dict[str, dict[str, pd.DataFrame]]], dict[str, dict[str, dict[str, pd.DataFrame]]]]

opynfield.fit_models.fit_individual_models.fit_all(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], defaults: opynfield.config.defaults_settings.Defaults, model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]]) dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]]

This function coordinates fitting the models for all the individuals in a all the groups for all the time and coverage-measure vs y-measure relationships

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – the necessary data in a dictionary indexed by group and y-measure

  • defaults (Defaults) – the default settings to use

  • model_params (dict[str, dict[str, ModelSpecification]]) – the model settings to use in a dictionary indexed by group and y-measure

Returns

the resultant parameter fits in a dictionary indexed by group, x-measure, and y-measure

Return type

dict[str, dict[str, dict[str, pd.DataFrame]]]

opynfield.fit_models.fit_individual_models.fit_by_cov_measure(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], coverage_averaged_measures: list[str], model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]], mode: str, group: str) dict[str, pandas.core.frame.DataFrame]

This function coordinates fitting the models for all the individuals in a group for all the coverage-measure vs y-measure relationships

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – the necessary data in a dictionary indexed by group and y-measure

  • coverage_averaged_measures (list[str]) – the y-measures to be modeled against coverage measures

  • model_params (dict[str, dict[str, ModelSpecification]]) – the model settings to use in a dictionary indexed by group and y-measure

  • mode (str) – the coverage measure to use as the x-measure

  • group (str) – the group to model

Returns

the resultant parameter fits in a dictionary indexed by y-measure

Return type

dict[str, pd.DataFrame]

opynfield.fit_models.fit_individual_models.fit_by_time(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], time_averaged_measures: list[str], model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]], group: str) dict[str, pandas.core.frame.DataFrame]

This function coordinates fitting the models for all the individuals in a group for all the time vs y-measure relationships

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – the necessary data in a dictionary indexed by group and y-measure

  • time_averaged_measures (list[str]) – the y-measures to be modeled against time

  • model_params (dict[str, dict[str, ModelSpecification]]) – the model settings to use in a dictionary indexed by group and y-measure

  • group (str) – the group to model

Returns

the resultant parameter fits in a dictionary indexed by y-measure

Return type

dict[str, pd.DataFrame]

opynfield.fit_models.fit_individual_models.fit_measure_by_cov(group_individual_measure_df: pandas.core.frame.DataFrame, group_individual_cov_df: pandas.core.frame.DataFrame, specs: opynfield.config.model_settings.ModelSpecification) pandas.core.frame.DataFrame

This function fits all the individuals in one group for a coverage-measure vs y-measure model

Parameters
  • group_individual_measure_df (pd.DataFrame) – the necessary y measure data

  • group_individual_cov_df (pd.DataFrame) – the necessary coverage measure data

  • specs (ModelSpecification) – the model settings to use

Returns

a dataframe of the resultant parameter fits for each individual in the group

Return type

pd.DataFrame

opynfield.fit_models.fit_individual_models.fit_measure_by_time(group_individual_measure_df: pandas.core.frame.DataFrame, specs: opynfield.config.model_settings.ModelSpecification) pandas.core.frame.DataFrame

This function fits all the individuals in one group for a time vs y-measure model

Parameters
  • group_individual_measure_df (pd.DataFrame) – the necessary data

  • specs (ModelSpecification) – the model settings to use

Returns

a dataframe of the resultant parameter fits for each individual in the group

Return type

pd.DataFrame

opynfield.fit_models.fit_individual_models.re_fit_all(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], defaults: opynfield.config.defaults_settings.Defaults, model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]], upper: dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]], lower: dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]], initial: dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]]) dict[str, dict[str, dict[str, pandas.core.frame.DataFrame]]]

This function re-fits all the individuals in one group for all the time and coverage measures

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – the necessary data indexed by group and y-measure

  • defaults (Defaults) – the default settings to use

  • model_params (dict[str, dict[str, ModelSpecification]]) – the model settings to use indexed by group and y-measure

  • upper (dict[str, dict[str, dict[str, pd.DataFrame]]]) – the upper bounds for model fits indexed by group and y-measure and x-measure

  • lower (dict[str, dict[str, dict[str, pd.DataFrame]]]) – the lower bounds for model fits indexed by group and y-measure and x-measure

  • initial (dict[str, dict[str, dict[str, pd.DataFrame]]]) – the p0 for model fits indexed by group and y-measure and x-measure

Returns

a dataframe of the resultant parameter fits for each individual in the group indexed by the group y-measure and x-measure

Return type

dict[str, dict[str, dict[str, pd.DataFrame]]]

opynfield.fit_models.fit_individual_models.re_fit_by_cov_measure(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], coverage_averaged_measures: list[str], model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]], mode: str, upper: dict[str, dict[str, pandas.core.frame.DataFrame]], lower: dict[str, dict[str, pandas.core.frame.DataFrame]], initial: dict[str, dict[str, pandas.core.frame.DataFrame]], group: str) dict[str, pandas.core.frame.DataFrame]

This function re-fits all the individuals in one group for all the coverage measures

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – the necessary data indexed by group and y-measure

  • coverage_averaged_measures (list[str]) – which y-measures to model by coverage measure

  • model_params (dict[str, dict[str, ModelSpecification]]) – the model settings to use indexed by group and y-measure

  • mode (str) – which coverage measure to model with

  • upper (dict[str, dict[str, pd.DataFrame]]) – the upper bounds for model fits indexed by group and y-measure

  • lower (dict[str, dict[str, pd.DataFrame]]) – the lower bounds for model fits indexed by group and y-measure

  • initial (dict[str, dict[str, pd.DataFrame]]) – the p0 for model fits indexed by group and y-measure

  • group (str) – the group to run the models for

Returns

a dataframe of the resultant parameter fits for each individual in the group

Return type

pd.DataFrame

opynfield.fit_models.fit_individual_models.re_fit_by_time(individual_measures_dfs: dict[str, dict[str, pandas.core.frame.DataFrame]], time_averaged_measures: list[str], model_params: dict[str, dict[str, opynfield.config.model_settings.ModelSpecification]], upper: dict[str, dict[str, pandas.core.frame.DataFrame]], lower: dict[str, dict[str, pandas.core.frame.DataFrame]], initial: dict[str, dict[str, pandas.core.frame.DataFrame]], group: str) dict[str, pandas.core.frame.DataFrame]

This function re-fits all the individuals in one group for all the time measures

Parameters
  • individual_measures_dfs (dict[str, dict[str, pd.DataFrame]]) – the necessary data indexed by group and y-measure

  • time_averaged_measures (list[str]) – which y-measures to model by time

  • model_params (dict[str, dict[str, ModelSpecification]]) – the model settings to use indexed by group and y-measure

  • upper (dict[str, dict[str, pd.DataFrame]]) – the upper bounds for model fits indexed by group and y-measure

  • lower (dict[str, dict[str, pd.DataFrame]]) – the lower bounds for model fits indexed by group and y-measure

  • initial (dict[str, dict[str, pd.DataFrame]]) – the p0 for model fits indexed by group and y-measure

  • group (str) – the group to run the models for

Returns

a dataframe of the resultant parameter fits for each individual in the group

Return type

pd.DataFrame

opynfield.fit_models.fit_individual_models.re_fit_measure_by_cov_measure(group_individual_measure_df: pandas.core.frame.DataFrame, group_individual_cov_df: pandas.core.frame.DataFrame, specs: opynfield.config.model_settings.ModelSpecification, uppers: pandas.core.frame.DataFrame, lowers: pandas.core.frame.DataFrame, initials: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame

This function re-fits all the individuals in one group for a coverage-measure vs y-measure model

Parameters
  • group_individual_measure_df (pd.DataFrame) – the necessary data for y measure

  • group_individual_cov_df (pd.DataFrame) – the necessary data for coverage measure

  • specs (ModelSpecification) – the model settings to use

  • uppers (pd.DataFrame) – the upper bounds for model fits

  • lowers (pd.DataFrame) – the lower bounds for model fits

  • initials (pd.DataFrame) – the p0 for model fits

Returns

a dataframe of the resultant parameter fits for each individual in the group

Return type

pd.DataFrame

opynfield.fit_models.fit_individual_models.re_fit_measure_by_time(group_individual_measure_df: pandas.core.frame.DataFrame, specs: opynfield.config.model_settings.ModelSpecification, uppers: pandas.core.frame.DataFrame, lowers: pandas.core.frame.DataFrame, initials: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame

This function re-fits all the individuals in one group for a time vs y-measure model

Parameters
  • group_individual_measure_df (pd.DataFrame) – the necessary data

  • specs (ModelSpecification) – the model settings to use

  • uppers (pd.DataFrame) – the upper bounds for model fits

  • lowers (pd.DataFrame) – the lower bounds for model fits

  • initials (pd.DataFrame) – the p0 for model fits

Returns

a dataframe of the resultant parameter fits for each individual in the group

Return type

pd.DataFrame

Module contents