respy.method_of_simulated_moments
Estimate models with the method of simulated moments (MSM).
The method of simulated moments is developed by [1], [2], and [3] and an estimation technique where the distance between the moments of the actual data and the moments implied by the model parameters is minimized.
McFadden, D. (1989). A method of simulated moments for estimation of discrete response models without numerical integration. Econometrica: Journal of the Econometric Society, 995-1026.
Lee, B. S., & Ingram, B. F. (1991). Simulation estimation of time-series models. Journal of Econometrics, 47(2-3), 197-205.
Duffie, D., & Singleton, K. (1993). Simulated Moments Estimation of Markov Models of Asset Prices. Econometrica, 61(4), 929-952.
get_msm_func(params, options, calc_moments, replace_nans, empirical_moments, weighting_matrix, n_simulation_periods=None, return_scalar=True, return_simulated_moments=False, return_comparison_plot_data=False)
get_msm_func
Get the MSM function.
msm(params, simulate, calc_moments, replace_nans, empirical_moments, weighting_matrix, return_scalar, return_simulated_moments, return_comparison_plot_data)
msm
Loss function for MSM estimation.
get_diag_weighting_matrix(empirical_moments, weights=None)
get_diag_weighting_matrix
Create a diagonal weighting matrix from weights.
get_flat_moments(empirical_moments)
get_flat_moments
Compute the empirical moments flat indexes.
_harmonize_input(data)
_harmonize_input
Harmonize different types of inputs by turning all inputs into lists.
_flatten_index(data)
_flatten_index
Flatten the index as a combination of the former index and the columns.
_create_comparison_plot_data_msm(empirical_moments, simulated_moments, moment_set_labels)
_create_comparison_plot_data_msm
Create pandas.DataFrame for estimagic’s comparison plot.
_create_tidy_data(data, moment_set_labels)
_create_tidy_data
Create tidy data from list of pandas.DataFrames.
_reconstruct_inputs(inputs, dict_keys=None)
_reconstruct_inputs
Reconstruct inputs from lists back to a dictionary or single object.
respy.method_of_simulated_moments.
pandas.DataFrame
pandas.Series
Contains parameters.
dict
Dictionary containing model options.
callable()
list
Function(s) used to calculate simulated moments. Must match structure of empirical moments i.e. if empirical_moments is a list of pandas.DataFrames, calc_moments must be a list of the same length containing functions that correspond to the moments in empirical_moments.
Functions(s) specifying how to handle missings in simulated_moments. Must match structure of empirical_moments. Exception: If only one replacement function is specified, it will be used on all sets of simulated moments.
Contains the empirical moments calculated for the observed data. Moments should be saved to pandas.DataFrame or pandas.Series that can either be passed to the function directly or as items of a list or dictionary. Index of pandas.DataFrames can be of type MultiIndex, but columns cannot.
numpy.ndarray
Square matrix of dimension (NxN) with N denoting the number of empirical_moments. Used to weight squared moment errors.
int
None
Dictates the number of periods in the simulated dataset. This option does not affect options["n_periods"] which controls the number of periods for which decision rules are computed.
options["n_periods"]
True
Indicates whether to return moment error vector (False) or weighted square product of moment error vectors (True).
Indicates whether simulated moments should be returned with other output. If True will return simulated moments of the same type as empirical_moments.
Indicator for whether a pandas.DataFrame with empirical and simulated moments for the visualization with estimagic should be returned. Data contains the following columns: - moment_column: Contains the column names of the moment DataFrames/Series names. - moment_index: Contains the index of the moment DataFrames/Series. MultiIndex indices will be joined to one string. - value: Contains moment values. - moment_set: Indicator for each set of moments, will use keys if empirical_moments are specified in a dict. Moments input as lists will be numbered according to position. - kind: Indicates whether moments are empirical or simulated.
MSM function where all arguments except the parameter vector are set.
Contains model parameters.
Function used to simulate data for MSM estimation.
List of function(s) used to calculate simulated moments. Must match length of empirical_moments i.e. calc_moments contains a moments function for each item in empirical_moments.
List of functions(s) specifying how to handle missings in simulated_moments. Must match length of empirical_moments.
Contains the empirical moments calculated for the observed data. Each item in the list constitutes a set of moments saved to a pandas.DataFrame or pandas.Series. Index of pandas.DataFrames can be of type MultiIndex, but columns cannot.
Indicates whether to return moment error vector (False) or weighted square product of moment error vector (True).
Will output moments in a tidy data format if True. Expects a list as input where the first element is a boolean indicating whether to return the comparison plot data. The second element in the list can be a list of keys used to identify sets of moments which otherwise will be numbered.
float
tuple
Scalar or moment error vector depending on value of return_scalar. Will be a tuple containing simulated moments of same type as empirical_moments or a tidy pandas.DataFrame if either return_simulated_moments or the first element in return_comparison_plot_data is True.
Contains the empirical moments calculated for the observed data. Moments should be saved to pandas.DataFrame or pandas.Series that can either be passed to the function directly or as items of a list or dictionary.
Contains weights (usually variances) of empirical moments. Must match structure of empirical_moments i.e. if empirical_moments is a list of pandas.DataFrames, weights be list of pandas.DataFrames as well where each DataFrame entry contains the weight for the corresponding moment in empirical_moments.
Array contains a diagonal weighting matrix.
containing pandas.DataFrame or pandas.Series. Contains the empirical moments calculated for the observed data. Moments should be saved to pandas.DataFrame or pandas.Series that can either be passed to the function directly or as items of a list or dictionary.
Vector of empirical_moments with flat index.
pandas.DataFrames/Series and callable functions will turn into a list containing a single item (i.e. the input).
Dictionaries will be sorted according to keys and then turn into a list containing the dictionary entries.
respy.likelihood
respy.parallelization