Repository navigation
[WIP] [GSoC 2016] VECM #3013 - #3070
yogabonito wants to merge 165 commits into
Conversation
…added them to vecm.py
added: - read data - parse JMulTi output - compute statsmodels output (some amendments needed) TODO: actual comparison between JMulTi and statsmodels
The necessary amendments were made, to make the code work in the tests-directory.
- The code worked correctly in a Jupyter notebook but not as methods of the VECM class (due to missing *self* as first parameter). - Variable names have been changed and method signatures have been shortened to make use of instance attributes. - Actual return of the estimated parameter matrices added.
add tests
- for 1 dataset (E6)
- for 3 parameters (alpha, beta, and Gamma)
- for 4 different deterministic terms ('', 'c', 'cs', 'clt')
That makes 12 tests, of which at the current tolerance 11 are passing. (The failing one would pass with a little more tolerance).
- output of JMulTi has been added and includes now information about the matrix \Sigma_u (files ending with Sigmau.txt). - tests for \Sigma_u added - tests for the matrix C added (deterministic terms) - tests for deterministic terms within the cointegration relation (linear trends) added - parsing of JMulTi output is now done with a function in another file to have a "cleaner" test file.
|
@yogabonito Thanks for this - looks very promising. Will give detailed feedback later today |
| if 's' in deterministic_terms: # TODO: How many seasons?? | ||
| seasons = np.zeros((3, Delta_x.shape[1])) # 3 = 4-1 (4=number_of_seasons) | ||
| for i in range(seasons.shape[0]): | ||
| seasons[i, i::4] = i+1 |
There was a problem hiding this comment.
AFAICS, this should be assigning 1, i.e.
seasons[i, i::4] = 1
This should fix the test failure for non-seasonal parameters, even though it might not be the same coding that JMulti is using, and it still leaves periodicity hardcoded at 4.
There was a problem hiding this comment.
Thanks! I have tried assigning 1 now but the test is still failing.
There was a problem hiding this comment.
Thanks! I have tried assigning 1 now but the test is still failing.
|
general we will drop all use of numpy.matrix and stick with arrays, even though we have to spell out add comment with equation or page number in Lutkepohl or whatever reference is used. VAR is doing that, and it makes it easier to compare notes during development. renaming: most can wait, the main one right now is Given that the basic estimation is working, I think you should use a basic, stub (?) I read through the main code a bit later. |
| r""" | ||
| Fit VECM process and do lag order selection | ||
|
|
||
| .. math:: y_t = A_1 y_{t-1} + \ldots + A_p y_{t-p} + u_t |
There was a problem hiding this comment.
Math in notes, one liner to start class
…stic="nc" Note that test cases for instantaneous causality fail. They would pass with "self.p+1" instead of "self.p" at the beginning of the method body. I think this might be a bug in JMulTi, since Lutkepohl (2005) is explicitly advising to use a VAR(p)-model and not a VAR(p+1)-model on page 320 (chapter 7.6.4).
To this end, also equation names have been added to the model (and parameter names too). Also, methods for confidence intervals were added to be able to use existing summary-related code. Here is a summary for the dataset interest_inflation with the two variables "Dp" and "R" (available in my vecm-testing-branch) in the case of no deterministic terms:
Det. terms outside coint. relation & lagged endog. parameters for equation Dp
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
L1.Dp -0.5877 0.144 -4.072 0.000 -0.871 -0.305
L1.R 0.1173 0.112 1.046 0.296 -0.103 0.337
L2.Dp -0.7036 0.099 -7.124 0.000 -0.897 -0.510
L2.R 0.1875 0.113 1.653 0.098 -0.035 0.410
L3.Dp -0.8253 0.053 -15.489 0.000 -0.930 -0.721
L3.R 0.0231 0.112 0.207 0.836 -0.196 0.242
Det. terms outside coint. relation & lagged endog. parameters for equation R
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
L1.Dp -0.0823 0.127 -0.646 0.518 -0.332 0.167
L1.R 0.1860 0.099 1.880 0.060 -0.008 0.380
L2.Dp -0.0403 0.087 -0.462 0.644 -0.211 0.131
L2.R -0.0447 0.100 -0.446 0.655 -0.241 0.151
L3.Dp 0.0091 0.047 0.194 0.846 -0.083 0.101
L3.R 0.1722 0.099 1.748 0.080 -0.021 0.365
Loading coefficients (alpha) for equation Dp
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
ec1 -0.5460 0.190 -2.880 0.004 -0.918 -0.174
Loading coefficients (alpha) for equation R
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
ec1 0.1057 0.167 0.632 0.527 -0.222 0.434
Cointegration relations for loading-coefficients-column 1
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
beta.0 1.0000 0 0 0.000 1.000 1.000
beta.1 -0.1106 0.014 -7.798 0.000 -0.138 -0.083
==============================================================================
Point estimation is working for all tested combinations of deterministic terms. This has been achieved by making the VECMResults-class compatible with vector_ar/irf.py. To this end, VECMResults had to be refactored (which also means that it now conforms to statsmodels' naming conventions, using "neqs", "nobs", and "k_ar" instead of "K", "T", and "p"). Todo: refactor VAR (include arbitrary deterministic terms). Then also confidence intervals will work and not only point estimations.
This feature works in the absence of deterministic terms. When VAR-refactoring is done (allowing arbitrary deterministic terms in VAR models), this feature will also work with deterministic terms.
Plotting functions allow plotting: - the input data - forecasts - impulse responses When implementing the test for normality I saw that the current implementation in VAR is not producing the same results as JMulTi. For now, I have rewritten the code such that it produces the same results as JMulTi for VARs. The corresponding code for VECMs is not finished yet.
+ Allow for more than one caused variable. TODO: make this work in var_model.py too. + Allow for specifying variables via integers and strings (also sequences containing both these types are handled correctly). + Simplify API by removing the `caused`-argument. Having a separate `causing` and `caused` parameter was actually a bug because it allowed the user to specify a subset of all variables via these two parameters. (Lutkepohl's derivation of the Granger-test-theory is based on the fact that `causing` and `caused` form a partition of the set of all variables.) TODO: fix this bug in var_model.py too.
This includes the possibility to have now more than one caused variable and the bug fix (i.e. restricting `caused` to always be the complement of `causing`.)
…t cases Change test cases: Add JMulTi output of causality tests which were produced using a lag order reduced by 1 in JMulTi (because JMulTi seems to base its test for instantaneous causality on a VAR(p+1) model which does not correspond to Lutkepohl where a VAR(p) model is used. Now the test cases are passing (for deterministic="nc", further deterministic terms will be available after VAR is refactored).
This function gives the same results as JMulTi for all 10 tested combinations of deterministic terms.
Added deterministic terms to VAR (via `exog`-parameter) Added the test for instantaneous causality to VAR (by moving the code from VECM to VAR) Added 459 unit tests for VAR (all passing) covering: - parameter estimation (for endog and deterministic terms) - Sigma_u - Loglikelihood - forecasting - Granger- and instantaneous causality - todo: add tests for the remaining methods Brought back "partial Granger causality" as discussed with Josef in statsmodels#3070 Unit tests so far in this PR: VAR: 459 (all passing) VECM: 422 / 426 passing (4 failures stem from t- & p-values for certain parameters)
|
This long list of commits suggests that something went wrong when trying to resolve the conflict. I have also a rebased branch (vecm-rebased) which is cleaner (only 55 instead of 112 commits but both branches contain the same files). |
|
@yogabonito Given that your rebased branch looks clean, you could continue with that one and open a new pull request. According to the network only the last commit merges the original branch into the rebased version, but the comment/commit sequence in here still shows the original sequence besides the last merge commit. According to git only the last merge commit would need to be removed, but AFAIK that would change the github comment/merge sequence. (I'm not quite sure how this matches up.) |
Added deterministic terms to VAR (via `exog`-parameter) Added the test for instantaneous causality to VAR (by moving the code from VECM to VAR) Added 459 unit tests for VAR (all passing) covering: - parameter estimation (for endog and deterministic terms) - Sigma_u - Loglikelihood - forecasting - Granger- and instantaneous causality - todo: add tests for the remaining methods Brought back "partial Granger causality" as discussed with Josef in statsmodels#3070 Unit tests so far in this PR: VAR: 459 (all passing) VECM: 422 / 426 passing (4 failures stem from t- & p-values for certain parameters)
Added deterministic terms to VAR (via `exog`-parameter) Added the test for instantaneous causality to VAR (by moving the code from VECM to VAR) Added 459 unit tests for VAR (all passing) covering: - parameter estimation (for endog and deterministic terms) - Sigma_u - Loglikelihood - forecasting - Granger- and instantaneous causality - todo: add tests for the remaining methods Brought back "partial Granger causality" as discussed with Josef in statsmodels#3070 Unit tests so far in this PR: VAR: 459 (all passing) VECM: 422 / 426 passing (4 failures stem from t- & p-values for certain parameters)
Added deterministic terms to VAR (via `exog`-parameter) Added the test for instantaneous causality to VAR (by moving the code from VECM to VAR) Added 459 unit tests for VAR (all passing) covering: - parameter estimation (for endog and deterministic terms) - Sigma_u - Loglikelihood - forecasting - Granger- and instantaneous causality - todo: add tests for the remaining methods Brought back "partial Granger causality" as discussed with Josef in statsmodels#3070 Unit tests so far in this PR: VAR: 459 (all passing) VECM: 422 / 426 passing (4 failures stem from t- & p-values for certain parameters)
Added deterministic terms to VAR (via `exog`-parameter) Added the test for instantaneous causality to VAR (by moving the code from VECM to VAR) Added 459 unit tests for VAR (all passing) covering: - parameter estimation (for endog and deterministic terms) - Sigma_u - Loglikelihood - forecasting - Granger- and instantaneous causality - todo: add tests for the remaining methods Brought back "partial Granger causality" as discussed with Josef in statsmodels#3070 Unit tests so far in this PR: VAR: 459 (all passing) VECM: 422 / 426 passing (4 failures stem from t- & p-values for certain parameters)
|
continuation of this PR in #3246 has now been merged |
|
Hi, I cannot find vecm in the current vector_ar class. Is it removed? Thanks! |
|
@tongkewu It has been merged, and is in master but not in any release yet examples (there is also another gist that I used for merge review https://gist.github.com/josef-pkt/b36cd8458ab2ed20ff784dc8ed3d3a1c looks messy and I don't remember.) |
|
Thank you! So if I want to implement the vecm alg, I need to pull th whole
git source?
…On Fri, Dec 1, 2017 at 8:36 PM, Josef Perktold ***@***.***> wrote:
@tongkewu <https://github.com/tongkewu> It has been merged, and is in
master but not in any release yet
examples
Here https://gist.github.com/josef-pkt/fda96edd7b15892a058f58ae0948ed71
is an updated version of yogabonito's notebook (updated at time of merge,
but it should be still up-to-date with master)
(there is also another gist that I used for merge review
https://gist.github.com/josef-pkt/b36cd8458ab2ed20ff784dc8ed3d3a1c looks
messy and I don't remember.)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3070 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX7bqeyWJB2lKKtqHszWM4y8kLeDcvdvks5s8NO4gaJpZM4I8jvL>
.
|
|
Yes, If you want to use VECM, then you need to build from source or wait for the next release. |
|
Got it. I really apreciate your work and I believe it will help a lot with
my data project. Thank you!
…On Fri, Dec 1, 2017 at 9:38 PM, Josef Perktold ***@***.***> wrote:
Yes, If you want to use VECM, then you need to build from source or wait
for the next release.
VECM itself is just one module, but it includes necessary changes and
enhancements to VAR
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3070 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX7bqXD-BvTvTg3-ikj4Q--u9gl1b5fhks5s8OJcgaJpZM4I8jvL>
.
|
|
any timeline for the next release ( with VECM) |
The VECM framework developed in this year's GSoC aims to add the support for non-stationary VAR processes to statsmodels.
Currently, the following topics are implemented (see also this Jupyter-notebook):
Some of them work without and with deterministic terms in the model. Some functions, however, make use of the existing VAR framework which lacks support for some deterministic terms, such as seasonal terms. As a consequence much of the VECM-functionality relying on the VAR framework is not working with deterministic terms yet. This limitation will be overcome with the refactoring of the VAR-related code.
Future development will also include the implementation of the following VECM-related functions:
It's been a great summer and I am looking forward to working on these open issues!
Original comment:
Estimation of parameters and tests have been added.
A failing test (related to the parameter matrix for the deterministic terms) indicates that deterministic seasonal terms are not implemented correctly yet.
@josef-pkt, @bashtage, can you have a look at it?