How to modify model specifications¶
skillmodels.utilities
contains functions to construct a model dictionary by varying
an existing one and to update the parameters of a larger model from estimated parameters
from smaller models.
All functions that modify model dictionaries can can also modify a params DataFrame that was constructed for the original model accordingly.
- extract_factors(factors, model_dict, params=None)[source]¶
Reduce a specification to a model with fewer latent factors.
If provided, a params DataFrame is also reduced correspondingly.
- Parameters
factors (str or list) – Name(s) of the factor(s) to extract.
model_dict (dict) – The model specification. See: Model specifications.
params (pandas.DataFrame or None) – The params DataFrame for the full model.
- Returns
dict – The reduced model dictionary pandas.DataFrame: The reduced parameter DataFrame (only if params is not None)
- update_parameter_values(params, others)[source]¶
Update the “value” column of params with values from other.
- Parameters
params (pandas.DataFrame or None) – The params DataFrame for the full model.
other (pandas.DataFrame or list) – Another DataFrame with parameters or list of thereof. The values from other are used to update the value column of
params
. If other is a list, the updates will be in order, i.e. later elements overwrite earlier ones.
- Returns
pandas.DataFrame – Updated copy of params.
- remove_factors(factors, model_dict, params=None)[source]¶
Remove factors from a model specification.
If provided, a params DataFrame is also reduced correspondingly.
It is possible that the reduced model has fewer periods than the original one. This happens if the remaining factors do not have measurements in later periods.
- Parameters
factors (str or list) – Name(s) of the factor(s) to remove.
model_dict (dict) – The model specification. See: Model specifications.
params (pandas.DataFrame or None) – The params DataFrame for the full model.
- Returns
dict – The reduced model dictionary pandas.DataFrame: The reduced parameter DataFrame (only if params is not None)
- remove_measurements(measurements, model_dict, params=None)[source]¶
Remove measurements from a model specification.
If provided, a params DataFrame is also reduced correspondingly.
- Parameters
measurements (str or list) – Name(s) of the measurement(s) to remove.
model_dict (dict) – The model specification. See: Model specifications.
params (pandas.DataFrame or None) – The params DataFrame for the full model.
- Returns
dict – The reduced model dictionary pandas.DataFrame: The reduced parameter DataFrame (only if params is not None)
- remove_controls(controls, model_dict, params=None)[source]¶
Remove control variables from a model specification.
If provided, a params DataFrame is also reduced correspondingly.
- Parameters
controls (str or list) – Name(s) of the contral variable(s) to remove.
model_dict (dict) – The model specification. See: Model specifications.
params (pandas.DataFrame or None) – The params DataFrame for the full model.
- Returns
dict – The reduced model dictionary pandas.DataFrame: The reduced parameter DataFrame (only if params is not None)
- switch_translog_to_linear(model_dict, params=None)[source]¶
Switch all translog production functions to linear.
If provided, a params DataFrame is also reduced correspondingly.
- Parameters
model_dict (dict) – The model specification. See: Model specifications.
params (pandas.DataFrame or None) – The params DataFrame for the full model.
- Returns
dict – The reduced model dictionary pandas.DataFrame: The reduced parameter DataFrame (only if params is not None)
- switch_linear_to_translog(model_dict, params=None)[source]¶
Switch all linear production functions to translog.
If provided, a params DataFrame is also extended correspondingly. The fill value for the additional terms is 0.05 because experience showed that estimating a translog model with start parameters obtained from a linear model is faster when the additional parameters are not initialized at zero.
- Parameters
model_dict (dict) – The model specification. See: Model specifications.
params (pandas.DataFrame or None) – The params DataFrame for the full model.
- Returns
dict – The reduced model dictionary pandas.DataFrame: The reduced parameter DataFrame (only if params is not None)
- reduce_n_periods(model_dict, new_n_periods, params=None)[source]¶
Remove all periods after n_periods.
- Parameters
model_dict (dict) – The model specification. See: Model specifications.
new_n_periods (int) – The new number of periods.
params (pandas.DataFrame or None) – The params DataFrame for the full model.
- Returns
dict – The reduced model dictionary pandas.DataFrame: The reduced parameter DataFrame (only if params is not None)