Repository navigation
Conversation
Added numpy style docstrings and created new methods/properties to create system matrices
Base version of a dynamic regression model with regression coefficients evolving according to a unobserved components model. At present it is possible for the UC model to have a local leve, trend and irregular component.
| import warnings | ||
|
|
||
| # Construct the model | ||
| class dynamic_regression(sm.tsa.statespace.MLEModel): |
There was a problem hiding this comment.
Needs to follow standard Python name rules, e.g. DynamicRegression
| it's value is not False, then it is included in the model. If the | ||
| corresponding value is "deterministic" then the state | ||
| corresponding to that component will not have a disturbance term. | ||
| dynamic_regression : bool |
There was a problem hiding this comment.
Should be just dynamic or possibly update
|
|
||
| Parameters | ||
| ---------- | ||
| unconstrained : array_like |
There was a problem hiding this comment.
array_like is for inputs that could be various classes, e.g. ndarray, Series, DataFrame. Should be ndarray or (I don't like) array (since array is a python type, and confuses some introspection)
There was a problem hiding this comment.
In this case, I think array_like is okay since we might actually have pd.Series (e.g. if you were to pass in the params from a previously estimated results object).
There was a problem hiding this comment.
I think I was looking at the output, which is always a ndarray. I take your point on the input.
There was a problem hiding this comment.
Good point - I should change that in the base class too.
| return constrained | ||
|
|
||
| def untransform_params(self, constrained): | ||
| """ |
There was a problem hiding this comment.
Are these useful publically or should they be private?
There was a problem hiding this comment.
transform_params and untransform_params are part of the typical state space class structure, so they're public (for better or worse)
| unconstrained[start:] = np.sqrt(constrained[start:]) | ||
| return unconstrained | ||
|
|
||
| def plot_dynamic_regression(results,which="smoothed",figsize=None, |
There was a problem hiding this comment.
Need spaces. Should run
flake8 --isolated statsmodels/tsa/statespace/dynamic_regression.py
and fix any issues.
| unconstrained[start:] = np.sqrt(constrained[start:]) | ||
| return unconstrained | ||
|
|
||
| def plot_dynamic_regression(results,which="smoothed",figsize=None, |
There was a problem hiding this comment.
And maybe this function should be included as a results method?
| A model in which the coefficients of the exogonous covariates are | ||
| described by a univariate unobserved components model. At present | ||
| only local level and trend models are available for the coefficinets. | ||
| Ulitmately it is intended to add the full suite of components that |
| only local level and trend models are available for the coefficinets. | ||
| Ulitmately it is intended to add the full suite of components that | ||
| are standard in unobserved components models: | ||
|
|
There was a problem hiding this comment.
Can you include the latex definition of the model here?
| exog_models : dict or list of dicts, optional | ||
| Either a dict, a list containing a single dict, or a list of dict | ||
| s, one for each exogonous regressor. | ||
| Admisble keys are the supported component types: 'irregular', |
| self.ssm['obs_cov'] = self.obs_cov | ||
| self.state_cov = np.zeros((self.k_state_cov,self.k_state_cov)) | ||
| self.ssm['state_cov'] = self.state_cov | ||
|
|
There was a problem hiding this comment.
Would be great if you could implement param_names
|
I've added some specific comments, but there are some more general ones:
|
| Either a dict, a list containing a single dict, or a list of dict | ||
| s, one for each exogonous regressor. | ||
| Admisble keys are the supported component types: 'irregular', | ||
| 'local_level', and 'trend'. If a key is included in the dict and |
There was a problem hiding this comment.
I think it should be level and trend, to match what UnobservedComponents has.
Many fixes in accordance with flake8. Rename base class to DynamicRegression. Rename parameter, dynamic_regression to dynamic.
Codecov Report
@@ Coverage Diff @@
## master #5299 +/- ##
==========================================
- Coverage 81.71% 81.67% -0.05%
==========================================
Files 569 569
Lines 89710 89754 +44
Branches 10028 9304 -724
==========================================
- Hits 73306 73305 -1
- Misses 14132 14171 +39
- Partials 2272 2278 +6
Continue to review full report at Codecov.
|
Adds options for the structural model for regression coefficients to have a stationary AR term and a trigonometric seasonal term
|
Just pushed a bunch of commits to address some of the above. The major outstanding issue is tests and documentation improvement I think. According to the Codacy report there is a syntax problem on line 186 but I'm not sure what this is - seems like a perfectly valid f-string to me. |
Previously param_names and set_param_indices did not correctly handle names and indices of freq_seasonal and stochastic_freq_seasonal components
Implements a dynamic regression model of the form
x and \beta can be vectors to support multiple exogenous regressors.
Each exogenous regressor in$\beta$ evolves according to a univariate unobserved components model.
At present$\beta$ may have an irregular, local level and linear trend component. The local level and trend can be deterministic or stochastic.
It is intended to extend the modelling options for$\beta$ to include the full suite of terms routinely found in unobserved components models including dummy seasonal terms, harmonic seasonal terms and autoregressive terms.
This is my fist contribution to an open source project so I don't expect the code to be acceptable in it's current state. In particular tests and documentation are required.
I'd appreciate any and all pointers for how to get this to a state where it is a valuable addition to Statsmodels.
Discussion of this feature can be found here:
https://groups.google.com/forum/?hl=en#!topic/pystatsmodels/rEbbZJPxzIo