respy.tests.random_model

This module contains the functions for the generation of random requests.

Module Contents

Functions

generate_random_model(point_constr=None, bound_constr=None, n_types=None, n_type_covariates=None, myopic=False)

Generate a random model specification.

_consolidate_bound_constraints(bound_constr)

_get_initial_shares(num_groups)

We simply need a valid request for the shares of types summing to one.

simulate_truncated_data(params, options, is_missings=True)

Simulate a (truncated) dataset.

_update_nested_dictionary(dict_, other)

Update a nested dictionary with another dictionary.

add_noise_to_params(params, options, delta_low_high=(-0.2, 0.2), wages_percent_absolute=(0, 0.2), wages_low_high=None, wages_null_low_high=(-0.2, 0.2), nonpecs_percent_absolute=(0, 0.2), nonpecs_low_high=None, nonpecs_null_low_high=(-5000, 5000), cholesky_low_high=(-0.5, 0.5), meas_sd_low_high=(1e-06, 0.5), ic_probabilities_low_high=False, ic_logit_low_high=False, seed=None)

Add noise to parameters.

_add_percentage_of_absolute_value_as_shock(rewards, rewards_percent_absolute)

Add percentage of value as the shock to rewards.

respy.tests.random_model._BASE_COVARIATES[source]

dict: Dictionary containing specification of covariates.

Deprecated since version x.x.x: This variable must be removed if generate_random_model is rewritten such that functions for each replicable paper are written.

respy.tests.random_model.generate_random_model(point_constr=None, bound_constr=None, n_types=None, n_type_covariates=None, myopic=False)[source]

Generate a random model specification.

Parameters
point_constrdict

A full or partial options specification. Elements that are specified here are not drawn randomly.

bound_constrdict

Upper bounds for some options to keep computation time reasonable. Can have the keys [“max_types”, “max_periods”, “max_edu_start”, “max_agents”, “max_draws”]

n_typesint

Number of unobserved types.

n_type_covariates :

Number of covariates to calculate type probabilities.

myopicbool

Indicator for myopic agents meaning the discount factor is set to zero.

respy.tests.random_model._consolidate_bound_constraints(bound_constr)[source]
respy.tests.random_model._get_initial_shares(num_groups)[source]

We simply need a valid request for the shares of types summing to one.

respy.tests.random_model.simulate_truncated_data(params, options, is_missings=True)[source]

Simulate a (truncated) dataset.

The data can have two more properties. First, truncated history, second, missing wages.

respy.tests.random_model._update_nested_dictionary(dict_, other)[source]

Update a nested dictionary with another dictionary.

The basic .update() method of dictionaries adds non-existing keys or replaces existing keys which works fine for unnested dictionaries. For nested dictionaries, levels under the current level are not updated but overwritten. This function recursively loops over keys and values and inserts the value if it is not a dictionary. If it is a dictionary, it applies the same process again.

respy.tests.random_model.add_noise_to_params(params, options, delta_low_high=- 0.2, 0.2, wages_percent_absolute=0, 0.2, wages_low_high=None, wages_null_low_high=- 0.2, 0.2, nonpecs_percent_absolute=0, 0.2, nonpecs_low_high=None, nonpecs_null_low_high=- 5000, 5000, cholesky_low_high=- 0.5, 0.5, meas_sd_low_high=1e-06, 0.5, ic_probabilities_low_high=False, ic_logit_low_high=False, seed=None)[source]

Add noise to parameters.

The function allows to vary the noise based on the absolute value for non-zero parameters or to simply add noise in forms of bounded random variables.

The function ensures that special parameters are valid:

  • Probabilities are between 0 and 1.

  • Correlations are between -1 and 1.

  • Diagonal elements of the Cholesky factor have 1e-6 as the lower bound.

  • The standard deviations of the measurement error have 1e-6 as the lower bound.

Parameters
paramspandas.DataFrame

The parameters in a DataFrame.

optionsdict

The options of the model.

delta_low_hightuple[float]

Lower and upper bound to shock to discount factor.

wages_percent_absolutefloat or tuple[float]

The deviation in percentages of the absolute value of a non-zero parameter is either a constant percentage for all parameters or a random percentage between upper and lower bounds.

wages_low_hightuple[float]

The deviation for a non-zero parameter value is between an lower and upper bound.

wages_null_low_hightuple[float]

The deviation for a parameter with value zero is between the lower and upper bound.

nonpecs_percent_absolutefloat or tuple[float]

The deviation in percentages of the absolute value of a non-zero parameter is either a constant percentage for all parameters or a random percentage between upper and lower bounds.

nonpecs_low_hightuple[float]

The deviation for a non-zero parameter value is between an lower and upper bound.

nonpecs_null_low_hightuple[float]

The deviation for a parameter with value zero is between the lower and upper bound.

cholesky_low_hightuple[float]

Lower and upper bound for a shock applied to the Cholesky factor of the shock matrix. To ensure proper scaling, the shock is multiplied with the square root of the product of diagonal elements for this entry. The shock for the diagonal elements is between zero and the upper bound and the resulting diagonal element in the Cholesky factor has 1e-6 as the lower bound.

meas_sd_low_hightuple[float]

Lower and upper bound for shock to measurement error standard deviations.

ic_probabilities_low_hightuple[float]

Lower and upper bound for shocks to the probabilities in the initial conditions.

ic_logit_low_hightuple[float]

Lower and upper bound for shocks to the logit coefficients in the initial conditions.

seedint or None

Seed to replicate the perturbation.

Returns
paramspandas.DataFrame

The new parameters.

respy.tests.random_model._add_percentage_of_absolute_value_as_shock(rewards, rewards_percent_absolute)[source]

Add percentage of value as the shock to rewards.