Compare commits
407 Commits
remove-pri
...
master
Author | SHA1 | Date |
---|---|---|
Stéphane Adjemian | 4f2b9b3e62 | |
Johannes Pfeifer | 5d47ac2aa9 | |
Sébastien Villemot | 1ce40d4df5 | |
Sébastien Villemot | 6820edd614 | |
Sébastien Villemot | 4a8c78f703 | |
Sébastien Villemot | 3000e6d691 | |
Johannes Pfeifer | 73d54cea04 | |
Willi Mutschler | 1b3c1c33ce | |
Sébastien Villemot | dd03d51112 | |
Johannes Pfeifer | 4a2724959d | |
Stéphane Adjemian (Argos) | 24fbc0d923 | |
Sébastien Villemot | fd76ce53af | |
Johannes Pfeifer | 6975aaef43 | |
Sébastien Villemot | ab7d741bf1 | |
Sébastien Villemot | 6f2af6943f | |
Sébastien Villemot | 0d9857e737 | |
Sébastien Villemot | adc42bb4cb | |
Sébastien Villemot | 641cf6a95c | |
Sébastien Villemot | a623cb1d12 | |
Sébastien Villemot | 28fc9e7c78 | |
Sébastien Villemot | d5cffba8fc | |
Sébastien Villemot | 3ebf824f3f | |
Sébastien Villemot | ec48980e1e | |
Sébastien Villemot | ebfd2aa0a1 | |
Sébastien Villemot | 433f00e224 | |
Sébastien Villemot | d61cb124ba | |
Sébastien Villemot | 05d82796c2 | |
Sébastien Villemot | cfa978b39e | |
Sébastien Villemot | 99883d4ca6 | |
Sébastien Villemot | 3053f9b7df | |
Sébastien Villemot | c125d35347 | |
Johannes Pfeifer | a40b0c146d | |
Johannes Pfeifer | 8e91841a39 | |
Stéphane Adjemian (Argos) | f5a5ebb910 | |
Sébastien Villemot | 6145bf9b31 | |
Stéphane Adjemian (Argos) | 415a86d1d9 | |
Stéphane Adjemian (Argos) | 8eab48aa5e | |
Stéphane Adjemian (Argos) | 9f9f4a99ba | |
Stéphane Adjemian (Argos) | a48a03bc67 | |
Stéphane Adjemian (Argos) | 942d8846e4 | |
Johannes Pfeifer | 2ed416532b | |
Sébastien Villemot | 60e3b6a19f | |
Sébastien Villemot | 505084f20b | |
Sébastien Villemot | b956a2253e | |
Sébastien Villemot | 00bba09986 | |
Sébastien Villemot | 6a0ee900a4 | |
Sébastien Villemot | 8954a682c7 | |
Sébastien Villemot | 13c9acba57 | |
Sébastien Villemot | aee581fd0b | |
Sébastien Villemot | 855e44cb17 | |
Sébastien Villemot | 881f5f2e62 | |
Johannes Pfeifer | b1cb309a73 | |
Sébastien Villemot | 330542a79f | |
Sébastien Villemot | b2f603091a | |
Sébastien Villemot | 88236b1cc0 | |
Sébastien Villemot | c14d410699 | |
Johannes Pfeifer | 619de017d6 | |
Sébastien Villemot | 85c637d3d1 | |
Sébastien Villemot | 6fe43545d8 | |
Sébastien Villemot | 6b6b648255 | |
Sébastien Villemot | aa76e06099 | |
Sébastien Villemot | e68be9ec55 | |
Sébastien Villemot | 2c6df2b668 | |
Sébastien Villemot | c6c179d8dd | |
Sébastien Villemot | aceebe9769 | |
Johannes Pfeifer | 28df34df06 | |
Johannes Pfeifer | d7242c056d | |
Johannes Pfeifer | 6ba9cb06e7 | |
Johannes Pfeifer | bcd57142c6 | |
Sébastien Villemot | 6868e2f27e | |
Johannes Pfeifer | 248d8ae84f | |
Sébastien Villemot | 6780b9a009 | |
Sébastien Villemot | 6235de3a82 | |
Sébastien Villemot | e1833c475d | |
Johannes Pfeifer | e5951650d9 | |
Johannes Pfeifer | 1b181fca57 | |
Johannes Pfeifer | 45e8ab14dc | |
Johannes Pfeifer | 6bb973a0fa | |
Johannes Pfeifer | 23225aca1b | |
Sébastien Villemot | 2d90ef9890 | |
Sébastien Villemot | 5d169d658e | |
Sébastien Villemot | 4683b9aeb6 | |
Sébastien Villemot | cb7bd0778b | |
Sébastien Villemot | 2fd4a6fac4 | |
Sébastien Villemot | 2bfa311636 | |
Sébastien Villemot | 3ab9be71c8 | |
Johannes Pfeifer | 0187ebe0a2 | |
Johannes Pfeifer | 6ff924550c | |
Sébastien Villemot | 346ee01107 | |
Sébastien Villemot | cc02690acf | |
Sébastien Villemot | ffb578276e | |
Johannes Pfeifer | 4a7851b069 | |
Johannes Pfeifer | 46d7e155d9 | |
Sébastien Villemot | f9cd465fea | |
Sébastien Villemot | 53d8278d8a | |
Sébastien Villemot | 049006a1bf | |
Sébastien Villemot | e7cd6eb408 | |
Sébastien Villemot | 0679da4cba | |
Sébastien Villemot | a99beac083 | |
Sébastien Villemot | 44044904c1 | |
Sébastien Villemot | b89e79862a | |
Sébastien Villemot | 3249d74220 | |
Sébastien Villemot | 8a7440c6ac | |
Johannes Pfeifer | 90266c0bfc | |
Johannes Pfeifer | 02d1e8d3ed | |
Johannes Pfeifer | a6ad26788e | |
Johannes Pfeifer | 8f07f37138 | |
Johannes Pfeifer | e9d79796cf | |
Johannes Pfeifer | b7e9d69874 | |
Sébastien Villemot | 7bf0395a27 | |
Willi Mutschler | ee2545f84d | |
Sébastien Villemot | dd1669082e | |
Johannes Pfeifer | 9c28f5feaf | |
Sébastien Villemot | 31ce155852 | |
Sébastien Villemot | c36b695cd9 | |
Sébastien Villemot | 6cad684980 | |
Marco Ratto | a4e6531420 | |
Sébastien Villemot | d09a206c7c | |
Marco Ratto | fbf62255c6 | |
Marco Ratto | e918589e02 | |
Sébastien Villemot | 368c93214e | |
Johannes Pfeifer | 8deeaa7252 | |
Johannes Pfeifer | e3e6f4c9b4 | |
Sébastien Villemot | 5216cec249 | |
Sébastien Villemot | cae5a00e80 | |
Sébastien Villemot | 42e2f77e4a | |
Sébastien Villemot | 7a5684bf4b | |
Willi Mutschler | c4bf6d079f | |
Willi Mutschler | c46eef685d | |
Willi Mutschler | 2f07fa2921 | |
Willi Mutschler | f14bbc73b1 | |
Willi Mutschler | 329f0d2d54 | |
Willi Mutschler | 68b92a1ab9 | |
Willi Mutschler | 8987576ff5 | |
Willi Mutschler | 9148b5b210 | |
Willi Mutschler | 0b839467e6 | |
Willi Mutschler | 547bdcc99b | |
Willi Mutschler | 0787589479 | |
Willi Mutschler | 37efafe475 | |
Willi Mutschler | 7f60674dae | |
Willi Mutschler | bd3ca58727 | |
Willi Mutschler | 65f8b56fb0 | |
Willi Mutschler | 2521314c39 | |
Willi Mutschler | 378e38c8c2 | |
Willi Mutschler | c59daa6139 | |
Willi Mutschler | 937ee0ef77 | |
Willi Mutschler | 8515a195ab | |
Willi Mutschler | 8a29933c6e | |
Willi Mutschler | f210ffa3ae | |
Willi Mutschler | 20ec0a6c97 | |
Willi Mutschler | e9871d7d47 | |
Willi Mutschler | 459842e4f6 | |
Willi Mutschler | 2d8bcd6918 | |
Willi Mutschler | c45c0efeba | |
Willi Mutschler | 613b3869e1 | |
Willi Mutschler | 95bfb84014 | |
Willi Mutschler | 37c7ca2d97 | |
Willi Mutschler | dedbb3be57 | |
Sébastien Villemot | d7850a2bbe | |
Willi Mutschler | b435aa7f27 | |
Willi Mutschler | f8a6020d2b | |
Willi Mutschler | 5f1ae3bb19 | |
Sébastien Villemot | bc69f6a102 | |
Sébastien Villemot | 8b9d1d1346 | |
Sébastien Villemot | 38d1c0538a | |
Johannes Pfeifer | 774cb18aac | |
Johannes Pfeifer | b215eedb4b | |
Sébastien Villemot | fb18777e58 | |
Sébastien Villemot | 311808db0a | |
Sébastien Villemot | 52b92ce64d | |
Johannes Pfeifer | ba52789020 | |
Johannes Pfeifer | c52c21ca24 | |
Sébastien Villemot | e649fa5494 | |
Sébastien Villemot | 346d2acbdf | |
Johannes Pfeifer | 278e767ea1 | |
Johannes Pfeifer | 90ced5ca47 | |
Sébastien Villemot | c9db9809d0 | |
Sébastien Villemot | 70b9d9277a | |
Johannes Pfeifer | 78abd68c9f | |
Johannes Pfeifer | 4512e85cb2 | |
Johannes Pfeifer | d7ae0d0039 | |
Marco Ratto | ac346ef83d | |
Marco Ratto | 9b165d7785 | |
Johannes Pfeifer | 7b94310fd4 | |
Marco Ratto | 8348cf009a | |
Marco Ratto | 75f5a463df | |
Marco Ratto | e8d82ad840 | |
Johannes Pfeifer | ab6ea60967 | |
Marco Ratto | 90fbb9559e | |
Marco Ratto | 3f1a37614f | |
Marco Ratto | ee5faf0783 | |
Marco Ratto | cf7be44257 | |
Sébastien Villemot | c363355dbf | |
Sébastien Villemot | d50330aad3 | |
Sébastien Villemot | 380e78be53 | |
Sébastien Villemot | 84a7b4b2cf | |
Johannes Pfeifer | 48380a1370 | |
Johannes Pfeifer | 3faaffacc6 | |
Sébastien Villemot | e9ffb16ec6 | |
Stéphane Adjemian (Ryûk) | 4982ce06b4 | |
Johannes Pfeifer | 37e4d68264 | |
Johannes Pfeifer | 4d6d4953e7 | |
Stéphane Adjemian (Ryûk) | c399f54581 | |
Stéphane Adjemian (Ryûk) | 735bd66d4d | |
Stéphane Adjemian (Ryûk) | 7468a903b7 | |
Stéphane Adjemian (Ryûk) | c841f1474c | |
Stéphane Adjemian (Ryûk) | b6619b342b | |
Stéphane Adjemian (Ryûk) | fef466ef34 | |
Stéphane Adjemian (Ryûk) | 52be9d08c1 | |
Stéphane Adjemian (Ryûk) | 5d8861ff29 | |
Stéphane Adjemian (Ryûk) | 743de7da5c | |
Stéphane Adjemian (Ryûk) | e962cb4dba | |
Stéphane Adjemian (Ryûk) | cf4c6cdf14 | |
Stéphane Adjemian (Guts) | 7915b91fdb | |
Johannes Pfeifer | 72a8d53df8 | |
Stéphane Adjemian (Guts) | 23af7f64b6 | |
Stéphane Adjemian (Guts) | 0249ea2116 | |
Stéphane Adjemian (Guts) | 44119077db | |
Stéphane Adjemian (Guts) | 47af0cde16 | |
Sébastien Villemot | eb043406e6 | |
Sébastien Villemot | ae082cffbe | |
Sébastien Villemot | febd39713e | |
Sébastien Villemot | 20b2c79ffb | |
Sébastien Villemot | 458926b17b | |
Sébastien Villemot | 162ca815bc | |
Sébastien Villemot | ff7cc9267e | |
Sébastien Villemot | 56e97e29aa | |
Sébastien Villemot | adddcf6197 | |
Sébastien Villemot | 79959aa587 | |
Sébastien Villemot | a0bafbcb95 | |
Sébastien Villemot | 2005f292e5 | |
Stéphane Adjemian (Guts) | 4a6783c690 | |
Johannes Pfeifer | 3e7291b573 | |
Sébastien Villemot | 9225e6b6df | |
Sébastien Villemot | d8f1e49221 | |
Sébastien Villemot | 1239842909 | |
Marco Ratto | 281f01f29e | |
Johannes Pfeifer | 8710ce0898 | |
Johannes Pfeifer | 74ac072549 | |
Marco Ratto | 8ddd35ddd8 | |
Marco Ratto | 3ee963c908 | |
Johannes Pfeifer | d25d95b3b5 | |
Marco Ratto | 2898407764 | |
Marco Ratto | 3931451250 | |
Marco Ratto | e1e79d3177 | |
Sébastien Villemot | d94e5bd7b9 | |
Sébastien Villemot | 66bc9fd9c2 | |
Sébastien Villemot | 19dcd4a0f2 | |
Johannes Pfeifer | f05a2de89e | |
Johannes Pfeifer | c3268c0279 | |
Johannes Pfeifer | 2e73856f5a | |
Sébastien Villemot | 565667c6b7 | |
Johannes Pfeifer | 75cd1042c8 | |
Sébastien Villemot | fd0d93ba13 | |
Sébastien Villemot | 668f6de5df | |
Johannes Pfeifer | 0c07460f3b | |
Johannes Pfeifer | dbcc0aeb9f | |
Stéphane Adjemian (Guts) | 1983dc13a3 | |
Johannes Pfeifer | 162813225d | |
Johannes Pfeifer | 1b2e1d2856 | |
Sébastien Villemot | 81cd0f1cb5 | |
Sébastien Villemot | 441ef7e102 | |
Johannes Pfeifer | 2df08f88c7 | |
Marco Ratto | f102a992aa | |
Marco Ratto | 53b57da8ba | |
Marco Ratto | aad5c36081 | |
Marco Ratto | de152a3de3 | |
Marco Ratto | 8f73564634 | |
Marco Ratto | 0c4b59b19e | |
Marco Ratto | 9b71845b87 | |
Marco Ratto | 91a2cd2496 | |
Sébastien Villemot | 858b534c22 | |
Johannes Pfeifer | e17bf15042 | |
Sébastien Villemot | ea28fcb4b4 | |
Sébastien Villemot | a7f5fd571d | |
Sébastien Villemot | 05cb10f8f7 | |
Sébastien Villemot | 594facdb03 | |
Sébastien Villemot | 7ba1fc1c63 | |
Sébastien Villemot | 63d5569cf4 | |
Sébastien Villemot | 00434c595d | |
Stéphane Adjemian (Ryûk) | 60c0ed0180 | |
Johannes Pfeifer | 42fc1ec40a | |
Johannes Pfeifer | 1b4fb46c75 | |
Stéphane Adjemian (Ryûk) | 2fbbe66c0a | |
Stéphane Adjemian (Ryûk) | 61498e644a | |
Stéphane Adjemian (Ryûk) | 3606b10f05 | |
Stéphane Adjemian (Ryûk) | 5077969aad | |
Stéphane Adjemian (Ryûk) | 3d50844ae4 | |
Stéphane Adjemian (Ryûk) | 3c3353b7ed | |
Stéphane Adjemian (Ryûk) | 03a68ddb89 | |
Sébastien Villemot | b1aa88e8da | |
Sébastien Villemot | d3aac5e2d7 | |
Sébastien Villemot | 62b31aa279 | |
Sébastien Villemot | 9d6a25e368 | |
Sébastien Villemot | 43b24facb9 | |
Sébastien Villemot | cc15281b1f | |
Sébastien Villemot | c99230825f | |
Sébastien Villemot | b7805cc667 | |
Johannes Pfeifer | ec76bda254 | |
Johannes Pfeifer | 021b9dbb25 | |
Johannes Pfeifer | daecd1f720 | |
Johannes Pfeifer | 5a3d545db2 | |
Johannes Pfeifer | ed80c4ff3f | |
Johannes Pfeifer | 678bd7aca9 | |
Johannes Pfeifer | 97f6a4219b | |
Johannes Pfeifer | 31c91080e1 | |
Johannes Pfeifer | 62e8b275a0 | |
Johannes Pfeifer | 435b103cf5 | |
Sébastien Villemot | d844043877 | |
Sébastien Villemot | a31c76403d | |
Sébastien Villemot | 4ef9245a95 | |
Sébastien Villemot | 91c677ca7f | |
Sébastien Villemot | 56289c72d0 | |
Sébastien Villemot | 1f5f668313 | |
Johannes Pfeifer | 54c4e9df09 | |
Stéphane Adjemian (Guts) | 8d8176fc30 | |
Sébastien Villemot | 40ef192e37 | |
Johannes Pfeifer | 1e5a04c2c5 | |
Johannes Pfeifer | f3a1ba56e3 | |
Johannes Pfeifer | af53c65172 | |
Johannes Pfeifer | c3b9c499ba | |
Johannes Pfeifer | 7f027d8f5e | |
Johannes Pfeifer | 9efb784763 | |
Johannes Pfeifer | 19b2619d06 | |
Johannes Pfeifer | 5d07ff9f8b | |
Johannes Pfeifer | fca782f8e4 | |
Johannes Pfeifer | 43fc6263af | |
Johannes Pfeifer | 37ab539a10 | |
Johannes Pfeifer | 6adf1c2639 | |
Johannes Pfeifer | 709ef9230f | |
Johannes Pfeifer | 0ba91259d8 | |
Johannes Pfeifer | dce0967deb | |
Johannes Pfeifer | 392721097c | |
Johannes Pfeifer | e68793030c | |
Johannes Pfeifer | bf6d88a472 | |
Sébastien Villemot | 6a58316a3e | |
Sébastien Villemot | 91f2dcdfe1 | |
Sébastien Villemot | de476ad5ac | |
Sébastien Villemot | 123f909b67 | |
Sébastien Villemot | fd9a89ab38 | |
Sébastien Villemot | 15b6e6e6b3 | |
Sébastien Villemot | 9d98811cfc | |
Sébastien Villemot | 8953007440 | |
Sébastien Villemot | d82eecfd39 | |
Sébastien Villemot | 3df4856259 | |
Sébastien Villemot | 11c1f6175e | |
Sébastien Villemot | 7864370bfb | |
Sébastien Villemot | 911437378c | |
Sébastien Villemot | 6f38dcd1d5 | |
Sébastien Villemot | bc6840ff6f | |
Sébastien Villemot | aeec4494b0 | |
Sébastien Villemot | 857e5b00f5 | |
Sébastien Villemot | bd7703d160 | |
Sébastien Villemot | a5445c52be | |
Sébastien Villemot | 403f20a7f3 | |
Johannes Pfeifer | 53f12e81fa | |
Sébastien Villemot | bea87aafad | |
Johannes Pfeifer | 526e6841b1 | |
Johannes Pfeifer | c21199a3e9 | |
Johannes Pfeifer | 36a4ad0fbc | |
Johannes Pfeifer | f218127220 | |
Stéphane Adjemian (Ryûk) | edaf938582 | |
Stéphane Adjemian (Ryûk) | dadcd9a2bf | |
Sébastien Villemot | c6a7801ba8 | |
Sébastien Villemot | 7edf01a2a9 | |
Sébastien Villemot | cb56dcc569 | |
Sébastien Villemot | f0420fa219 | |
Sébastien Villemot | ed332e3ba1 | |
Sébastien Villemot | ca16f7f848 | |
Sébastien Villemot | 847f940f78 | |
Johannes Pfeifer | d5f7fbe96a | |
Johannes Pfeifer | d29228bb5f | |
Johannes Pfeifer | 152991864d | |
Johannes Pfeifer | f8a0a99683 | |
Johannes Pfeifer | 5060f246ea | |
Johannes Pfeifer | 4199f57788 | |
Johannes Pfeifer | 94c1343671 | |
Johannes Pfeifer | a80ead7d94 | |
Johannes Pfeifer | da438d5099 | |
Johannes Pfeifer | ffaf6c8559 | |
Sébastien Villemot | 54e72a4d35 | |
Sébastien Villemot | c3d91d5ce8 | |
Sébastien Villemot | c6c6f4f549 | |
Sébastien Villemot | b0197da05f | |
Sébastien Villemot | ccff7d3560 | |
Johannes Pfeifer | e718402357 | |
Johannes Pfeifer | 59c9f70a7d | |
Sébastien Villemot | 6ccc7fd69e | |
Sébastien Villemot | b220be6d3e | |
Sébastien Villemot | f21fda7dfa | |
Sébastien Villemot | c0e39d40a7 | |
Johannes Pfeifer | d0e99daf9a | |
Sébastien Villemot | f62d76cbcf | |
Sébastien Villemot | 56410be973 | |
Johannes Pfeifer | 07d859d018 | |
Sébastien Villemot | b513214570 | |
Sébastien Villemot | 9545dcc8d9 | |
Sébastien Villemot | 08c9eca8ee | |
Sébastien Villemot | 701afd2c7c | |
Sébastien Villemot | 1d5a442fe5 | |
Sébastien Villemot | d55b6c68f9 | |
Sébastien Villemot | 72ac69eb97 | |
Sébastien Villemot | ec7a4ba84f | |
Sébastien Villemot | 3bfe2c5500 | |
Sébastien Villemot | 7f58e819c6 | |
Sébastien Villemot | 0efe0c9844 | |
Johannes Pfeifer | 37f747bb3b |
|
@ -1,21 +1,25 @@
|
|||
# NB: whenever the present file is modified, the same modification should be
|
||||
# applied to the copy in preprocessor.git
|
||||
|
||||
# For the list of options (clang-format 14, present in Debian “bookworm” 12), see:
|
||||
# https://releases.llvm.org/14.0.0/tools/clang/docs/ClangFormatStyleOptions.html
|
||||
# For general information about our coding style, and the specific version
|
||||
# of clang-format used, see:
|
||||
# https://git.dynare.org/Dynare/dynare/-/wikis/CodingGuidelines#c-code
|
||||
# For the list of options of clang-format, see:
|
||||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
# Effective configuration can be obtained with:
|
||||
# clang-format --dump-config
|
||||
Language: Cpp
|
||||
Standard: c++20
|
||||
ColumnLimit: 100
|
||||
BasedOnStyle: GNU
|
||||
AllowShortFunctionsOnASingleLine: InlineOnly
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BreakConstructorInitializers: AfterColon
|
||||
BreakInheritanceList: AfterColon
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: false
|
||||
IndentPPDirectives: AfterHash
|
||||
PackConstructorInitializers: NextLine
|
||||
PPIndentWidth: 1
|
||||
PointerAlignment: Left
|
||||
SpaceAfterTemplateKeyword: false
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# NB: to use clang-tidy on the MEX source code, make sure that you have
|
||||
# libomp-dev installed (the LLVM implementation of OpenMP)
|
||||
|
||||
# TODO: add the following check families:
|
||||
# - bugprone-*
|
||||
# - cppcoreguidelines-
|
||||
|
||||
Checks: 'performance-*,modernize-*,-modernize-use-trailing-return-type,-clang-diagnostic-unqualified-std-cast-call'
|
|
@ -1,6 +1,8 @@
|
|||
((c-mode . ((indent-tabs-mode . nil)
|
||||
(fill-column . 100)
|
||||
(c-file-style . "gnu")))
|
||||
(c++-mode . ((indent-tabs-mode . nil)
|
||||
(fill-column . 100)
|
||||
(c-file-style . "gnu")))
|
||||
(makefile-mode . ((indent-tabs-mode . t)))
|
||||
(octave-mode . ((indent-tabs-mode . nil)
|
||||
|
|
|
@ -2,21 +2,23 @@ variables:
|
|||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
TERM: linux
|
||||
MATLAB_VERSION: R2023b
|
||||
OLD_MATLAB_VERSION: R2014a
|
||||
OLD_MATLAB_VERSION: R2018b
|
||||
# To ensure that "false && true" fails, see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/25394#note_412609647
|
||||
FF_ENABLE_BASH_EXIT_CODE_CHECK: 'true'
|
||||
|
||||
# The next stanza creates the version number used for the source tarball and the
|
||||
# binary packages. Here are the following possible cases:
|
||||
# - if VERSION was already set (when manually running a pipeline), use it
|
||||
# - if we are in the official Dynare repository:
|
||||
# + if on a tag: use the tag
|
||||
# + if on master: use 6-unstable-$TIMESTAMP-$COMMIT
|
||||
# + if on master: use 7-unstable-$TIMESTAMP-$COMMIT
|
||||
# + on another branch: use $BRANCH-$TIMESTAMP-$COMMIT
|
||||
# - if in a personal repository: use $USER-$TIMESTAMP-$COMMIT
|
||||
before_script:
|
||||
- '[[ -z $VERSION ]] && [[ $CI_PROJECT_NAMESPACE == Dynare ]] && [[ -n $CI_COMMIT_TAG ]] && export VERSION=$CI_COMMIT_TAG'
|
||||
- '[[ -z $VERSION ]] && [[ $CI_PROJECT_NAMESPACE == Dynare ]] && [[ $CI_COMMIT_REF_NAME == master ]] && export VERSION=6-unstable-$(date +%F-%H%M)-$CI_COMMIT_SHORT_SHA'
|
||||
- '[[ -z $VERSION ]] && [[ $CI_PROJECT_NAMESPACE == Dynare ]] && export VERSION=$CI_COMMIT_REF_NAME-$(date +%F-%H%M)-$CI_COMMIT_SHORT_SHA'
|
||||
- '[[ -z $VERSION ]] && export VERSION=$CI_PROJECT_NAMESPACE-$(date +%F-%H%M)-$CI_COMMIT_SHORT_SHA'
|
||||
- 'if [[ -z $VERSION ]] && [[ $CI_PROJECT_NAMESPACE == Dynare ]] && [[ -n $CI_COMMIT_TAG ]]; then export VERSION=$CI_COMMIT_TAG; fi'
|
||||
- 'if [[ -z $VERSION ]] && [[ $CI_PROJECT_NAMESPACE == Dynare ]] && [[ $CI_COMMIT_REF_NAME == master ]]; then export VERSION=7-unstable-$(date +%F-%H%M)-$CI_COMMIT_SHORT_SHA; fi'
|
||||
- 'if [[ -z $VERSION ]] && [[ $CI_PROJECT_NAMESPACE == Dynare ]]; then export VERSION=$CI_COMMIT_REF_NAME-$(date +%F-%H%M)-$CI_COMMIT_SHORT_SHA; fi'
|
||||
- 'if [[ -z $VERSION ]]; then export VERSION=$CI_PROJECT_NAMESPACE-$(date +%F-%H%M)-$CI_COMMIT_SHORT_SHA; fi'
|
||||
|
||||
stages:
|
||||
- build
|
||||
|
@ -175,6 +177,13 @@ test_octave:
|
|||
needs: [ "build_octave" ]
|
||||
when: manual
|
||||
|
||||
test_clang_format:
|
||||
stage: test
|
||||
script:
|
||||
- meson setup -Dbuild_for=octave build-clang-format
|
||||
- ninja -C build-clang-format clang-format-check
|
||||
needs: []
|
||||
|
||||
# For the sign and deploy jobs, we don’t use the “needs” keyword, since we
|
||||
# don’t want those jobs to start before the “test” and “pkg” stages have
|
||||
# succeeded. Hence we stick to the “dependencies” keyword.
|
||||
|
|
|
@ -11,12 +11,9 @@
|
|||
path = matlab/utilities/tests
|
||||
url = ../../Dynare/m-unit-tests.git
|
||||
[submodule "matlab/modules/dseries"]
|
||||
path = matlab/modules/dseries
|
||||
path = matlab/dseries
|
||||
url = ../../Dynare/dseries.git
|
||||
branch = master
|
||||
[submodule "contrib/jsonlab"]
|
||||
path = contrib/jsonlab
|
||||
url = https://github.com/fangq/jsonlab.git
|
||||
[submodule "preprocessor"]
|
||||
path = preprocessor
|
||||
url = ../../Dynare/preprocessor.git
|
||||
|
|
402
NEWS.md
402
NEWS.md
|
@ -1,3 +1,405 @@
|
|||
Announcement for Dynare 6.0 (on 2024-02-02)
|
||||
===========================================
|
||||
|
||||
We are pleased to announce the release of Dynare 6.0.
|
||||
|
||||
This major release adds new features and fixes various bugs.
|
||||
|
||||
The Windows, macOS, MATLAB Online and source packages are already available for
|
||||
download at [the Dynare website](https://www.dynare.org/download/).
|
||||
|
||||
This release is compatible with MATLAB versions ranging from 9.5 (R2018b) to
|
||||
23.2 (R2023b), and with GNU Octave versions ranging from 7.1.0 to 8.4.0 (NB:
|
||||
the Windows package requires version 8.4.0 specifically).
|
||||
|
||||
Major user-visible changes
|
||||
--------------------------
|
||||
|
||||
- The Sequential Monte Carlo sampler as described by Herbst and Schorfheide
|
||||
(2014) is now available under value `hssmc` for option
|
||||
`posterior_sampling_method`.
|
||||
|
||||
- New routines for perfect foresight simulation with expectation errors. In
|
||||
such a scenario, agents make expectation errors in that the path they had
|
||||
anticipated in period 1 is not realized exactly. More precisely, in some
|
||||
simulation periods, they may receive new information that makes them revise
|
||||
their anticipation for the path of future shocks. Also, under this scenario,
|
||||
it is assumed that agents behave as under perfect foresight, *i.e.* they
|
||||
make their decisions as if there were no uncertainty and they knew exactly
|
||||
the path of future shocks; the new information that they may receive comes
|
||||
as a total surprise to them. Available under new
|
||||
`perfect_foresight_with_expectation_errors_setup` and
|
||||
`perfect_foresight_with_expectation_errors_solver` commands, and
|
||||
`shocks(learnt_in=…)`, `mshocks(learnt_in=…)` and `endval(learnt_in=…)`
|
||||
blocks.
|
||||
|
||||
- New routines for IRF matching with stochastic simulations:
|
||||
|
||||
- Both frequentist (as in Christiano, Eichenbaum, and Evans, 2005) and
|
||||
Bayesian (as in Christiano, Trabandt, and Walentin, 2010) IRF matching
|
||||
approaches are implemented. The core idea of IRF matching is to treat
|
||||
empirical impulse responses (*e.g.* given from an SVAR or local projection
|
||||
estimation) as data and select model parameters that align the model’s
|
||||
IRFs closely with their empirical counterparts.
|
||||
|
||||
- Available under option `mom_method = irf_matching` option to the
|
||||
`method_of_moments` command.
|
||||
|
||||
- New blocks `matched_irfs` and `matched_irfs_weights` for specifying the
|
||||
values and weights of the empirical impulse response functions.
|
||||
|
||||
- Pruning à la Andreasen et al. (2018) is now available at an arbitrary
|
||||
approximation order when performing stochastic simulations with
|
||||
`stoch_simul`, and at 3rd order when performing particle filtering.
|
||||
|
||||
- New `log` option to the `var` statement. In addition to the endogenous
|
||||
variable(s) thus declared, this option also triggers the creation of
|
||||
auxiliary variable(s) equal to the log of the corresponding endogenous
|
||||
variable(s). For example, given a `var(log) y;` statement, two endogenous
|
||||
will be created (`y` and `LOG_y`), and an auxiliary equation linking the two
|
||||
will also be added (equal to `y = exp(LOG_y);`). Moreover, every occurrence
|
||||
of `y` in the model will be replaced by `exp(LOG_y)`. This option is, for
|
||||
example, useful for performing a loglinear approximation of some variable(s)
|
||||
in the context of a first-order stochastic approximation; or for ensuring
|
||||
that the variable(s) stay(s) in the definition domain of the function
|
||||
defining the steady state or the dynamic residuals when the nonlinear solver
|
||||
is used.
|
||||
|
||||
- New model editing features
|
||||
|
||||
- Multiple `model` blocks are now supported (this was already working but
|
||||
not explicitly documented).
|
||||
|
||||
- Multiple `estimated_params` blocks now concatenate their contents (instead
|
||||
of overwriting previous ones, which was the former undocumented behavior);
|
||||
an `overwrite` option has been added to provide the old behavior.
|
||||
|
||||
- New `model_options` statement to set model options in a global fashion.
|
||||
|
||||
- New `model_remove` command to remove equations.
|
||||
|
||||
- New `model_replace` block to replace equations.
|
||||
|
||||
- New `var_remove` command to remove variables (or parameters).
|
||||
|
||||
- New `estimated_params_remove` block to remove estimated parameters.
|
||||
|
||||
- Stochastic simulations
|
||||
|
||||
- Performance improvements for simulation of the solution under perturbation
|
||||
and for particle filtering at higher order (⩾ 3).
|
||||
|
||||
- Performance improvement for the first order perturbation solution using
|
||||
either cycle reduction (`dr=cycle_reduction` option) or logarithmic
|
||||
reduction (`dr=logarithmic_reduction`).
|
||||
|
||||
- New `nomodelsummary` option to the `stoch_simul` command, to suppress the
|
||||
printing of the model summary and the covariance of the exogenous shocks.
|
||||
|
||||
- Estimation
|
||||
|
||||
- A truncated normal distribution can now be specified as a prior, using the
|
||||
3rd and 4th parameters of the `estimated_params` block as the bounds.
|
||||
|
||||
- New `conditional_likelihood` option to the `estimation` command. When the
|
||||
option is set, instead of using the Kalman filter to evaluate the
|
||||
likelihood, Dynare will evaluate the conditional likelihood based on the
|
||||
first-order reduced form of the model by assuming that the initial state
|
||||
vector is at its steady state.
|
||||
|
||||
- New `additional_optimizer_steps` option to the `estimation` command to
|
||||
trigger the sequential execution of several optimizers when looking for
|
||||
the posterior mode.
|
||||
|
||||
- The `generate_trace_plots` command now allows comparing multiple chains.
|
||||
|
||||
- The Geweke and Raftery-Lewis convergence diagnostics will now also be
|
||||
displayed when `mh_nblocks>1`.
|
||||
|
||||
- New `robust`, `TolGstep`, and `TolGstepRel` options to the optimizer
|
||||
available under `mode_compute=5` (“newrat”).
|
||||
|
||||
- New `brooks_gelman_plotrows` option to the `estimation` command for
|
||||
controlling the number of parameters to depict along the rows of the
|
||||
figures depicting the Brooks and Gelman (1998) convergence diagnostics.
|
||||
|
||||
- New `mh_init_scale_factor` option to the `estimation` command tor govern
|
||||
the overdispersion of the starting draws when initializing several Monte
|
||||
Carlo Markov Chains. This option supersedes the `mh_init_scale` option,
|
||||
which is now deprecated.
|
||||
|
||||
- Steady state computation
|
||||
|
||||
- Steady state computation now accounts for occasionally-binding constraints
|
||||
of mixed-complementarity problems (as defined by `mcp` tags).
|
||||
|
||||
- New `tolx` option to the `steady` command for governing the termination
|
||||
based on the step tolerance.
|
||||
|
||||
- New `fsolve_options` option to the `steady` command for passing options to
|
||||
`fsolve` (in conjunction with the `solve_algo=0` option).
|
||||
|
||||
- New option `from_initval_to_endval` option to the `homotopy_setup` block,
|
||||
for easily computing homotopy from initial to terminal steady state (when
|
||||
the former is already computed).
|
||||
|
||||
- New `non_zero` option to `resid` command to restrict display to non-zero
|
||||
residuals.
|
||||
|
||||
- Perfect foresight
|
||||
|
||||
- Significant performance improvement of the `stack_solve_algo=1` option to
|
||||
the `perfect_foresight_solver` command (Laffargue-Boucekkine-Juillard
|
||||
algorithm) when used in conjunction with options `block` and/or `bytecode`
|
||||
of the `model` block.
|
||||
|
||||
- New `relative_to_initval` option to the `mshocks` block, to use the
|
||||
initial steady state as a basis for the multiplication when there is an
|
||||
`endval` block.
|
||||
|
||||
- New `static_mfs` option to the `model` block (and to the `model_options`
|
||||
command), for controlling the minimum feedback set computation for the
|
||||
static model. It defaults to `0` (corresponding to the behavior in Dynare
|
||||
version 5).
|
||||
|
||||
- Various improvements to homotopy
|
||||
|
||||
- New `endval_steady` option to the `perfect_foresight_setup` command for
|
||||
computing the terminal steady state at the same time as the transitory
|
||||
dynamics (and new options `steady_solve_algo`, `steady_tolf`,
|
||||
`steady_tolx`, `steady_maxit` and `steady_markowitz` for controlling the
|
||||
steady state nonlinear solver).
|
||||
|
||||
- New `homotopy_linearization_fallback` and
|
||||
`homotopy_marginal_linearization_fallback` options to the
|
||||
`perfect_foresight_solver` command to get an approximate solution when
|
||||
homotopy fails to go to 100%.
|
||||
|
||||
- New `homotopy_initial_step_size`, `homotopy_min_step_size`,
|
||||
`homotopy_step_size_increase_success_count` and
|
||||
`homotopy_max_completion_share` options to the
|
||||
`perfect_foresight_solver` command to fine tune the homotopy behavior.
|
||||
|
||||
- Purely backward, forward and static models are now supported by the
|
||||
homotopy procedure.
|
||||
|
||||
- The `stack_solve_algo=1` and `stack_solve_algo=6` options of the
|
||||
`perfect_foresight_solver` command were merged and are now synonymous.
|
||||
They both provide the Laffargue-Boucekkine-Juillard algorithm and work
|
||||
with and without the `block` and `bytecode` options of the `model` block.
|
||||
Using `stack_solve_algo=1` is now recommended, but `stack_solve_algo=6` is
|
||||
kept for backward compatibility.
|
||||
|
||||
- OccBin
|
||||
|
||||
- New `simul_reset_check_ahead_periods` option to the `occbin_setup` and
|
||||
`occbin_solver` commands, for resetting `check_ahead_periods` in each
|
||||
simulation period.
|
||||
|
||||
- new `simul_max_check_ahead_periods`, `likelihood_max_check_ahead_periods`,
|
||||
and `smoother_max_check_ahead_periods` options to the `occbin_setup`
|
||||
command, for truncating the number of periods for which agents check ahead
|
||||
which regime is present.
|
||||
|
||||
- Optimal policy
|
||||
|
||||
- The `osr` command now accepts the `analytic_derivation` and
|
||||
`analytic_derivation_mode` options.
|
||||
|
||||
- The `evaluate_planner_objective` command now computes the unconditional
|
||||
welfare for higher-order approximations (⩾ 3).
|
||||
|
||||
- New `periods` and `drop` options to the `evaluate_planner_objective`
|
||||
command.
|
||||
|
||||
- Semi-structural models
|
||||
|
||||
- New `pac_target_info` block for decomposing the PAC target into an
|
||||
arbitrary number of components. Furthermore, in the presence of such a
|
||||
block, the new `pac_target_nonstationary` operator can be used to select
|
||||
the non stationary part of the target (typically useful in the error
|
||||
correction term of the PAC equation).
|
||||
|
||||
- New `kind` option to the `pac_model` command. This option allows the user
|
||||
to select the formula used to compute the weights on the VAR companion
|
||||
matrix variables that are used to form PAC expectations.
|
||||
|
||||
- Performance improvement to `solve_algo=12` and `solve_algo=14`, which
|
||||
significantly accelerates the simulation of purely backward, forward and
|
||||
static models with the `perfect_foresight_solver` command and the routines
|
||||
for semi-structural models.
|
||||
|
||||
- dseries classes
|
||||
|
||||
- The `remove` and `remove_` methods now accept a list of variables (they
|
||||
would previously only accept a single variable).
|
||||
|
||||
- New MATLAB/Octave command `dplot` to plot mathematical expressions
|
||||
generated from variables fetched from (different) dseries objects.
|
||||
|
||||
- Misc
|
||||
|
||||
- New `display_parameter_values` command to print the parameter values in
|
||||
the command window.
|
||||
|
||||
- New `collapse_figures_in_tabgroup` command to dock all figures.
|
||||
|
||||
- Performance improvement for the `use_dll` option of the `model` block. The
|
||||
preprocessor now takes advantage of parallelization when compiling the MEX
|
||||
files.
|
||||
|
||||
- New mathematical primitives available: complementary error function
|
||||
(`erfc`), hyperbolic functions (`cosh`, `sinh`, `tanh`, `acosh`, `asinh`,
|
||||
`atanh`).
|
||||
|
||||
- New `last_simulation_period` option to the `initval_file` command.
|
||||
|
||||
- The `calib_smoother` command now accepts the `nobs` and
|
||||
`heteroskedastic_filter` options.
|
||||
|
||||
- Under the MATLAB Desktop, autocompletion is now available for the `dynare`
|
||||
command and other CLI commands (thanks to Eduard Benet Cerda from
|
||||
MathWorks).
|
||||
|
||||
- Model debugging: The preprocessor now creates files for evaluating the
|
||||
left- and right-hand sides of model equations separately. For a model file
|
||||
called `ramst.mod`, you can call
|
||||
`[lhs,rhs]=ramst.debug.static_resid(y,x,params);` (for the static model)
|
||||
and `[lhs,rhs]=ramst.debug.dynamic_resid(y,x,params,steady_state);` (for
|
||||
the dynamic model), where `y` are the endogenous, `x` the exogenous,
|
||||
`params` the parameters, and `steady_state` is self-explanatory. NB: In
|
||||
the dynamic case, the vector `y` of endogenous must have 3n elements
|
||||
where n is the number of endogenous (including auxiliary ones); the
|
||||
first n elements correspond to the lagged values, the middle n
|
||||
elements to the contemporaneous values, and the last n elements to the
|
||||
lead values.
|
||||
|
||||
- New interactive MATLAB/Octave command `search` for listing the equations
|
||||
in which given variable(s) appear (requires `json` command line option).
|
||||
|
||||
- The `model_info` command allows to print the block decomposition even if
|
||||
the `block` option of the `model` block has not been used, by specifying
|
||||
the new options `block_static` and `block_dynamic`.
|
||||
|
||||
- There is now a default value for the global initialization file
|
||||
(`GlobalInitFile` option of the configuration file): the `global_init.m`
|
||||
in the Dynare configuration directory (typically
|
||||
`$HOME/.config/dynare/global_init.m` under Linux and macOS, and
|
||||
`c:\Users\USERNAME\AppData\Roaming\dynare\global_init.m` under Windows).
|
||||
|
||||
- For those compiling Dynare from source, the build system has been entirely
|
||||
rewritten and now uses Meson; as a consequence, it is now faster and
|
||||
easier to understand.
|
||||
|
||||
- References:
|
||||
|
||||
- Andreasen, Martin M., Jesús Fernández-Villaverde, and Juan Rubio-Ramírez
|
||||
(2018): “The Pruned State-Space System for Non-Linear DSGE Models: Theory
|
||||
and Empirical Applications,” *Review of Economic Studies*, 85(1), 1-49.
|
||||
- Brooks, Stephen P., and Andrew Gelman (1998): “General methods for
|
||||
monitoring convergence of iterative simulations,” *Journal of Computational
|
||||
and Graphical Statistics*, 7, pp. 434–455.
|
||||
- Christiano, Eichenbaum and Charles L. Evans (2005): “Nominal Rigidities and
|
||||
the Dynamic Effects of a Shock to Monetary Policy,” *Journal of Political
|
||||
Economy*, 113(1), 1–45.
|
||||
- Christiano, Lawrence J., Mathias Trabandt, and Karl Walentin (2010): “DSGE
|
||||
Models for Monetary Policy Analysis,” In: *Handbook of Monetary Economics
|
||||
3*, 285–367.
|
||||
- Herbst, Edward and Schorfheide, Frank (2014): "Sequential Monte Carlo
|
||||
Sampling for DSGE Models," *Journal of Applied Econometrics*, 29,
|
||||
1073-1098.
|
||||
|
||||
Incompatible changes
|
||||
--------------------
|
||||
|
||||
- The default value of the `mode_compute` option of the `estimation` command
|
||||
has been changed to `5` (it was previously `4`).
|
||||
|
||||
- When using block decomposition (with the `block` option of the `model`
|
||||
block), the option `mfs` now defaults to `1`. This setting should deliver
|
||||
better performance in perfect foresight simulation on most models.
|
||||
|
||||
- The default location for the configuration file has changed. On Linux and
|
||||
macOS, the configuration file is now searched by default under
|
||||
`dynare/dynare.ini` in the configuration directories defined by the XDG
|
||||
specification (typically `$HOME/.config/dynare/dynare.ini` for the
|
||||
user-specific configuration and `/etc/xdg/dynare/dynare.ini` for the
|
||||
system-wide configuration, the former having precedence over the latter).
|
||||
Under Windows, the configuration file is now searched by default in
|
||||
`%APPDATA%\dynare\dynare.ini` (typically
|
||||
`c:\Users\USERNAME\AppData\Roaming\dynare\dynare.ini`).
|
||||
|
||||
- The information stored in `oo_.endo_simul, oo_.exo_simul`, and `oo_.irfs` is
|
||||
no longer duplicated in the base workspace. New helper functions
|
||||
`send_endogenous_variables_to_workspace`,
|
||||
`send_exogenous_variables_to_workspace`, and `send_irfs_to_workspace` have
|
||||
been introduced to explicitly request these outputs and to mimic the old
|
||||
behavior.
|
||||
|
||||
- The `dynare_sensitivity` command has been renamed `sensitivity`. The old
|
||||
name is still accepted but triggers a warning.
|
||||
|
||||
- The syntax `resid(1)` is no longer supported.
|
||||
|
||||
- The `mode_compute=6` option to the `estimation` command now recursively
|
||||
updates the covariance matrix across the `NumberOfMh` Metropolis-Hastings
|
||||
runs, starting with the `InitialCovarianceMatrix` in the first run, instead
|
||||
of computing it from scratch in every Metropolis-Hastings run.
|
||||
|
||||
- The `periods` command has been removed.
|
||||
|
||||
- The `Sigma_e` command has been removed.
|
||||
|
||||
- The `block` option of the `model` block no longer has an effect when used in
|
||||
conjunction with `stoch_simul` or `estimation` commands.
|
||||
|
||||
- The Dynare++ executable is no longer distributed since almost all of its
|
||||
functionalities have been integrated inside Dynare for MATLAB/Octave.
|
||||
|
||||
- A macro-processor variable defined without a value (such as `@#define var`
|
||||
in the `.mod` file or alternatively `-Dvar` on the `dynare` command line) is
|
||||
now assigned the `true` logical value (it was previously assigned `1`).
|
||||
|
||||
- The `parallel_slave_open_mode` option of the `dynare` command has been
|
||||
renamed `parallel_follower_open_mode`.
|
||||
|
||||
- The `static` option of the `model_info` command is now deprecated and is
|
||||
replaced by the `block_static` option.
|
||||
|
||||
Bugs that were present in 5.5 and that have been fixed in 6.0
|
||||
-------------------------------------------------------------
|
||||
|
||||
* The `mh_initialize_from_previous_mcmc` option of the `estimation` command
|
||||
would not work if estimation was conducted with a different prior and the
|
||||
last draw in the previous MCMC fell outside the new prior bounds
|
||||
* When specifying a generalized inverse Gamma prior, the hyperparameter
|
||||
computation would erroneously ignore the resulting mean shift
|
||||
* When using the `mh_recover` option of the `estimation` command, the status
|
||||
bar always started at zero instead of showing the overall progress of the
|
||||
recovered chain
|
||||
* The `model_diagnostics` command would fail to check the correctness of
|
||||
user-defined steady state files
|
||||
* GSA: LaTeX output was not working as expected
|
||||
* Forecasts and filtered variables could not be retrieved with the
|
||||
`heteroskedastic_shocks` block
|
||||
* The OccBin smoother would potentially not display all smoothed shocks with
|
||||
`heteroskedastic_filter` option
|
||||
* The OccBin smoother would crash if the number of requested periods was
|
||||
smaller than the data length
|
||||
* The multivariate OccBin smoother would return wrong results if the constraint
|
||||
was binding in the first period
|
||||
* The `plot_shock_decomposition` command would fail with the `init2shocks`
|
||||
block if the `initial_condition_decomposition` was not run before
|
||||
* LaTeX output under Windows failed to compile for `plot_priors=1` option of
|
||||
the `estimation` command and Brooks and Gelman (1998) convergence diagnostics
|
||||
* The plot produced by the `shock_decomposition` command was too big, making
|
||||
the close button inaccessible
|
||||
* Monthly dates for October, November and December (*i.e.* with a 2-digit month
|
||||
number) were not properly interpreted by the preprocessor
|
||||
* Theoretical moments computed by `stoch_simul` at `order=2` with `pruning`
|
||||
would not contain unconditional and conditional variance decomposition
|
||||
|
||||
|
||||
Announcement for Dynare 5.5 (on 2023-10-23)
|
||||
===========================================
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ A number of tools and libraries are needed in order to recompile everything. You
|
|||
- [GNU Octave](https://www.octave.org) with
|
||||
- the development headers (if you want to compile the MEX for Octave)
|
||||
- the development libraries corresponding to the [UMFPACK](https://people.engr.tamu.edu/davis/suitesparse.html) packaged with Octave (if you want to compile the MEX for Octave)
|
||||
- Optionally, the [Control](https://octave.sourceforge.io/control/), [IO](https://octave.sourceforge.io/io/), [Optimization](https://octave.sourceforge.io/optim/) and [Statistics](https://octave.sourceforge.io/statistics/) package either installed via your package manager or through [Octave Forge](https://octave.sourceforge.io/).
|
||||
- the [statistics](https://octave.sourceforge.io/statistics/) package and, optionally, the [control](https://octave.sourceforge.io/control/), [io](https://octave.sourceforge.io/io/) and [optimization](https://octave.sourceforge.io/optim/) packages, either installed via your package manager or through [Octave Forge](https://octave.sourceforge.io/)
|
||||
- [Meson](https://mesonbuild.com), version 0.64.0 or later
|
||||
- [Pkgconf](http://pkgconf.org/), or another pkg-config implementation
|
||||
- [Bash](https://www.gnu.org/software/bash/)
|
||||
|
@ -149,9 +149,10 @@ Note that running the testsuite with Octave requires the additional packages `ps
|
|||
|
||||
Often, it does not make sense to run the complete testsuite. For instance, if you modify codes only related to the perfect foresight model solver, you can decide to run only a subset of the integration tests, with:
|
||||
```sh
|
||||
meson test -C <builddir> deterministic_simulations
|
||||
meson test -C <builddir> --suite deterministic_simulations
|
||||
```
|
||||
This will run all the integration tests in `tests/deterministic_simulations`.
|
||||
This syntax also works with a nested directory (e.g. `--suite deterministic_simulations/purely_forward`).
|
||||
|
||||
Finally if you want to run a single integration test, e.g. `deterministic_simulations/lbj/rbc.mod`:
|
||||
```sh
|
||||
|
@ -479,7 +480,7 @@ If you want a certain version (e.g. 5.x) , then add `--single-branch --branch 5.
|
|||
```sh
|
||||
export BUILDDIR=build-matlab
|
||||
export MATLABPATH=/Applications/MATLAB_R2023b.app
|
||||
arch -$ARCH meson setup --native-file scripts/homebrew-native-$ARCH.ini -Dmatlab_path=$MATLABPATH -Dbuildtype=debugoptimized -Dfortran_args="['-B','$DYNAREDIR/slicot/lib']" $BUILDDIR
|
||||
arch -$ARCH meson setup --native-file macOS/homebrew-native-$ARCH.ini -Dmatlab_path=$MATLABPATH -Dbuildtype=debugoptimized -Dfortran_args="['-B','$DYNAREDIR/slicot/lib']" $BUILDDIR
|
||||
```
|
||||
where you need to adapt the path to MATLAB.
|
||||
Similarly, if you want to compile for Octave, replace the `-Dmatlab_path` option by `-Dbuild_for=octave`, and change the build directory to `build-octave`.
|
||||
|
@ -514,4 +515,4 @@ e.g. by adding this to your mod file. Alternatively, you can create a `startup.m
|
|||
## Docker
|
||||
We offer a variety of pre-configured Docker containers for Dynare, pre-configured with Octave and MATLAB including all recommended toolboxes.
|
||||
These are readily available for your convenience on [Docker Hub](https://hub.docker.com/r/dynare/dynare).
|
||||
The docker folder contains [information and instructions](docker/README.md) to interact, built and customize the containers.
|
||||
The `scripts/docker` folder contains [information and instructions](scripts/docker/README.md) to interact, built and customize the containers.
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 5a58fafdca239e61be4d7b2270307b2445bb571a
|
139
doc/gsa/gsa.tex
139
doc/gsa/gsa.tex
|
@ -22,7 +22,7 @@
|
|||
\begin{document}
|
||||
|
||||
% ----------------------------------------------------------------
|
||||
\title{Sensitivity Analysis Toolbox for DYNARE\thanks{Copyright \copyright~2012 Dynare
|
||||
\title{Sensitivity Analysis Toolbox for Dynare\thanks{Copyright \copyright~2012-2024 Dynare
|
||||
Team. Permission is granted to copy, distribute and/or modify
|
||||
this document under the terms of the GNU Free Documentation
|
||||
License, Version 1.3 or any later version published by the Free
|
||||
|
@ -32,9 +32,9 @@
|
|||
|
||||
\author{Marco Ratto\\
|
||||
European Commission, Joint Research Centre \\
|
||||
TP361, IPSC, \\21027 Ispra
|
||||
TP581\\21027 Ispra
|
||||
(VA) Italy\\
|
||||
\texttt{marco.ratto@jrc.ec.europa.eu}
|
||||
\texttt{Marco.Ratto@ec.europa.eu}
|
||||
\thanks{The author gratefully thanks Christophe Planas, Kenneth Judd, Michel Juillard,
|
||||
Alessandro Rossi, Frank Schorfheide and the participants to the
|
||||
Courses on Global Sensitivity Analysis for Macroeconomic
|
||||
|
@ -52,21 +52,21 @@ helpful suggestions.}}
|
|||
|
||||
%-----------------------------------------------------------------------
|
||||
\begin{abstract}
|
||||
\noindent The Sensitivity Analysis Toolbox for DYNARE is a set of
|
||||
\noindent The Sensitivity Analysis Toolbox for Dynare is a set of
|
||||
MATLAB routines for the analysis of DSGE models with global
|
||||
sensitivity analysis. The routines are thought to be used within
|
||||
the DYNARE v4 environment.
|
||||
the Dynare 6 environment.
|
||||
|
||||
|
||||
\begin{description}
|
||||
\item \textbf{Keywords}: Stability Mapping , Reduced form solution, DSGE models,
|
||||
Monte Carlo filtering, Global Sensitivity Analysis.
|
||||
Monte Carlo filtering, Global Sensitivity Analysis.
|
||||
\end{description}
|
||||
\end{abstract}
|
||||
\newpage
|
||||
% ----------------------------------------------------------------
|
||||
\section{Introduction} \label{s:intro}
|
||||
The Sensitivity Analysis Toolbox for DYNARE is a collection of
|
||||
The Sensitivity Analysis Toolbox for Dynare is a collection of
|
||||
MATLAB routines implemented to answer the following questions: (i)
|
||||
Which is the domain of structural coefficients assuring the
|
||||
stability and determinacy of a DSGE model? (ii) Which parameters
|
||||
|
@ -81,20 +81,18 @@ described in \cite{Ratto_CompEcon_2008}.
|
|||
|
||||
|
||||
\section{Use of the Toolbox}
|
||||
The DYNARE parser now recognizes sensitivity analysis commands.
|
||||
The Dynare parser now recognizes sensitivity analysis commands.
|
||||
The syntax is based on a single command:
|
||||
\vspace{0.5cm}
|
||||
|
||||
\verb"dynare_sensitivity(option1=<opt1_val>,option2=<opt2_val>,...)"
|
||||
\verb"sensitivity(option1=<opt1_val>,option2=<opt2_val>,...)"
|
||||
|
||||
\vspace{0.5cm} \noindent with a list of options described in the
|
||||
next section.
|
||||
|
||||
With respect to the previous version of the toolbox, in order to
|
||||
work properly, the sensitivity analysis Toolbox \emph{no longer}
|
||||
needs that the DYNARE estimation environment is set-up.
|
||||
|
||||
Therefore, \verb"dynare_sensitivity" is the only command to run to
|
||||
In order to work properly, the sensitivity analysis Toolbox does not need
|
||||
a Dynare estimation environment to be set up. Rather, \verb"sensitivity"
|
||||
is the only command to run to
|
||||
make a sensitivity analysis on a DSGE model\footnote{Of course,
|
||||
when the user needs to perform the mapping of the fit with a
|
||||
posterior sample, a Bayesian estimation has to be performed
|
||||
|
@ -208,16 +206,17 @@ a multivariate normal MC sample, with covariance matrix based on
|
|||
the inverse Hessian at the optimum: this analysis is useful when
|
||||
ML estimation is done (i.e. no Bayesian estimation);
|
||||
\item when \verb"ppost=1" the Toolbox analyses
|
||||
the RMSE's for the posterior sample obtained by DYNARE's
|
||||
the RMSE's for the posterior sample obtained by Dynare's
|
||||
Metropolis procedure.
|
||||
\end{enumerate}
|
||||
|
||||
The use of cases 2. and 3. requires an estimation step beforehand!
|
||||
The use of cases 2. and 3. require an estimation step beforehand!
|
||||
To facilitate the sensitivity analysis after estimation, the
|
||||
\verb"dynare_sensitivity" command also allows to indicate some
|
||||
options of \verb"dynare_estimation". These are:
|
||||
\verb"sensitivity" command also allows to indicate some
|
||||
options of \verb"estimation". These are:
|
||||
\begin{itemize}
|
||||
\item \verb"datafile"
|
||||
\item \verb"diffuse_filter"
|
||||
\item \verb"mode_file"
|
||||
\item \verb"first_obs"
|
||||
\item \verb"lik_init"
|
||||
|
@ -278,10 +277,10 @@ identifiable.
|
|||
\end{tabular}
|
||||
|
||||
\vspace{1cm}
|
||||
\noindent For example, the following commands in the DYNARE model file
|
||||
\noindent For example, the following commands in the Dynare model file
|
||||
|
||||
\vspace{1cm}
|
||||
\noindent\verb"dynare_sensitivity(identification=1, morris=2);"
|
||||
\noindent\verb"sensitivity(identification=1, morris=2);"
|
||||
|
||||
\vspace{1cm}
|
||||
\noindent trigger the identification analysis using \cite{Iskrev2010,Iskrev2011}, jointly with the mapping of the acceptable region.
|
||||
|
@ -293,75 +292,75 @@ Sensitivity analysis results are saved on the hard-disk of the
|
|||
computer. The Toolbox uses a dedicated folder called \verb"GSA",
|
||||
located in \\
|
||||
\\
|
||||
\verb"<DYNARE_file>\GSA", \\
|
||||
\verb"<Dynare_file>\GSA", \\
|
||||
\\
|
||||
where \verb"<DYNARE_file>.mod" is the name of the DYNARE model
|
||||
where \verb"<Dynare_file>.mod" is the name of the Dynare model
|
||||
file.
|
||||
|
||||
\subsection{Binary data files}
|
||||
A set of binary data files is saved in the \verb"GSA" folder:
|
||||
\begin{description}
|
||||
\item[]\verb"<DYNARE_file>_prior.mat": this file stores
|
||||
\item[]\verb"<Dynare_file>_prior.mat": this file stores
|
||||
information about the analyses performed sampling from the prior
|
||||
ranges, i.e. \verb"pprior=1" and \verb"ppost=0";
|
||||
\item[]\verb"<DYNARE_file>_mc.mat": this file stores
|
||||
\item[]\verb"<Dynare_file>_mc.mat": this file stores
|
||||
information about the analyses performed sampling from
|
||||
multivariate normal, i.e. \verb"pprior=0" and \verb"ppost=0";
|
||||
\item[]\verb"<DYNARE_file>_post.mat": this file stores information
|
||||
\item[]\verb"<Dynare_file>_post.mat": this file stores information
|
||||
about analyses performed using the Metropolis posterior sample,
|
||||
i.e. \verb"ppost=1".
|
||||
\end{description}
|
||||
|
||||
\begin{description}
|
||||
\item[]\verb"<DYNARE_file>_prior_*.mat": these files store
|
||||
\item[]\verb"<Dynare_file>_prior_*.mat": these files store
|
||||
the filtered and smoothed variables for the prior MC sample,
|
||||
generated when doing RMSE analysis (\verb"pprior=1" and
|
||||
\verb"ppost=0");
|
||||
\item[]\verb"<DYNARE_file>_mc_*.mat": these files store
|
||||
\item[]\verb"<Dynare_file>_mc_*.mat": these files store
|
||||
the filtered and smoothed variables for the multivariate normal MC
|
||||
sample, generated when doing RMSE analysis (\verb"pprior=0" and
|
||||
\verb"ppost=0").
|
||||
\end{description}
|
||||
|
||||
\subsection{Stability analysis}
|
||||
Figure files \verb"<DYNARE_file>_prior_*.fig" store results for
|
||||
Figure files \verb"<Dynare_file>_prior_*.fig" store results for
|
||||
the stability mapping from prior MC samples:
|
||||
\begin{description}
|
||||
\item[]\verb"<DYNARE_file>_prior_stab_SA_*.fig": plots of the Smirnov
|
||||
test analyses confronting the cdf of the sample fulfilling
|
||||
Blanchard-Kahn conditions with the cdf of the rest of the sample;
|
||||
\item[]\verb"<DYNARE_file>_prior_stab_indet_SA_*.fig": plots of the Smirnov
|
||||
test analyses confronting the cdf of the sample producing
|
||||
indeterminacy with the cdf of the original prior sample;
|
||||
\item[]\verb"<DYNARE_file>_prior_stab_unst_SA_*.fig": plots of the Smirnov
|
||||
test analyses confronting the cdf of the sample producing unstable
|
||||
(explosive roots) behaviour with the cdf of the original prior
|
||||
\item[]\verb"<Dynare_file>_prior_stab_SA_*.fig": plots of the Smirnov
|
||||
test analyses confronting the CDF of the sample fulfilling
|
||||
Blanchard-Kahn conditions with the CDF of the rest of the sample;
|
||||
\item[]\verb"<Dynare_file>_prior_stab_indet_SA_*.fig": plots of the Smirnov
|
||||
test analyses confronting the CDF of the sample producing
|
||||
indeterminacy with the CDF of the original prior sample;
|
||||
\item[]\verb"<Dynare_file>_prior_stab_unst_SA_*.fig": plots of the Smirnov
|
||||
test analyses confronting the CDF of the sample producing unstable
|
||||
(explosive roots) behaviour with the CDF of the original prior
|
||||
sample;
|
||||
\item[]\verb"<DYNARE_file>_prior_stable_corr_*.fig": plots of
|
||||
\item[]\verb"<Dynare_file>_prior_stable_corr_*.fig": plots of
|
||||
bivariate projections of the sample fulfilling Blanchard-Kahn
|
||||
conditions;
|
||||
\item[]\verb"<DYNARE_file>_prior_indeterm_corr_*.fig": plots of
|
||||
\item[]\verb"<Dynare_file>_prior_indeterm_corr_*.fig": plots of
|
||||
bivariate projections of the sample producing indeterminacy;
|
||||
\item[]\verb"<DYNARE_file>_prior_unstable_corr_*.fig": plots of
|
||||
\item[]\verb"<Dynare_file>_prior_unstable_corr_*.fig": plots of
|
||||
bivariate projections of the sample producing instability;
|
||||
\item[]\verb"<DYNARE_file>_prior_unacceptable_corr_*.fig": plots of
|
||||
\item[]\verb"<Dynare_file>_prior_unacceptable_corr_*.fig": plots of
|
||||
bivariate projections of the sample producing unacceptable
|
||||
solutions, i.e. either instability or indeterminacy or the
|
||||
solution could not be found (e.g. the steady state solution could
|
||||
not be found by the solver).
|
||||
\end{description}
|
||||
Similar conventions apply for \verb"<DYNARE_file>_mc_*.fig" files,
|
||||
Similar conventions apply for \verb"<Dynare_file>_mc_*.fig" files,
|
||||
obtained when samples from multivariate normal are used.
|
||||
|
||||
\subsection{RMSE analysis}
|
||||
Figure files \verb"<DYNARE_file>_rmse_*.fig" store results for the
|
||||
Figure files \verb"<Dynare_file>_rmse_*.fig" store results for the
|
||||
RMSE analysis.
|
||||
\begin{description}
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior*.fig": save results for
|
||||
\item[]\verb"<Dynare_file>_rmse_prior*.fig": save results for
|
||||
the analysis using prior MC samples;
|
||||
\item[]\verb"<DYNARE_file>_rmse_mc*.fig": save results for
|
||||
\item[]\verb"<Dynare_file>_rmse_mc*.fig": save results for
|
||||
the analysis using multivariate normal MC samples;
|
||||
\item[]\verb"<DYNARE_file>_rmse_post*.fig": save results for
|
||||
\item[]\verb"<Dynare_file>_rmse_post*.fig": save results for
|
||||
the analysis using Metropolis posterior samples.
|
||||
\end{description}
|
||||
|
||||
|
@ -369,33 +368,33 @@ The following types of figures are saved (we show prior sample to
|
|||
fix ideas, but the same conventions are used for multivariate
|
||||
normal and posterior):
|
||||
\begin{description}
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior_*.fig": for each parameter, plots the cdf's
|
||||
\item[]\verb"<Dynare_file>_rmse_prior_*.fig": for each parameter, plots the CDF's
|
||||
corresponding to the best 10\% RMES's of each observed series;
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior_dens_*.fig": for each parameter, plots the pdf's
|
||||
\item[]\verb"<Dynare_file>_rmse_prior_dens_*.fig": for each parameter, plots the pdf's
|
||||
corresponding to the best 10\% RMES's of each observed series;
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior_<name of observedseries>_corr_*.fig": for each observed series plots the
|
||||
\item[]\verb"<Dynare_file>_rmse_prior_<name of observedseries>_corr_*.fig": for each observed series plots the
|
||||
bi-dimensional projections of samples with the best 10\% RMSE's,
|
||||
when the correlation is significant;
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior_lnlik*.fig": for each observed
|
||||
series, plots \emph{in red} the cdf of the log-likelihood
|
||||
corresponding to the best 10\% RMSE's, \emph{in green} the cdf of
|
||||
the rest of the sample and \emph{in blue }the cdf of the full
|
||||
\item[]\verb"<Dynare_file>_rmse_prior_lnlik*.fig": for each observed
|
||||
series, plots \emph{in red} the CDF of the log-likelihood
|
||||
corresponding to the best 10\% RMSE's, \emph{in green} the CDF of
|
||||
the rest of the sample and \emph{in blue }the CDF of the full
|
||||
sample; this allows to see the presence of some idiosyncratic
|
||||
behaviour;
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior_lnpost*.fig": for each observed
|
||||
series, plots \emph{in red} the cdf of the log-posterior
|
||||
corresponding to the best 10\% RMSE's, \emph{in green} the cdf of
|
||||
the rest of the sample and \emph{in blue }the cdf of the full
|
||||
\item[]\verb"<Dynare_file>_rmse_prior_lnpost*.fig": for each observed
|
||||
series, plots \emph{in red} the CDF of the log-posterior
|
||||
corresponding to the best 10\% RMSE's, \emph{in green} the CDF of
|
||||
the rest of the sample and \emph{in blue }the CDF of the full
|
||||
sample; this allows to see idiosyncratic behaviour;
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior_lnprior*.fig": for each observed
|
||||
series, plots \emph{in red} the cdf of the log-prior corresponding
|
||||
to the best 10\% RMSE's, \emph{in green} the cdf of the rest of
|
||||
the sample and \emph{in blue }the cdf of the full sample; this
|
||||
\item[]\verb"<Dynare_file>_rmse_prior_lnprior*.fig": for each observed
|
||||
series, plots \emph{in red} the CDF of the log-prior corresponding
|
||||
to the best 10\% RMSE's, \emph{in green} the CDF of the rest of
|
||||
the sample and \emph{in blue }the CDF of the full sample; this
|
||||
allows to see idiosyncratic behaviour;
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior_lik_SA_*.fig": when
|
||||
\item[]\verb"<Dynare_file>_rmse_prior_lik_SA_*.fig": when
|
||||
\verb"lik_only=1", this shows the Smirnov tests for the filtering
|
||||
of the best 10\% log-likelihood values;
|
||||
\item[]\verb"<DYNARE_file>_rmse_prior_post_SA_*.fig": when
|
||||
\item[]\verb"<Dynare_file>_rmse_prior_post_SA_*.fig": when
|
||||
\verb"lik_only=1", this shows the Smirnov test for the filtering
|
||||
of the best 10\% log-posterior values.
|
||||
\end{description}
|
||||
|
@ -405,19 +404,19 @@ In the case of the mapping of the reduced form solution, synthetic
|
|||
figures are saved in the \verb"\GSA" folder:
|
||||
|
||||
\begin{description}
|
||||
\item[]\verb"<DYNARE_file>_redform_<endo name>_vs_lags_*.fig":
|
||||
\item[]\verb"<Dynare_file>_redform_<endo name>_vs_lags_*.fig":
|
||||
shows bar charts of the sensitivity indices for the \emph{ten most
|
||||
important} parameters driving the reduced form coefficients of the
|
||||
selected endogenous variables (\verb"namendo") versus lagged
|
||||
endogenous variables (\verb"namlagendo"); suffix \verb"log"
|
||||
indicates the results for log-transformed entries;
|
||||
\item[]\verb"<DYNARE_file>_redform_<endo name>_vs_shocks_*.fig":
|
||||
\item[]\verb"<Dynare_file>_redform_<endo name>_vs_shocks_*.fig":
|
||||
shows bar charts of the sensitivity indices for the \emph{ten most
|
||||
important} parameters driving the reduced form coefficients of the
|
||||
selected endogenous variables (\verb"namendo") versus exogenous
|
||||
variables (\verb"namexo"); suffix \verb"log" indicates the results
|
||||
for log-transformed entries;
|
||||
\item[]\verb"<DYNARE_file>_redform_GSA(_log).fig": shows bar chart of
|
||||
\item[]\verb"<Dynare_file>_redform_GSA(_log).fig": shows bar chart of
|
||||
all sensitivity indices for each parameter: this allows to notice
|
||||
parameters that have a minor effect for \emph{any} of the reduced
|
||||
form coefficients,
|
||||
|
@ -449,24 +448,24 @@ without the need of any user's intervention.
|
|||
\subsection{Screening analysis}
|
||||
The results of the screening analysis with Morris sampling design
|
||||
are stored in the subfolder \verb"\GSA\SCREEN". The data file
|
||||
\verb"<DYNARE_file>_prior" stores all the information of the
|
||||
\verb"<Dynare_file>_prior" stores all the information of the
|
||||
analysis (Morris sample, reduced form coefficients, etc.).
|
||||
|
||||
Screening analysis merely concerns reduced form coefficients.
|
||||
Similar synthetic bar charts as for the reduced form analysis with
|
||||
MC samples are saved:
|
||||
\begin{description}
|
||||
\item[]\verb"<DYNARE_file>_redform_<endo name>_vs_lags_*.fig":
|
||||
\item[]\verb"<Dynare_file>_redform_<endo name>_vs_lags_*.fig":
|
||||
shows bar charts of the elementary effect tests for the \emph{ten
|
||||
most important} parameters driving the reduced form coefficients
|
||||
of the selected endogenous variables (\verb"namendo") versus
|
||||
lagged endogenous variables (\verb"namlagendo");
|
||||
\item[]\verb"<DYNARE_file>_redform_<endo name>_vs_shocks_*.fig":
|
||||
\item[]\verb"<Dynare_file>_redform_<endo name>_vs_shocks_*.fig":
|
||||
shows bar charts of the elementary effect tests for the \emph{ten
|
||||
most important} parameters driving the reduced form coefficients
|
||||
of the selected endogenous variables (\verb"namendo") versus
|
||||
exogenous variables (\verb"namexo");
|
||||
\item[]\verb"<DYNARE_file>_redform_screen.fig": shows bar chart of
|
||||
\item[]\verb"<Dynare_file>_redform_screen.fig": shows bar chart of
|
||||
all elementary effect tests for each parameter: this allows to
|
||||
identify parameters that have a minor effect for \emph{any} of the
|
||||
reduced form coefficients.
|
||||
|
|
|
@ -2,7 +2,6 @@ function build_internal_documentation()
|
|||
% The name of the function should be explicit...
|
||||
|
||||
datafiles = [];
|
||||
datafiles = [ datafiles ; {'../../matlab/utilities/dataset'}, {'initialize_dataset'}];
|
||||
datafiles = [ datafiles ; {'../../matlab/utilities/dataset'}, {'descriptive_statistics'}];
|
||||
datafiles = [ datafiles ; {'../../matlab/utilities/dataset'}, {'compute_stdv'}];
|
||||
datafiles = [ datafiles ; {'../../matlab/utilities/dataset'}, {'compute_cova'}];
|
||||
|
@ -81,4 +80,4 @@ if rows(miscfiles)
|
|||
fprintf(fid,'\n\n\n');
|
||||
end
|
||||
end
|
||||
fclose(fid);
|
||||
fclose(fid);
|
||||
|
|
|
@ -16,18 +16,20 @@ Bibliography
|
|||
* Bini, Dario A., Guy Latouche, and Beatrice Meini (2002): “Solving matrix polynomial equations arising in queueing problems,” *Linear Algebra and its Applications*, 340, 225–244.
|
||||
* Born, Benjamin and Johannes Pfeifer (2014): “Policy risk and the business cycle”, *Journal of Monetary Economics*, 68, 68-85.
|
||||
* Boucekkine, Raouf (1995): “An alternative methodology for solving nonlinear forward-looking models,” *Journal of Economic Dynamics and Control*, 19, 711–734.
|
||||
* Brayton, Flint and Peter Tinsley (1996): "A Guide to FRB/US: A Macroeconomic Model of the United States", *Finance and Economics Discussion Series*, 1996-42.
|
||||
* Brayton, Flint, Morris Davis and Peter Tulip (2000): "Polynomial Adjustment Costs in FRB/US", *Unpublished manuscript*.
|
||||
* Brayton, Flint and Peter Tinsley (1996): “A Guide to FRB/US: A Macroeconomic Model of the United States,” *Finance and Economics Discussion Series*, 1996-42.
|
||||
* Brayton, Flint, Morris Davis and Peter Tulip (2000): “Polynomial Adjustment Costs in FRB/US,” *Unpublished manuscript*.
|
||||
* Brooks, Stephen P., and Andrew Gelman (1998): “General methods for monitoring convergence of iterative simulations,” *Journal of Computational and Graphical Statistics*, 7, pp. 434–455.
|
||||
* Cardoso, Margarida F., R. L. Salcedo and S. Feyo de Azevedo (1996): “The simplex simulated annealing approach to continuous non-linear optimization,” *Computers & Chemical Engineering*, 20(9), 1065-1080.
|
||||
* Chib, Siddhartha and Srikanth Ramamurthy (2010): “Tailored randomized block MCMC methods with application to DSGE models,” *Journal of Econometrics*, 155, 19–38.
|
||||
* Christiano, Lawrence J., Martin Eichenbaum and Charles L. Evans (2005): “Nominal Rigidities and the Dynamic Effects of a Shock to Monetary Policy,” *Journal of Political Economy*, 113(1), 1–45.
|
||||
* Christiano, Lawrence J., Mathias Trabandt, and Karl Walentin (2010): “DSGE Models for Monetary Policy Analysis,” In: *Handbook of Monetary Economics 3*, 285–367.
|
||||
* Christiano, Lawrence J., Mathias Trabandt and Karl Walentin (2011): “Introducing financial frictions and unemployment into a small open economy model,” *Journal of Economic Dynamics and Control*, 35(12), 1999–2041.
|
||||
* Christoffel, Kai, Günter Coenen and Anders Warne (2010): “Forecasting with DSGE models,” *ECB Working Paper Series*, 1185.
|
||||
* Collard, Fabrice (2001): “Stochastic simulations with Dynare: A practical guide”.
|
||||
* Collard, Fabrice and Michel Juillard (2001a): “Accuracy of stochastic perturbation methods: The case of asset pricing models,” *Journal of Economic Dynamics and Control*, 25, 979–999.
|
||||
* Collard, Fabrice and Michel Juillard (2001b): “A Higher-Order Taylor Expansion Approach to Simulation of Stochastic Forward-Looking Models with an Application to a Non-Linear Phillips Curve,” *Computational Economics*, 17, 125–139.
|
||||
* Corana, Angelo, M. Marchesi, Claudio Martini, and Sandro Ridella (1987): “Minimizing multimodal functions of continuous variables with the “simulated annealing” algorithm”, *ACM Transactions on Mathematical Software*, 13(3), 262–280.
|
||||
* Cuba-Borda, Pablo, Luca Guerrieri, Matteo Iacoviello, and Molin Zhong (2019): "Likelihood evaluation of models with occasionally binding constraints", Journal of Applied Econometrics, 34(7), 1073-1085
|
||||
* Cuba-Borda, Pablo, Luca Guerrieri, Matteo Iacoviello, and Molin Zhong (2019): “Likelihood evaluation of models with occasionally binding constraints,” Journal of Applied Econometrics, 34(7), 1073-1085
|
||||
* Del Negro, Marco and Frank Schorfheide (2004): “Priors from General Equilibrium Models for VARs”, *International Economic Review*, 45(2), 643–673.
|
||||
* Dennis, Richard (2007): “Optimal Policy In Rational Expectations Models: New Solution Algorithms”, *Macroeconomic Dynamics*, 11(1), 31–55.
|
||||
* Duffie, Darrel and Kenneth J. Singleton (1993): “Simulated Moments Estimation of Markov Models of Asset Prices”, *Econometrica*, 61(4), 929-952.
|
||||
|
@ -47,6 +49,7 @@ Bibliography
|
|||
* Hansen, Lars P. (1982): “Large sample properties of generalized method of moments estimators,” Econometrica, 50(4), 1029–1054.
|
||||
* Hansen, Nikolaus and Stefan Kern (2004): “Evaluating the CMA Evolution Strategy on Multimodal Test Functions”. In: *Eighth International Conference on Parallel Problem Solving from Nature PPSN VIII*, Proceedings, Berlin: Springer, 282–291.
|
||||
* Harvey, Andrew C. and Garry D.A. Phillips (1979): “Maximum likelihood estimation of regression models with autoregressive-moving average disturbances,” *Biometrika*, 66(1), 49–58.
|
||||
* Herbst, Edward and Schorfheide, Frank (2014): “Sequential Monte Carlo Sampling for DSGE Models,” *Journal of Applied Econometrics*, 29, 1073-1098.
|
||||
* Herbst, Edward (2015): “Using the “Chandrasekhar Recursions” for Likelihood Evaluation of DSGE Models,” *Computational Economics*, 45(4), 693–705.
|
||||
* Ireland, Peter (2004): “A Method for Taking Models to the Data,” *Journal of Economic Dynamics and Control*, 28, 1205–26.
|
||||
* Iskrev, Nikolay (2010): “Local identification in DSGE models,” *Journal of Monetary Economics*, 57(2), 189–202.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright © 2018-2023 Dynare Team
|
||||
# Copyright © 2018-2024 Dynare Team
|
||||
#
|
||||
# This file is part of Dynare.
|
||||
#
|
||||
|
@ -34,7 +34,7 @@ html_static_path = ['_static']
|
|||
master_doc = 'index'
|
||||
|
||||
project = u'Dynare'
|
||||
copyright = u'1996–2023 Dynare Team'
|
||||
copyright = u'1996–2024 Dynare Team'
|
||||
author = u'Dynare Team'
|
||||
|
||||
add_function_parentheses = False
|
||||
|
@ -71,12 +71,11 @@ latex_elements = {
|
|||
warningBorderColor={RGB}{255,50,50},OuterLinkColor={RGB}{34,139,34}, \
|
||||
InnerLinkColor={RGB}{51,51,255},TitleColor={RGB}{51,51,255}',
|
||||
'papersize': 'a4paper',
|
||||
'preamble': r'\DeclareUnicodeCharacter{200B}{}', # Part of the workaround for #1707
|
||||
}
|
||||
|
||||
latex_documents = [
|
||||
(master_doc, 'dynare-manual.tex', u'Dynare Reference Manual',
|
||||
u'Dynare team', 'manual'),
|
||||
u'Dynare Team', 'manual'),
|
||||
]
|
||||
|
||||
man_pages = [
|
||||
|
|
|
@ -8,6 +8,20 @@
|
|||
Dynare misc commands
|
||||
####################
|
||||
|
||||
.. matcomm:: send_endogenous_variables_to_workspace ;
|
||||
|
||||
Puts the simulation results for the endogenous variables stored in ``oo_.endo_simul``
|
||||
into vectors with the same name as the respective variables into the base workspace.
|
||||
|
||||
.. matcomm:: send_exogenous_variables_to_workspace ;
|
||||
|
||||
Puts the simulation results for the exogenous variables stored in ``oo_.exo_simul``
|
||||
into vectors with the same name as the respective variables into the base workspace.
|
||||
|
||||
.. matcomm:: send_irfs_to_workspace ;
|
||||
|
||||
Puts the IRFs stored in ``oo_.irfs`` into vectors with the same name into the base workspace.
|
||||
|
||||
.. command:: prior_function(OPTIONS);
|
||||
|
||||
Executes a user-defined function on parameter draws from the prior
|
||||
|
@ -216,27 +230,97 @@ Dynare misc commands
|
|||
Searches all occurrences of a variable in a model, and prints the
|
||||
equations where the variable appear in the command line window. If OPTION is
|
||||
set to `withparamvalues`, the values of the parameters (if available) are
|
||||
displayed instead of the name of the parameters.
|
||||
displayed instead of the name of the parameters. Requires the `json` command
|
||||
line option to be set.
|
||||
|
||||
*Example*
|
||||
|
||||
Assuming that we already ran a `.mod` file and that the workspace has not
|
||||
been cleaned after, we can search for all the equations containing variable `X`
|
||||
Assuming that we already ran a `.mod` file and that the workspace has not
|
||||
been cleaned after, we can search for all the equations containing variable `X`
|
||||
|
||||
::
|
||||
::
|
||||
|
||||
>> search X
|
||||
>> search X
|
||||
|
||||
Y = alpha*X/(1-X)+e;
|
||||
Y = alpha*X/(1-X)+e;
|
||||
|
||||
diff(X) = beta*(X(-1)-mX) + gamma1*Z + gamma2*R + u;
|
||||
diff(X) = beta*(X(-1)-mX) + gamma1*Z + gamma2*R + u;
|
||||
|
||||
To replace the parameters with estimated or calibrated parameters:
|
||||
To replace the parameters with estimated or calibrated parameters:
|
||||
|
||||
::
|
||||
::
|
||||
|
||||
>> search X withparamvalues
|
||||
>> search X withparamvalues
|
||||
|
||||
Y = 1.254634*X/(1-X)+e;
|
||||
Y = 1.254634*X/(1-X)+e;
|
||||
|
||||
diff(X) = -0.031459*(X(-1)-mX) + 0.1*Z - 0.2*R + u;
|
||||
diff(X) = -0.031459*(X(-1)-mX) + 0.1*Z - 0.2*R + u;
|
||||
|
||||
|br|
|
||||
|
||||
|
||||
.. matcomm:: dplot [OPTION VALUE[ ...]]
|
||||
|
||||
Plot expressions extracting data from different dseries objects.
|
||||
|
||||
*Options*
|
||||
|
||||
.. option:: --expression EXPRESSION
|
||||
|
||||
``EXPRESSION`` is a mathematical expression involving variables
|
||||
available in the dseries objects, dseries methods, numbers or
|
||||
parameters. All the referenced objects are supposed to be
|
||||
available in the calling workspace.
|
||||
|
||||
.. option:: --dseries NAME
|
||||
|
||||
``NAME`` is the name of a dseries object from which the
|
||||
variables involved in ``EXPRESSION`` will be extracted.
|
||||
|
||||
.. option:: --range DATE1:DATE2
|
||||
|
||||
This option is not mandatory and allows to plot the expressions
|
||||
only over a sub-range. ``DATE1`` and ``DATE2`` must be dates as
|
||||
defined in :ref:`dates in a mod file`.
|
||||
|
||||
.. option:: --style MATLAB_SCRIPT_NAME
|
||||
|
||||
Name of a Matlab script (without extension) containing Matlab
|
||||
commands to customize the produced figure.
|
||||
|
||||
.. option:: --title MATLAB_STRING
|
||||
|
||||
Adds a title to the figure.
|
||||
|
||||
.. option:: --with-legend
|
||||
|
||||
Prints a legend below the produced plot.
|
||||
|
||||
*Remarks*
|
||||
|
||||
- More than one --expression argument is allowed, and they must come first.
|
||||
|
||||
- For each dseries object we plot all the expressions. We use two
|
||||
nested loops, the outer loop is over the dseries objects and the
|
||||
inner loop over the expressions. This determines the ordering of
|
||||
the plotted lines.
|
||||
|
||||
- All dseries objects must be defined in the calling workspace, if a
|
||||
dseries object is missing the routine throws a warning (we only
|
||||
build the plots for the available dseries objects), if all dseries
|
||||
objects are missing the routine throws an error.
|
||||
|
||||
- If the range is not provided, the expressions cannot involve leads or lags.
|
||||
|
||||
*Example*
|
||||
|
||||
::
|
||||
|
||||
>> toto = dseries(randn(100,3), dates('2000Q1'), {'x','y','z'});
|
||||
>> noddy = dseries(randn(100,3), dates('2000Q1'), {'x','y','z'});
|
||||
>> b = 3;
|
||||
>> dplot --expression 2/b*cumsum(x/y(-1)-1) --dseries toto --dseries noddy --range 2001Q1:2024Q1 --title 'This is my plot'
|
||||
|
||||
will produce plots for ``2/b*cumsum(x/y(-1)-1)``, where ``x`` and
|
||||
``y`` are variables in dseries objects ``toto`` and ``noddy``, in
|
||||
the same figure.
|
||||
|
|
|
@ -11,7 +11,7 @@ Currently the development team of Dynare is composed of:
|
|||
* Willi Mutschler (University of Tübingen)
|
||||
* Johannes Pfeifer (University of the Bundeswehr Munich)
|
||||
* Marco Ratto (European Commission, Joint Research Centre - JRC)
|
||||
* Normann Rion (CY Cergy Paris Université and CEPREMAP)
|
||||
* Normann Rion (CEPREMAP)
|
||||
* Sébastien Villemot (CEPREMAP)
|
||||
|
||||
The following people used to be members of the team:
|
||||
|
@ -26,7 +26,7 @@ The following people used to be members of the team:
|
|||
* Ferhat Mihoubi
|
||||
* George Perendia
|
||||
|
||||
Copyright © 1996-2023, Dynare Team.
|
||||
Copyright © 1996-2024, Dynare Team.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ compilation steps are necessary in that case.
|
|||
|
||||
In order to run Dynare, you need one of the following:
|
||||
|
||||
* MATLAB, any version ranging from 8.3 (R2014a) to 23.2 (R2023b);
|
||||
* GNU Octave, any version ranging from 6.2.0 to 8.4.0, with the statistics package
|
||||
* MATLAB, any version ranging from 9.5 (R2018b) to 23.2 (R2023b);
|
||||
* GNU Octave, any version ranging from 7.1.0 to 8.4.0, with the ``statistics`` package
|
||||
from `Octave-Forge`_. Note however that the Dynare installer for Windows
|
||||
requires a more specific version of Octave, as indicated on the download
|
||||
page.
|
||||
|
@ -26,8 +26,8 @@ extra features, but are in no way required:
|
|||
* If under MATLAB: the Optimization Toolbox, the Statistics Toolbox,
|
||||
the Control System Toolbox;
|
||||
|
||||
* If under Octave, the following `Octave-Forge`_ packages: ``optim, io,
|
||||
control``.
|
||||
* If under Octave, the following `Octave-Forge`_ packages: ``optim``, ``io``,
|
||||
``control``.
|
||||
|
||||
|
||||
Installation of Dynare
|
||||
|
|
|
@ -94,26 +94,24 @@ Citing Dynare in your research
|
|||
You should cite Dynare if you use it in your research. The
|
||||
recommended way todo this is to cite the present manual, as:
|
||||
|
||||
Stéphane Adjemian, Houtan Bastani, Michel Juillard, Frédéric Karamé,
|
||||
Ferhat Mihoubi, Willi Mutschler, Johannes Pfeifer, Marco Ratto,
|
||||
Normann Rion and Sébastien Villemot (2022), “Dynare: Reference Manual,
|
||||
Version 5,” *Dynare Working Papers*, 72, CEPREMAP
|
||||
Stéphane Adjemian, Michel Juillard, Frédéric Karamé, Willi Mutschler,
|
||||
Johannes Pfeifer, Marco Ratto, Normann Rion and Sébastien Villemot (2024),
|
||||
“Dynare: Reference Manual, Version 6,” *Dynare Working Papers*, 80, CEPREMAP
|
||||
|
||||
For convenience, you can copy and paste the following into your BibTeX file:
|
||||
|
||||
.. code-block:: bibtex
|
||||
|
||||
@TechReport{Adjemianetal2022,
|
||||
author = {Adjemian, St\'ephane and Bastani, Houtan and
|
||||
Juillard, Michel and Karam\'e, Fr\'ederic and
|
||||
Mihoubi, Ferhat and Mutschler, Willi
|
||||
and Pfeifer, Johannes and Ratto, Marco and
|
||||
@TechReport{Adjemianetal2024,
|
||||
author = {Adjemian, St\'ephane and Juillard, Michel and
|
||||
Karam\'e, Fr\'ederic and Mutschler, Willi and
|
||||
Pfeifer, Johannes and Ratto, Marco and
|
||||
Rion, Normann and Villemot, S\'ebastien},
|
||||
title = {Dynare: Reference Manual Version 5},
|
||||
year = {2022},
|
||||
title = {Dynare: Reference Manual, Version 6},
|
||||
year = {2024},
|
||||
institution = {CEPREMAP},
|
||||
type = {Dynare Working Papers},
|
||||
number = {72},
|
||||
number = {80},
|
||||
}
|
||||
|
||||
If you want to give a URL, use the address of the Dynare website:
|
||||
|
|
|
@ -15,11 +15,16 @@ related to the model (and hence not placed in the model file). At the
|
|||
moment, it is only used when using Dynare to run parallel
|
||||
computations.
|
||||
|
||||
On Linux and macOS, the default location of the configuration file is
|
||||
``$HOME/.dynare``, while on Windows it is ``%APPDATA%\dynare.ini``
|
||||
(typically ``c:\Users\USERNAME\AppData\dynare.ini``). You
|
||||
can specify a non standard location using the ``conffile`` option of
|
||||
the ``dynare`` command (see :ref:`dyn-invoc`).
|
||||
On Linux and macOS, the configuration file is searched by default under
|
||||
``dynare/dynare.ini`` in the configuration directories defined by the XDG
|
||||
specification (typically ``$HOME/.config/dynare/dynare.ini`` for the
|
||||
user-specific configuration and ``/etc/xdg/dynare/dynare.ini`` for the
|
||||
system-wide configuration, the former having precedence over the latter). Under
|
||||
Windows, the configuration file is searched by default in
|
||||
``%APPDATA%\dynare\dynare.ini`` (typically
|
||||
``c:\Users\USERNAME\AppData\Roaming\dynare\dynare.ini``). You can specify a non
|
||||
standard location using the ``conffile`` option of the ``dynare`` command (see
|
||||
:ref:`dyn-invoc`).
|
||||
|
||||
The parsing of the configuration file is case-sensitive and it should
|
||||
take the following form, with each option/choice pair placed on a
|
||||
|
@ -76,8 +81,15 @@ processing. Currently, there is only one option available.
|
|||
|
||||
.. option:: GlobalInitFile = PATH_AND_FILE
|
||||
|
||||
The location of the global initialization file to be run at
|
||||
the end of ``global_initialization.m``.
|
||||
The location of a global initialization file that can be used to
|
||||
customize some Dynare internals (typically default option values). This
|
||||
is a MATLAB/Octave script.
|
||||
|
||||
If this option is not specified, Dynare will look for a
|
||||
``global_init.m`` file in its configuration directory (typically
|
||||
``$HOME/.config/dynare/global_init.m`` under Linux and macOS, and
|
||||
``c:\Users\USERNAME\AppData\Roaming\dynare\global_init.m`` under
|
||||
Windows).
|
||||
|
||||
*Example*
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -22,6 +22,8 @@ Dates
|
|||
=====
|
||||
.. highlight:: matlab
|
||||
|
||||
.. _dates in a mod file:
|
||||
|
||||
Dates in a mod file
|
||||
-------------------
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright © 2018-2019 Dynare Team
|
||||
# Copyright © 2018-2024 Dynare Team
|
||||
#
|
||||
# This file is part of Dynare.
|
||||
#
|
||||
|
@ -80,9 +80,7 @@ class DynObject(ObjectDescription):
|
|||
signode += addnodes.desc_name(name, name)
|
||||
|
||||
if self.has_arguments:
|
||||
if not arglist:
|
||||
signode += addnodes.desc_parameterlist()
|
||||
else:
|
||||
if arglist:
|
||||
signode += addnodes.desc_addname(arglist,arglist)
|
||||
return fullname, prefix
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class DynareLexer(RegexLexer):
|
|||
"addSeries","addParagraph","addVspace","write","compile")
|
||||
|
||||
operators = (
|
||||
"STEADY_STATE","EXPECTATION","var_expectation","pac_expectation")
|
||||
"STEADY_STATE","EXPECTATION","var_expectation","pac_expectation","pac_target_nonstationary")
|
||||
|
||||
macro_dirs = (
|
||||
"@#includepath", "@#include", "@#define", "@#if",
|
||||
|
@ -83,7 +83,8 @@ class DynareLexer(RegexLexer):
|
|||
'osr_params_bounds','ramsey_constraints','irf_calibration',
|
||||
'moment_calibration','identification','svar_identification',
|
||||
'matched_moments','occbin_constraints','surprise','overwrite','bind','relax',
|
||||
'verbatim','end','node','cluster','paths','hooks'), prefix=r'\b', suffix=r'\s*\b'),Keyword.Reserved),
|
||||
'verbatim','end','node','cluster','paths','hooks','target','pac_target_info','auxname_target_nonstationary',
|
||||
'component', 'growth', 'auxname', 'kind'), prefix=r'\b', suffix=r'\s*\b'),Keyword.Reserved),
|
||||
|
||||
# FIXME: Commands following multiline comments are not highlighted properly.
|
||||
(words(commands + report_commands,
|
||||
|
|
|
@ -26,13 +26,17 @@
|
|||
* The model is written in the beginning of period stock notation. To make the model
|
||||
* conform with Dynare’s end of period stock notation, we use the
|
||||
* predetermined_variables-command.
|
||||
*
|
||||
*
|
||||
* The model has been implemented in detrended form, i.e. the \mu_{i,t} are actually
|
||||
* the the growth rates of the original \mu_{i,t}^{orig} in the paper, i.e.
|
||||
* log(\mu_{i,t})=log(\mu_{i,t}^{orig}/\mu_{i,t-1}^{orig})
|
||||
*
|
||||
* Please note that the following copyright notice only applies to this Dynare
|
||||
* implementation of the model.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright © 2013-2020 Dynare Team
|
||||
* Copyright © 2013-2023 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -151,12 +155,12 @@ gammmaPI =1.29;
|
|||
PIbar = 1.01;
|
||||
rhod = 0.12;
|
||||
rhophi = 0.93;
|
||||
sigma_A = -3.97;
|
||||
sigma_d = -1.51;
|
||||
sigma_A = exp(-3.97);
|
||||
sigma_d = exp(-1.51);
|
||||
|
||||
sigma_phi =-2.36;
|
||||
sigma_mu =-5.43;
|
||||
sigma_m =-5.85;
|
||||
sigma_phi =exp(-2.36);
|
||||
sigma_mu =exp(-5.43);
|
||||
sigma_m =exp(-5.85);
|
||||
Lambdamu=3.4e-3;
|
||||
LambdaA = 2.8e-3;
|
||||
|
||||
|
@ -214,7 +218,7 @@ mc=(1/(1-alppha))^(1-alppha)*(1/alppha)^alppha*w^(1-alppha)*r^alppha;
|
|||
1=thetap*(PI(-1)^chi/PI)^(1-epsilon)+(1-thetap)*PIstar^(1-epsilon);
|
||||
|
||||
[name='Taylor Rule']
|
||||
R/Rbar=(R(-1)/Rbar)^gammmaR*((PI/PIbar)^gammmaPI*((yd/yd(-1)*mu_z)/exp(LambdaYd))^gammmay)^(1-gammmaR)*exp(epsm);
|
||||
R/Rbar=(R(-1)/Rbar)^gammmaR*((PI/PIbar)^gammmaPI*((yd/yd(-1)*mu_z)/exp(LambdaYd))^gammmay)^(1-gammmaR)*exp(sigma_m*epsm);
|
||||
|
||||
[name='Resource constraint']
|
||||
yd=c+x+mu_z^(-1)*mu_I^(-1)*(gammma1*(u-1)+gammma2/2*(u-1)^2)*k;
|
||||
|
@ -235,24 +239,24 @@ PIstarw=wstar/w;
|
|||
|
||||
//exogenous processes
|
||||
[name='Preference Shock']
|
||||
log(d)=rhod*log(d(-1))+epsd;
|
||||
log(d)=rhod*log(d(-1))+sigma_d*epsd;
|
||||
[name='Labor disutility Shock']
|
||||
log(phi)=rhophi*log(phi(-1))+epsphi;
|
||||
log(phi)=rhophi*log(phi(-1))+sigma_phi*epsphi;
|
||||
[name='Investment specific technology']
|
||||
log(mu_I)=Lambdamu+epsmu_I;
|
||||
log(mu_I)=Lambdamu+sigma_mu*epsmu_I;
|
||||
[name='Neutral technology']
|
||||
log(mu_A)=LambdaA+epsA;
|
||||
log(mu_A)=LambdaA+sigma_A*epsA;
|
||||
[name='Defininition composite technology']
|
||||
mu_z=mu_A^(1/(1-alppha))*mu_I^(alppha/(1-alppha));
|
||||
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var epsd; stderr exp(sigma_d);
|
||||
var epsphi; stderr exp(sigma_phi);
|
||||
var epsmu_I; stderr exp(sigma_mu);
|
||||
var epsA; stderr exp(sigma_A);
|
||||
var epsm; stderr exp(sigma_m);
|
||||
var epsd; stderr 1;
|
||||
var epsphi; stderr 1;
|
||||
var epsmu_I; stderr 1;
|
||||
var epsA; stderr 1;
|
||||
var epsm; stderr 1;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
Assuming that the dynare++ binary is in your PATH, you can run the example by using the following command
|
||||
in a Command Prompt Window:
|
||||
|
||||
... > dynare++ example1.mod
|
||||
|
||||
Please, read the manual (doc\dynare++\dynare++-tutorial.pdf) for a description of the generated output.
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* This Dynare++ mod-file implements the RBC model with time-to-build
|
||||
* described in Kamenik (2011): "DSGE Models with Dynare++. A Tutorial."
|
||||
* Note that Dynare++ uses the same stock-at-the-end-of-period timing convention
|
||||
* as the regular Dynare
|
||||
*/
|
||||
|
||||
var Y, C, K, A, H, B;
|
||||
|
||||
varexo EPS, NU;
|
||||
|
||||
parameters beta, rho, alpha, delta, theta, psi, tau;
|
||||
|
||||
alpha = 0.36;
|
||||
rho = 0.95;
|
||||
tau = 0.025;
|
||||
beta = 1/(1.03^0.25);
|
||||
delta = 0.025;
|
||||
psi = 0;
|
||||
theta = 2.95;
|
||||
|
||||
model;
|
||||
C*theta*H^(1+psi) = (1-alpha)*Y;
|
||||
beta*exp(B)*C/exp(B(1))/C(1)*
|
||||
(exp(B(1))*alpha*Y(1)/K(1)+1-delta) = 1;
|
||||
Y = exp(A)*K^alpha*H^(1-alpha);
|
||||
K = exp(B(-1))*(Y(-1)-C(-1)) + (1-delta)*K(-1);
|
||||
A = rho*A(-1) + tau*B(-1) + EPS;
|
||||
B = tau*A(-1) + rho*B(-1) + NU;
|
||||
end;
|
||||
|
||||
initval;
|
||||
A = 0;
|
||||
B = 0;
|
||||
H = ((1-alpha)/(theta*(1-(delta*alpha)/(1/beta-1+delta))))^(1/(1+psi));
|
||||
Y = (alpha/(1/beta-1+delta))^(alpha/(1-alpha))*H;
|
||||
K = alpha/(1/beta-1+delta)*Y;
|
||||
C = Y - delta*K;
|
||||
end;
|
||||
|
||||
vcov = [0.0002 0.00005;
|
||||
0.00005 0.0001
|
||||
];
|
||||
|
||||
order = 7;
|
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
* This file replicates the estimation of the cash in advance model (termed M1
|
||||
* in the paper) described in Frank Schorfheide (2000): "Loss function-based
|
||||
* This file replicates the estimation of the cash in advance model (termed M1
|
||||
* in the paper) described in Frank Schorfheide (2000): "Loss function-based
|
||||
* evaluation of DSGE models", Journal of Applied Econometrics, 15(6), 645-670.
|
||||
*
|
||||
* The data are in file "fsdat_simul.m", and have been artificially generated.
|
||||
* They are therefore different from the original dataset used by Schorfheide.
|
||||
* The data are taken from the replication package at
|
||||
* http://dx.doi.org/10.15456/jae.2022314.0708799949
|
||||
*
|
||||
* The prior distribution follows the one originally specified in Schorfheide's
|
||||
* paper, except for parameter rho. In the paper, the elicited beta prior for rho
|
||||
* paper. Note that the elicited beta prior for rho in the paper
|
||||
* implies an asymptote and corresponding prior mode at 0. It is generally
|
||||
* recommended to avoid this extreme type of prior. Some optimizers, for instance
|
||||
* mode_compute=12 (Mathworks' particleswarm algorithm) may find a posterior mode
|
||||
* with rho equal to zero. We lowered the value of the prior standard deviation
|
||||
* (changing .223 to .100) to remove the asymptote.
|
||||
* recommended to avoid this extreme type of prior.
|
||||
*
|
||||
* Because the data are already logged and we use the loglinear option to conduct
|
||||
* a full log-linearization, we need to use the logdata option.
|
||||
*
|
||||
* The equations are taken from J. Nason and T. Cogley (1994): "Testing the
|
||||
* implications of long-run neutrality for monetary business cycle models",
|
||||
* Journal of Applied Econometrics, 9, S37-S70.
|
||||
* Journal of Applied Econometrics, 9, S37-S70, NC in the following.
|
||||
* Note that there is an initial minus sign missing in equation (A1), p. S63.
|
||||
*
|
||||
* This implementation was originally written by Michel Juillard. Please note that the
|
||||
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright © 2004-2017 Dynare Team
|
||||
* Copyright © 2004-2023 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -43,33 +43,71 @@
|
|||
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var m P c e W R k d n l gy_obs gp_obs y dA;
|
||||
varexo e_a e_m;
|
||||
var m ${m}$ (long_name='money growth')
|
||||
P ${P}$ (long_name='Price level')
|
||||
c ${c}$ (long_name='consumption')
|
||||
e ${e}$ (long_name='capital stock')
|
||||
W ${W}$ (long_name='Wage rate')
|
||||
R ${R}$ (long_name='interest rate')
|
||||
k ${k}$ (long_name='capital stock')
|
||||
d ${d}$ (long_name='dividends')
|
||||
n ${n}$ (long_name='labor')
|
||||
l ${l}$ (long_name='loans')
|
||||
gy_obs ${\Delta \ln GDP}$ (long_name='detrended capital stock')
|
||||
gp_obs ${\Delta \ln P}$ (long_name='detrended capital stock')
|
||||
y ${y}$ (long_name='detrended output')
|
||||
dA ${\Delta A}$ (long_name='TFP growth')
|
||||
;
|
||||
varexo e_a ${\epsilon_A}$ (long_name='TFP shock')
|
||||
e_m ${\epsilon_M}$ (long_name='Money growth shock')
|
||||
;
|
||||
|
||||
parameters alp bet gam mst rho psi del;
|
||||
parameters alp ${\alpha}$ (long_name='capital share')
|
||||
bet ${\beta}$ (long_name='discount factor')
|
||||
gam ${\gamma}$ (long_name='long-run TFP growth')
|
||||
logmst ${\log(m^*)}$ (long_name='long-run money growth')
|
||||
rho ${\rho}$ (long_name='autocorrelation money growth')
|
||||
phi ${\phi}$ (long_name='labor weight in consumption')
|
||||
del ${\delta}$ (long_name='depreciation rate')
|
||||
;
|
||||
|
||||
% roughly picked values to allow simulating the model before estimation
|
||||
alp = 0.33;
|
||||
bet = 0.99;
|
||||
gam = 0.003;
|
||||
mst = 1.011;
|
||||
logmst = log(1.011);
|
||||
rho = 0.7;
|
||||
psi = 0.787;
|
||||
phi = 0.787;
|
||||
del = 0.02;
|
||||
|
||||
model;
|
||||
[name='NC before eq. (1), TFP growth equation']
|
||||
dA = exp(gam+e_a);
|
||||
log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
|
||||
[name='NC eq. (2), money growth rate']
|
||||
log(m) = (1-rho)*logmst + rho*log(m(-1))+e_m;
|
||||
[name='NC eq. (A1), Euler equation']
|
||||
-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
|
||||
[name='NC below eq. (A1), firm borrowing constraint']
|
||||
W = l/n;
|
||||
-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
|
||||
[name='NC eq. (A2), intratemporal labour market condition']
|
||||
-(phi/(1-phi))*(c*P/(1-n))+l/n = 0;
|
||||
[name='NC below eq. (A2), credit market clearing']
|
||||
R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
|
||||
[name='NC eq. (A3), credit market optimality']
|
||||
1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
|
||||
[name='NC eq. (18), aggregate resource constraint']
|
||||
c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
|
||||
[name='NC eq. (19), money market condition']
|
||||
P*c = m;
|
||||
[name='NC eq. (20), credit market equilibrium condition']
|
||||
m-1+d = l;
|
||||
[name='Definition TFP shock']
|
||||
e = exp(e_a);
|
||||
[name='Implied by NC eq. (18), production function']
|
||||
y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
|
||||
[name='Observation equation GDP growth']
|
||||
gy_obs = dA*y/y(-1);
|
||||
[name='Observation equation price level']
|
||||
gp_obs = (P/P(-1))*m(-1)/dA;
|
||||
end;
|
||||
|
||||
|
@ -81,40 +119,41 @@ end;
|
|||
steady_state_model;
|
||||
dA = exp(gam);
|
||||
gst = 1/dA;
|
||||
m = mst;
|
||||
m = exp(logmst);
|
||||
khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
|
||||
xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
|
||||
nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
|
||||
xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/m )^(-1);
|
||||
nust = phi*m^2/( (1-alp)*(1-phi)*bet*gst^alp*khst^alp );
|
||||
n = xist/(nust+xist);
|
||||
P = xist + nust;
|
||||
k = khst*n;
|
||||
|
||||
l = psi*mst*n/( (1-psi)*(1-n) );
|
||||
c = mst/P;
|
||||
d = l - mst + 1;
|
||||
l = phi*m*n/( (1-phi)*(1-n) );
|
||||
c = m/P;
|
||||
d = l - m + 1;
|
||||
y = k^alp*n^(1-alp)*gst^alp;
|
||||
R = mst/bet;
|
||||
R = m/bet;
|
||||
W = l/n;
|
||||
ist = y-c;
|
||||
q = 1 - d;
|
||||
|
||||
e = 1;
|
||||
|
||||
|
||||
gp_obs = m/dA;
|
||||
gy_obs = dA;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
steady;
|
||||
check;
|
||||
|
||||
% Table 1 of Schorfheide (2000)
|
||||
estimated_params;
|
||||
alp, beta_pdf, 0.356, 0.02;
|
||||
bet, beta_pdf, 0.993, 0.002;
|
||||
gam, normal_pdf, 0.0085, 0.003;
|
||||
mst, normal_pdf, 1.0002, 0.007;
|
||||
rho, beta_pdf, 0.129, 0.100;
|
||||
psi, beta_pdf, 0.65, 0.05;
|
||||
logmst, normal_pdf, 0.0002, 0.007;
|
||||
rho, beta_pdf, 0.129, 0.223;
|
||||
phi, beta_pdf, 0.65, 0.05;
|
||||
del, beta_pdf, 0.01, 0.005;
|
||||
stderr e_a, inv_gamma_pdf, 0.035449, inf;
|
||||
stderr e_m, inv_gamma_pdf, 0.008862, inf;
|
||||
|
@ -122,14 +161,8 @@ end;
|
|||
|
||||
varobs gp_obs gy_obs;
|
||||
|
||||
estimation(order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8, mode_check);
|
||||
estimation(order=1, datafile=fs2000_data, loglinear,logdata, mode_compute=4, mh_replic=20000, nodiagnostic, mh_nblocks=2, mh_jscale=0.8, mode_check);
|
||||
|
||||
|
||||
/*
|
||||
* The following lines were used to generate the data file. If you want to
|
||||
* generate another random data file, comment the "estimation" line and uncomment
|
||||
* the following lines.
|
||||
*/
|
||||
|
||||
//stoch_simul(periods=200, order=1);
|
||||
//datatomfile('fsdat_simul', {'gy_obs', 'gp_obs'});
|
||||
%uncomment the following lines to generate LaTeX-code of the model equations
|
||||
%write_latex_original_model(write_equation_tags);
|
||||
%collect_latex_files;
|
||||
|
|
|
@ -0,0 +1,215 @@
|
|||
%This file is a direct Matlab implementation of the loaddata.g and data.prn files
|
||||
%of Schorfheide, Frank (2000): Loss function-based evaluation of DSGE models
|
||||
%(replication data). Version: 1. Journal of Applied Econometrics. Dataset.
|
||||
%http://dx.doi.org/10.15456/jae.2022314.0708799949
|
||||
% Copyright: 2000-2022 Frank Schorfheide
|
||||
% Copyright: 2023 Dynare Team
|
||||
|
||||
% License: CC BY 4.0
|
||||
% (https://creativecommons.org/licenses/by/4.0/legalcode)
|
||||
|
||||
% Time series, extracted 05/04/00
|
||||
% columms are quarterly data from 1949:IV to 1997:IV
|
||||
% 1: GDPD = GROSS DOMESTIC PRODUCT:IMPLICIT PRICE DEFLATOR (INDEX,92=100)(T7.1)
|
||||
% 2: GDPQ = GROSS DOMESTIC PRODUCT
|
||||
% 3: GPOP = POPULATION, NIPA basis (THOUS.,NSA)
|
||||
|
||||
data_q=[18.02 1474.5 150.2
|
||||
17.94 1538.2 150.9
|
||||
18.01 1584.5 151.4
|
||||
18.42 1644.1 152
|
||||
18.73 1678.6 152.7
|
||||
19.46 1693.1 153.3
|
||||
19.55 1724 153.9
|
||||
19.56 1758.2 154.7
|
||||
19.79 1760.6 155.4
|
||||
19.77 1779.2 156
|
||||
19.82 1778.8 156.6
|
||||
20.03 1790.9 157.3
|
||||
20.12 1846 158
|
||||
20.1 1882.6 158.6
|
||||
20.14 1897.3 159.2
|
||||
20.22 1887.4 160
|
||||
20.27 1858.2 160.7
|
||||
20.34 1849.9 161.4
|
||||
20.39 1848.5 162
|
||||
20.42 1868.9 162.8
|
||||
20.47 1905.6 163.6
|
||||
20.56 1959.6 164.3
|
||||
20.62 1994.4 164.9
|
||||
20.78 2020.1 165.7
|
||||
21 2030.5 166.5
|
||||
21.2 2023.6 167.2
|
||||
21.33 2037.7 167.9
|
||||
21.62 2033.4 168.7
|
||||
21.71 2066.2 169.5
|
||||
22.01 2077.5 170.2
|
||||
22.15 2071.9 170.9
|
||||
22.27 2094 171.7
|
||||
22.29 2070.8 172.5
|
||||
22.56 2012.6 173.1
|
||||
22.64 2024.7 173.8
|
||||
22.77 2072.3 174.5
|
||||
22.88 2120.6 175.3
|
||||
22.92 2165 176.045
|
||||
22.91 2223.3 176.727
|
||||
22.94 2221.4 177.481
|
||||
23.03 2230.95 178.268
|
||||
23.13 2279.22 179.694
|
||||
23.22 2265.48 180.335
|
||||
23.32 2268.29 181.094
|
||||
23.4 2238.57 181.915
|
||||
23.45 2251.68 182.634
|
||||
23.51 2292.02 183.337
|
||||
23.56 2332.61 184.103
|
||||
23.63 2381.01 184.894
|
||||
23.75 2422.59 185.553
|
||||
23.81 2448.01 186.203
|
||||
23.87 2471.86 186.926
|
||||
23.94 2476.67 187.68
|
||||
24 2508.7 188.299
|
||||
24.07 2538.05 188.906
|
||||
24.12 2586.26 189.631
|
||||
24.29 2604.62 190.362
|
||||
24.35 2666.69 190.954
|
||||
24.41 2697.54 191.56
|
||||
24.52 2729.63 192.256
|
||||
24.64 2739.75 192.938
|
||||
24.77 2808.88 193.467
|
||||
24.88 2846.34 193.994
|
||||
25.01 2898.79 194.647
|
||||
25.17 2970.48 195.279
|
||||
25.32 3042.35 195.763
|
||||
25.53 3055.53 196.277
|
||||
25.79 3076.51 196.877
|
||||
26.02 3102.36 197.481
|
||||
26.14 3127.15 197.967
|
||||
26.31 3129.53 198.455
|
||||
26.6 3154.19 199.012
|
||||
26.9 3177.98 199.572
|
||||
27.21 3236.18 199.995
|
||||
27.49 3292.07 200.452
|
||||
27.75 3316.11 200.997
|
||||
28.12 3331.22 201.538
|
||||
28.39 3381.86 201.955
|
||||
28.73 3390.23 202.419
|
||||
29.14 3409.65 202.986
|
||||
29.51 3392.6 203.584
|
||||
29.94 3386.49 204.086
|
||||
30.36 3391.61 204.721
|
||||
30.61 3422.95 205.419
|
||||
31.02 3389.36 206.13
|
||||
31.5 3481.4 206.763
|
||||
31.93 3500.95 207.362
|
||||
32.27 3523.8 208
|
||||
32.54 3533.79 208.642
|
||||
33.02 3604.73 209.142
|
||||
33.2 3687.9 209.637
|
||||
33.49 3726.18 210.181
|
||||
33.95 3790.44 210.737
|
||||
34.36 3892.22 211.192
|
||||
34.94 3919.01 211.663
|
||||
35.61 3907.08 212.191
|
||||
36.29 3947.11 212.708
|
||||
37.01 3908.15 213.144
|
||||
37.79 3922.57 213.602
|
||||
38.96 3879.98 214.147
|
||||
40.13 3854.13 214.7
|
||||
41.05 3800.93 215.135
|
||||
41.66 3835.21 215.652
|
||||
42.41 3907.02 216.289
|
||||
43.19 3952.48 216.848
|
||||
43.69 4044.59 217.314
|
||||
44.15 4072.19 217.776
|
||||
44.77 4088.49 218.338
|
||||
45.57 4126.39 218.917
|
||||
46.32 4176.28 219.427
|
||||
47.07 4260.08 219.956
|
||||
47.66 4329.46 220.573
|
||||
48.63 4328.33 221.201
|
||||
49.42 4345.51 221.719
|
||||
50.41 4510.73 222.281
|
||||
51.27 4552.14 222.933
|
||||
52.35 4603.65 223.583
|
||||
53.51 4605.65 224.152
|
||||
54.65 4615.64 224.737
|
||||
55.82 4644.93 225.418
|
||||
56.92 4656.23 226.117
|
||||
58.18 4678.96 226.754
|
||||
59.55 4566.62 227.389
|
||||
61.01 4562.25 228.07
|
||||
62.59 4651.86 228.689
|
||||
64.15 4739.16 229.155
|
||||
65.37 4696.82 229.674
|
||||
66.65 4753.02 230.301
|
||||
67.87 4693.76 230.903
|
||||
68.86 4615.89 231.395
|
||||
69.72 4634.88 231.906
|
||||
70.66 4612.08 232.498
|
||||
71.44 4618.26 233.074
|
||||
72.08 4662.97 233.546
|
||||
72.83 4763.57 234.028
|
||||
73.48 4849 234.603
|
||||
74.19 4939.23 235.153
|
||||
75.02 5053.56 235.605
|
||||
75.58 5132.87 236.082
|
||||
76.25 5170.34 236.657
|
||||
76.81 5203.68 237.232
|
||||
77.63 5257.26 237.673
|
||||
78.25 5283.73 238.176
|
||||
78.76 5359.6 238.789
|
||||
79.45 5393.57 239.387
|
||||
79.81 5460.83 239.861
|
||||
80.22 5466.95 240.368
|
||||
80.84 5496.29 240.962
|
||||
81.45 5526.77 241.539
|
||||
82.09 5561.8 242.009
|
||||
82.68 5618 242.52
|
||||
83.33 5667.39 243.12
|
||||
84.09 5750.57 243.721
|
||||
84.67 5785.29 244.208
|
||||
85.56 5844.05 244.716
|
||||
86.66 5878.7 245.354
|
||||
87.44 5952.83 245.966
|
||||
88.45 6010.96 246.46
|
||||
89.39 6055.61 247.017
|
||||
90.13 6087.96 247.698
|
||||
90.88 6093.51 248.374
|
||||
92 6152.59 248.928
|
||||
93.18 6171.57 249.564
|
||||
94.14 6142.1 250.299
|
||||
95.11 6078.96 251.031
|
||||
96.27 6047.49 251.65
|
||||
97 6074.66 252.295
|
||||
97.7 6090.14 253.033
|
||||
98.31 6105.25 253.743
|
||||
99.13 6175.69 254.338
|
||||
99.79 6214.22 255.032
|
||||
100.17 6260.74 255.815
|
||||
100.88 6327.12 256.543
|
||||
101.84 6327.93 257.151
|
||||
102.35 6359.9 257.785
|
||||
102.83 6393.5 258.516
|
||||
103.51 6476.86 259.191
|
||||
104.13 6524.5 259.738
|
||||
104.71 6600.31 260.351
|
||||
105.39 6629.47 261.04
|
||||
106.09 6688.61 261.692
|
||||
106.75 6717.46 262.236
|
||||
107.24 6724.2 262.847
|
||||
107.75 6779.53 263.527
|
||||
108.29 6825.8 264.169
|
||||
108.91 6882 264.681
|
||||
109.24 6983.91 265.258
|
||||
109.74 7020 265.887
|
||||
110.23 7093.12 266.491
|
||||
111 7166.68 266.987
|
||||
111.43 7236.5 267.545
|
||||
111.76 7311.24 268.171
|
||||
112.08 7364.63 268.815];
|
||||
|
||||
%Compute growth rates: from 1950:I to 1997:IV
|
||||
gy_obs=1000*data_q(:,2)./data_q(:,3); %real GDP per capita
|
||||
gy_obs=diff(log(gy_obs));
|
||||
|
||||
gp_obs = diff(log(data_q(:,1))); %GDP deflator inflation
|
|
@ -0,0 +1,101 @@
|
|||
// --+ options: json=compute, stochastic +--
|
||||
|
||||
var y x z v;
|
||||
|
||||
varexo ex ey ez ;
|
||||
|
||||
parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 d_y; // VAR parameters
|
||||
|
||||
parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters
|
||||
|
||||
a_y_1 = .2;
|
||||
a_y_2 = .3;
|
||||
b_y_1 = .1;
|
||||
b_y_2 = .4;
|
||||
b_x_1 = -.1;
|
||||
b_x_2 = -.2;
|
||||
d_y = .5;
|
||||
|
||||
|
||||
beta = .9;
|
||||
e_c_m = .1;
|
||||
c_z_1 = .7;
|
||||
c_z_2 = -.3;
|
||||
|
||||
var_model(model_name=toto, eqtags=['eq:x', 'eq:y']);
|
||||
|
||||
pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman);
|
||||
|
||||
pac_target_info(pacman);
|
||||
target v;
|
||||
auxname_target_nonstationary vns;
|
||||
|
||||
component y;
|
||||
auxname pv_y_;
|
||||
kind ll;
|
||||
|
||||
component x;
|
||||
growth diff(x(-1));
|
||||
auxname pv_dx_;
|
||||
kind dd;
|
||||
|
||||
end;
|
||||
|
||||
model;
|
||||
|
||||
[name='eq:y']
|
||||
y = a_y_1*y(-1) + a_y_2*diff(x(-1)) + b_y_1*y(-2) + b_y_2*diff(x(-2)) + ey ;
|
||||
|
||||
|
||||
[name='eq:x']
|
||||
diff(x) = b_x_1*y(-2) + b_x_2*diff(x(-1)) + ex ;
|
||||
|
||||
[name='eq:v']
|
||||
v = x + d_y*y ; // Composite target, no residuals here only variables defined in the auxiliary VAR model.
|
||||
|
||||
[name='zpac']
|
||||
diff(z) = e_c_m*(pac_target_nonstationary(pacman)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez;
|
||||
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var ex = .10;
|
||||
var ey = .15;
|
||||
var ez = .05;
|
||||
end;
|
||||
|
||||
// Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
|
||||
pac.initialize('pacman');
|
||||
|
||||
// Update the parameters of the PAC expectation model (h0 and h1 vectors).
|
||||
pac.update.expectation('pacman');
|
||||
|
||||
/*
|
||||
**
|
||||
** Simulate artificial dataset
|
||||
**
|
||||
*/
|
||||
|
||||
// Set initial conditions to zero.
|
||||
initialconditions = dseries(zeros(10, M_.endo_nbr+M_.exo_nbr), 2000Q1, vertcat(M_.endo_names,M_.exo_names));
|
||||
|
||||
// Simulate the model for 5000 periods
|
||||
TrueData = simul_backward_model(initialconditions, 5000);
|
||||
|
||||
/*
|
||||
**
|
||||
** Estimate PAC equation (using the artificial data)
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
// Provide initial conditions for the estimated parameters
|
||||
clear eparams
|
||||
eparams.e_c_m = .9;
|
||||
eparams.c_z_1 = .5;
|
||||
eparams.c_z_2 = .2;
|
||||
|
||||
edata = TrueData; // Set the dataset used for estimation
|
||||
edata.ez = dseries(NaN, 2000Q1); // Remove residuals for the PAC equation from the database.
|
||||
|
||||
pac.estimate.nls('zpac', eparams, edata, 2005Q1:2005Q1+4000, 'fmincon'); // Should produce a table with the estimates (close to the calibration given in lines 21-23)
|
142
license.txt
142
license.txt
|
@ -1,6 +1,6 @@
|
|||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: Dynare
|
||||
Upstream-Contact: Dynare Team, whose members in 2023 are:
|
||||
Upstream-Contact: Dynare Team, whose members in 2024 are:
|
||||
- Stéphane Adjemian <stephane.adjemian@univ-lemans.fr>
|
||||
- Michel Juillard <michel.juillard@mjui.fr>
|
||||
- Frédéric Karamé <frederic.karame@univ-lemans.fr>
|
||||
|
@ -23,7 +23,7 @@ Upstream-Contact: Dynare Team, whose members in 2023 are:
|
|||
Source: https://www.dynare.org
|
||||
|
||||
Files: *
|
||||
Copyright: 1996-2023 Dynare Team
|
||||
Copyright: 1996-2024 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/+occbin/IVF_core.m
|
||||
|
@ -86,7 +86,7 @@ License: public-domain-aim
|
|||
Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
|
||||
pages 472-489
|
||||
|
||||
Files: matlab/optimization/bfgsi1.m matlab/csolve.m matlab/optimization/csminit1.m matlab/optimization/numgrad2.m
|
||||
Files: matlab/optimization/bfgsi1.m matlab/optimization/csolve.m matlab/optimization/csminit1.m matlab/optimization/numgrad2.m
|
||||
matlab/optimization/numgrad3.m matlab/optimization/numgrad3_.m matlab/optimization/numgrad5.m
|
||||
matlab/optimization/numgrad5_.m matlab/optimization/csminwel1.m matlab/+bvar/density.m
|
||||
matlab/+bvar/toolbox.m matlab/partial_information/PI_gensys.m matlab/partial_information/qzswitch.m
|
||||
|
@ -113,7 +113,7 @@ Copyright: 1995 E.G.Tsionas
|
|||
2015-2017 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/endogenous_prior.m
|
||||
Files: matlab/estimation/endogenous_prior.m
|
||||
Copyright: 2011 Lawrence J. Christiano, Mathias Trabandt and Karl Walentin
|
||||
2013-2017 Dynare Team
|
||||
License: GPL-3+
|
||||
|
@ -123,12 +123,17 @@ Copyright: 2010-2015 Alexander Meyer-Gohde
|
|||
2015-2017 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/collapse_figures_in_tabgroup.m
|
||||
Copyright: 2023 Eduard Benet Cerda
|
||||
2024 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/convergence_diagnostics/raftery_lewis.m
|
||||
Copyright: 2016 Benjamin Born and Johannes Pfeifer
|
||||
2016-2017 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/commutation.m matlab/duplication.m
|
||||
Files: matlab/+pruned_SS/commutation.m matlab/+pruned_SS/duplication.m
|
||||
Copyright: 1997 Tom Minka <minka@microsoft.com>
|
||||
2019-2020 Dynare Team
|
||||
License: GPL-3+
|
||||
|
@ -141,7 +146,7 @@ Comment: The original author gave authorization to change
|
|||
the license from BSD-2-clause to GPL-3+ and redistribute
|
||||
it under GPL-3+ with Dynare.
|
||||
|
||||
Files: matlab/uperm.m
|
||||
Files: matlab/+pruned_SS/uperm.m
|
||||
Copyright: 2014 Bruno Luong <brunoluong@yahoo.com>
|
||||
2020 Dynare Team
|
||||
License: GPL-3+
|
||||
|
@ -149,9 +154,9 @@ Comment: The original author gave authorization to change
|
|||
the license from BSD-2-clause to GPL-3+ and redistribute
|
||||
it under GPL-3+ with Dynare.
|
||||
|
||||
Files: matlab/prodmom.m matlab/bivmom.m
|
||||
Files: matlab/+pruned_SS/prodmom.m matlab/+pruned_SS/bivmom.m
|
||||
Copyright: 2008-2015 Raymond Kan <kan@chass.utoronto.ca>
|
||||
2019-2020 Dynare Team
|
||||
2019-2023 Dynare Team
|
||||
License: GPL-3+
|
||||
Comment: The author gave authorization to redistribute
|
||||
these functions under GPL-3+ with Dynare and would
|
||||
|
@ -161,57 +166,37 @@ Comment: The author gave authorization to redistribute
|
|||
Journal of Multivariate Analysis, 2008, vol. 99, issue 3,
|
||||
pages 542-554.
|
||||
|
||||
Files: matlab/gsa/Morris_Measure_Groups.m
|
||||
matlab/gsa/Sampling_Function_2.m
|
||||
Files: matlab/+gsa/Morris_Measure_Groups.m
|
||||
matlab/+gsa/Sampling_Function_2.m
|
||||
Copyright: 2005 European Commission
|
||||
2012-2017 Dynare Team
|
||||
2012-2013 Dynare Team
|
||||
License: GPL-3+
|
||||
Comment: Written by Jessica Cariboni and Francesca Campolongo
|
||||
Joint Research Centre, The European Commission,
|
||||
|
||||
Files: matlab/gsa/cumplot.m
|
||||
matlab/gsa/filt_mc_.m
|
||||
matlab/gsa/gsa_plotmatrix.m
|
||||
matlab/gsa/gsa_skewness.m
|
||||
matlab/gsa/gsa_speed.m
|
||||
matlab/gsa/log_trans_.m
|
||||
matlab/gsa/map_calibration.m
|
||||
matlab/gsa/map_ident_.m
|
||||
matlab/gsa/mcf_analysis.m
|
||||
matlab/gsa/myboxplot.m
|
||||
matlab/gsa/myprctilecol.m
|
||||
matlab/gsa/prior_draw_gsa.m
|
||||
matlab/gsa/read_data.m
|
||||
matlab/gsa/redform_map.m
|
||||
matlab/gsa/redform_screen.m
|
||||
matlab/gsa/scatter_mcf.m
|
||||
matlab/gsa/smirnov.m
|
||||
matlab/gsa/stab_map_.m
|
||||
matlab/gsa/stab_map_1.m
|
||||
matlab/gsa/stab_map_2.m
|
||||
matlab/gsa/stand_.m
|
||||
matlab/gsa/tcrit.m
|
||||
matlab/gsa/teff.m
|
||||
matlab/gsa/trank.m
|
||||
Files: matlab/+gsa/cumplot.m
|
||||
matlab/+gsa/monte_carlo_filtering.m
|
||||
matlab/+gsa/skewness.m
|
||||
matlab/+gsa/log_transform.m
|
||||
matlab/+gsa/map_calibration.m
|
||||
matlab/+gsa/map_identification.m
|
||||
matlab/+gsa/monte_carlo_filtering_analysis.m
|
||||
matlab/+gsa/boxplot.m
|
||||
matlab/+gsa/prior_draw.m
|
||||
matlab/+gsa/reduced_form_mapping.m
|
||||
matlab/+gsa/reduced_form_screening.m
|
||||
matlab/+gsa/scatter_mcf.m
|
||||
matlab/+gsa/smirnov_test.m
|
||||
matlab/+gsa/stability_mapping.m
|
||||
matlab/+gsa/stability_mapping_univariate.m
|
||||
matlab/+gsa/stability_mapping_bivariate.m
|
||||
matlab/+gsa/standardize_columns.m
|
||||
matlab/+gsa/tcrit.m
|
||||
matlab/+gsa/teff.m
|
||||
Copyright: 2011-2018 European Commission
|
||||
2011-2018 Dynare Team
|
||||
2011-2023 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/gsa/pick.m
|
||||
Copyright: none
|
||||
License: public-domain-jrc
|
||||
This software has been developed at the Joint Research Centre of European Commission
|
||||
by officers in the course of their official duties. This software is not subject to copyright
|
||||
protection and is in the public domain. It is an experimental system. The Joint Research Centre
|
||||
of European Commission assumes no responsibility whatsoever for its use by other parties
|
||||
and makes no guarantees, expressed or implied, about its quality, reliability, or any other
|
||||
characteristic. We would appreciate acknowledgement if the software is used.
|
||||
Comment: This file is part of GLUEWIN.
|
||||
The program has been developed by M. Ratto, European Commission, Joint Research Centre,
|
||||
Institute for the Protection and Security of The Citizen, Technological and Economic Risk Management,
|
||||
Applied Statistics, as a deliverable of the IMPACT project
|
||||
(EC Fifth Framework Programme, SCA Project, IST-1999-11313, DG-INFSO).
|
||||
|
||||
Files: matlab/optimization/simpsa.m matlab/optimization/simpsaget.m matlab/optimization/simpsaset.m
|
||||
Copyright: 2005 Henning Schmidt, FCC, henning@fcc.chalmers.se
|
||||
2006 Brecht Donckels, BIOMATH, brecht.donckels@ugent.be
|
||||
|
@ -262,9 +247,14 @@ License: BSD-2-clause
|
|||
|
||||
Files: matlab/utilities/graphics/colorspace.m
|
||||
Copyright: 2005-2010 Pascal Getreuer
|
||||
2017 Dynare Team
|
||||
2017-2023 Dynare Team
|
||||
License: BSD-2-clause
|
||||
|
||||
Files: examples/fs2000_data.m
|
||||
Copyright: 2000-2022 Frank Schorfheide
|
||||
2023 Dynare Team
|
||||
License: CC-BY-SA-4.0
|
||||
|
||||
Files: doc/*.rst doc/*.tex doc/*.svg doc/*.pdf doc/*.bib
|
||||
Copyright: 1996-2022 Dynare Team
|
||||
License: GFDL-NIV-1.3+
|
||||
|
@ -307,28 +297,6 @@ Files: preprocessor/doc/preprocessor/*
|
|||
Copyright: 2007-2019 Dynare Team
|
||||
License: CC-BY-SA-4.0
|
||||
|
||||
Files: contrib/jsonlab/*
|
||||
Copyright: 2011-2020 Qianqian Fang <q.fang at neu.edu>
|
||||
2016 Bastian Bechtold
|
||||
License: GPL-3+ or BSD-3-clause
|
||||
|
||||
Files: contrib/jsonlab/base64decode.m
|
||||
contrib/jsonlab/base64encode.m
|
||||
contrib/jsonlab/gzipdecode.m
|
||||
contrib/jsonlab/gzipencode.m
|
||||
contrib/jsonlab/zlibdecode.m
|
||||
contrib/jsonlab/zlibencode.m
|
||||
Copyright: 2012 Kota Yamaguchi
|
||||
2011-2020 Qianqian Fang <q.fang at neu.edu>
|
||||
License: GPL-3+ or BSD-2-clause
|
||||
|
||||
Files: contrib/jsonlab/loadjson.m
|
||||
Copyright: 2011-2020 Qianqian Fang
|
||||
2009 Nedialko Krouchev
|
||||
2009 François Glineur
|
||||
2008 Joel Feenstra
|
||||
License: GPL-3+ or BSD-2-clause or BSD-3-clause
|
||||
|
||||
Files: contrib/ms-sbvar/utilities_dw/*
|
||||
Copyright: 1996-2011 Daniel Waggoner
|
||||
License: GPL-3+
|
||||
|
@ -435,32 +403,6 @@ License: BSD-2-clause
|
|||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
License: BSD-3-clause
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
.
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
.
|
||||
* Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
License: GFDL-NIV-1.3+
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright © 2019-2023 Dynare Team
|
||||
# Copyright © 2019-2024 Dynare Team
|
||||
#
|
||||
# This file is part of Dynare.
|
||||
#
|
||||
|
@ -37,8 +37,6 @@ else
|
|||
# Remove /opt/homebrew/bin from PATH, so it does not intervene with the x86_64 compilations
|
||||
path_remove PATH /opt/homebrew/bin
|
||||
MATLAB_ARCH=maci64
|
||||
# On x86_64 we need to differentiate between older and newer MATLAB versions
|
||||
OLD_MATLAB_PATH=/Applications/"$PKG_ARCH"/MATLAB_R2016b.app
|
||||
fi
|
||||
MATLAB_PATH=/Applications/"$PKG_ARCH"/MATLAB_R2023b.app
|
||||
|
||||
|
@ -56,7 +54,7 @@ LIB64="$ROOTDIR"/macOS/deps/"$PKG_ARCH"/lib64
|
|||
## - the macOS linker is different from GNU ld and does not have the equivalent of -Bstatic/-Bdynamic
|
||||
## - libgfortran.spec does not include --as-needed on macOS, hence it will link the library anyways
|
||||
## Also, it does not seem possible to override libgfortran.spec with the --specs option.
|
||||
GCC_VERSION=$(sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" "$ROOTDIR"/scripts/homebrew-native-"$PKG_ARCH".ini)
|
||||
GCC_VERSION=$(sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" "$ROOTDIR"/macOS/homebrew-native-"$PKG_ARCH".ini)
|
||||
|
||||
QUADMATH_DIR=$(mktemp -d)
|
||||
ln -s "$BREWDIR"/opt/gcc/lib/gcc/"$GCC_VERSION"/libquadmath.a "$QUADMATH_DIR"
|
||||
|
@ -69,18 +67,12 @@ cd "$ROOTDIR"
|
|||
# NB: the addition of -Wl,-ld_classic is a workaround for https://github.com/mesonbuild/meson/issues/12282 (see also the native file)
|
||||
common_meson_opts=(-Dbuild_for=matlab -Dbuildtype=release -Dprefer_static=true -Dfortran_args="[ '-B', '$LIB64/Slicot/' ]" \
|
||||
-Dc_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" -Dcpp_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" -Dfortran_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" \
|
||||
--native-file scripts/homebrew-native-$PKG_ARCH.ini)
|
||||
--native-file macOS/homebrew-native-$PKG_ARCH.ini)
|
||||
|
||||
# Build for MATLAB ⩾ R2018a (x86_64) and MATLAB ⩾ R2023b (arm64)
|
||||
# Build for MATLAB ⩾ R2018b (x86_64) and MATLAB ⩾ R2023b (arm64)
|
||||
arch -"$PKG_ARCH" meson setup "${common_meson_opts[@]}" -Dmatlab_path="$MATLAB_PATH" build-matlab --wipe
|
||||
arch -"$PKG_ARCH" meson compile -v -C build-matlab
|
||||
|
||||
if [[ "$PKG_ARCH" == x86_64 ]]; then
|
||||
# Build for MATLAB < R2018a
|
||||
arch -"$PKG_ARCH" meson setup "${common_meson_opts[@]}" -Dmatlab_path="$OLD_MATLAB_PATH" build-old-matlab --wipe
|
||||
arch -"$PKG_ARCH" meson compile -v -C build-old-matlab
|
||||
fi
|
||||
|
||||
# If not in CI, build the docs
|
||||
if [[ -z $CI ]]; then
|
||||
arch -"$PKG_ARCH" meson compile -v -C build-matlab doc
|
||||
|
@ -125,8 +117,7 @@ mkdir -p \
|
|||
"$PKGFILES"/scripts \
|
||||
"$PKGFILES"/contrib/ms-sbvar/TZcode
|
||||
if [[ "$PKG_ARCH" == x86_64 ]]; then
|
||||
mkdir -p "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-8.3-9.3 \
|
||||
"$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-9.4-23.2
|
||||
mkdir -p "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-9.5-23.2
|
||||
else
|
||||
mkdir -p "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-23.2
|
||||
fi
|
||||
|
@ -147,22 +138,20 @@ mkdir -p "$PKGFILES"
|
|||
ln -sf ../../preprocessor/dynare-preprocessor "$PKGFILES"/matlab/preprocessor64/dynare_m
|
||||
|
||||
if [[ "$PKG_ARCH" == x86_64 ]]; then
|
||||
cp -L "$ROOTDIR"/build-matlab/*.mex"$MATLAB_ARCH" "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-9.4-23.2
|
||||
cp -L "$ROOTDIR"/build-old-matlab/*.mex"$MATLAB_ARCH" "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-8.3-9.3
|
||||
cp -L "$ROOTDIR"/build-matlab/*.mex"$MATLAB_ARCH" "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-9.5-23.2
|
||||
else
|
||||
cp -L "$ROOTDIR"/build-matlab/*.mex"$MATLAB_ARCH" "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-23.2
|
||||
fi
|
||||
|
||||
cp -p "$ROOTDIR"/scripts/dynare.el "$PKGFILES"/scripts
|
||||
cp -pr "$ROOTDIR"/contrib/ms-sbvar/TZcode/MatlabFiles "$PKGFILES"/contrib/ms-sbvar/TZcode
|
||||
cp -pr "$ROOTDIR"/contrib/jsonlab "$PKGFILES"/contrib
|
||||
|
||||
cp "$ROOTDIR"/build-doc/*.pdf "$PKGFILES"/doc
|
||||
cp "$ROOTDIR"/build-doc/preprocessor/doc/*.pdf "$PKGFILES"/doc
|
||||
cp -r "$ROOTDIR"/build-doc/dynare-manual.html "$PKGFILES"/doc
|
||||
|
||||
mkdir -p "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64
|
||||
cp -p "$ROOTDIR"/macOS/deps/"$PKG_ARCH"/lib64/x13as/x13as "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64
|
||||
mkdir -p "$PKGFILES"/matlab/dseries/externals/x13/macOS/64
|
||||
cp -p "$ROOTDIR"/macOS/deps/"$PKG_ARCH"/lib64/x13as/x13as "$PKGFILES"/matlab/dseries/externals/x13/macOS/64
|
||||
|
||||
|
||||
cd "$ROOTDIR"/macOS/pkg
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright © 2019-2023 Dynare Team
|
||||
# Copyright © 2019-2024 Dynare Team
|
||||
#
|
||||
# This file is part of Dynare.
|
||||
#
|
||||
|
@ -22,7 +22,7 @@ DEPS_ARCH ?= x86_64 # use x86_64 by default
|
|||
|
||||
BREWDIR := $(if $(filter arm64,$(DEPS_ARCH)),/opt/homebrew,/usr/local)
|
||||
|
||||
GCC_VERSION = $(shell sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" ../../scripts/homebrew-native-$(DEPS_ARCH).ini)
|
||||
GCC_VERSION = $(shell sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" ../homebrew-native-$(DEPS_ARCH).ini)
|
||||
|
||||
ROOT_PATH = $(realpath .)
|
||||
|
||||
|
@ -53,7 +53,7 @@ clean-all: clean-lib clean-src clean-tar
|
|||
#
|
||||
tarballs/slicot-$(SLICOT_VERSION).tar.gz:
|
||||
mkdir -p tarballs
|
||||
wget $(WGET_OPTIONS) -O $@ https://deb.debian.org/debian/pool/main/s/slicot/slicot_$(SLICOT_VERSION).orig.tar.gz
|
||||
wget $(WGET_OPTIONS) -O $@ https://deb.debian.org/debian/pool/main/s/slicot/slicot_$(SLICOT_VERSION).orig.tar.xz
|
||||
|
||||
$(DEPS_ARCH)/sources64/slicot-$(SLICOT_VERSION): tarballs/slicot-$(SLICOT_VERSION).tar.gz
|
||||
rm -rf $(DEPS_ARCH)/sources64/slicot-*
|
||||
|
@ -62,7 +62,7 @@ $(DEPS_ARCH)/sources64/slicot-$(SLICOT_VERSION): tarballs/slicot-$(SLICOT_VERSIO
|
|||
touch $@
|
||||
|
||||
$(DEPS_ARCH)/lib64/slicot/libslicot64_pic.a: $(DEPS_ARCH)/sources64/slicot-$(SLICOT_VERSION)
|
||||
make -C $< FORTRAN=$(BREWDIR)/bin/gfortran LOADER=$(BREWDIR)/bin/gfortran SLICOTLIB=../libslicot64_pic.a OPTS="-O3 -fdefault-integer-8" lib -j$(NTHREADS)
|
||||
make -C $< -f makefile_Unix FORTRAN=$(BREWDIR)/bin/gfortran LOADER=$(BREWDIR)/bin/gfortran SLICOTLIB=../libslicot64_pic.a OPTS="-O3 -fdefault-integer-8" lib -j$(NTHREADS)
|
||||
strip -S $</libslicot64_pic.a
|
||||
mkdir -p $(dir $@)
|
||||
cp $</libslicot64_pic.a $@
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
SLICOT_VERSION = 5.0+20101122
|
||||
SLICOT_VERSION = 5.9~20240205.gita037f7e
|
||||
X13AS_VERSION = 1-1-b60
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
_mexFunction
|
|
@ -34,7 +34,7 @@ global oo_
|
|||
oo_.bvar.log_marginal_data_density=NaN(maxnlags,1);
|
||||
|
||||
for nlags = 1:maxnlags
|
||||
[ny, nx, posterior, prior] = bvar.toolbox(nlags);
|
||||
[ny, ~, posterior, prior] = bvar.toolbox(nlags);
|
||||
oo_.bvar.posterior{nlags}=posterior;
|
||||
oo_.bvar.prior{nlags}=prior;
|
||||
|
||||
|
@ -75,8 +75,8 @@ function w = matrictint(S, df, XXi)
|
|||
|
||||
k=size(XXi,1);
|
||||
ny=size(S,1);
|
||||
[cx,p]=chol(XXi);
|
||||
[cs,q]=chol(S);
|
||||
[cx,p] = chol(XXi); %second output required to prevent error
|
||||
[cs,p] = chol(S); %second output required to prevent error
|
||||
|
||||
if any(diag(cx)<100*eps)
|
||||
error('singular XXi')
|
||||
|
|
|
@ -33,7 +33,7 @@ global options_ oo_ M_
|
|||
if options_.forecast == 0
|
||||
error('bvar.forecast: you must specify "forecast" option')
|
||||
end
|
||||
[ny, nx, posterior, prior, forecast_data] = bvar.toolbox(nlags);
|
||||
[ny, nx, posterior, ~, forecast_data] = bvar.toolbox(nlags);
|
||||
|
||||
sims_no_shock = NaN(options_.forecast, ny, options_.bvar_replic);
|
||||
sims_with_shocks = NaN(options_.forecast, ny, options_.bvar_replic);
|
||||
|
@ -95,7 +95,7 @@ end
|
|||
|
||||
if p > 0
|
||||
skipline()
|
||||
disp(['Some of the VAR models sampled from the posterior distribution'])
|
||||
disp('Some of the VAR models sampled from the posterior distribution')
|
||||
disp(['were found to be explosive (' num2str(p/options_.bvar_replic) ' percent).'])
|
||||
skipline()
|
||||
end
|
||||
|
@ -119,7 +119,7 @@ OutputDirectoryName = CheckPath('graphs',M_.dname);
|
|||
dyn_graph=bvar.graph_init(sprintf('BVAR forecasts (nlags = %d)', nlags), ny, {'b-' 'g-' 'g-' 'r-' 'r-'});
|
||||
|
||||
for i = 1:ny
|
||||
dyn_graph=dynare_graph(dyn_graph,[ sims_no_shock_median(:, i) ...
|
||||
dyn_graph=plot_graph(dyn_graph,[ sims_no_shock_median(:, i) ...
|
||||
sims_no_shock_up_conf(:, i) sims_no_shock_down_conf(:, i) ...
|
||||
sims_with_shocks_up_conf(:, i) sims_with_shocks_down_conf(:, i) ], ...
|
||||
options_.varobs{i});
|
||||
|
@ -154,8 +154,8 @@ end
|
|||
% Store results
|
||||
|
||||
DirectoryName = [ M_.dname '/bvar_forecast' ];
|
||||
if ~isdir(DirectoryName)
|
||||
if ~isdir(M_.dname)
|
||||
if ~isfolder(DirectoryName)
|
||||
if ~isfolder(M_.dname)
|
||||
mkdir(M_.dname);
|
||||
end
|
||||
mkdir(DirectoryName);
|
||||
|
@ -183,3 +183,31 @@ for i = 1:length(options_.varobs)
|
|||
oo_.bvar.forecast.rmse.(name) = rmse(i);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function dyn_graph=plot_graph(dyn_graph,y,tit,x)
|
||||
% function plot_graph(dyn_graph, y,tit,x)
|
||||
|
||||
if nargin < 4
|
||||
x = (1:size(y,1))';
|
||||
end
|
||||
nplot = dyn_graph.plot_nbr + 1;
|
||||
if nplot > dyn_graph.max_nplot
|
||||
figure('Name',dyn_graph.figure_name);
|
||||
nplot = 1;
|
||||
end
|
||||
dyn_graph.plot_nbr = nplot;
|
||||
subplot(dyn_graph.nr,dyn_graph.nc,nplot);
|
||||
|
||||
line_types = dyn_graph.line_types;
|
||||
line_type = line_types{1};
|
||||
for i=1:size(y,2)
|
||||
if length(line_types) > 1
|
||||
line_type = line_types{i};
|
||||
end
|
||||
|
||||
plot(x,y(:,i),line_type);
|
||||
hold on
|
||||
end
|
||||
title(tit);
|
||||
hold off
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function dyn_graph=dynare_graph_init(figure_name,nplot,line_types,line_width)
|
||||
% function dynare_graph_init(figure_name,colors)
|
||||
function dyn_graph=graph_init(figure_name,nplot,line_types,line_width)
|
||||
% function graph_init(figure_name,colors)
|
||||
% initializes set of graphs
|
||||
%
|
||||
% INPUTS:
|
||||
|
@ -12,7 +12,7 @@ function dyn_graph=dynare_graph_init(figure_name,nplot,line_types,line_width)
|
|||
% SPECIAL REQUIREMENT
|
||||
% none
|
||||
|
||||
% Copyright © 2006-2017 Dynare Team
|
||||
% Copyright © 2006-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
|
|
@ -35,7 +35,7 @@ if nargin==1
|
|||
identification = 'Cholesky';
|
||||
end
|
||||
|
||||
[ny, nx, posterior, prior] = bvar.toolbox(nlags);
|
||||
[ny, nx, posterior] = bvar.toolbox(nlags);
|
||||
|
||||
S_inv_upper_chol = chol(inv(posterior.S));
|
||||
|
||||
|
@ -96,7 +96,7 @@ end
|
|||
|
||||
if p > 0
|
||||
skipline()
|
||||
disp(['Some of the VAR models sampled from the posterior distribution'])
|
||||
disp('Some of the VAR models sampled from the posterior distribution')
|
||||
disp(['were found to be explosive (' int2str(p) ' samples).'])
|
||||
skipline()
|
||||
end
|
||||
|
@ -130,7 +130,7 @@ end
|
|||
|
||||
% Save intermediate results
|
||||
DirectoryName = [ M_.dname '/bvar_irf' ];
|
||||
if ~isdir(DirectoryName)
|
||||
if ~isfolder(DirectoryName)
|
||||
mkdir('.',DirectoryName);
|
||||
end
|
||||
save([ DirectoryName '/simulations.mat'], 'sampled_irfs');
|
||||
|
@ -146,4 +146,4 @@ for i=1:ny
|
|||
oo_.bvar.irf.Upper_bound.(variable_name).(shock_name) = posterior_up_conf_irfs(j,i,:);
|
||||
oo_.bvar.irf.Lower_bound.(variable_name).(shock_name) = posterior_down_conf_irfs(j,i,:);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function [ny, nx, posterior, prior, forecast_data] = bvar_toolbox(nlags)
|
||||
%function [ny, nx, posterior, prior, forecast_data] = bvar_toolbox(nlags)
|
||||
function [ny, nx, posterior, prior, forecast_data] = toolbox(nlags)
|
||||
%function [ny, nx, posterior, prior, forecast_data] = toolbox(nlags)
|
||||
% bvar_toolbox Routines shared between BVAR methods
|
||||
% Computes several things for the estimations of a BVAR(nlags)
|
||||
%
|
||||
|
@ -42,7 +42,7 @@ function [ny, nx, posterior, prior, forecast_data] = bvar_toolbox(nlags)
|
|||
% - bvar_prior_{tau,decay,lambda,mu,omega,flat,train}
|
||||
|
||||
% Copyright © 2003-2007 Christopher Sims
|
||||
% Copyright © 2007-2017 Dynare Team
|
||||
% Copyright © 2007-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function [forcs, e] = mcforecast3(cL, H, mcValue, shocks, forcs, T, R, mv, mu)
|
||||
|
||||
function [forcs, e] = get_shock_paths(cL, H, mcValue, shocks, forcs, T, R, mv, mu)
|
||||
% [forcs, e] = get_shock_paths(cL, H, mcValue, shocks, forcs, T, R, mv, mu)
|
||||
% Computes the shock values for constrained forecasts necessary to keep
|
||||
% endogenous variables at their constrained paths
|
||||
%
|
|
@ -1,4 +1,5 @@
|
|||
function plot_icforecast(Variables,periods,options_,oo_)
|
||||
function plot(Variables,periods,options_,oo_)
|
||||
% plot(Variables,periods,options_,oo_)
|
||||
% Build plots for the conditional forecasts.
|
||||
%
|
||||
% INPUTS
|
||||
|
@ -11,7 +12,7 @@ function plot_icforecast(Variables,periods,options_,oo_)
|
|||
% None.
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% This routine has to be called after imcforecast.m.
|
||||
% This routine has to be called after conditional_forecasts.run
|
||||
|
||||
% Copyright © 2006-2023 Dynare Team
|
||||
%
|
||||
|
@ -44,7 +45,7 @@ else
|
|||
end
|
||||
|
||||
if periods>forecast_periods
|
||||
fprintf('\nplot_icforecast:: Number of periods for plotting exceeds forecast horizon. Setting periods to %d.\n',forecast_periods-1)
|
||||
fprintf('\nconditional_forecasts.plot:: Number of periods for plotting exceeds forecast horizon. Setting periods to %d.\n',forecast_periods-1)
|
||||
periods=forecast_periods;
|
||||
end
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
function imcforecast(constrained_paths, constrained_vars, options_cond_fcst)
|
||||
|
||||
function forecasts=run(M_,options_,oo_,bayestopt_,estim_params_,constrained_paths, constrained_vars, options_cond_fcst)
|
||||
% run(constrained_paths, constrained_vars, options_cond_fcst)
|
||||
% Computes conditional forecasts.
|
||||
%
|
||||
% INPUTS
|
||||
% - constrained_paths [double] m*p array, where m is the number of constrained endogenous variables and p is the number of constrained periods.
|
||||
% - constrained_vars [integer] m*1 array, indices in M_.endo_names of the constrained variables.
|
||||
% - options_cond_fcst [structure] containing the options. The fields are:
|
||||
% M_ [structure] describing the model
|
||||
% options_ [structure] describing the options
|
||||
% oo_: [structure] storing the results
|
||||
% bayestopt_ [structure] describing the priors
|
||||
% estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - constrained_paths [double] m*p array, where m is the number of constrained endogenous variables and p is the number of constrained periods.
|
||||
% - constrained_vars [integer] m*1 array, indices in M_.endo_names of the constrained variables.
|
||||
% - options_cond_fcst [structure] containing the options. The fields are:
|
||||
%
|
||||
% + replic [integer] scalar, number of monte carlo simulations.
|
||||
% + parameter_set [char] values of the estimated parameters:
|
||||
|
@ -19,16 +24,16 @@ function imcforecast(constrained_paths, constrained_vars, options_cond_fcst)
|
|||
% + conf_sig [double] scalar in [0,1], probability mass covered by the confidence bands.
|
||||
%
|
||||
% OUTPUTS
|
||||
% None.
|
||||
% - forecasts [structure] results of the conditional forecast exercise
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% This routine has to be called after an estimation statement or an estimated_params block.
|
||||
%
|
||||
% REMARKS
|
||||
% [1] Results are stored in oo_.conditional_forecast.
|
||||
% [2] Use the function plot_icforecast to plot the results.
|
||||
% [2] Use the function conditional_forecasts.plot to plot the results.
|
||||
|
||||
% Copyright © 2006-2020 Dynare Team
|
||||
% Copyright © 2006-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -45,8 +50,6 @@ function imcforecast(constrained_paths, constrained_vars, options_cond_fcst)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global options_ oo_ M_ bayestopt_ estim_params_
|
||||
|
||||
if ~isfield(options_cond_fcst,'parameter_set') || isempty(options_cond_fcst.parameter_set)
|
||||
if isfield(oo_,'posterior_mode')
|
||||
options_cond_fcst.parameter_set = 'posterior_mode';
|
||||
|
@ -123,7 +126,6 @@ if estimated_model
|
|||
missing_value = dataset_info.missing.state;
|
||||
|
||||
%store qz_criterium
|
||||
qz_criterium_old=options_.qz_criterium;
|
||||
options_=select_qz_criterium_value(options_);
|
||||
options_smoothed_state_uncertainty_old = options_.smoothed_state_uncertainty;
|
||||
[atT, ~, ~, ~,ys, ~, ~, ~, ~, ~, ~, ~, ~, ~,oo_,bayestopt_] = ...
|
||||
|
@ -155,7 +157,6 @@ if estimated_model
|
|||
trend = constant(oo_.dr.order_var,:);
|
||||
InitState(:,1) = atT(:,end);
|
||||
else
|
||||
qz_criterium_old=options_.qz_criterium;
|
||||
if isempty(options_.qz_criterium)
|
||||
options_.qz_criterium = 1+1e-6;
|
||||
end
|
||||
|
@ -246,7 +247,7 @@ FORCS1_shocks = zeros(n1,cL,options_cond_fcst.replic);
|
|||
for b=1:options_cond_fcst.replic %conditional forecast using cL set to constrained values
|
||||
shocks = sQ*randn(ExoSize,options_cond_fcst.periods);
|
||||
shocks(controlled_varexo,:) = zeros(n1, options_cond_fcst.periods);
|
||||
[FORCS1(:,:,b), FORCS1_shocks(:,:,b)] = mcforecast3(cL,options_cond_fcst.periods,constrained_paths,shocks,FORCS1(:,:,b),T,R,mv, mu);
|
||||
[FORCS1(:,:,b), FORCS1_shocks(:,:,b)] = conditional_forecasts.get_shock_paths(cL,options_cond_fcst.periods,constrained_paths,shocks,FORCS1(:,:,b),T,R,mv, mu);
|
||||
FORCS1(:,:,b)=FORCS1(:,:,b)+trend; %add trend
|
||||
end
|
||||
if max(max(max(abs(bsxfun(@minus,FORCS1(constrained_vars,1+1:1+cL,:),trend(constrained_vars,1:cL)+constrained_paths)))))>1e-4
|
||||
|
@ -292,7 +293,7 @@ FORCS2(:,1,:) = repmat(InitState,1,options_cond_fcst.replic); %set initial stead
|
|||
for b=1:options_cond_fcst.replic %conditional forecast using cL set to 0
|
||||
shocks = sQ*randn(ExoSize,options_cond_fcst.periods);
|
||||
shocks(controlled_varexo,:) = zeros(n1, options_cond_fcst.periods);
|
||||
FORCS2(:,:,b) = mcforecast3(0,options_cond_fcst.periods,constrained_paths,shocks,FORCS2(:,:,b),T,R,mv, mu)+trend;
|
||||
FORCS2(:,:,b) = conditional_forecasts.get_shock_paths(0,options_cond_fcst.periods,constrained_paths,shocks,FORCS2(:,:,b),T,R,mv, mu)+trend;
|
||||
end
|
||||
|
||||
mFORCS2 = mean(FORCS2,3);
|
||||
|
@ -307,8 +308,4 @@ for i = 1:EndoSize
|
|||
forecasts.uncond.ci.(M_.endo_names{oo_.dr.order_var(i)}) = [tmp(t1,:)' ,tmp(t2,:)' ]';
|
||||
end
|
||||
forecasts.graph.title = graph_title;
|
||||
forecasts.graph.fname = M_.fname;
|
||||
|
||||
%reset qz_criterium
|
||||
options_.qz_criterium=qz_criterium_old;
|
||||
oo_.conditional_forecast = forecasts;
|
||||
forecasts.graph.fname = M_.fname;
|
|
@ -28,7 +28,7 @@ function nls(eqname, params, data, range, optimizer, varargin)
|
|||
% equation must have NaN values in the object.
|
||||
% [4] It is assumed that the residual is additive.
|
||||
|
||||
% Copyright © 2021-2022 Dynare Team
|
||||
% Copyright © 2021-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -179,12 +179,6 @@ write_residuals_routine(lhs, rhs, eqname, ipnames_, M_);
|
|||
% Create a routine for evaluating the sum of squared residuals of the nonlinear model
|
||||
write_ssr_routine(lhs, rhs, eqname, ipnames_, M_);
|
||||
|
||||
% Workaround for Octave bug https://savannah.gnu.org/bugs/?46282
|
||||
% Octave will randomly fail to read the ssr_* file generated in the +folder
|
||||
if isoctave && octave_ver_less_than('7')
|
||||
path(path)
|
||||
end
|
||||
|
||||
% Create a function handle returning the sum of square residuals for a given vector of parameters.
|
||||
ssrfun = @(p) feval([M_.fname '.ssr_' eqname], p, DATA, M_, oo_);
|
||||
|
||||
|
@ -298,23 +292,23 @@ end
|
|||
%
|
||||
|
||||
if is_gauss_newton
|
||||
[params1, SSR, exitflag] = gauss_newton(resfun, params0);
|
||||
[params1, SSR] = gauss_newton(resfun, params0);
|
||||
elseif is_lsqnonlin
|
||||
if ismember('levenberg-marquardt', varargin)
|
||||
% Levenberg Marquardt does not handle boundary constraints.
|
||||
[params1, SSR, ~, exitflag] = lsqnonlin(resfun, params0, [], [], optimset(varargin{:}));
|
||||
[params1, SSR] = lsqnonlin(resfun, params0, [], [], optimset(varargin{:}));
|
||||
else
|
||||
[params1, SSR, ~, exitflag] = lsqnonlin(resfun, params0, bounds(:,1), bounds(:,2), optimset(varargin{:}));
|
||||
[params1, SSR] = lsqnonlin(resfun, params0, bounds(:,1), bounds(:,2), optimset(varargin{:}));
|
||||
end
|
||||
else
|
||||
% Estimate the parameters by minimizing the sum of squared residuals.
|
||||
[params1, SSR, exitflag] = dynare_minimize_objective(ssrfun, params0, ...
|
||||
minalgo, ...
|
||||
options_, ...
|
||||
bounds, ...
|
||||
parameter_names, ...
|
||||
[], ...
|
||||
[]);
|
||||
[params1, SSR] = dynare_minimize_objective(ssrfun, params0, ...
|
||||
minalgo, ...
|
||||
options_, ...
|
||||
bounds, ...
|
||||
parameter_names, ...
|
||||
[], ...
|
||||
[]);
|
||||
end
|
||||
|
||||
% Revert local modifications to the options.
|
||||
|
|
|
@ -6,20 +6,20 @@ function [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p,
|
|||
% INPUTS
|
||||
% -------------------------------------------------------------------------
|
||||
% Group [NumFactor, NumGroups] := Matrix describing the groups.
|
||||
% Each column represents one group.
|
||||
% The element of each column are zero if the factor is not in the
|
||||
% group. Otherwise it is 1.
|
||||
% Each column represents one group.
|
||||
% The element of each column are zero if the factor is not in the
|
||||
% group. Otherwise it is 1.
|
||||
%
|
||||
% Sample := Matrix of the Morris sampled trajectories
|
||||
%
|
||||
% Output := Matrix of the output(s) values in correspondence of each point
|
||||
% of each trajectory
|
||||
% of each trajectory
|
||||
%
|
||||
% k = Number of factors
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUTS
|
||||
% OutMatrix (NumFactor*NumOutputs, 3)= [Mu*, Mu, StDev]
|
||||
% for each output it gives the three measures of each factor
|
||||
% for each output it gives the three measures of each factor
|
||||
% -------------------------------------------------------------------------
|
||||
%
|
||||
% Written by Jessica Cariboni and Francesca Campolongo
|
||||
|
@ -27,7 +27,7 @@ function [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p,
|
|||
%
|
||||
|
||||
% Copyright © 2005 European Commission
|
||||
% Copyright © 2012-2017 Dynare Team
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -50,32 +50,34 @@ if nargin==0
|
|||
return
|
||||
end
|
||||
|
||||
OutMatrix=[];
|
||||
if nargin < 5, Group=[]; end
|
||||
|
||||
NumGroups = size(Group,2);
|
||||
if nargin < 4 | isempty(p)
|
||||
|
||||
if nargin < 4 || isempty(p)
|
||||
p = 4;
|
||||
end
|
||||
Delt = p/(2*p-2);
|
||||
|
||||
if NumGroups ~ 0
|
||||
if NumGroups ~= 0
|
||||
sizea = NumGroups; % Number of groups
|
||||
GroupMat=Group;
|
||||
GroupMat = GroupMat';
|
||||
else
|
||||
sizea = NumFact;
|
||||
end
|
||||
|
||||
r=size(Sample,1)/(sizea+1); % Number of trajectories
|
||||
if NumGroups > 0
|
||||
OutMatrix = NaN(sizea*size(Output,2),1);
|
||||
else
|
||||
OutMatrix = NaN(sizea*size(Output,2),3);
|
||||
end
|
||||
|
||||
% For Each Output
|
||||
for k=1:size(Output,2)
|
||||
|
||||
OutValues=Output(:,k);
|
||||
|
||||
% For each r trajectory
|
||||
for i=1:r
|
||||
|
||||
% For each step j in the trajectory
|
||||
% Read the orientation matrix fact for the r-th sampling
|
||||
% Read the corresponding output values
|
||||
|
@ -86,13 +88,11 @@ for k=1:size(Output,2)
|
|||
|
||||
% For each point of the fixed trajectory compute the values of the Morris function. The function
|
||||
% is partitioned in four parts, from order zero to order 4th.
|
||||
% SAmeas=NaN();
|
||||
for j=1:sizea % For each point in the trajectory i.e for each factor
|
||||
% matrix of factor which changes
|
||||
if NumGroups ~ 0
|
||||
if NumGroups ~= 0
|
||||
AuxFind (:,1) = A(:,j);
|
||||
% AuxFind(find(A(:,j)),1)=1;
|
||||
% Pippo = sum((Group - repmat(AuxFind,1,NumGroups)),1);
|
||||
% Change_factor(j,i) = find(Pippo==0);
|
||||
Change_factor = find(abs(AuxFind)>1e-010);
|
||||
% If we deal with groups we can only estimate the new mu*
|
||||
% measure since factors in the same groups can move in
|
||||
|
@ -100,7 +100,6 @@ for k=1:size(Output,2)
|
|||
% Morris mu cannopt be applied.
|
||||
% In the new version the elementary effect is defined with
|
||||
% the absolute value.
|
||||
%SAmeas(find(GroupMat(Change_factor(j,i),:)),i) = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); %(2/3));
|
||||
SAmeas(i,Change_factor') = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt);
|
||||
else
|
||||
Change_factor(j,i) = find(Single_Sample(j+1,:)-Single_Sample(j,:));
|
||||
|
@ -116,12 +115,17 @@ for k=1:size(Output,2)
|
|||
|
||||
end %for i=1:r
|
||||
|
||||
if NumGroups ~ 0
|
||||
if NumGroups ~= 0
|
||||
SAmeas = SAmeas';
|
||||
end
|
||||
|
||||
% Compute Mu AbsMu and StDev
|
||||
if any(any(isnan(SAmeas)))
|
||||
AbsMu=NaN(NumFact,1);
|
||||
if NumGroups == 0
|
||||
Mu=NaN(NumFact,1);
|
||||
StDev=NaN(NumFact,1);
|
||||
end
|
||||
for j=1:NumFact
|
||||
SAm = SAmeas(j,:);
|
||||
SAm = SAm(find(~isnan(SAm)));
|
||||
|
@ -143,8 +147,8 @@ for k=1:size(Output,2)
|
|||
% Define the output Matrix - if we have groups we cannot define the old
|
||||
% measure mu, only mu* makes sense
|
||||
if NumGroups > 0
|
||||
OutMatrix = [OutMatrix; AbsMu];
|
||||
OutMatrix((k-1)*sizea+1:k*sizea,:) = AbsMu;
|
||||
else
|
||||
OutMatrix = [OutMatrix; AbsMu, Mu, StDev];
|
||||
OutMatrix((k-1)*sizea+1:k*sizea,:) = [AbsMu, Mu, StDev];
|
||||
end
|
||||
end % For Each Output
|
|
@ -1,6 +1,7 @@
|
|||
function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
|
||||
%[Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
|
||||
% Inputs: k (1,1) := number of factors examined or number of groups examined.
|
||||
% Inputs:
|
||||
% k (1,1) := number of factors examined or number of groups examined.
|
||||
% In case the groups are chosen the number of factors is stores in NumFact and
|
||||
% sizea becomes the number of created groups.
|
||||
% NumFact (1,1) := number of factors examined in the case when groups are chosen
|
||||
|
@ -13,7 +14,7 @@ function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
|
|||
% are set to 1 in correspondence of the factors that belong to the fixed group. All
|
||||
% the other elements are zero.
|
||||
% Local Variables:
|
||||
% sizeb (1,1) := sizea+1
|
||||
% sizeb (1,1) := sizea+1
|
||||
% sizec (1,1) := 1
|
||||
% randmult (sizea,1) := vector of random +1 and -1
|
||||
% perm_e(1,sizea) := vector of sizea random permutated indeces
|
||||
|
@ -34,7 +35,8 @@ function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
|
|||
% AuxMat(sizeb,sizea) := Delta*0.5*((2*B - A) * DD0 + A) in Morris, 1991. The AuxMat is used as in Morris design
|
||||
% for single factor analysis, while it constitutes an intermediate step for the group analysis.
|
||||
%
|
||||
% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices
|
||||
% Outputs:
|
||||
% Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices
|
||||
% OutFact(sizea*r,1) := for the entire sample size computed Fact(i,1) vectors
|
||||
%
|
||||
% Note: B0 is constructed as in Morris design when groups are not considered. When groups are considered the routine
|
||||
|
@ -56,7 +58,7 @@ function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
|
|||
%
|
||||
|
||||
% Copyright © 2005 European Commission
|
||||
% Copyright © 2012-2017 Dynare Team
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -80,25 +82,23 @@ Delta = p/(2*p-2);
|
|||
NumFact = sizea;
|
||||
GroupNumber = size(GroupMat,2);
|
||||
|
||||
if GroupNumber ~ 0;
|
||||
if GroupNumber ~= 0
|
||||
sizea = size(GroupMat,2);
|
||||
end
|
||||
|
||||
sizeb = sizea + 1;
|
||||
sizec = 1;
|
||||
Outmatrix = [];
|
||||
OutFact = [];
|
||||
|
||||
% For each i generate a trajectory
|
||||
for i=1:r
|
||||
|
||||
% Construct DD0 - OLD VERSION - it does not need communication toolbox
|
||||
% RAND(N,M) is an NXM matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0).
|
||||
% Note that DD0 tells if the factor have to be increased or ddecreased
|
||||
% by Delta.
|
||||
randmult = ones(k,1);
|
||||
v = rand(k,1);
|
||||
randmult (find(v < 0.5))=-1;
|
||||
randmult (v < 0.5)=-1;
|
||||
randmult = repmat(randmult,1,k);
|
||||
DD0 = randmult .* eye(k);
|
||||
|
||||
|
@ -133,7 +133,7 @@ for i=1:r
|
|||
|
||||
% When groups are present the random permutation is done only on B. The effect is the same since
|
||||
% the added part (A0*x0') is completely random.
|
||||
if GroupNumber ~ 0
|
||||
if GroupNumber ~= 0
|
||||
B = B * (GroupMat*P0')';
|
||||
end
|
||||
|
||||
|
@ -147,7 +147,7 @@ for i=1:r
|
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% a --> Define the random vector x0 for the factors. Note that x0 takes value in the hypercube
|
||||
% [0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]
|
||||
MyInt = repmat([0:(1/(p-1)):(1-Delta)],NumFact,1); % Construct all possible values of the factors
|
||||
MyInt = repmat(0:(1/(p-1)):(1-Delta),NumFact,1); % Construct all possible values of the factors
|
||||
|
||||
% OLD VERSION - it needs communication toolbox
|
||||
% w = randint(NumFact,1,[1,size(MyInt,2)]);
|
||||
|
@ -158,9 +158,9 @@ for i=1:r
|
|||
% 3) check in which interval the random numbers fall
|
||||
% 4) generate the corresponding integer
|
||||
v = repmat(rand(NumFact,1),1,size(MyInt,2)+1); % 1)
|
||||
IntUsed = repmat([0:1/size(MyInt,2):1],NumFact,1); % 2)
|
||||
IntUsed = repmat(0:1/size(MyInt,2):1,NumFact,1); % 2)
|
||||
DiffAuxVec = IntUsed - v; % 3)
|
||||
|
||||
w=NaN(1,size(DiffAuxVec,1));
|
||||
for ii = 1:size(DiffAuxVec,1)
|
||||
w(1,ii) = max(find(DiffAuxVec(ii,:)<0)); % 4)
|
||||
end
|
||||
|
@ -168,7 +168,7 @@ for i=1:r
|
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% b --> Compute the matrix B*, here indicated as B0. Each row in B0 is a
|
||||
% trajectory for Morris Calculations. The dimension of B0 is (Numfactors+1,Numfactors)
|
||||
if GroupNumber ~ 0
|
||||
if GroupNumber ~= 0
|
||||
B0 = (A0*x0' + AuxMat);
|
||||
else
|
||||
B0 = (A0*x0' + AuxMat)*P0;
|
||||
|
@ -183,6 +183,7 @@ for i=1:r
|
|||
|
||||
% Create the Factor vector. Each component of this vector indicate which factor or group of factor
|
||||
% has been changed in each step of the trajectory.
|
||||
Fact=NaN(1,sizea);
|
||||
for j=1:sizea
|
||||
Fact(1,j) = find(P0(j,:));
|
||||
end
|
||||
|
@ -190,5 +191,4 @@ for i=1:r
|
|||
|
||||
Outmatrix = [Outmatrix; In];
|
||||
OutFact = [OutFact; Fact'];
|
||||
|
||||
end
|
|
@ -1,10 +1,8 @@
|
|||
function sout = boxplot (data,notched,symbol,vertical,maxwhisker)
|
||||
% sout = boxplot (data,notched,symbol,vertical,maxwhisker)
|
||||
% Creates a box plot
|
||||
|
||||
function sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
|
||||
|
||||
% sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
|
||||
|
||||
%
|
||||
% Copyright © 2010-2017 Dynare Team
|
||||
% Copyright © 2010-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -21,7 +19,6 @@ function sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
% % % % endif
|
||||
if nargin < 5 || isempty(maxwhisker), maxwhisker = 1.5; end
|
||||
if nargin < 4 || isempty(vertical), vertical = 1; end
|
||||
if nargin < 3 || isempty(symbol), symbol = ['+','o']; end
|
||||
|
@ -32,7 +29,7 @@ if length(symbol)==1, symbol(2)=symbol(1); end
|
|||
if notched==1, notched=0.25; end
|
||||
a=1-notched;
|
||||
|
||||
% ## figure out how many data sets we have
|
||||
% % figure out how many data sets we have
|
||||
if iscell(data)
|
||||
nc = length(data);
|
||||
else
|
||||
|
@ -40,11 +37,11 @@ else
|
|||
nc = size(data,2);
|
||||
end
|
||||
|
||||
% ## compute statistics
|
||||
% ## s will contain
|
||||
% ## 1,5 min and max
|
||||
% ## 2,3,4 1st, 2nd and 3rd quartile
|
||||
% ## 6,7 lower and upper confidence intervals for median
|
||||
% compute statistics
|
||||
% s will contain
|
||||
% 1,5 min and max
|
||||
% 2,3,4 1st, 2nd and 3rd quartile
|
||||
% 6,7 lower and upper confidence intervals for median
|
||||
s = zeros(7,nc);
|
||||
box = zeros(1,nc);
|
||||
whisker_x = ones(2,1)*[1:nc,1:nc];
|
||||
|
@ -55,44 +52,36 @@ outliers2_x = [];
|
|||
outliers2_y = [];
|
||||
|
||||
for i=1:nc
|
||||
% ## Get the next data set from the array or cell array
|
||||
% Get the next data set from the array or cell array
|
||||
if iscell(data)
|
||||
col = data{i}(:);
|
||||
else
|
||||
col = data(:,i);
|
||||
end
|
||||
% ## Skip missing data
|
||||
% Skip missing data
|
||||
% % % % % % % col(isnan(col) | isna (col)) = [];
|
||||
col(isnan(col)) = [];
|
||||
|
||||
% ## Remember the data length
|
||||
% Remember the data length
|
||||
nd = length(col);
|
||||
box(i) = nd;
|
||||
if (nd > 1)
|
||||
% ## min,max and quartiles
|
||||
% s(1:5,i) = statistics(col)(1:5);
|
||||
% min,max and quartiles
|
||||
s(1,i)=min(col);
|
||||
s(5,i)=max(col);
|
||||
s(2,i)=myprctilecol(col,25);
|
||||
s(3,i)=myprctilecol(col,50);
|
||||
s(4,i)=myprctilecol(col,75);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
% ## confidence interval for the median
|
||||
% confidence interval for the median
|
||||
est = 1.57*(s(4,i)-s(2,i))/sqrt(nd);
|
||||
s(6,i) = max([s(3,i)-est, s(2,i)]);
|
||||
s(7,i) = min([s(3,i)+est, s(4,i)]);
|
||||
% ## whiskers out to the last point within the desired inter-quartile range
|
||||
% whiskers out to the last point within the desired inter-quartile range
|
||||
IQR = maxwhisker*(s(4,i)-s(2,i));
|
||||
whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)];
|
||||
whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)];
|
||||
% ## outliers beyond 1 and 2 inter-quartile ranges
|
||||
% outliers beyond 1 and 2 inter-quartile ranges
|
||||
outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR));
|
||||
outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR);
|
||||
outliers_x = [outliers_x; i*ones(size(outliers))];
|
||||
|
@ -100,41 +89,37 @@ for i=1:nc
|
|||
outliers2_x = [outliers2_x; i*ones(size(outliers2))];
|
||||
outliers2_y = [outliers2_y; outliers2];
|
||||
elseif (nd == 1)
|
||||
% ## all statistics collapse to the value of the point
|
||||
% all statistics collapse to the value of the point
|
||||
s(:,i) = col;
|
||||
% ## single point data sets are plotted as outliers.
|
||||
% single point data sets are plotted as outliers.
|
||||
outliers_x = [outliers_x; i];
|
||||
outliers_y = [outliers_y; col];
|
||||
else
|
||||
% ## no statistics if no points
|
||||
% no statistics if no points
|
||||
s(:,i) = NaN;
|
||||
end
|
||||
end
|
||||
% % % % if isempty(outliers2_y)
|
||||
% % % % outliers2_y=
|
||||
% ## Note which boxes don't have enough stats
|
||||
% Note which boxes don't have enough stats
|
||||
chop = find(box <= 1);
|
||||
|
||||
% ## Draw a box around the quartiles, with width proportional to the number of
|
||||
% ## items in the box. Draw notches if desired.
|
||||
% Draw a box around the quartiles, with width proportional to the number of
|
||||
% items in the box. Draw notches if desired.
|
||||
box = box*0.23/max(box);
|
||||
quartile_x = ones(11,1)*[1:nc] + [-a;-1;-1;1;1;a;1;1;-1;-1;-a]*box;
|
||||
quartile_y = s([3,7,4,4,7,3,6,2,2,6,3],:);
|
||||
|
||||
% ## Draw a line through the median
|
||||
% Draw a line through the median
|
||||
median_x = ones(2,1)*[1:nc] + [-a;+a]*box;
|
||||
% median_x=median(col);
|
||||
median_y = s([3,3],:);
|
||||
|
||||
% ## Chop all boxes which don't have enough stats
|
||||
% Chop all boxes which don't have enough stats
|
||||
quartile_x(:,chop) = [];
|
||||
quartile_y(:,chop) = [];
|
||||
whisker_x(:,[chop,chop+nc]) = [];
|
||||
whisker_y(:,[chop,chop+nc]) = [];
|
||||
median_x(:,chop) = [];
|
||||
median_y(:,chop) = [];
|
||||
% % % %
|
||||
% ## Add caps to the remaining whiskers
|
||||
% Add caps to the remaining whiskers
|
||||
cap_x = whisker_x;
|
||||
cap_x(1,:) =cap_x(1,:)- 0.05;
|
||||
cap_x(2,:) =cap_x(2,:)+ 0.05;
|
||||
|
@ -144,12 +129,14 @@ cap_y = whisker_y([1,1],:);
|
|||
% #whisker_x,whisker_y
|
||||
% #median_x,median_y
|
||||
% #cap_x,cap_y
|
||||
%
|
||||
% ## Do the plot
|
||||
|
||||
% Do the plot
|
||||
mm=min(min(data));
|
||||
MM=max(max(data));
|
||||
if isnan(mm), mm=0; MM=0; end
|
||||
if isnan(mm)
|
||||
mm=0;
|
||||
MM=0;
|
||||
end
|
||||
|
||||
if vertical
|
||||
plot (quartile_x, quartile_y, 'b', ...
|
||||
|
@ -161,17 +148,30 @@ if vertical
|
|||
set(gca,'XTick',1:nc);
|
||||
set(gca, 'XLim', [0.5, nc+0.5]);
|
||||
set(gca, 'YLim', [mm-(MM-mm)*0.05-eps, MM+(MM-mm)*0.05+eps]);
|
||||
|
||||
else
|
||||
% % % % % plot (quartile_y, quartile_x, "b;;",
|
||||
% % % % % whisker_y, whisker_x, "b;;",
|
||||
% % % % % cap_y, cap_x, "b;;",
|
||||
% % % % % median_y, median_x, "r;;",
|
||||
% % % % % outliers_y, outliers_x, [symbol(1),"r;;"],
|
||||
% % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]);
|
||||
end
|
||||
|
||||
if nargout
|
||||
sout=s;
|
||||
end
|
||||
% % % endfunction
|
||||
|
||||
function y = myprctilecol(x,p)
|
||||
|
||||
xx = sort(x);
|
||||
[m,n] = size(x);
|
||||
|
||||
if m==1 | n==1
|
||||
m = max(m,n);
|
||||
if m == 1
|
||||
y = x*ones(length(p),1);
|
||||
return
|
||||
end
|
||||
n = 1;
|
||||
q = 100*(0.5:m - 0.5)./m;
|
||||
xx = [min(x); xx(:); max(x)];
|
||||
else
|
||||
q = 100*(0.5:m - 0.5)./m;
|
||||
xx = [min(x); xx; max(x)];
|
||||
end
|
||||
|
||||
q = [0 q 100];
|
||||
y = interp1(q,xx,p);
|
|
@ -1,5 +1,10 @@
|
|||
function h = cumplot(x)
|
||||
%function h =cumplot(x)
|
||||
% Inputs:
|
||||
% - x [double] data series
|
||||
%
|
||||
% Outputs:
|
||||
% - h [handle] figure handle
|
||||
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -26,9 +31,5 @@ function h = cumplot(x)
|
|||
n=length(x);
|
||||
x=[-inf; sort(x); Inf];
|
||||
y=[0:n n]./n;
|
||||
h0 = stairs(x,y);
|
||||
grid on,
|
||||
|
||||
if nargout
|
||||
h=h0;
|
||||
end
|
||||
h = stairs(x,y);
|
||||
grid on
|
|
@ -1,4 +1,29 @@
|
|||
function [yy, xdir, isig, lam]=log_trans_(y0,xdir0,isig,lam)
|
||||
function [yy, xdir, isig, lam]=log_transform(y0,xdir0,isig,lam)
|
||||
% [yy, xdir, isig, lam]=log_transform(y0,xdir0,isig,lam)
|
||||
% Conduct automatic log transformation lam(yy/isig+lam)
|
||||
% Inputs:
|
||||
% - y0 [double] series to transform
|
||||
% - xdir [char] string indating the type of transformation:
|
||||
% - log: standard log transformation
|
||||
% - minuslog: log of minus (y0)
|
||||
% - logsquared: log of y0^2
|
||||
% - logskew: log of y0 shifted by lam
|
||||
% - isig [double] scaling factor for y0
|
||||
% - lam [double] shifting for y0
|
||||
%
|
||||
% Outputs:
|
||||
% - yy [double] transformed series
|
||||
% - xdir [char] string indating the type of transformation:
|
||||
% - log: standard log transformation
|
||||
% - minuslog: log of minus (y0)
|
||||
% - logsquared: log of y0^2
|
||||
% - logskew: log of y0 shifted by lam
|
||||
% - isig [double] scaling factor for y0
|
||||
% - lam [double] shifting for y0
|
||||
%
|
||||
% Notes: takes either one or four arguments. For one argument, the log
|
||||
% transformation is conducted. For four arguments, the inverse
|
||||
% transformation is applied.
|
||||
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -31,14 +56,18 @@ end
|
|||
if nargin==1
|
||||
xdir0='';
|
||||
end
|
||||
f=@(lam,y)gsa_skewness(log(y+lam));
|
||||
f=@(lam,y)gsa.skewness(log(y+lam));
|
||||
isig=1;
|
||||
if ~(max(y0)<0 | min(y0)>0)
|
||||
if gsa_skewness(y0)<0,
|
||||
if ~(max(y0)<0 || min(y0)>0)
|
||||
if gsa.skewness(y0)<0
|
||||
isig=-1;
|
||||
y0=-y0;
|
||||
end
|
||||
n=hist(y0,10);
|
||||
if isoctave
|
||||
n=hist(y0,10);
|
||||
else
|
||||
n=histcounts(y0,10);
|
||||
end
|
||||
if n(1)>20*n(end)
|
||||
try
|
||||
lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0);
|
||||
|
@ -48,7 +77,7 @@ if ~(max(y0)<0 | min(y0)>0)
|
|||
if abs(yl(1))<abs(yl(2))
|
||||
lam=-min(y0)+eps;
|
||||
else
|
||||
lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0)));
|
||||
lam = -min(y0)+abs(median(y0));
|
||||
end
|
||||
end
|
||||
yy = log(y0+lam);
|
||||
|
@ -63,10 +92,8 @@ else
|
|||
if max(y0)<0
|
||||
isig=-1;
|
||||
y0=-y0;
|
||||
%yy=log(-y0);
|
||||
xdir=[xdir0,'_minuslog'];
|
||||
elseif min(y0)>0
|
||||
%yy=log(y0);
|
||||
xdir=[xdir0,'_log'];
|
||||
end
|
||||
try
|
||||
|
@ -77,7 +104,7 @@ else
|
|||
if abs(yl(1))<abs(yl(2))
|
||||
lam=-min(y0)+eps;
|
||||
else
|
||||
lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0)));
|
||||
lam = -min(y0)+abs(median(y0));
|
||||
end
|
||||
end
|
||||
lam = max(lam,0);
|
|
@ -1,7 +1,13 @@
|
|||
function map_calibration(OutputDirectoryName, M_, options_, oo_, estim_params_, bayestopt_)
|
||||
% map_calibration(OutputDirectoryName, M_, options_, oo_, estim_params_, bayestopt_)
|
||||
|
||||
|
||||
% Inputs:
|
||||
% - OutputDirectoryName [string] name of the output directory
|
||||
% - M_ [structure] describing the model
|
||||
% - options_ [structure] describing the options
|
||||
% - oo_ [structure] storing the results
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
% marco.ratto@ec.europa.eu
|
||||
|
@ -32,16 +38,15 @@ pnames=cell(np,1);
|
|||
pnames_tex=cell(np,1);
|
||||
for jj=1:np
|
||||
if options_.TeX
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(nshock+jj, options_.TeX, M_, estim_params_, options_);
|
||||
pnames_tex{jj,1} = strrep(param_name_tex_temp,'$','');
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(nshock+jj, options_.TeX, M_, estim_params_, options_.varobs);
|
||||
pnames_tex{jj,1} = param_name_tex_temp;
|
||||
pnames{jj,1} = param_name_temp;
|
||||
else
|
||||
param_name_temp = get_the_name(nshock+jj, options_.TeX, M_, estim_params_, options_);
|
||||
param_name_temp = get_the_name(nshock+jj, options_.TeX, M_, estim_params_, options_.varobs);
|
||||
pnames{jj,1} = param_name_temp;
|
||||
end
|
||||
end
|
||||
|
||||
pvalue_ks = options_.opt_gsa.pvalue_ks;
|
||||
indx_irf = [];
|
||||
indx_moment = [];
|
||||
init = ~options_.opt_gsa.load_stab;
|
||||
|
@ -63,7 +68,7 @@ if options_.opt_gsa.ppost
|
|||
filetoload=dir([M_.dname filesep 'metropolis' filesep fname_ '_param_irf*.mat']);
|
||||
lpmat=[];
|
||||
for j=1:length(filetoload)
|
||||
load([M_.dname filesep 'metropolis' filesep fname_ '_param_irf',int2str(j),'.mat'])
|
||||
load([M_.dname filesep 'metropolis' filesep fname_ '_param_irf',int2str(j),'.mat'],'stock')
|
||||
lpmat = [lpmat; stock];
|
||||
clear stock
|
||||
end
|
||||
|
@ -71,12 +76,12 @@ if options_.opt_gsa.ppost
|
|||
else
|
||||
if options_.opt_gsa.pprior
|
||||
filetoload=[OutputDirectoryName '/' fname_ '_prior'];
|
||||
load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
|
||||
load(filetoload,'lpmat','lpmat0')
|
||||
lpmat = [lpmat0 lpmat];
|
||||
type = 'prior';
|
||||
else
|
||||
filetoload=[OutputDirectoryName '/' fname_ '_mc'];
|
||||
load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
|
||||
load(filetoload,'lpmat','lpmat0')
|
||||
lpmat = [lpmat0 lpmat];
|
||||
type = 'mc';
|
||||
end
|
||||
|
@ -99,17 +104,17 @@ if init
|
|||
mat_moment{ij}=NaN(Nsam,length(options_.endogenous_prior_restrictions.moment{ij,3}));
|
||||
end
|
||||
|
||||
irestrictions = [1:Nsam];
|
||||
irestrictions = 1:Nsam;
|
||||
h = dyn_waitbar(0,'Please wait...');
|
||||
for j=1:Nsam
|
||||
M_ = set_all_parameters(lpmat(j,:)',estim_params_,M_);
|
||||
if nbr_moment_restrictions
|
||||
[Tt,Rr,SteadyState,info,oo_.dr, M_.params] = dynare_resolve(M_,options_,oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
[Tt,Rr,~,info,oo_.dr, M_.params] = dynare_resolve(M_,options_,oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
else
|
||||
[Tt,Rr,SteadyState,info,oo_.dr, M_.params] = dynare_resolve(M_,options_,oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state,'restrict');
|
||||
[Tt,Rr,~,info,oo_.dr, M_.params] = dynare_resolve(M_,options_,oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state,'restrict');
|
||||
end
|
||||
if info(1)==0
|
||||
[info, info_irf, info_moment, data_irf, data_moment]=endogenous_prior_restrictions(Tt,Rr,M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
[~, info_irf, info_moment, data_irf, data_moment]=endogenous_prior_restrictions(Tt,Rr,M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
if ~isempty(info_irf)
|
||||
for ij=1:nbr_irf_restrictions
|
||||
mat_irf{ij}(j,:)=data_irf{ij}(:,2)';
|
||||
|
@ -125,7 +130,9 @@ if init
|
|||
else
|
||||
irestrictions(j)=0;
|
||||
end
|
||||
dyn_waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)])
|
||||
if mod(j,3)==0
|
||||
dyn_waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)])
|
||||
end
|
||||
end
|
||||
dyn_waitbar_close(h);
|
||||
|
||||
|
@ -183,7 +190,7 @@ if ~isempty(indx_irf)
|
|||
maxijv=0;
|
||||
for ij=1:nbr_irf_restrictions
|
||||
if length(endo_prior_restrictions.irf{ij,3})>maxijv
|
||||
maxij=ij;maxijv=length(endo_prior_restrictions.irf{ij,3});
|
||||
maxijv=length(endo_prior_restrictions.irf{ij,3});
|
||||
end
|
||||
plot_indx(ij) = find(strcmp(irf_couples,all_irf_couples(ij,:)));
|
||||
time_matrix{plot_indx(ij)} = [time_matrix{plot_indx(ij)} endo_prior_restrictions.irf{ij,3}];
|
||||
|
@ -205,7 +212,7 @@ if ~isempty(indx_irf)
|
|||
indx_irf_matrix(:,plot_indx(ij)) = indx_irf_matrix(:,plot_indx(ij)) + indx_irf(:,ij);
|
||||
for ik=1:size(mat_irf{ij},2)
|
||||
[Mean,Median,Var,HPD,Distrib] = ...
|
||||
posterior_moments(mat_irf{ij}(:,ik),0,options_.mh_conf_sig);
|
||||
posterior_moments(mat_irf{ij}(:,ik),options_.mh_conf_sig);
|
||||
irf_mean{plot_indx(ij)} = [irf_mean{plot_indx(ij)}; Mean];
|
||||
irf_median{plot_indx(ij)} = [irf_median{plot_indx(ij)}; Median];
|
||||
irf_var{plot_indx(ij)} = [irf_var{plot_indx(ij)}; Var];
|
||||
|
@ -222,7 +229,7 @@ if ~isempty(indx_irf)
|
|||
if ~options_.nograph && length(time_matrix{plot_indx(ij)})==1
|
||||
set(0,'currentfigure',h1),
|
||||
subplot(nrow,ncol, plot_indx(ij)),
|
||||
hc = cumplot(mat_irf{ij}(:,ik));
|
||||
hc = gsa.cumplot(mat_irf{ij}(:,ik));
|
||||
a=axis;
|
||||
delete(hc);
|
||||
x1val=max(endo_prior_restrictions.irf{ij,4}(1),a(1));
|
||||
|
@ -230,43 +237,30 @@ if ~isempty(indx_irf)
|
|||
hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
|
||||
hold all,
|
||||
set(hp,'FaceColor', [0.7 0.8 1])
|
||||
hc = cumplot(mat_irf{ij}(:,ik));
|
||||
hc = gsa.cumplot(mat_irf{ij}(:,ik));
|
||||
set(hc,'color','k','linewidth',2)
|
||||
hold off,
|
||||
% hold off,
|
||||
title([endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')'],'interpreter','none'),
|
||||
%set(legend_h,'Xlim',[0 1]);
|
||||
% if ij==maxij
|
||||
% leg1 = num2str(endo_prior_restrictions.irf{ij,3}(:));
|
||||
% [legend_h,object_h,plot_h,text_strings]=legend(leg1);
|
||||
% Position=get(legend_h,'Position');Position(1:2)=[-0.055 0.95-Position(4)];
|
||||
% set(legend_h,'Position',Position);
|
||||
% end
|
||||
end
|
||||
% hc = get(h,'Children');
|
||||
%for i=2:2:length(hc)
|
||||
%end
|
||||
indx1 = find(indx_irf(:,ij)==0);
|
||||
indx2 = find(indx_irf(:,ij)~=0);
|
||||
atitle0=[endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')'];
|
||||
fprintf(['%4.1f%% of the ',type,' support matches IRF ',atitle0,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,endo_prior_restrictions.irf{ij,4})
|
||||
% aname=[type '_irf_calib_',int2str(ij)];
|
||||
aname=[type '_irf_calib_',endo_prior_restrictions.irf{ij,1},'_vs_',endo_prior_restrictions.irf{ij,2},'_',aleg];
|
||||
atitle=[type ' IRF Calib: Parameter(s) driving ',endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')'];
|
||||
options_mcf.amcf_name = aname;
|
||||
options_mcf.amcf_title = atitle;
|
||||
options_mcf.beha_title = 'IRF restriction';
|
||||
options_mcf.nobeha_title = 'NO IRF restriction';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'IRF restriction';
|
||||
options_mcf.nobeha_title_latex = 'NO IRF restriction';
|
||||
end
|
||||
options_mcf.title = atitle0;
|
||||
if ~isempty(indx1) && ~isempty(indx2)
|
||||
mcf_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
|
||||
% [proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0);
|
||||
% indplot=find(proba<pvalue_ks);
|
||||
% if ~isempty(indplot)
|
||||
% stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle);
|
||||
% end
|
||||
end
|
||||
for ij=1:nbr_irf_couples
|
||||
if length(time_matrix{ij})>1
|
||||
|
@ -284,7 +278,6 @@ if ~isempty(indx_irf)
|
|||
tmp(temp_index,:) = endo_prior_restrictions.irf{itmp(ir),4};
|
||||
end
|
||||
end
|
||||
% tmp = cell2mat(endo_prior_restrictions.irf(itmp,4));
|
||||
tmp(isinf(tmp(:,1)),1)=a(3);
|
||||
tmp(isinf(tmp(:,2)),2)=a(4);
|
||||
hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'c');
|
||||
|
@ -297,7 +290,6 @@ if ~isempty(indx_irf)
|
|||
hold off
|
||||
axis([max(1,a(1)) a(2:4)])
|
||||
box on
|
||||
%set(gca,'xtick',sort(time_matrix{ij}))
|
||||
itmp = min(itmp);
|
||||
title([endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}],'interpreter','none'),
|
||||
end
|
||||
|
@ -311,16 +303,20 @@ if ~isempty(indx_irf)
|
|||
aleg = 'ALL';
|
||||
atitle0=[endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}, '(', leg,')'];
|
||||
fprintf(['%4.1f%% of the ',type,' support matches IRF restrictions ',atitle0,'\n'],length(indx1)/length(irestrictions)*100)
|
||||
% aname=[type '_irf_calib_',int2str(ij)];
|
||||
aname=[type '_irf_calib_',endo_prior_restrictions.irf{itmp,1},'_vs_',endo_prior_restrictions.irf{itmp,2},'_',aleg];
|
||||
atitle=[type ' IRF Calib: Parameter(s) driving ',endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}, '(', leg,')'];
|
||||
options_mcf.amcf_name = aname;
|
||||
options_mcf.amcf_title = atitle;
|
||||
options_mcf.beha_title = 'IRF restriction';
|
||||
options_mcf.nobeha_title = 'NO IRF restriction';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'IRF restriction';
|
||||
options_mcf.nobeha_title_latex = 'NO IRF restriction';
|
||||
end
|
||||
|
||||
options_mcf.title = atitle0;
|
||||
if ~isempty(indx1) && ~isempty(indx2)
|
||||
mcf_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -368,11 +364,11 @@ if ~isempty(indx_moment)
|
|||
name_tex=cell(np,1);
|
||||
for jj=1:np
|
||||
if options_.TeX
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(jj,options_.TeX,M_,estim_params_,options_);
|
||||
name_tex{jj,1} = strrep(param_name_tex_temp,'$','');
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
name_tex{jj,1} = param_name_tex_temp;
|
||||
name{jj,1} = param_name_temp;
|
||||
else
|
||||
param_name_temp = get_the_name(jj,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_temp = get_the_name(jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
name{jj,1} = param_name_temp;
|
||||
end
|
||||
end
|
||||
|
@ -398,7 +394,7 @@ if ~isempty(indx_moment)
|
|||
for ij=1:nbr_moment_restrictions
|
||||
endo_prior_restrictions.moment{ij,3} = sort(endo_prior_restrictions.moment{ij,3});
|
||||
if length(endo_prior_restrictions.moment{ij,3})>maxijv
|
||||
maxij=ij;maxijv=length(endo_prior_restrictions.moment{ij,3});
|
||||
maxijv=length(endo_prior_restrictions.moment{ij,3});
|
||||
end
|
||||
plot_indx(ij) = find(strcmp(moment_couples,all_moment_couples(ij,:)));
|
||||
time_matrix{plot_indx(ij)} = [time_matrix{plot_indx(ij)} endo_prior_restrictions.moment{ij,3}];
|
||||
|
@ -421,7 +417,7 @@ if ~isempty(indx_moment)
|
|||
indx_moment_matrix(:,plot_indx(ij)) = indx_moment_matrix(:,plot_indx(ij)) + indx_moment(:,ij);
|
||||
for ik=1:size(mat_moment{ij},2)
|
||||
[Mean,Median,Var,HPD,Distrib] = ...
|
||||
posterior_moments(mat_moment{ij}(:,ik),0,options_.mh_conf_sig);
|
||||
posterior_moments(mat_moment{ij}(:,ik),options_.mh_conf_sig);
|
||||
moment_mean{plot_indx(ij)} = [moment_mean{plot_indx(ij)}; Mean];
|
||||
moment_median{plot_indx(ij)} = [moment_median{plot_indx(ij)}; Median];
|
||||
moment_var{plot_indx(ij)} = [moment_var{plot_indx(ij)}; Var];
|
||||
|
@ -438,7 +434,7 @@ if ~isempty(indx_moment)
|
|||
if ~options_.nograph && length(time_matrix{plot_indx(ij)})==1
|
||||
set(0,'currentfigure',h2);
|
||||
subplot(nrow,ncol,plot_indx(ij)),
|
||||
hc = cumplot(mat_moment{ij}(:,ik));
|
||||
hc = gsa.cumplot(mat_moment{ij}(:,ik));
|
||||
a=axis; delete(hc),
|
||||
% hist(mat_moment{ij}),
|
||||
x1val=max(endo_prior_restrictions.moment{ij,4}(1),a(1));
|
||||
|
@ -446,38 +442,29 @@ if ~isempty(indx_moment)
|
|||
hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
|
||||
set(hp,'FaceColor', [0.7 0.8 1])
|
||||
hold all
|
||||
hc = cumplot(mat_moment{ij}(:,ik));
|
||||
hc = gsa.cumplot(mat_moment{ij}(:,ik));
|
||||
set(hc,'color','k','linewidth',2)
|
||||
hold off
|
||||
title([endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2},'(',leg,')'],'interpreter','none'),
|
||||
% if ij==maxij
|
||||
% leg1 = num2str(endo_prior_restrictions.moment{ij,3}(:));
|
||||
% [legend_h,object_h,plot_h,text_strings]=legend(leg1);
|
||||
% Position=get(legend_h,'Position');Position(1:2)=[-0.055 0.95-Position(4)];
|
||||
% set(legend_h,'Position',Position);
|
||||
% end
|
||||
end
|
||||
indx1 = find(indx_moment(:,ij)==0);
|
||||
indx2 = find(indx_moment(:,ij)~=0);
|
||||
atitle0=[endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2}, '(', leg,')'];
|
||||
fprintf(['%4.1f%% of the ',type,' support matches MOMENT ',atitle0,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,endo_prior_restrictions.moment{ij,4})
|
||||
% aname=[type '_moment_calib_',int2str(ij)];
|
||||
aname=[type '_moment_calib_',endo_prior_restrictions.moment{ij,1},'_vs_',endo_prior_restrictions.moment{ij,2},'_',aleg];
|
||||
atitle=[type ' MOMENT Calib: Parameter(s) driving ',endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2}, '(', leg,')'];
|
||||
options_mcf.amcf_name = aname;
|
||||
options_mcf.amcf_title = atitle;
|
||||
options_mcf.beha_title = 'moment restriction';
|
||||
options_mcf.nobeha_title = 'NO moment restriction';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'moment restriction';
|
||||
options_mcf.nobeha_title_latex = 'NO moment restriction';
|
||||
end
|
||||
options_mcf.title = atitle0;
|
||||
if ~isempty(indx1) && ~isempty(indx2)
|
||||
mcf_analysis(xmat, indx1, indx2, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(xmat, indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
|
||||
% [proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0);
|
||||
% indplot=find(proba<pvalue_ks);
|
||||
% if ~isempty(indplot)
|
||||
% stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle);
|
||||
% end
|
||||
end
|
||||
for ij=1:nbr_moment_couples
|
||||
time_matrix{ij} = sort(time_matrix{ij});
|
||||
|
@ -496,7 +483,6 @@ if ~isempty(indx_moment)
|
|||
tmp(temp_index,:) = endo_prior_restrictions.moment{itmp(ir),4};
|
||||
end
|
||||
end
|
||||
% tmp = cell2mat(endo_prior_restrictions.moment(itmp,4));
|
||||
tmp(isinf(tmp(:,1)),1)=a(3);
|
||||
tmp(isinf(tmp(:,2)),2)=a(4);
|
||||
hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b');
|
||||
|
@ -509,7 +495,6 @@ if ~isempty(indx_moment)
|
|||
hold off
|
||||
axis(a)
|
||||
box on
|
||||
% set(gca,'xtick',sort(time_matrix{ij}))
|
||||
itmp = min(itmp);
|
||||
title([endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}],'interpreter','none'),
|
||||
end
|
||||
|
@ -523,16 +508,19 @@ if ~isempty(indx_moment)
|
|||
aleg = 'ALL';
|
||||
atitle0=[endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}, '(', leg,')'];
|
||||
fprintf(['%4.1f%% of the ',type,' support matches MOMENT restrictions ',atitle0,'\n'],length(indx1)/length(irestrictions)*100)
|
||||
% aname=[type '_moment_calib_',int2str(ij)];
|
||||
aname=[type '_moment_calib_',endo_prior_restrictions.moment{itmp,1},'_vs_',endo_prior_restrictions.moment{itmp,2},'_',aleg];
|
||||
atitle=[type ' MOMENT Calib: Parameter(s) driving ',endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}, '(', leg,')'];
|
||||
options_mcf.amcf_name = aname;
|
||||
options_mcf.amcf_title = atitle;
|
||||
options_mcf.beha_title = 'moment restriction';
|
||||
options_mcf.nobeha_title = 'NO moment restriction';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'moment restriction';
|
||||
options_mcf.nobeha_title_latex = 'NO moment restriction';
|
||||
end
|
||||
options_mcf.title = atitle0;
|
||||
if ~isempty(indx1) && ~isempty(indx2)
|
||||
mcf_analysis(xmat, indx1, indx2, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(xmat, indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,305 @@
|
|||
function map_identification(OutputDirectoryName,opt_gsa,M_,oo_,options_,estim_params_,bayestopt_)
|
||||
% map_identification(OutputDirectoryName,opt_gsa,M_,oo_,options_,estim_params_,bayestopt_)
|
||||
% Inputs
|
||||
% - OutputDirectoryName [string] name of the output directory
|
||||
% - opt_gsa [structure] GSA options structure
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
% - oo_ [structure] Matlab's structure describing the results
|
||||
% - options_ [structure] Matlab's structure describing the current options
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
% marco.ratto@ec.europa.eu
|
||||
|
||||
% Copyright © 2012-2016 European Commission
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
fname_ = M_.fname;
|
||||
dr=oo_.dr;
|
||||
nliv = opt_gsa.morris_nliv;
|
||||
itrans = opt_gsa.trans_ident;
|
||||
|
||||
np = size(estim_params_.param_vals,1);
|
||||
|
||||
pnames = M_.param_names(estim_params_.param_vals(:,1));
|
||||
if opt_gsa.pprior
|
||||
filetoload=[OutputDirectoryName '/' fname_ '_prior'];
|
||||
else
|
||||
filetoload=[OutputDirectoryName '/' fname_ '_mc'];
|
||||
end
|
||||
load(filetoload,'lpmat','lpmat0','istable','T','yys')
|
||||
if ~isempty(lpmat0)
|
||||
lpmatx=lpmat0(istable,:);
|
||||
else
|
||||
lpmatx=[];
|
||||
end
|
||||
Nsam = size(lpmat,1);
|
||||
nshock = size(lpmat0,2);
|
||||
npT = np+nshock;
|
||||
|
||||
fname_ = M_.fname;
|
||||
|
||||
if opt_gsa.load_ident_files==0
|
||||
mss = yys(bayestopt_.mfys,:);
|
||||
mss = gsa.teff(mss(:,istable),Nsam,istable);
|
||||
yys = gsa.teff(yys(dr.order_var,istable),Nsam,istable);
|
||||
if exist('T','var')
|
||||
[vdec, cc, ac] = gsa.monte_carlo_moments(T, lpmatx, dr, M_, options_, estim_params_);
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
if opt_gsa.morris==2
|
||||
pdraws = identification.run(M_,oo_,options_,bayestopt_,estim_params_,options_.options_ident,[lpmatx lpmat(istable,:)]);
|
||||
if ~isempty(pdraws) && max(max(abs(pdraws-[lpmatx lpmat(istable,:)])))==0
|
||||
disp(['Sample check OK. Largest difference: ', num2str(max(max(abs(pdraws-[lpmatx lpmat(istable,:)]))))]),
|
||||
clear pdraws;
|
||||
end
|
||||
clear GAM gas
|
||||
end
|
||||
if opt_gsa.morris~=1 && M_.exo_nbr>1
|
||||
ifig=0;
|
||||
for j=1:M_.exo_nbr
|
||||
if mod(j,6)==1
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Variance decomposition shocks');
|
||||
ifig=ifig+1;
|
||||
iplo=0;
|
||||
end
|
||||
iplo=iplo+1;
|
||||
subplot(2,3,iplo)
|
||||
gsa.boxplot(squeeze(vdec(:,j,:))',[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:size(options_.varobs,1))
|
||||
set(gca,'xlim',[0.5 size(options_.varobs,1)+0.5])
|
||||
set(gca,'ylim',[-2 102])
|
||||
for ip=1:size(options_.varobs,1)
|
||||
if options_.TeX
|
||||
text(ip,-4,deblank(opt_gsa.varobs_tex(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-4,deblank(options_.varobs(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
xlabel(' ')
|
||||
ylabel(' ')
|
||||
title(M_.exo_names{j},'interpreter','none')
|
||||
if mod(j,6)==0 || j==M_.exo_nbr
|
||||
dyn_saveas(hh_fig,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)],ifig,'Variance decomposition shocks','vdec_exo',options_.figures.textwidth*min(iplo/3,1))
|
||||
end
|
||||
end
|
||||
end
|
||||
for j=1:size(cc,1)
|
||||
cc(j,j,:)=gsa.standardize_columns(squeeze(log(cc(j,j,:))))./2;
|
||||
end
|
||||
[vdec, ~, ir_vdec, ic_vdec] = gsa.teff(vdec,Nsam,istable);
|
||||
[cc, ~, ir_cc, ic_cc] = gsa.teff(cc,Nsam,istable);
|
||||
[ac, ~, ir_ac, ic_ac] = gsa.teff(ac,Nsam,istable);
|
||||
|
||||
nc1= size(T,2);
|
||||
endo_nbr = M_.endo_nbr;
|
||||
nstatic = M_.nstatic;
|
||||
nspred = M_.nspred;
|
||||
iv = (1:endo_nbr)';
|
||||
ic = [ nstatic+(1:nspred) endo_nbr+(1:size(dr.ghx,2)-nspred) ]';
|
||||
|
||||
dr.ghx = T(:, 1:(nc1-M_.exo_nbr),1);
|
||||
dr.ghu = T(:, (nc1-M_.exo_nbr+1):end, 1);
|
||||
[Aa,Bb] = kalman_transition_matrix(dr,iv,ic);
|
||||
A = zeros(size(Aa,1),size(Aa,2)+size(Aa,1),length(istable));
|
||||
if ~isempty(lpmatx)
|
||||
M_=gsa.set_shocks_param(M_,estim_params_,lpmatx(1,:));
|
||||
end
|
||||
A(:,:,1)=[Aa, triu(Bb*M_.Sigma_e*Bb')];
|
||||
for j=2:length(istable)
|
||||
dr.ghx = T(:, 1:(nc1-M_.exo_nbr),j);
|
||||
dr.ghu = T(:, (nc1-M_.exo_nbr+1):end, j);
|
||||
[Aa,Bb] = kalman_transition_matrix(dr, iv, ic);
|
||||
if ~isempty(lpmatx)
|
||||
M_=gsa.set_shocks_param(M_,estim_params_,lpmatx(j,:));
|
||||
end
|
||||
A(:,:,j)=[Aa, triu(Bb*M_.Sigma_e*Bb')];
|
||||
end
|
||||
clear T
|
||||
clear lpmatx
|
||||
|
||||
[yt, j0]=gsa.teff(A,Nsam,istable);
|
||||
yt = [yys yt];
|
||||
if opt_gsa.morris==2
|
||||
clear TAU A
|
||||
else
|
||||
clear A
|
||||
end
|
||||
save([OutputDirectoryName,'/',fname_,'_main_eff.mat'],'ac','cc','vdec','yt','mss')
|
||||
else %load identification files
|
||||
load([OutputDirectoryName,'/',fname_,'_main_eff.mat'],'ac','cc','vdec','yt','mss')
|
||||
end
|
||||
|
||||
if opt_gsa.morris==1
|
||||
if ~isempty(vdec)
|
||||
if opt_gsa.load_ident_files==0
|
||||
SAMorris=NaN(npT,3,size(vdec,2));
|
||||
for i=1:size(vdec,2)
|
||||
[~, SAMorris(:,:,i)] = gsa.Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv);
|
||||
end
|
||||
SAvdec = squeeze(SAMorris(:,1,:))';
|
||||
save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAvdec','vdec','ir_vdec','ic_vdec')
|
||||
else
|
||||
load([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAvdec')
|
||||
end
|
||||
|
||||
hh_fig = dyn_figure(options_.nodisplay,'name','Screening identification: variance decomposition');
|
||||
gsa.boxplot(SAvdec,[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:npT)
|
||||
set(gca,'xlim',[0.5 npT+0.5])
|
||||
ydum = get(gca,'ylim');
|
||||
set(gca,'ylim',[0 ydum(2)])
|
||||
set(gca,'position',[0.13 0.2 0.775 0.7])
|
||||
for ip=1:npT
|
||||
if options_.TeX
|
||||
[~, param_name_tex_temp]= get_the_name(ip,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
text(ip,-2,param_name_tex_temp,'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
xlabel(' ')
|
||||
title('Elementary effects variance decomposition')
|
||||
dyn_saveas(hh_fig,[OutputDirectoryName,'/',fname_,'_morris_vdec'],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_vdec'],1,'Screening identification: variance decomposition','morris_vdec',1)
|
||||
else
|
||||
save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'vdec')
|
||||
end
|
||||
|
||||
if opt_gsa.load_ident_files==0
|
||||
ccac = [mss cc ac];
|
||||
SAMorris=NaN(npT,3,size(ccac,2));
|
||||
for i=1:size(ccac,2)
|
||||
[~, SAMorris(:,:,i)] = gsa.Morris_Measure_Groups(npT, [lpmat0 lpmat], [ccac(:,i)],nliv);
|
||||
end
|
||||
SAcc = squeeze(SAMorris(:,1,:))';
|
||||
SAcc = SAcc./(max(SAcc,[],2)*ones(1,npT));
|
||||
save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAcc','cc','ir_cc','ic_cc','-append')
|
||||
save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'ac','ir_ac','ic_ac','-append')
|
||||
else
|
||||
load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc')
|
||||
load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac')
|
||||
end
|
||||
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Screening identification: theoretical moments');
|
||||
gsa.boxplot(SAcc,[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:npT)
|
||||
set(gca,'xlim',[0.5 npT+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
set(gca,'position',[0.13 0.2 0.775 0.7])
|
||||
for ip=1:npT
|
||||
if options_.TeX
|
||||
[~, param_name_tex_temp]= get_the_name(ip,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
text(ip,-0.02,param_name_tex_temp,'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
xlabel(' ')
|
||||
title('Elementary effects in the moments')
|
||||
dyn_saveas(hh_fig,[OutputDirectoryName,'/',fname_,'_morris_moments'],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_moments'],1,'Screening identification: theoretical moments','morris_moments',1)
|
||||
|
||||
if opt_gsa.load_ident_files==0
|
||||
SAMorris=NaN(npT,3,j0);
|
||||
for j=1:j0
|
||||
[~, SAMorris(:,:,j)] = gsa.Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv);
|
||||
end
|
||||
|
||||
SAM = squeeze(SAMorris(1:end,1,:));
|
||||
SAnorm=NaN(npT,j0);
|
||||
irex=NaN(j0);
|
||||
for j=1:j0
|
||||
SAnorm(:,j)=SAM(:,j)./max(SAM(:,j));
|
||||
irex(j)=length(find(SAnorm(:,j)>0.01));
|
||||
end
|
||||
|
||||
SAMmu = squeeze(SAMorris(1:end,2,:));
|
||||
SAmunorm=NaN(npT,j0);
|
||||
for j=1:j0
|
||||
SAmunorm(:,j)=SAMmu(:,j)./max(SAM(:,j)); % normalised w.r.t. mu*
|
||||
end
|
||||
SAMsig = squeeze(SAMorris(1:end,3,:));
|
||||
SAsignorm=NaN(npT,j0);
|
||||
for j=1:j0
|
||||
SAsignorm(:,j)=SAMsig(:,j)./max(SAMsig(:,j));
|
||||
end
|
||||
save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAnorm','SAmunorm','SAsignorm','-append')
|
||||
else
|
||||
load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm')
|
||||
end
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Screening identification: model');
|
||||
gsa.boxplot(SAnorm',[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:npT)
|
||||
set(gca,'xlim',[0.5 npT+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
set(gca,'position',[0.13 0.2 0.775 0.7])
|
||||
xlabel(' ')
|
||||
for ip=1:npT
|
||||
if options_.TeX
|
||||
[~, param_name_tex_temp]= get_the_name(ip,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
text(ip,-0.02,param_name_tex_temp,'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
xlabel(' ')
|
||||
title('Elementary effects in the model')
|
||||
dyn_saveas(hh_fig,[OutputDirectoryName,'/',fname_,'_morris_par'],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_par'],1,'Screening identification: model','morris_par',1)
|
||||
|
||||
elseif opt_gsa.morris==3
|
||||
return
|
||||
elseif opt_gsa.morris==2 % ISKREV stuff
|
||||
return
|
||||
else
|
||||
error('gsa/map_identification: unsupported option morris=%u',opt_gsa.morris)
|
||||
end
|
||||
|
||||
function []=create_TeX_loader(options_,figpath,ifig_number,caption,label_name,scale_factor)
|
||||
if nargin<6
|
||||
scale_factor=1;
|
||||
end
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([figpath '.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by map_ident_.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s}\n',scale_factor,strrep(figpath,'\','/'));
|
||||
fprintf(fidTeX,'\\caption{%s.}',caption);
|
||||
fprintf(fidTeX,'\\label{Fig:%s:%u}\n',label_name,ifig_number);
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
fprintf(fidTeX,'%% End Of TeX file. \n');
|
||||
fclose(fidTeX);
|
||||
end
|
||||
|
||||
|
||||
function yr = trank(y)
|
||||
% yr is the rank transformation of y
|
||||
yr=NaN(size(y));
|
||||
[nr, nc] = size(y);
|
||||
for j=1:nc
|
||||
[~, is]=sort(y(:,j));
|
||||
yr(is,j)=[1:nr]'./nr;
|
||||
end
|
|
@ -1,5 +1,25 @@
|
|||
function [rmse_MC, ixx] = filt_mc_(OutDir,options_gsa_,dataset_,dataset_info)
|
||||
% function [rmse_MC, ixx] = filt_mc_(OutDir)
|
||||
function [rmse_MC, ixx] = monte_carlo_filtering(OutDir,options_gsa_,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
% [rmse_MC, ixx] = monte_carlo_filtering(OutDir,options_gsa_,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_
|
||||
% Inputs:
|
||||
% - OutputDirectoryName [string] name of the output directory
|
||||
% - options_gsa_ [structure] GSA options
|
||||
% - dataset_ [dseries] object storing the dataset
|
||||
% - dataset_info [structure] storing informations about the sample.
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
% - oo_ [structure] storing the results
|
||||
% - options_ [structure] Matlab's structure describing the current options
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
%
|
||||
% Outputs:
|
||||
% - rmse_MC [double] RMSE by nvar matrix of the RMSEs
|
||||
% - ixx [double] RMSE by nvar matrix of sorting
|
||||
% indices (descending order of RMSEs)
|
||||
%
|
||||
% Notes: the R^2 definition is 1-var(ymodel-ydata)/var(ydata). It ranges
|
||||
% bewteen (-inf, 1], with negative values indicating that themodel is a worse
|
||||
% predictor than the sample mean of the data
|
||||
|
||||
% inputs (from opt_gsa structure)
|
||||
% vvarvecm = options_gsa_.var_rmse;
|
||||
% loadSA = options_gsa_.load_rmse;
|
||||
|
@ -7,7 +27,6 @@ function [rmse_MC, ixx] = filt_mc_(OutDir,options_gsa_,dataset_,dataset_info)
|
|||
% alpha = options_gsa_.alpha_rmse;
|
||||
% alpha2 = options_gsa_.alpha2_rmse;
|
||||
% istart = options_gsa_.istart_rmse;
|
||||
% alphaPC = 0.5;
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -31,9 +50,6 @@ function [rmse_MC, ixx] = filt_mc_(OutDir,options_gsa_,dataset_,dataset_info)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global bayestopt_ estim_params_ M_ options_ oo_
|
||||
|
||||
% options_gsa_=options_.opt_gsa;
|
||||
vvarvecm = options_gsa_.var_rmse;
|
||||
if options_.TeX
|
||||
vvarvecm_tex = options_gsa_.var_rmse_tex;
|
||||
|
@ -46,13 +62,10 @@ alpha = options_gsa_.alpha_rmse;
|
|||
alpha2 = 0;
|
||||
pvalue = options_gsa_.alpha2_rmse;
|
||||
istart = max(2,options_gsa_.istart_rmse);
|
||||
alphaPC = 0.5;
|
||||
|
||||
fname_ = M_.fname;
|
||||
lgy_ = M_.endo_names;
|
||||
dr_ = oo_.dr;
|
||||
|
||||
skipline(2)
|
||||
skipline(1)
|
||||
disp('Starting sensitivity analysis')
|
||||
disp('for the fit of EACH observed series ...')
|
||||
skipline()
|
||||
|
@ -61,12 +74,12 @@ if ~options_.nograph
|
|||
a=dir([OutDir,filesep,'*.*']);
|
||||
tmp1='0';
|
||||
if options_.opt_gsa.ppost
|
||||
tmp=['_rmse_post'];
|
||||
tmp='_rmse_post';
|
||||
else
|
||||
if options_.opt_gsa.pprior
|
||||
tmp=['_rmse_prior'];
|
||||
tmp='_rmse_prior';
|
||||
else
|
||||
tmp=['_rmse_mc'];
|
||||
tmp='_rmse_mc';
|
||||
end
|
||||
if options_gsa_.lik_only
|
||||
tmp1 = [tmp,'_post_SA'];
|
||||
|
@ -75,17 +88,23 @@ if ~options_.nograph
|
|||
end
|
||||
for j=1:length(a)
|
||||
if strmatch([fname_,tmp],a(j).name)
|
||||
disp(a(j).name)
|
||||
if options_.debug
|
||||
disp(a(j).name)
|
||||
end
|
||||
delete([OutDir,filesep,a(j).name])
|
||||
end
|
||||
if strmatch([fname_,tmp1],a(j).name)
|
||||
disp(a(j).name)
|
||||
if options_.debug
|
||||
disp(a(j).name)
|
||||
end
|
||||
delete([OutDir,filesep,a(j).name])
|
||||
end
|
||||
end
|
||||
disp('done !')
|
||||
end
|
||||
|
||||
[param_names,param_names_tex]=get_LaTeX_parameter_names(M_,options_,estim_params_,bayestopt_);
|
||||
|
||||
nshock=estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn;
|
||||
npar=estim_params_.np;
|
||||
if ~isempty(options_.mode_file)
|
||||
|
@ -94,10 +113,12 @@ end
|
|||
if options_.opt_gsa.ppost
|
||||
c=load([M_.dname filesep 'Output' filesep fname_,'_mean.mat'],'xparam1');
|
||||
xparam1_mean=c.xparam1;
|
||||
xparam1=c.xparam1;
|
||||
clear c
|
||||
elseif ~isempty(options_.mode_file) && exist([M_.dname filesep 'Output' filesep fname_,'_mean.mat'])==2
|
||||
elseif ~isempty(options_.mode_file) && exist([M_.dname filesep 'Output' filesep fname_,'_mean.mat'],'file')==2
|
||||
c=load([M_.dname filesep 'Output' filesep fname_,'_mean.mat'],'xparam1');
|
||||
xparam1_mean=c.xparam1;
|
||||
xparam1=c.xparam1;
|
||||
clear c
|
||||
end
|
||||
|
||||
|
@ -124,31 +145,11 @@ if loadSA
|
|||
end
|
||||
end
|
||||
if ~loadSA
|
||||
if exist('xparam1','var')
|
||||
M_ = set_all_parameters(xparam1,estim_params_,M_);
|
||||
ys_mode=evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,~options_.steadystate.nocheck);
|
||||
end
|
||||
if exist('xparam1_mean','var')
|
||||
M_ = set_all_parameters(xparam1_mean,estim_params_,M_);
|
||||
ys_mean=evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,~options_.steadystate.nocheck);
|
||||
end
|
||||
Y = transpose(dataset_.data);
|
||||
gend = dataset_.nobs;
|
||||
data_index = dataset_info.missing.aindex;
|
||||
missing_value = dataset_info.missing.state;
|
||||
for jx=1:gend
|
||||
data_indx(jx,data_index{jx})=true;
|
||||
end
|
||||
load([DirectoryName filesep M_.fname '_data.mat']);
|
||||
filfilt = dir([DirectoryName filesep M_.fname '_filter_step_ahead*.mat']);
|
||||
temp_smooth_file_list = dir([DirectoryName filesep M_.fname '_smooth*.mat']);
|
||||
jfile=0;
|
||||
for j=1:length(temp_smooth_file_list)
|
||||
if isempty(strfind(temp_smooth_file_list(j).name,'smoothed')),
|
||||
jfile=jfile+1;
|
||||
filsmooth(jfile)=temp_smooth_file_list(j);
|
||||
end
|
||||
end
|
||||
filupdate = dir([DirectoryName filesep M_.fname '_update*.mat']);
|
||||
filparam = dir([DirectoryName filesep M_.fname '_param*.mat']);
|
||||
x=[];
|
||||
|
@ -156,11 +157,11 @@ if ~loadSA
|
|||
sto_ys=[];
|
||||
for j=1:length(filparam)
|
||||
if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name))
|
||||
load([DirectoryName filesep filparam(j).name]);
|
||||
x=[x; stock];
|
||||
logpo2=[logpo2; stock_logpo];
|
||||
sto_ys=[sto_ys; stock_ys];
|
||||
clear stock stock_logpo stock_ys;
|
||||
temp=load([DirectoryName filesep filparam(j).name]); % from prior_posterior_statistics_core
|
||||
x=[x; temp.stock];
|
||||
logpo2=[logpo2; temp.stock_logpo];
|
||||
sto_ys=[sto_ys; temp.stock_ys];
|
||||
clear temp;
|
||||
end
|
||||
end
|
||||
nruns=size(x,1);
|
||||
|
@ -168,38 +169,41 @@ if ~loadSA
|
|||
if options_.opt_gsa.ppost || (options_.opt_gsa.ppost==0 && options_.opt_gsa.lik_only==0)
|
||||
skipline()
|
||||
disp('Computing RMSE''s...')
|
||||
jxj=NaN(length(vvarvecm),1);
|
||||
js=NaN(length(vvarvecm),1);
|
||||
yss=NaN(length(vvarvecm),gend,size(sto_ys,1));
|
||||
for i = 1:length(vvarvecm)
|
||||
vj = vvarvecm{i};
|
||||
jxj(i) = strmatch(vj, lgy_(dr_.order_var), 'exact');
|
||||
js(i) = strmatch(vj, lgy_, 'exact');
|
||||
jxj(i) = strmatch(vj, M_.endo_names(oo_.dr.order_var), 'exact');
|
||||
js(i) = strmatch(vj, M_.endo_names, 'exact');
|
||||
yss(i,:,:)=repmat(sto_ys(:,js(i))',[gend,1]);
|
||||
end
|
||||
if exist('xparam1','var')
|
||||
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
y0 = reshape( squeeze(aK(1,jxj,1:gend)),[gend length(jxj)]);% + kron(ys_mode(js),ones(1,gend)));
|
||||
yobs = transpose( ahat(jxj,:));% + kron(ys_mode(js),ones(1,gend)));
|
||||
[~,~,~,ahat,~,~,aK] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
y0 = reshape( squeeze(aK(1,jxj,1:gend)),[gend length(jxj)]);
|
||||
yobs = transpose( ahat(jxj,:));
|
||||
rmse_mode = sqrt(mean((yobs(istart:end,:)-y0(istart:end,:)).^2));
|
||||
r2_mode = 1-sum((yobs(istart:end,:)-y0(istart:end,:)).^2)./sum(yobs(istart:end,:).^2);
|
||||
end
|
||||
y0=-yss;
|
||||
|
||||
y0=-yss; %demean everything using the theoretical mean, i.e. steady state
|
||||
nbb=0;
|
||||
for j=1:length(filfilt)
|
||||
load([DirectoryName filesep M_.fname '_filter_step_ahead',num2str(j),'.mat']);
|
||||
nb = size(stock,4);
|
||||
y0(:,:,nbb+1:nbb+nb)=y0(:,:,nbb+1:nbb+nb)+reshape(stock(1,js,1:gend,:),[length(js) gend nb]);
|
||||
temp=load([DirectoryName filesep M_.fname '_filter_step_ahead',num2str(j),'.mat']);
|
||||
nb = size(temp.stock,4);
|
||||
y0(:,:,nbb+1:nbb+nb)=y0(:,:,nbb+1:nbb+nb)+reshape(temp.stock(1,js,1:gend,:),[length(js) gend nb]);
|
||||
nbb=nbb+nb;
|
||||
clear stock;
|
||||
clear temp;
|
||||
end
|
||||
yobs=-yss;
|
||||
nbb=0;
|
||||
for j=1:length(filupdate)
|
||||
load([DirectoryName filesep M_.fname '_update',num2str(j),'.mat']);
|
||||
nb = size(stock,3);
|
||||
yobs(:,:,nbb+1:nbb+nb)=yobs(:,:,nbb+1:nbb+nb)+reshape(stock(js,1:gend,:),[length(js) gend nb]);
|
||||
temp=load([DirectoryName filesep M_.fname '_update',num2str(j),'.mat']);
|
||||
nb = size(temp.stock,3);
|
||||
yobs(:,:,nbb+1:nbb+nb)=yobs(:,:,nbb+1:nbb+nb)+reshape(temp.stock(js,1:gend,:),[length(js) gend nb]);
|
||||
nbb=nbb+nb;
|
||||
clear stock;
|
||||
clear temp;
|
||||
end
|
||||
y0M=mean(y0,2);
|
||||
rmse_MC=zeros(nruns,length(js));
|
||||
r2_MC=zeros(nruns,length(js));
|
||||
for j=1:nruns
|
||||
|
@ -207,14 +211,15 @@ if ~loadSA
|
|||
r2_MC(j,:) = 1-mean((yobs(:,istart:end,j)'-y0(:,istart:end,j)').^2)./mean((yobs(:,istart:end,j)').^2);
|
||||
end
|
||||
if exist('xparam1_mean','var')
|
||||
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1_mean,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
y0 = reshape( squeeze(aK(1,jxj,1:gend)),[gend length(jxj)]);% + kron(ys_mean(js),ones(1,gend)));
|
||||
yobs = transpose( ahat(jxj,:));% + kron(ys_mean(js),ones(1,gend)));
|
||||
[~,~,~,ahat,~,~,aK] = DsgeSmoother(xparam1_mean,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
y0 = reshape( squeeze(aK(1,jxj,1:gend)),[gend length(jxj)]);
|
||||
yobs = transpose( ahat(jxj,:));
|
||||
rmse_pmean = sqrt(mean((yobs(istart:end,:)-y0(istart:end,:)).^2));
|
||||
r2_pmean = 1-mean((yobs(istart:end,:)-y0(istart:end,:)).^2)./mean(yobs(istart:end,:).^2);
|
||||
end
|
||||
clear stock_filter;
|
||||
end
|
||||
lnprior=NaN(nruns,1);
|
||||
for j=1:nruns
|
||||
lnprior(j,1) = priordens(x(j,:)',bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7,bayestopt_.p3,bayestopt_.p4);
|
||||
end
|
||||
|
@ -242,7 +247,7 @@ if ~loadSA
|
|||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
else % loadSA
|
||||
if options_.opt_gsa.lik_only && options_.opt_gsa.ppost==0
|
||||
load([OutDir,filesep,fnamtmp, '.mat'],'x','logpo2','likelihood');
|
||||
else
|
||||
|
@ -252,27 +257,27 @@ else
|
|||
nruns=size(x,1);
|
||||
nfilt=floor(pfilt*nruns);
|
||||
end
|
||||
% smirnov tests
|
||||
% Smirnov tests
|
||||
nfilt0 = nfilt*ones(length(vvarvecm), 1);
|
||||
logpo2=logpo2(:);
|
||||
if ~options_.opt_gsa.ppost
|
||||
[dum, ipost]=sort(-logpo2);
|
||||
[dum, ilik]=sort(-likelihood);
|
||||
[~, ipost]=sort(-logpo2);
|
||||
[~, ilik]=sort(-likelihood);
|
||||
end
|
||||
|
||||
% visual scatter analysis!
|
||||
if options_.opt_gsa.ppost
|
||||
tmp_title='R2 Posterior:';
|
||||
atitle='R2 Posterior:';
|
||||
tmp_title='R2 Scatter plot: Posterior';
|
||||
atitle='R2 Scatter plot: Posterior';
|
||||
asname='r2_post';
|
||||
else
|
||||
if options_.opt_gsa.pprior
|
||||
tmp_title='R2 Prior:';
|
||||
atitle='R2 Prior:';
|
||||
tmp_title='R2 Scatter plot: Prior';
|
||||
atitle='R2 Scatter plot: Prior';
|
||||
asname='r2_prior';
|
||||
else
|
||||
tmp_title='R2 MC:';
|
||||
atitle='R2 MC:';
|
||||
tmp_title='R2 Scatter plot: MC';
|
||||
atitle='R2 Scatter plot: MC';
|
||||
asname='r2_mc';
|
||||
end
|
||||
end
|
||||
|
@ -283,7 +288,7 @@ options_scatter.OutputDirectoryName = OutDir;
|
|||
options_scatter.amcf_name = asname;
|
||||
options_scatter.amcf_title = atitle;
|
||||
options_scatter.title = tmp_title;
|
||||
scatter_analysis(r2_MC, x,options_scatter, options_);
|
||||
gsa.scatter_analysis(r2_MC, x,options_scatter, options_);
|
||||
% end of visual scatter analysis
|
||||
|
||||
if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only
|
||||
|
@ -297,13 +302,10 @@ if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only
|
|||
options_mcf.pvalue_ks = alpha;
|
||||
options_mcf.pvalue_corr = pvalue;
|
||||
options_mcf.alpha2 = alpha2;
|
||||
options_mcf.param_names = param_names;
|
||||
if options_.TeX
|
||||
[pnames,pnames_tex]=get_LaTeX_parameter_names(M_,options_,estim_params_,bayestopt_);
|
||||
options_mcf.param_names = pnames;
|
||||
options_mcf.param_names_tex = pnames_tex;
|
||||
options_mcf.param_names_tex = param_names_tex;
|
||||
else
|
||||
[pnames]=get_LaTeX_parameter_names(M_,options_,estim_params_,bayestopt_);
|
||||
options_mcf.param_names = pnames;
|
||||
options_mcf.param_names_tex = {};
|
||||
end
|
||||
options_mcf.fname_ = fname_;
|
||||
|
@ -313,7 +315,12 @@ if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only
|
|||
options_mcf.title = atitle;
|
||||
options_mcf.beha_title = 'better posterior kernel';
|
||||
options_mcf.nobeha_title = 'worse posterior kernel';
|
||||
mcf_analysis(x, ipost(1:nfilt), ipost(nfilt+1:end), options_mcf, options_);
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'better posterior kernel';
|
||||
options_mcf.nobeha_title_latex = 'worse posterior kernel';
|
||||
end
|
||||
|
||||
gsa.monte_carlo_filtering_analysis(x, ipost(1:nfilt), ipost(nfilt+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
if options_.opt_gsa.pprior
|
||||
anam = 'rmse_prior_lik';
|
||||
atitle = 'RMSE prior: Log Likelihood Kernel';
|
||||
|
@ -326,15 +333,20 @@ if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only
|
|||
options_mcf.title = atitle;
|
||||
options_mcf.beha_title = 'better likelihood';
|
||||
options_mcf.nobeha_title = 'worse likelihood';
|
||||
mcf_analysis(x, ilik(1:nfilt), ilik(nfilt+1:end), options_mcf, options_);
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'better likelihood';
|
||||
options_mcf.nobeha_title_latex = 'worse likelihood';
|
||||
end
|
||||
|
||||
gsa.monte_carlo_filtering_analysis(x, ilik(1:nfilt), ilik(nfilt+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
else
|
||||
if options_.opt_gsa.ppost
|
||||
rmse_txt=rmse_pmean;
|
||||
r2_txt=r2_pmean;
|
||||
else
|
||||
if options_.opt_gsa.pprior || ~exist('rmse_pmean')
|
||||
if exist('rmse_mode')
|
||||
if options_.opt_gsa.pprior || ~exist('rmse_pmean','var')
|
||||
if exist('rmse_mode','var')
|
||||
rmse_txt=rmse_mode;
|
||||
r2_txt=r2_mode;
|
||||
else
|
||||
|
@ -346,18 +358,19 @@ else
|
|||
r2_txt=r2_pmean;
|
||||
end
|
||||
end
|
||||
ixx=NaN(size(rmse_MC,1),length(vvarvecm));
|
||||
for i = 1:length(vvarvecm)
|
||||
[dum, ixx(:,i)] = sort(rmse_MC(:,i));
|
||||
[~, ixx(:,i)] = sort(rmse_MC(:,i));
|
||||
end
|
||||
PP = ones(npar+nshock, length(vvarvecm));
|
||||
PPV = ones(length(vvarvecm), length(vvarvecm), npar+nshock);
|
||||
SS = zeros(npar+nshock, length(vvarvecm));
|
||||
for j = 1:npar+nshock
|
||||
for i = 1:length(vvarvecm)
|
||||
[H, P, KSSTAT] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j), alpha);
|
||||
[H1, P1, KSSTAT1] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,1);
|
||||
[H2, P2, KSSTAT2] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,-1);
|
||||
if H1 & H2==0
|
||||
[~, P] = gsa.smirnov_test(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j), alpha);
|
||||
[H1] = gsa.smirnov_test(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,1);
|
||||
[H2] = gsa.smirnov_test(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,-1);
|
||||
if H1==0 && H2==0
|
||||
SS(j,i)=1;
|
||||
elseif H1==0
|
||||
SS(j,i)=-1;
|
||||
|
@ -369,7 +382,7 @@ else
|
|||
for i = 1:length(vvarvecm)
|
||||
for l = 1:length(vvarvecm)
|
||||
if l~=i && PP(j,i)<alpha && PP(j,l)<alpha
|
||||
[H,P,KSSTAT] = smirnov(x(ixx(1:nfilt0(i),i),j),x(ixx(1:nfilt0(l),l),j), alpha);
|
||||
[~,P] = gsa.smirnov_test(x(ixx(1:nfilt0(i),i),j),x(ixx(1:nfilt0(l),l),j), alpha);
|
||||
PPV(i,l,j) = P;
|
||||
elseif l==i
|
||||
PPV(i,l,j) = PP(j,i);
|
||||
|
@ -394,13 +407,17 @@ else
|
|||
hh_fig=dyn_figure(options_.nodisplay,'name',[temp_name,' ',int2str(ifig)]);
|
||||
end
|
||||
subplot(3,3,i-9*(ifig-1))
|
||||
h=cumplot(lnprior(ixx(1:nfilt0(i),i)));
|
||||
h=gsa.cumplot(lnprior(ixx(1:nfilt0(i),i)));
|
||||
set(h,'color','blue','linewidth',2)
|
||||
hold on, h=cumplot(lnprior);
|
||||
hold on, h=gsa.cumplot(lnprior);
|
||||
set(h,'color','k','linewidth',1)
|
||||
h=cumplot(lnprior(ixx(nfilt0(i)+1:end,i)));
|
||||
h=gsa.cumplot(lnprior(ixx(nfilt0(i)+1:end,i)));
|
||||
set(h,'color','red','linewidth',2)
|
||||
title(vvarvecm{i},'interpreter','none')
|
||||
if options_.TeX
|
||||
title(vvarvecm_tex{i},'interpreter','latex')
|
||||
else
|
||||
title(vvarvecm{i},'interpreter','none')
|
||||
end
|
||||
if mod(i,9)==0 || i==length(vvarvecm)
|
||||
if ~isoctave
|
||||
annotation('textbox', [0.1,0,0.35,0.05],'String', 'Log-prior for BETTER R2','Color','Blue','horizontalalignment','center');
|
||||
|
@ -442,13 +459,17 @@ else
|
|||
hh_fig = dyn_figure(options_.nodisplay,'Name',[temp_name,' ',int2str(ifig)]);
|
||||
end
|
||||
subplot(3,3,i-9*(ifig-1))
|
||||
h=cumplot(likelihood(ixx(1:nfilt0(i),i)));
|
||||
h=gsa.cumplot(likelihood(ixx(1:nfilt0(i),i)));
|
||||
set(h,'color','blue','linewidth',2)
|
||||
hold on, h=cumplot(likelihood);
|
||||
hold on, h=gsa.cumplot(likelihood);
|
||||
set(h,'color','k','linewidth',1)
|
||||
h=cumplot(likelihood(ixx(nfilt0(i)+1:end,i)));
|
||||
h=gsa.cumplot(likelihood(ixx(nfilt0(i)+1:end,i)));
|
||||
set(h,'color','red','linewidth',2)
|
||||
title(vvarvecm{i},'interpreter','none')
|
||||
if options_.TeX
|
||||
title(vvarvecm_tex{i},'interpreter','latex')
|
||||
else
|
||||
title(vvarvecm{i},'interpreter','none')
|
||||
end
|
||||
if options_.opt_gsa.ppost==0
|
||||
set(gca,'xlim',[min( likelihood(ixx(1:nfilt0(i),i)) ) max( likelihood(ixx(1:nfilt0(i),i)) )])
|
||||
end
|
||||
|
@ -493,13 +514,17 @@ else
|
|||
hh_fig = dyn_figure(options_.nodisplay,'Name',[temp_name,' ',int2str(ifig)]);
|
||||
end
|
||||
subplot(3,3,i-9*(ifig-1))
|
||||
h=cumplot(logpo2(ixx(1:nfilt0(i),i)));
|
||||
h=gsa.cumplot(logpo2(ixx(1:nfilt0(i),i)));
|
||||
set(h,'color','blue','linewidth',2)
|
||||
hold on, h=cumplot(logpo2);
|
||||
hold on, h=gsa.cumplot(logpo2);
|
||||
set(h,'color','k','linewidth',1)
|
||||
h=cumplot(logpo2(ixx(nfilt0(i)+1:end,i)));
|
||||
h=gsa.cumplot(logpo2(ixx(nfilt0(i)+1:end,i)));
|
||||
set(h,'color','red','linewidth',2)
|
||||
title(vvarvecm{i},'interpreter','none')
|
||||
if options_.TeX
|
||||
title(vvarvecm_tex{i},'interpreter','latex')
|
||||
else
|
||||
title(vvarvecm{i},'interpreter','none')
|
||||
end
|
||||
if options_.opt_gsa.ppost==0
|
||||
set(gca,'xlim',[min( logpo2(ixx(1:nfilt0(i),i)) ) max( logpo2(ixx(1:nfilt0(i),i)) )])
|
||||
end
|
||||
|
@ -529,15 +554,6 @@ else
|
|||
end
|
||||
end
|
||||
end
|
||||
if options_.TeX
|
||||
[pnames,pnames_tex]=get_LaTeX_parameter_names(M_,options_,estim_params_,bayestopt_);
|
||||
param_names = pnames;
|
||||
param_names_tex = pnames_tex;
|
||||
else
|
||||
[pnames]=get_LaTeX_parameter_names(M_,options_,estim_params_,bayestopt_);
|
||||
param_names = pnames;
|
||||
param_names_tex = {};
|
||||
end
|
||||
skipline()
|
||||
title_string='RMSE over the MC sample:';
|
||||
data_mat=[min(rmse_MC)' max(rmse_MC)'];
|
||||
|
@ -549,7 +565,7 @@ else
|
|||
end
|
||||
invar = find( std(rmse_MC)./mean(rmse_MC)<=0.0001 );
|
||||
if ~isempty(invar)
|
||||
skipline(2)
|
||||
skipline(1)
|
||||
disp('RMSE is not varying significantly over the MC sample for the following variables:')
|
||||
disp(vvarvecm{invar})
|
||||
disp('These variables are excluded from SA')
|
||||
|
@ -561,8 +577,7 @@ else
|
|||
rmse_MC = rmse_MC(:,ivar);
|
||||
skipline()
|
||||
disp(['Sample filtered the ',num2str(pfilt*100),'% best RMSE''s for each observed series ...' ])
|
||||
skipline(2)
|
||||
disp('RMSE ranges after filtering:')
|
||||
skipline(1)
|
||||
title_string='RMSE ranges after filtering:';
|
||||
if options_.opt_gsa.ppost==0 && options_.opt_gsa.pprior
|
||||
headers = {'Variable'; 'min'; 'max'; 'min'; 'max'; 'posterior mode'};
|
||||
|
@ -589,7 +604,7 @@ else
|
|||
else
|
||||
values_length = max(ceil(max(max(log10(abs(data_mat(isfinite(data_mat))))))),1)+val_precis+1;
|
||||
end
|
||||
if any(data_mat) < 0 %add one character for minus sign
|
||||
if any(data_mat < 0) %add one character for minus sign
|
||||
values_length = values_length+1;
|
||||
end
|
||||
headers_length = cellofchararraymaxlength(headers(2:end));
|
||||
|
@ -598,7 +613,6 @@ else
|
|||
else
|
||||
val_width = max(headers_length, values_length)+2;
|
||||
end
|
||||
value_format = sprintf('%%%d.%df',val_width,val_precis);
|
||||
header_string_format = sprintf('%%%ds',val_width);
|
||||
if options_.opt_gsa.ppost==0 && options_.opt_gsa.pprior
|
||||
optional_header=sprintf([label_format_leftbound,header_string_format,header_string_format,header_string_format,header_string_format],'','',['best ',num2str(pfilt*100),'% filtered'],'','remaining 90%');
|
||||
|
@ -610,7 +624,7 @@ else
|
|||
if options_.opt_gsa.ppost==0 && options_.opt_gsa.pprior
|
||||
optional_header={[' & \multicolumn{2}{c}{best ',num2str(pfilt*100),' filtered} & \multicolumn{2}{c}{remaining 90\%}\\']};
|
||||
else
|
||||
optional_header={[' & \multicolumn{2}{c}{best filtered} & \multicolumn{2}{c}{remaining}\\']};
|
||||
optional_header={' & \multicolumn{2}{c}{best filtered} & \multicolumn{2}{c}{remaining}\\'};
|
||||
end
|
||||
dyn_latex_table(M_, options_, title_string, 'RMSE_ranges_after_filtering', headers_tex, vvarvecm_tex, data_mat, 0, val_width, val_precis, optional_header);
|
||||
end
|
||||
|
@ -657,7 +671,7 @@ else
|
|||
else
|
||||
values_length = max(ceil(max(max(log10(abs(data_mat(isfinite(data_mat))))))),1)+val_precis+1;
|
||||
end
|
||||
if any(data_mat) < 0 %add one character for minus sign
|
||||
if any(data_mat < 0) %add one character for minus sign
|
||||
values_length = values_length+1;
|
||||
end
|
||||
headers_length = cellofchararraymaxlength(headers(2:end));
|
||||
|
@ -666,7 +680,6 @@ else
|
|||
else
|
||||
val_width = max(headers_length, values_length)+2;
|
||||
end
|
||||
value_format = sprintf('%%%d.%df',val_width,val_precis);
|
||||
header_string_format = sprintf('%%%ds',val_width);
|
||||
|
||||
if options_.opt_gsa.ppost==0 && options_.opt_gsa.pprior
|
||||
|
@ -679,7 +692,7 @@ else
|
|||
if ~options_.opt_gsa.ppost && options_.opt_gsa.pprior
|
||||
optional_header = {[' & \multicolumn{2}{c}{best ',num2str(pfilt*100),' filtered} & \multicolumn{2}{c}{remaining 90\%}\\']};
|
||||
else
|
||||
optional_header = {[' & \multicolumn{2}{c}{best filtered} & \multicolumn{2}{c}{remaining}\\']};
|
||||
optional_header = {' & \multicolumn{2}{c}{best filtered} & \multicolumn{2}{c}{remaining}\\'};
|
||||
end
|
||||
dyn_latex_table(M_, options_, title_string, 'R2_ranges_after_filtering', headers_tex, vvarvecm_tex, data_mat, 0, val_width, val_precis, optional_header);
|
||||
end
|
||||
|
@ -690,16 +703,15 @@ else
|
|||
SP(ns,j)=ones(size(ns));
|
||||
SS(:,j)=SS(:,j).*SP(:,j);
|
||||
end
|
||||
|
||||
for j=1:npar+nshock %estim_params_.np,
|
||||
nsp=NaN(npar+nshock,1);
|
||||
for j=1:npar+nshock
|
||||
nsp(j)=length(find(SP(j,:)));
|
||||
end
|
||||
snam0=param_names(find(nsp==0));
|
||||
snam1=param_names(find(nsp==1));
|
||||
snam2=param_names(find(nsp>1));
|
||||
snam=param_names(find(nsp>0));
|
||||
snam0=param_names(nsp==0);
|
||||
snam1=param_names(nsp==1);
|
||||
snam2=param_names(nsp>1);
|
||||
nsnam=(find(nsp>1));
|
||||
skipline(2)
|
||||
skipline(1)
|
||||
disp('These parameters do not affect significantly the fit of ANY observed series:')
|
||||
disp(char(snam0))
|
||||
skipline()
|
||||
|
@ -708,7 +720,6 @@ else
|
|||
skipline()
|
||||
disp('These parameters affect MORE THAN ONE observed series: trade off exists!')
|
||||
disp(char(snam2))
|
||||
pnam=bayestopt_.name;
|
||||
% plot trade-offs
|
||||
if ~options_.nograph
|
||||
a00=jet(length(vvarvecm));
|
||||
|
@ -740,8 +751,12 @@ else
|
|||
options_mcf.amcf_title = [atitle ' ' vvarvecm{iy}];
|
||||
options_mcf.beha_title = ['better fit of ' vvarvecm{iy}];
|
||||
options_mcf.nobeha_title = ['worse fit of ' vvarvecm{iy}];
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = ['better fit of ' vvarvecm_tex{iy}];
|
||||
options_mcf.nobeha_title_latex = ['worse fit of ' vvarvecm_tex{iy}];
|
||||
end
|
||||
options_mcf.title = ['the fit of ' vvarvecm{iy}];
|
||||
mcf_analysis(x, ixx(1:nfilt0(iy),iy), ixx(nfilt0(iy)+1:end,iy), options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(x, ixx(1:nfilt0(iy),iy), ixx(nfilt0(iy)+1:end,iy), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
for iy = 1:length(vvarvecm)
|
||||
ipar = find(any(squeeze(PPV(iy,:,:))<alpha));
|
||||
|
@ -749,53 +764,61 @@ else
|
|||
hh_fig = dyn_figure(options_.nodisplay,'name',[temp_name,' observed variable ', vvarvecm{iy}]);
|
||||
for j=1+5*(ix-1):min(length(ipar),5*ix)
|
||||
subplot(2,3,j-5*(ix-1))
|
||||
h0=cumplot(x(:,ipar(j)));
|
||||
h0=gsa.cumplot(x(:,ipar(j)));
|
||||
set(h0,'color',[0 0 0])
|
||||
hold on,
|
||||
iobs=find(squeeze(PPV(iy,:,ipar(j)))<alpha);
|
||||
for i = 1:length(vvarvecm)
|
||||
if any(iobs==i) || i==iy
|
||||
h0=cumplot(x(ixx(1:nfilt0(i),i),ipar(j)));
|
||||
h0=gsa.cumplot(x(ixx(1:nfilt0(i),i),ipar(j)));
|
||||
if ~isoctave
|
||||
hcmenu = uicontextmenu;
|
||||
uimenu(hcmenu,'Label',vvarvecm{i});
|
||||
set(h0,'uicontextmenu',hcmenu)
|
||||
end
|
||||
else
|
||||
h0=cumplot(x(ixx(1:nfilt0(i),i),ipar(j))*NaN);
|
||||
h0=gsa.cumplot(x(ixx(1:nfilt0(i),i),ipar(j))*NaN);
|
||||
end
|
||||
set(h0,'color',a00(i,:),'linewidth',2)
|
||||
end
|
||||
ydum=get(gca,'ylim');
|
||||
if exist('xparam1')
|
||||
if exist('xparam1','var')
|
||||
xdum=xparam1(ipar(j));
|
||||
h1=plot([xdum xdum],ydum);
|
||||
set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
|
||||
end
|
||||
xlabel('')
|
||||
title([pnam{ipar(j)}],'interpreter','none')
|
||||
if options_.TeX
|
||||
title([param_names_tex{ipar(j)}],'interpreter','latex')
|
||||
else
|
||||
title([param_names{ipar(j)}],'interpreter','none')
|
||||
end
|
||||
end
|
||||
if isoctave
|
||||
legend(vertcat('base',vvarvecm),'location','eastoutside');
|
||||
else
|
||||
h0=legend(vertcat('base',vvarvecm));
|
||||
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none');
|
||||
if options_.TeX
|
||||
h0=legend(vertcat('base',vvarvecm_tex),'interpreter','latex');
|
||||
else
|
||||
h0=legend(vertcat('base',vvarvecm),'interpreter','none');
|
||||
end
|
||||
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3]);
|
||||
end
|
||||
if options_.opt_gsa.ppost
|
||||
dyn_saveas(hh_fig,[ OutDir filesep fname_ '_rmse_post_' vvarvecm{iy} '_' int2str(ix)],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX
|
||||
create_TeX_loader(options_,[ OutDir filesep fname_ '_rmse_post_' vvarvecm{iy} '_' int2str(ix)],ix,[temp_name,' observed variable $',vvarvecm_tex{iy} '$'],['rmse_post_' vvarvecm{iy}],1)
|
||||
create_TeX_loader(options_,[ OutDir filesep fname_ '_rmse_post_' vvarvecm{iy} '_' int2str(ix)],ix,[temp_name,' observed variable ',vvarvecm_tex{iy} ],['rmse_post_' vvarvecm{iy}],1)
|
||||
end
|
||||
else
|
||||
if options_.opt_gsa.pprior
|
||||
dyn_saveas(hh_fig,[OutDir filesep fname_ '_rmse_prior_' vvarvecm{iy} '_' int2str(ix) ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX
|
||||
create_TeX_loader(options_,[OutDir filesep fname_ '_rmse_prior_' vvarvecm{iy} '_' int2str(ix) ],ix,[temp_name,' observed variable $',vvarvecm_tex{iy} '$'],['rmse_prior_' vvarvecm{iy}],1)
|
||||
create_TeX_loader(options_,[OutDir filesep fname_ '_rmse_prior_' vvarvecm{iy} '_' int2str(ix) ],ix,[temp_name,' observed variable ',vvarvecm_tex{iy}],['rmse_prior_' vvarvecm{iy}],1)
|
||||
end
|
||||
else
|
||||
dyn_saveas(hh_fig,[OutDir filesep fname_ '_rmse_mc_' vvarvecm{iy} '_' int2str(ix)],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX
|
||||
create_TeX_loader(options_,[OutDir filesep fname_ '_rmse_mc_' vvarvecm{iy} '_' int2str(ix)],ix,[temp_name,' observed variable $',vvarvecm_tex{iy} '$'],['rmse_mc_' vvarvecm{iy}],1)
|
||||
create_TeX_loader(options_,[OutDir filesep fname_ '_rmse_mc_' vvarvecm{iy} '_' int2str(ix)],ix,[temp_name,' observed variable ',vvarvecm_tex{iy}],['rmse_mc_' vvarvecm{iy}],1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -806,15 +829,15 @@ else
|
|||
hh_fig = dyn_figure(options_.nodisplay,'name',[temp_name,' estimated params and shocks ',int2str(ix)]);
|
||||
for j=1+5*(ix-1):min(size(snam2,1),5*ix)
|
||||
subplot(2,3,j-5*(ix-1))
|
||||
h0=cumplot(x(:,nsnam(j)));
|
||||
h0=gsa.cumplot(x(:,nsnam(j)));
|
||||
set(h0,'color',[0 0 0])
|
||||
hold on,
|
||||
npx=find(SP(nsnam(j),:)==0);
|
||||
for i = 1:length(vvarvecm)
|
||||
if any(npx==i)
|
||||
h0=cumplot(x(ixx(1:nfilt0(i),i),nsnam(j))*NaN);
|
||||
h0=gsa.cumplot(x(ixx(1:nfilt0(i),i),nsnam(j))*NaN);
|
||||
else
|
||||
h0=cumplot(x(ixx(1:nfilt0(i),i),nsnam(j)));
|
||||
h0=gsa.cumplot(x(ixx(1:nfilt0(i),i),nsnam(j)));
|
||||
if ~isoctave
|
||||
hcmenu = uicontextmenu;
|
||||
uimenu(hcmenu,'Label', vvarvecm{i});
|
||||
|
@ -824,20 +847,28 @@ else
|
|||
set(h0,'color',a00(i,:),'linewidth',2)
|
||||
end
|
||||
ydum=get(gca,'ylim');
|
||||
if exist('xparam1')
|
||||
if exist('xparam1','var')
|
||||
xdum=xparam1(nsnam(j));
|
||||
h1=plot([xdum xdum],ydum);
|
||||
set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
|
||||
end
|
||||
xlabel('')
|
||||
title([pnam{nsnam(j)}],'interpreter','none')
|
||||
if options_.TeX
|
||||
title([param_names_tex{nsnam(j)}],'interpreter','latex')
|
||||
else
|
||||
title([param_names{nsnam(j)}],'interpreter','none')
|
||||
end
|
||||
end
|
||||
%subplot(3,2,6)
|
||||
if isoctave
|
||||
legend(vertcat('base',vvarvecm),'location','eastoutside');
|
||||
else
|
||||
h0=legend(vertcat('base',vvarvecm));
|
||||
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none');
|
||||
if options_.TeX
|
||||
h0=legend(vertcat('base',vvarvecm_tex),'interpreter','latex');
|
||||
else
|
||||
h0=legend(vertcat('base',vvarvecm),'interpreter','none');
|
||||
end
|
||||
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3]);
|
||||
end
|
||||
if options_.opt_gsa.ppost
|
||||
dyn_saveas(hh_fig,[ OutDir filesep fname_ '_rmse_post_params_' int2str(ix)],options_.nodisplay,options_.graph_format);
|
||||
|
@ -885,11 +916,11 @@ pnames=cell(np,1);
|
|||
pnames_tex=cell(np,1);
|
||||
for ii=1:length(bayestopt_.name)
|
||||
if options_.TeX
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(ii,options_.TeX,M_,estim_params_,options_);
|
||||
pnames_tex{ii,1} = strrep(param_name_tex_temp,'$','');
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(ii,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
pnames_tex{ii,1} = param_name_tex_temp;
|
||||
pnames{ii,1} = param_name_temp;
|
||||
else
|
||||
param_name_temp = get_the_name(ii,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_temp = get_the_name(ii,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
pnames{ii,1} = param_name_temp;
|
||||
end
|
||||
end
|
|
@ -1,5 +1,17 @@
|
|||
function indmcf = mcf_analysis(lpmat, ibeha, inobeha, options_mcf, options_)
|
||||
% indmcf = mcf_analysis(lpmat, ibeha, inobeha, options_mcf, options_)
|
||||
function indmcf = monte_carlo_filtering_analysis(lpmat, ibeha, inobeha, options_mcf, M_, options_, bayestopt_, estim_params_)
|
||||
% indmcf = monte_carlo_filtering_analysis(lpmat, ibeha, inobeha, options_mcf, M_, options_, bayestopt_, estim_params_)
|
||||
% Inputs:
|
||||
% - lpmat [double] Monte Carlo matrix
|
||||
% - ibeha [integer] index of behavioural runs
|
||||
% - inobeha [integer] index of non-behavioural runs
|
||||
% - options_gsa_ [structure] GSA options_
|
||||
% - M_ [structure] describing the model
|
||||
% - options_ [structure] describing the options
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
%
|
||||
% Outputs:
|
||||
% - indmcf [double] results of matrix
|
||||
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -42,6 +54,10 @@ amcf_name = options_mcf.amcf_name;
|
|||
amcf_title = options_mcf.amcf_title;
|
||||
beha_title = options_mcf.beha_title;
|
||||
nobeha_title = options_mcf.nobeha_title;
|
||||
if options_.TeX
|
||||
beha_title_latex = options_mcf.beha_title_latex;
|
||||
nobeha_title_latex = options_mcf.nobeha_title_latex;
|
||||
end
|
||||
title = options_mcf.title;
|
||||
fname_ = options_mcf.fname_;
|
||||
xparam1=[];
|
||||
|
@ -50,15 +66,15 @@ if isfield(options_mcf,'xparam1')
|
|||
end
|
||||
OutputDirectoryName = options_mcf.OutputDirectoryName;
|
||||
|
||||
[proba, dproba] = stab_map_1(lpmat, ibeha, inobeha, [],0);
|
||||
[proba, dproba] = gsa.stability_mapping_univariate(lpmat, ibeha, inobeha, [],fname_, options_, bayestopt_.name, estim_params_,0);
|
||||
indmcf=find(proba<pvalue_ks);
|
||||
[tmp,jtmp] = sort(proba(indmcf),2,'ascend');
|
||||
[~,jtmp] = sort(proba(indmcf),1,'ascend');
|
||||
indmcf = indmcf(jtmp);
|
||||
if ~isempty(indmcf)
|
||||
skipline()
|
||||
headers = {'Parameter','d-stat','p-value'};
|
||||
labels = param_names(indmcf);
|
||||
data_mat=[dproba(indmcf)' proba(indmcf)'];
|
||||
data_mat=[dproba(indmcf) proba(indmcf)];
|
||||
options_temp.noprint=0;
|
||||
dyntable(options_temp,['Smirnov statistics in driving ', title],headers,labels,data_mat,size(labels,2)+2,16,3);
|
||||
if options_.TeX
|
||||
|
@ -69,10 +85,14 @@ if ~isempty(indmcf)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
if length(ibeha)>10 && length(inobeha)>10
|
||||
indcorr1 = stab_map_2(lpmat(ibeha,:),alpha2, pvalue_corr, beha_title);
|
||||
indcorr2 = stab_map_2(lpmat(inobeha,:),alpha2, pvalue_corr, nobeha_title);
|
||||
if options_.TeX
|
||||
indcorr1 = gsa.stability_mapping_bivariate(lpmat(ibeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, beha_title, beha_title_latex);
|
||||
indcorr2 = gsa.stability_mapping_bivariate(lpmat(inobeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, nobeha_title, nobeha_title_latex);
|
||||
else
|
||||
indcorr1 = gsa.stability_mapping_bivariate(lpmat(ibeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, beha_title);
|
||||
indcorr2 = gsa.stability_mapping_bivariate(lpmat(inobeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, nobeha_title);
|
||||
end
|
||||
indcorr = union(indcorr1(:), indcorr2(:));
|
||||
indcorr = indcorr(~ismember(indcorr(:),indmcf));
|
||||
indmcf = [indmcf(:); indcorr(:)];
|
||||
|
@ -80,8 +100,16 @@ end
|
|||
if ~isempty(indmcf) && ~options_.nograph
|
||||
skipline()
|
||||
xx=[];
|
||||
if ~ isempty(xparam1), xx=xparam1(indmcf); end
|
||||
scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names_tex(indmcf), ...
|
||||
'.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,xx, options_, ...
|
||||
beha_title, nobeha_title)
|
||||
if ~ isempty(xparam1)
|
||||
xx=xparam1(indmcf);
|
||||
end
|
||||
if options_.TeX
|
||||
gsa.scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names_tex(indmcf), ...
|
||||
'.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,xx, options_, ...
|
||||
beha_title, nobeha_title, beha_title_latex, nobeha_title_latex)
|
||||
else
|
||||
gsa.scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names_tex(indmcf), ...
|
||||
'.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,xx, options_, ...
|
||||
beha_title, nobeha_title)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,60 @@
|
|||
function [vdec, cc, ac] = monte_carlo_moments(mm, ss, dr, M_, options_, estim_params_)
|
||||
% [vdec, cc, ac] = monte_carlo_moments(mm, ss, dr, M_, options_,estim_params_)
|
||||
% Conduct Monte Carlo simulation of second moments for GSA
|
||||
% Inputs:
|
||||
% - dr [structure] decision rules
|
||||
% - M_ [structure] model structure
|
||||
% - options_ [structure] Matlab's structure describing the current options
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
%
|
||||
% Outputs:
|
||||
% - vdec [double] variance decomposition matrix
|
||||
% - cc [double] vector of unique elements of cross correlation matrix
|
||||
% - ac [cell] autocorrelation matrix
|
||||
|
||||
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
[~, nc1, nsam] = size(mm);
|
||||
nobs=length(options_.varobs);
|
||||
disp('monte_carlo_moments: Computing theoretical moments ...')
|
||||
h = dyn_waitbar(0,'Theoretical moments ...');
|
||||
vdec = zeros(nobs,M_.exo_nbr,nsam);
|
||||
cc = zeros(nobs,nobs,nsam);
|
||||
ac = zeros(nobs,nobs*options_.ar,nsam);
|
||||
|
||||
for j=1:nsam
|
||||
dr.ghx = mm(:, 1:(nc1-M_.exo_nbr),j);
|
||||
dr.ghu = mm(:, (nc1-M_.exo_nbr+1):end, j);
|
||||
if ~isempty(ss)
|
||||
M_=gsa.set_shocks_param(M_,estim_params_,ss(j,:));
|
||||
end
|
||||
[vdec(:,:,j), corr, autocorr] = gsa.th_moments(dr,options_,M_);
|
||||
cc(:,:,j)=triu(corr);
|
||||
dum=NaN(nobs,nobs*options_.ar);
|
||||
for i=1:options_.ar
|
||||
dum(:,(i-1)*nobs+1:i*nobs)=autocorr{i};
|
||||
end
|
||||
ac(:,:,j)=dum;
|
||||
if mod(j,3)==0
|
||||
dyn_waitbar(j/nsam,h)
|
||||
end
|
||||
end
|
||||
dyn_waitbar_close(h)
|
||||
skipline()
|
||||
disp('... done !')
|
|
@ -1,9 +1,14 @@
|
|||
function pdraw = prior_draw_gsa(init,rdraw)
|
||||
function pdraw = prior_draw(M_,bayestopt_,options_,estim_params_,init,rdraw)
|
||||
% pdraw = prior_draw(M_,bayestopt_,options_,estim_params_,init,rdraw)
|
||||
% Draws from the prior distributions for use with Sensitivity Toolbox for DYNARE
|
||||
%
|
||||
% INPUTS
|
||||
% o init [integer] scalar equal to 1 (first call) or 0.
|
||||
% o rdraw
|
||||
% - M_ [structure] describing the model
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
% - options_ [structure] describing the options
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - init [integer] scalar equal to 1 (first call) or 0.
|
||||
% - rdraw
|
||||
%
|
||||
% OUTPUTS
|
||||
% o pdraw [double] draw from the joint prior density.
|
||||
|
@ -35,8 +40,7 @@ function pdraw = prior_draw_gsa(init,rdraw)
|
|||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global bayestopt_ options_ estim_params_ M_
|
||||
|
||||
persistent npar pshape p6 p7 p3 p4 lbcum ubcum
|
||||
|
||||
if init
|
||||
|
@ -49,7 +53,7 @@ if init
|
|||
pdraw = zeros(npar,1);
|
||||
lbcum = zeros(npar,1);
|
||||
ubcum = ones(npar,1);
|
||||
[~,~,~,lb,ub,~] = set_prior(estim_params_,M_,options_); %Prepare bounds
|
||||
[~,~,~,lb,ub] = set_prior(estim_params_,M_,options_); %Prepare bounds
|
||||
if ~isempty(bayestopt_) && any(bayestopt_.pshape > 0)
|
||||
% Set prior bounds
|
||||
bounds = prior_bounds(bayestopt_, options_.prior_trunc);
|
||||
|
@ -64,29 +68,29 @@ if init
|
|||
% set bounds for cumulative probabilities
|
||||
for i = 1:npar
|
||||
switch pshape(i)
|
||||
case 5% Uniform prior.
|
||||
p4(i) = min(p4(i),bounds.ub(i));
|
||||
p3(i) = max(p3(i),bounds.lb(i));
|
||||
case 3% Gaussian prior.
|
||||
lbcum(i) = 0.5 * erfc(-(bounds.lb(i)-p6(i))/p7(i) ./ sqrt(2));
|
||||
ubcum(i) = 0.5 * erfc(-(bounds.ub(i)-p6(i))/p7(i) ./ sqrt(2));
|
||||
case 2% Gamma prior.
|
||||
lbcum(i) = gamcdf(bounds.lb(i)-p3(i),p6(i),p7(i));
|
||||
ubcum(i) = gamcdf(bounds.ub(i)-p3(i),p6(i),p7(i));
|
||||
case 1% Beta distribution (TODO: generalized beta distribution)
|
||||
lbcum(i) = betainc((bounds.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
|
||||
ubcum(i) = betainc((bounds.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
|
||||
case 2% Gamma prior.
|
||||
lbcum(i) = gamcdf(bounds.lb(i)-p3(i),p6(i),p7(i));
|
||||
ubcum(i) = gamcdf(bounds.ub(i)-p3(i),p6(i),p7(i));
|
||||
case 3% Gaussian prior.
|
||||
lbcum(i) = 0.5 * erfc(-(bounds.lb(i)-p6(i))/p7(i) ./ sqrt(2));
|
||||
ubcum(i) = 0.5 * erfc(-(bounds.ub(i)-p6(i))/p7(i) ./ sqrt(2));
|
||||
case 4% INV-GAMMA1 distribution
|
||||
% TO BE CHECKED
|
||||
lbcum(i) = gamcdf(1/(bounds.ub(i)-p3(i))^2,p7(i)/2,2/p6(i));
|
||||
ubcum(i) = gamcdf(1/(bounds.lb(i)-p3(i))^2,p7(i)/2,2/p6(i));
|
||||
case 5% Uniform prior.
|
||||
p4(i) = min(p4(i),bounds.ub(i));
|
||||
p3(i) = max(p3(i),bounds.lb(i));
|
||||
case 6% INV-GAMMA2 distribution
|
||||
% TO BE CHECKED
|
||||
lbcum(i) = gamcdf(1/(bounds.ub(i)-p3(i)),p7(i)/2,2/p6(i));
|
||||
ubcum(i) = gamcdf(1/(bounds.lb(i)-p3(i)),p7(i)/2,2/p6(i));
|
||||
case 8
|
||||
lbcum(i) = weibcdf(bounds.lb(i)-p3(i),p6(i),p7(i));
|
||||
ubcum(i) = weibcdf(bounds.ub(i)-p3(i),p6(i),p7(i));
|
||||
lbcum(i) = wblcdf(bounds.lb(i)-p3(i),p6(i),p7(i));
|
||||
ubcum(i) = wblcdf(bounds.ub(i)-p3(i),p6(i),p7(i));
|
||||
otherwise
|
||||
% Nothing to do here.
|
||||
end
|
||||
|
@ -94,7 +98,7 @@ if init
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
pdraw=NaN(size(rdraw,1),npar);
|
||||
for i = 1:npar
|
||||
rdraw(:,i) = rdraw(:,i).*(ubcum(i)-lbcum(i))+lbcum(i);
|
||||
switch pshape(i)
|
|
@ -1,5 +1,5 @@
|
|||
function xcum = priorcdf(para, pshape, p6, p7, p3, p4)
|
||||
|
||||
% xcum = priorcdf(para, pshape, p6, p7, p3, p4)
|
||||
% This procedure transforms x vectors into cumulative values
|
||||
% pshape: 0 is point mass, both para and p2 are ignored
|
||||
% 1 is BETA(mean,stdd)
|
||||
|
@ -11,7 +11,7 @@ function xcum = priorcdf(para, pshape, p6, p7, p3, p4)
|
|||
% 8 is WEIBULL(s, k)
|
||||
% Adapted by M. Ratto from MJ priordens.m
|
||||
|
||||
% Copyright © 2012-2015 Dynare Team
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -28,6 +28,7 @@ function xcum = priorcdf(para, pshape, p6, p7, p3, p4)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
xcum=NaN(size(para));
|
||||
for i=1:length(pshape)
|
||||
switch pshape(i)
|
||||
case 1 % (generalized) BETA Prior
|
|
@ -1,15 +1,13 @@
|
|||
function redform_map(dirname,options_gsa_)
|
||||
%function redform_map(dirname)
|
||||
% inputs (from opt_gsa structure
|
||||
% anamendo = options_gsa_.namendo;
|
||||
% anamlagendo = options_gsa_.namlagendo;
|
||||
% anamexo = options_gsa_.namexo;
|
||||
% iload = options_gsa_.load_redform;
|
||||
% pprior = options_gsa_.pprior;
|
||||
% ilog = options_gsa_.logtrans_redform;
|
||||
% threshold = options_gsa_.threshold_redform;
|
||||
% ksstat = options_gsa_.ksstat_redform;
|
||||
% alpha2 = options_gsa_.alpha2_redform;
|
||||
function reduced_form_mapping(dirname,options_gsa_,M_,estim_params_,options_,bayestopt_,oo_)
|
||||
% reduced_form_mapping(dirname,options_gsa_,M_,estim_params_,options_,bayestopt_,oo_)
|
||||
% Inputs:
|
||||
% - dirname [string] name of the output directory
|
||||
% - options_gsa_ [structure] GSA options_
|
||||
% - M_ [structure] describing the model
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - options_ [structure] describing the options
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
% - oo_ [structure] storing the results
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -33,23 +31,16 @@ function redform_map(dirname,options_gsa_)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
global M_ oo_ estim_params_ options_ bayestopt_
|
||||
|
||||
% options_gsa_ = options_.opt_gsa;
|
||||
|
||||
anamendo = options_gsa_.namendo;
|
||||
anamlagendo = options_gsa_.namlagendo;
|
||||
anamexo = options_gsa_.namexo;
|
||||
anamendo_tex = options_gsa_.namendo_tex;
|
||||
anamlagendo_tex = options_gsa_.namlagendo_tex;
|
||||
anamexo_tex = options_gsa_.namexo_tex;
|
||||
iload = options_gsa_.load_redform;
|
||||
pprior = options_gsa_.pprior;
|
||||
ilog = options_gsa_.logtrans_redform;
|
||||
threshold = options_gsa_.threshold_redform;
|
||||
% ksstat = options_gsa_.ksstat_redform;
|
||||
alpha2 = options_gsa_.alpha2_redform;
|
||||
alpha2=0;
|
||||
pvalue_ks = options_gsa_.ksstat_redform;
|
||||
pvalue_corr = options_gsa_.alpha2_redform;
|
||||
|
||||
np = estim_params_.np;
|
||||
nshock = estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn;
|
||||
|
@ -57,11 +48,11 @@ pnames=cell(np,1);
|
|||
pnames_tex=cell(np,1);
|
||||
for jj=1:np
|
||||
if options_.TeX
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(nshock+jj,options_.TeX,M_,estim_params_,options_);
|
||||
pnames_tex{jj,1} = strrep(param_name_tex_temp,'$','');
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(nshock+jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
pnames_tex{jj,1} = param_name_tex_temp;
|
||||
pnames{jj,1} = param_name_temp;
|
||||
else
|
||||
param_name_temp = get_the_name(nshock+jj,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_temp = get_the_name(nshock+jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
pnames{jj,1} = param_name_temp;
|
||||
end
|
||||
end
|
||||
|
@ -93,14 +84,14 @@ end
|
|||
options_mcf.fname_ = M_.fname;
|
||||
options_mcf.OutputDirectoryName = adir;
|
||||
|
||||
if ~exist('T')
|
||||
stab_map_(dirname,options_gsa_);
|
||||
if ~exist('T','var')
|
||||
gsa.stability_mapping(dirname,options_gsa_,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
if pprior
|
||||
load([dirname,filesep,M_.fname,'_prior'],'T');
|
||||
else
|
||||
load([dirname,filesep,M_.fname,'_mc'],'T');
|
||||
end
|
||||
if ~exist('T')
|
||||
if ~exist('T','var')
|
||||
disp('The model is too large!')
|
||||
disp('Reduced form mapping stopped!')
|
||||
return
|
||||
|
@ -109,8 +100,6 @@ end
|
|||
if isempty(dir(adir))
|
||||
mkdir(adir)
|
||||
end
|
||||
adir0=pwd;
|
||||
%cd(adir)
|
||||
|
||||
nspred=size(T,2)-M_.exo_nbr;
|
||||
x0=lpmat(istable,:);
|
||||
|
@ -121,7 +110,7 @@ else
|
|||
xx0=lpmat0(istable,:);
|
||||
nshocks=size(xx0,2);
|
||||
end
|
||||
[kn, np]=size(x0);
|
||||
[~, np]=size(x0);
|
||||
offset = length(bayestopt_.pshape)-np;
|
||||
if options_gsa_.prior_range
|
||||
pshape=5*(ones(np,1));
|
||||
|
@ -144,23 +133,22 @@ options_map.pshape = pshape;
|
|||
options_map.pd = pd;
|
||||
|
||||
nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:)));
|
||||
lpmat=[];
|
||||
lpmat0=[];
|
||||
js=0;
|
||||
for j = 1:length(anamendo)
|
||||
namendo = anamendo{j};
|
||||
namendo_tex = anamendo_tex{j};
|
||||
iendo = strmatch(namendo, M_.endo_names(oo_.dr.order_var), 'exact');
|
||||
ifig = 0;
|
||||
iplo = 0;
|
||||
for jx = 1:length(anamexo)
|
||||
namexo = anamexo{jx};
|
||||
namexo_tex = anamexo_tex{jx};
|
||||
iexo=strmatch(namexo, M_.exo_names, 'exact');
|
||||
skipline()
|
||||
disp(['[', namendo,' vs ',namexo,']'])
|
||||
|
||||
|
||||
if ~isempty(iexo)
|
||||
%y0=squeeze(T(iendo,iexo+nspred,istable));
|
||||
y0=squeeze(T(iendo,iexo+nspred,:));
|
||||
if (max(y0)-min(y0))>1.e-10
|
||||
if mod(iplo,9)==0 && isempty(threshold) && ~options_.nograph
|
||||
|
@ -194,20 +182,23 @@ for j = 1:length(anamendo)
|
|||
end
|
||||
if ~options_.nograph
|
||||
hf=dyn_figure(options_.nodisplay,'name',['Reduced Form Mapping (Monte Carlo Filtering): ',namendo,' vs ', namexo]);
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
a=axis; delete(hc);
|
||||
% hist(mat_moment{ij}),
|
||||
x1val=max(threshold(1),a(1));
|
||||
x2val=min(threshold(2),a(2));
|
||||
hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
|
||||
set(hp,'FaceColor', [0.7 0.8 1])
|
||||
hold all,
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
set(hc,'color','k','linewidth',2)
|
||||
hold off,
|
||||
title([namendo,' vs ', namexo ' - threshold [' num2str(threshold(1)) ' ' num2str(threshold(2)) ']'],'interpreter','none')
|
||||
if options_.TeX
|
||||
title([namendo_tex,' vs ', namexo_tex ' - threshold [' num2str(threshold(1)) ' ' num2str(threshold(2)) ']'],'interpreter','latex')
|
||||
else
|
||||
title([namendo,' vs ', namexo ' - threshold [' num2str(threshold(1)) ' ' num2str(threshold(2)) ']'],'interpreter','none')
|
||||
end
|
||||
dyn_saveas(hf,[xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namexo],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namexo],['Reduced Form Mapping (Monte Carlo Filtering): ',strrep(namendo,'_','\_'),' vs ', strrep(namexo,'_','\_')],[type '_' namendo,'_vs_', namexo])
|
||||
create_TeX_loader(options_,[xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namexo],['Reduced Form Mapping (Monte Carlo Filtering): ',namendo_tex,' vs ', namexo_tex],[type '_' namendo,'_vs_', namexo])
|
||||
end
|
||||
si(:,js) = NaN(np,1);
|
||||
delete([xdir, '/*threshold*.*'])
|
||||
|
@ -219,19 +210,23 @@ for j = 1:length(anamendo)
|
|||
options_mcf.amcf_title = atitle;
|
||||
options_mcf.beha_title = 'inside threshold';
|
||||
options_mcf.nobeha_title = 'outside threshold';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'inside threshold';
|
||||
options_mcf.nobeha_title_latex = 'outside threshold';
|
||||
end
|
||||
options_mcf.title = atitle0;
|
||||
options_mcf.OutputDirectoryName = xdir;
|
||||
if ~isempty(iy) && ~isempty(iyc)
|
||||
fprintf(['%4.1f%% of the ',type,' support matches ',atitle0,'\n'],length(iy)/length(y0)*100)
|
||||
icheck = mcf_analysis(x0, iy, iyc, options_mcf, options_);
|
||||
icheck = gsa.monte_carlo_filtering_analysis(x0, iy, iyc, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
lpmat=x0(iy,:);
|
||||
if nshocks
|
||||
lpmat0=xx0(iy,:);
|
||||
end
|
||||
istable=[1:length(iy)];
|
||||
istable=1:length(iy);
|
||||
save([xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namexo '_threshold' ],'lpmat','lpmat0','istable','y0','x0','xx0','iy','iyc')
|
||||
lpmat=[]; lpmat0=[]; istable=[];
|
||||
lpmat0=[];
|
||||
if length(iy)<=10 || length(iyc)<=10
|
||||
icheck = []; % do the generic plot in any case
|
||||
end
|
||||
|
@ -255,12 +250,10 @@ for j = 1:length(anamendo)
|
|||
end
|
||||
atitle0=['Monte Carlo Filtering for ',namendo,' vs ', namexo];
|
||||
options_mcf.title = atitle0;
|
||||
indmcf = redform_mcf(y0, x0, options_mcf, options_);
|
||||
|
||||
redform_mcf(y0, x0, options_mcf, options_, M_.fname, bayestopt_.name, estim_params_);
|
||||
end
|
||||
end
|
||||
else
|
||||
[yy, xdir] = log_trans_(y0,xdir0);
|
||||
atitle0=['Reduced Form Mapping (ANOVA) for log-transformed ',namendo,' vs ', namexo];
|
||||
aname=[type '_' namendo '_vs_' namexo];
|
||||
atitle=[type ' Reduced Form Mapping (ANOVA): Parameter(s) driving ',namendo,' vs ',namexo];
|
||||
|
@ -276,24 +269,31 @@ for j = 1:length(anamendo)
|
|||
figure(hh_fig)
|
||||
subplot(3,3,iplo),
|
||||
if ilog
|
||||
[saso, iso] = sort(-silog(:,js));
|
||||
[~, iso] = sort(-silog(:,js));
|
||||
bar([silog(iso(1:min(np,10)),js)])
|
||||
logflag='log';
|
||||
else
|
||||
[saso, iso] = sort(-si(:,js));
|
||||
[~, iso] = sort(-si(:,js));
|
||||
bar(si(iso(1:min(np,10)),js))
|
||||
logflag='';
|
||||
end
|
||||
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
|
||||
set(gca,'xticklabel',' ','fontsize',10)
|
||||
set(gca,'xlim',[0.5 10.5])
|
||||
for ip=1:min(np,10)
|
||||
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,-0.02,deblank(pnames_tex(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
if options_.TeX
|
||||
title([logflag,' ',namendo_tex,' vs ',namexo_tex],'interpreter','none')
|
||||
else
|
||||
title([logflag,' ',namendo,' vs ',namexo],'interpreter','none')
|
||||
end
|
||||
title([logflag,' ',namendo,' vs ',namexo],'interpreter','none')
|
||||
if iplo==9
|
||||
dyn_saveas(hh_fig,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)],[logflag,' ',strrep(namendo,'_','\_'),' vs ',strrep(namexo,'_','\_')],['redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)],1)
|
||||
create_TeX_loader(options_,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)],[logflag,' ',namendo_tex,' vs ',namexo_tex],['redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)],1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -310,12 +310,12 @@ for j = 1:length(anamendo)
|
|||
iplo=0;
|
||||
for je=1:length(anamlagendo)
|
||||
namlagendo = anamlagendo{je};
|
||||
namlagendo_tex = anamlagendo_tex{je};
|
||||
ilagendo=strmatch(namlagendo, M_.endo_names(oo_.dr.order_var(M_.nstatic+1:M_.nstatic+nsok)), 'exact');
|
||||
skipline()
|
||||
disp(['[', namendo,' vs lagged ',namlagendo,']'])
|
||||
|
||||
if ~isempty(ilagendo)
|
||||
%y0=squeeze(T(iendo,ilagendo,istable));
|
||||
y0=squeeze(T(iendo,ilagendo,:));
|
||||
if (max(y0)-min(y0))>1.e-10
|
||||
if mod(iplo,9)==0 && isempty(threshold) && ~options_.nograph
|
||||
|
@ -331,9 +331,9 @@ for j = 1:length(anamendo)
|
|||
if isempty(dir(xdir0))
|
||||
mkdir(xdir0)
|
||||
end
|
||||
atitle0=['Reduced Form Mapping (ANOVA) for ',namendo,' vs ', namlagendo];
|
||||
aname=[type '_' namendo '_vs_' namlagendo];
|
||||
atitle=[type ' Reduced Form Mapping (ANOVA): Parameter(s) driving ',namendo,' vs ',namlagendo];
|
||||
atitle0=['Reduced Form Mapping (ANOVA) for ',namendo,' vs lagged', namlagendo];
|
||||
aname=[type '_' namendo '_vs_lag_' namlagendo];
|
||||
atitle=[type ' Reduced Form Mapping (ANOVA): Parameter(s) driving ',namendo,' vs lagged',namlagendo];
|
||||
options_map.amap_name = aname;
|
||||
options_map.amap_title = atitle;
|
||||
options_map.figtitle = atitle0;
|
||||
|
@ -349,20 +349,23 @@ for j = 1:length(anamendo)
|
|||
end
|
||||
if ~options_.nograph
|
||||
hf=dyn_figure(options_.nodisplay,'name',['Reduced Form Mapping (Monte Carlo Filtering): ',namendo,' vs lagged ', namlagendo]);
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
a=axis; delete(hc);
|
||||
% hist(mat_moment{ij}),
|
||||
x1val=max(threshold(1),a(1));
|
||||
x2val=min(threshold(2),a(2));
|
||||
hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
|
||||
set(hp,'FaceColor', [0.7 0.8 1])
|
||||
hold all,
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
set(hc,'color','k','linewidth',2)
|
||||
hold off,
|
||||
title([namendo,' vs lagged ', namlagendo ' - threshold [' num2str(threshold(1)) ' ' num2str(threshold(2)) ']'],'interpreter','none')
|
||||
hold off
|
||||
if options_.TeX
|
||||
title([namendo_tex,' vs lagged ', namlagendo_tex ' - threshold [' num2str(threshold(1)) ' ' num2str(threshold(2)) ']'],'interpreter','latex')
|
||||
else
|
||||
title([namendo,' vs lagged ', namlagendo ' - threshold [' num2str(threshold(1)) ' ' num2str(threshold(2)) ']'],'interpreter','none')
|
||||
end
|
||||
dyn_saveas(hf,[xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namlagendo],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namlagendo],['Reduced Form Mapping (Monte Carlo Filtering): ',strrep(namendo,'_','\_'),' vs lagged ', strrep(namlagendo,'_','\_')],[type '_' namendo,'_vs_', namlagendo],1)
|
||||
create_TeX_loader(options_,[xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namlagendo],['Reduced Form Mapping (Monte Carlo Filtering): ',namendo_tex,' vs lagged ', namlagendo_tex],[type '_' namendo,'_vs_', namlagendo],1)
|
||||
end
|
||||
|
||||
delete([xdir, '/*threshold*.*'])
|
||||
|
@ -374,24 +377,28 @@ for j = 1:length(anamendo)
|
|||
options_mcf.amcf_title = atitle;
|
||||
options_mcf.beha_title = 'inside threshold';
|
||||
options_mcf.nobeha_title = 'outside threshold';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'inside threshold';
|
||||
options_mcf.nobeha_title_latex = 'outside threshold';
|
||||
end
|
||||
|
||||
options_mcf.title = atitle0;
|
||||
options_mcf.OutputDirectoryName = xdir;
|
||||
if ~isempty(iy) && ~isempty(iyc)
|
||||
|
||||
fprintf(['%4.1f%% of the ',type,' support matches ',atitle0,'\n'],length(iy)/length(y0)*100)
|
||||
icheck = mcf_analysis(x0, iy, iyc, options_mcf, options_);
|
||||
icheck = gsa.monte_carlo_filtering_analysis(x0, iy, iyc, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
lpmat=x0(iy,:);
|
||||
if nshocks
|
||||
lpmat0=xx0(iy,:);
|
||||
end
|
||||
istable=[1:length(iy)];
|
||||
istable=1:length(iy);
|
||||
save([xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namlagendo '_threshold' ],'lpmat','lpmat0','istable','y0','x0','xx0','iy','iyc')
|
||||
lpmat=[]; lpmat0=[]; istable=[];
|
||||
if length(iy)<=10 || length(iyc)<=10,
|
||||
lpmat0=[];
|
||||
if length(iy)<=10 || length(iyc)<=10
|
||||
icheck = []; % do the generic plot in any case
|
||||
end
|
||||
|
||||
else
|
||||
icheck = [];
|
||||
end
|
||||
|
@ -412,11 +419,10 @@ for j = 1:length(anamendo)
|
|||
end
|
||||
atitle0=['Monte Carlo Filtering for ',namendo,' vs ', namlagendo];
|
||||
options_mcf.title = atitle0;
|
||||
indmcf = redform_mcf(y0, x0, options_mcf, options_);
|
||||
redform_mcf(y0, x0, options_mcf, options_, M_.fname, bayestopt_.name, estim_params_);
|
||||
end
|
||||
end
|
||||
else
|
||||
[yy, xdir] = log_trans_(y0,xdir0);
|
||||
atitle0=['Reduced Form Mapping (ANOVA) for log-transformed ',namendo,' vs ', namlagendo];
|
||||
aname=[type '_' namendo '_vs_' namlagendo];
|
||||
atitle=[type ' Reduced Form Mapping (ANOVA): Parameter(s) driving ',namendo,' vs ',namlagendo];
|
||||
|
@ -432,24 +438,27 @@ for j = 1:length(anamendo)
|
|||
figure(hh_fig),
|
||||
subplot(3,3,iplo),
|
||||
if ilog
|
||||
[saso, iso] = sort(-silog(:,js));
|
||||
[~, iso] = sort(-silog(:,js));
|
||||
bar([silog(iso(1:min(np,10)),js)])
|
||||
logflag='log';
|
||||
else
|
||||
[saso, iso] = sort(-si(:,js));
|
||||
[~, iso] = sort(-si(:,js));
|
||||
bar(si(iso(1:min(np,10)),js))
|
||||
logflag='';
|
||||
end
|
||||
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
|
||||
set(gca,'xticklabel',' ','fontsize',10)
|
||||
set(gca,'xlim',[0.5 10.5])
|
||||
for ip=1:min(np,10)
|
||||
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,-0.02,deblank(pnames_tex(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
title([logflag,' ',namendo,' vs ',namlagendo,'(-1)'],'interpreter','none')
|
||||
if iplo==9
|
||||
dyn_saveas(hh_fig,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)],[logflag,' ',strrep(namendo,'_','\_'),' vs ',strrep(namlagendo,'_','\_'),'(-1)'],['redform_', namendo,'_vs_lags_',logflag,':',num2str(ifig)],1)
|
||||
create_TeX_loader(options_,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)],[logflag,' ',namendo_tex,' vs ',namlagendo_tex,'(-1)'],['redform_', namendo,'_vs_lags_',logflag,':',num2str(ifig)],1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -460,48 +469,37 @@ for j = 1:length(anamendo)
|
|||
end
|
||||
if iplo<9 && iplo>0 && ifig && ~options_.nograph
|
||||
dyn_saveas(hh_fig,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)],[logflag,' ',strrep(namendo,'_','\_'),' vs ',strrep(namlagendo,'_','\_'),'(-1)'],['redform_', namendo,'_vs_lags_',logflag,':',num2str(ifig)],options_.figures.textwidth*min(iplo/3,1));
|
||||
create_TeX_loader(options_,[dirname,filesep,M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)],[logflag,' ',namendo_tex,' vs ',namlagendo_tex,'(-1)'],['redform_', namendo,'_vs_lags_',logflag,':',num2str(ifig)],options_.figures.textwidth*min(iplo/3,1));
|
||||
end
|
||||
end
|
||||
|
||||
if isempty(threshold) && ~options_.nograph
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Reduced Form GSA');
|
||||
if ilog==0
|
||||
gsa.boxplot(si',[],'.',[],10)
|
||||
else
|
||||
gsa.boxplot(silog',[],'.',[],10)
|
||||
end
|
||||
xlabel(' ')
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:np)
|
||||
set(gca,'xlim',[0.5 np+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
set(gca,'position',[0.13 0.2 0.775 0.7])
|
||||
for ip=1:np
|
||||
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
if ilog==0
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Reduced Form GSA'); %bar(si)
|
||||
% boxplot(si','whis',10,'symbol','r.')
|
||||
myboxplot(si',[],'.',[],10)
|
||||
xlabel(' ')
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
|
||||
set(gca,'xlim',[0.5 np+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
set(gca,'position',[0.13 0.2 0.775 0.7])
|
||||
for ip=1:np
|
||||
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
title('Reduced form GSA')
|
||||
dyn_saveas(hh_fig,[dirname,filesep,M_.fname,'_redform_gsa'],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[dirname,filesep,M_.fname,'_redform_gsa'],'Reduced Form GSA','redform_gsa')
|
||||
|
||||
else
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Reduced Form GSA'); %bar(silog)
|
||||
% boxplot(silog','whis',10,'symbol','r.')
|
||||
myboxplot(silog',[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
|
||||
xlabel(' ')
|
||||
set(gca,'xlim',[0.5 np+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
set(gca,'position',[0.13 0.2 0.775 0.7])
|
||||
for ip=1:np
|
||||
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
title('Reduced form GSA - Log-transformed elements')
|
||||
dyn_saveas(hh_fig,[dirname,filesep,M_.fname,'_redform_gsa_log'],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[dirname,filesep,M_.fname,'_redform_gsa_log'],'Reduced form GSA - Log-transformed elements','redform_gsa_log')
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function si = redform_private(x0, y0, options_map, options_)
|
||||
|
||||
np=size(x0,2);
|
||||
x00=x0;
|
||||
ilog = options_map.log_trans;
|
||||
|
@ -515,7 +513,7 @@ if options_map.prior_range
|
|||
x0(:,j)=(x0(:,j)-pd(j,3))./(pd(j,4)-pd(j,3));
|
||||
end
|
||||
else
|
||||
x0=priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4));
|
||||
x0=gsa.priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4));
|
||||
end
|
||||
|
||||
if ilog
|
||||
|
@ -531,14 +529,12 @@ if iload==0
|
|||
nest=max(50,nrun/2);
|
||||
nest=min(250,nest);
|
||||
nfit=min(1000,nrun);
|
||||
% dotheplots = (nfit<=nest);
|
||||
% gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[-1 -1 -1 -1 -1 0],[],0,[fname,'_est'], pnames);
|
||||
[ys,is] = sort(y0);
|
||||
[~,is] = sort(y0);
|
||||
istep = ceil(nrun/nest);
|
||||
if istep>1
|
||||
iest = is(floor(istep/2):istep:end);
|
||||
nest = length(iest);
|
||||
irest = is(setdiff([1:nrun],[floor(istep/2):istep:nrun]));
|
||||
irest = is(setdiff(1:nrun,floor(istep/2):istep:nrun));
|
||||
istep = ceil(length(irest)/(nfit-nest));
|
||||
ifit = union(iest, irest(1:istep:end));
|
||||
else
|
||||
|
@ -550,29 +546,34 @@ if iload==0
|
|||
ifit = union(ifit, irest(end));
|
||||
end
|
||||
nfit=length(ifit);
|
||||
% ifit = union(iest, irest(randperm(nrun-nest,nfit-nest)));
|
||||
% ifit = iest;
|
||||
% nfit=nest;
|
||||
ipred = setdiff([1:nrun],ifit);
|
||||
ipred = setdiff(1:nrun,ifit);
|
||||
|
||||
if ilog
|
||||
[y1, tmp, isig, lam] = log_trans_(y0(iest));
|
||||
[~, ~, isig, lam] = gsa.log_transform(y0(iest));
|
||||
y1 = log(y0*isig+lam);
|
||||
end
|
||||
if ~options_.nograph
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name',options_map.figtitle);
|
||||
subplot(221)
|
||||
if ilog
|
||||
hist(y1,30)
|
||||
if isoctave
|
||||
hist(y1,30)
|
||||
else
|
||||
histogram(y1,30)
|
||||
end
|
||||
else
|
||||
hist(y0,30)
|
||||
if isoctave
|
||||
hist(y0,30)
|
||||
else
|
||||
histogram(y0,30)
|
||||
end
|
||||
end
|
||||
title(options_map.title,'interpreter','none')
|
||||
subplot(222)
|
||||
if ilog
|
||||
hc = cumplot(y1);
|
||||
hc = gsa.cumplot(y1);
|
||||
else
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
end
|
||||
set(hc,'color','k','linewidth',2)
|
||||
title([options_map.title ' CDF'],'interpreter','none')
|
||||
|
@ -582,15 +583,7 @@ if iload==0
|
|||
if ilog
|
||||
[gsa22, gsa1, gsax] = ss_anova_log(y1(iest), x0(iest,:), isig, lam, gsa0);
|
||||
end
|
||||
% if (gsa1.out.bic-gsa0.out.bic) < 10,
|
||||
% y00=y0;
|
||||
% gsa00=gsa0;
|
||||
% gsa0=gsa1;
|
||||
% y0=y1;
|
||||
% ilog=1;
|
||||
% end
|
||||
if nfit>nest
|
||||
% gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[-1 -1 -1 -1 -1 0],[],0,fname, pnames);
|
||||
nvr = gsa0.nvr*nest^3/nfit^3;
|
||||
nvr(gsa0.stat<2) = gsa0.nvr(gsa0.stat<2)*nest^5/nfit^5;
|
||||
gsa_ = ss_anova(y0(ifit), x0(ifit,:), 1, 0, 2, nvr);
|
||||
|
@ -601,33 +594,6 @@ if iload==0
|
|||
nvrx = gsax.nvr*nest^3/nfit^3;
|
||||
nvrx(gsax.stat<2) = gsax.nvr(gsax.stat<2)*nest^5/nfit^5;
|
||||
[gsa22, gsa1, gsax] = ss_anova_log(y1(ifit), x0(ifit,:), isig, lam, gsa0, [nvr1' nvrx']);
|
||||
% gsa1 = ss_anova(y1(ifit), x0(ifit,:), 1, 0, 2, nvr);
|
||||
% gsa2=gsa1;
|
||||
% gsa2.y = gsa0.y;
|
||||
% gsa2.fit = (exp(gsa1.fit)-lam)*isig;
|
||||
% gsa2.f0 = mean(gsa2.fit);
|
||||
% gsa2.out.SSE = sum((gsa2.fit-gsa2.y).^2);
|
||||
% gsa2.out.bic = gsa2.out.bic-nest*log(gsa1.out.SSE)+nest*log(gsa2.out.SSE);
|
||||
% gsa2.r2 = 1-cov(gsa2.fit-gsa2.y)/cov(gsa2.y);
|
||||
% for j=1:np,
|
||||
% gsa2.fs(:,j) = exp(gsa1.fs(:,j)).*mean(exp(gsa1.fit-gsa1.f(:,j)))*isig-lam*isig-gsa2.f0;
|
||||
% gsa2.f(:,j) = exp(gsa1.f(:,j)).*mean(exp(gsa1.fit-gsa1.f(:,j)))*isig-lam*isig-gsa2.f0;
|
||||
% gsa2.si(j) = var(gsa2.f(:,j))/var(gsa2.y);
|
||||
% end
|
||||
% nvr = gsax.nvr*nest^3/nfit^3;
|
||||
% nvr(gsax.stat<2) = gsax.nvr(gsax.stat<2)*nest^5/nfit^5;
|
||||
% gsax = ss_anova([gsa2.y-gsa2.fit], x0(ifit,:), 1, 0, 2, nvr);
|
||||
% gsa22=gsa2;
|
||||
% gsa22.fit = gsa2.fit+gsax.fit;
|
||||
% gsa22.f0 = mean(gsa22.fit);
|
||||
% gsa22.out.SSE = sum((gsa22.fit-gsa22.y).^2);
|
||||
% gsa22.out.bic = nest*log(gsa22.out.SSE/nest) + (gsax.out.df+gsa2.out.df-1)*log(nest);
|
||||
% gsa22.r2 = 1-sum((gsa22.fit-gsa22.y).^2)/sum((gsa22.y-mean(gsa22.y)).^2);
|
||||
% for j=1:np,
|
||||
% gsa22.fs(:,j) = gsa2.fs(:,j)+gsax.fs(:,j);
|
||||
% gsa22.f(:,j) = gsa2.f(:,j)+gsax.f(:,j);
|
||||
% gsa22.si(j) = var(gsa22.f(:,j))/var(gsa22.y);
|
||||
% end
|
||||
gsa_ = gsa22;
|
||||
end
|
||||
else
|
||||
|
@ -638,31 +604,23 @@ if iload==0
|
|||
end
|
||||
end
|
||||
save([fname,'_map.mat'],'gsa_')
|
||||
[sidum, iii]=sort(-gsa_.si);
|
||||
[~, iii]=sort(-gsa_.si);
|
||||
gsa_.x0=x00(ifit,:);
|
||||
if ~options_.nograph
|
||||
hmap=gsa_sdp_plot(gsa_,[fname '_map'],pnames,iii(1:min(12,np)));
|
||||
set(hmap,'name',options_map.amap_title);
|
||||
end
|
||||
gsa_.x0=x0(ifit,:);
|
||||
% copyfile([fname,'_est.mat'],[fname,'.mat'])
|
||||
if ~options_.nograph
|
||||
figure(hh_fig);
|
||||
subplot(223),
|
||||
plot(y0(ifit),[gsa_.fit y0(ifit)],'.'),
|
||||
r2 = gsa_.r2;
|
||||
% if ilog,
|
||||
% plot(y00(ifit),[log_trans_(gsa_.fit,'',isig,lam) y00(ifit)],'.'),
|
||||
% r2 = 1 - cov(log_trans_(gsa_.fit,'',isig,lam)-y00(ifit))/cov(y00(ifit));
|
||||
% else
|
||||
% plot(y0(ifit),[gsa_.fit y0(ifit)],'.'),
|
||||
% r2 = gsa_.r2;
|
||||
% end
|
||||
title(['Learning sample fit - R2=' num2str(r2,2)],'interpreter','none')
|
||||
if nfit<nrun
|
||||
if ilog
|
||||
yf = ss_anova_fcast(x0(ipred,:), gsa1);
|
||||
yf = log_trans_(yf,'',isig,lam)+ss_anova_fcast(x0(ipred,:), gsax);
|
||||
yf = gsa.log_transform(yf,'',isig,lam)+ss_anova_fcast(x0(ipred,:), gsax);
|
||||
else
|
||||
yf = ss_anova_fcast(x0(ipred,:), gsa_);
|
||||
end
|
||||
|
@ -680,8 +638,6 @@ if iload==0
|
|||
end
|
||||
end
|
||||
else
|
||||
% gsa_ = gsa_sdp_dyn(y0, x0, 0, [],[],[],0,fname, pnames);
|
||||
% gsa_ = gsa_sdp(y0, x0, 0, [],[],[],0,fname, pnames);
|
||||
load([fname,'_map.mat'],'gsa_')
|
||||
if ~options_.nograph
|
||||
yf = ss_anova_fcast(x0, gsa_);
|
||||
|
@ -690,10 +646,8 @@ else
|
|||
title([namy,' vs ', namx,' pred'],'interpreter','none')
|
||||
dyn_saveas(hh_fig,[fname '_pred'],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[fname '_pred'],options_map.title,[namy,' vs ', namx,' pred'])
|
||||
|
||||
end
|
||||
end
|
||||
% si = gsa_.multivariate.si;
|
||||
si = gsa_.si;
|
||||
|
||||
return
|
||||
|
@ -703,7 +657,7 @@ function gsa2 = log2level_map(gsa1, isig, lam)
|
|||
nest=length(gsa1.y);
|
||||
np = size(gsa1.x0,2);
|
||||
gsa2=gsa1;
|
||||
gsa2.y = log_trans_(gsa1.y,'',isig,lam);
|
||||
gsa2.y = gsa.log_transform(gsa1.y,'',isig,lam);
|
||||
gsa2.fit = (exp(gsa1.fit)-lam)*isig;
|
||||
gsa2.f0 = mean(gsa2.fit);
|
||||
gsa2.out.SSE = sum((gsa2.fit-gsa2.y).^2);
|
||||
|
@ -730,6 +684,8 @@ else
|
|||
end
|
||||
gsa2 = log2level_map(gsa1, isig, lam);
|
||||
if nargin >=5 && ~isempty(gsa0)
|
||||
nvr2=NaN(np,1);
|
||||
nvr0=NaN(np,1);
|
||||
for j=1:np
|
||||
nvr2(j) = var(diff(gsa2.fs(:,j),2));
|
||||
nvr0(j) = var(diff(gsa0.fs(:,j),2));
|
||||
|
@ -760,26 +716,24 @@ end
|
|||
|
||||
return
|
||||
|
||||
function indmcf = redform_mcf(y0, x0, options_mcf, options_)
|
||||
function indmcf = redform_mcf(y0, x0, options_mcf, options_, fname, parnames, estim_params_)
|
||||
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name',options_mcf.amcf_title);
|
||||
|
||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, ...
|
||||
density] = posterior_moments(y0,1,0.9);
|
||||
[~, ~, ~, ~, post_deciles] = posterior_moments(y0,0.9);
|
||||
post_deciles = [-inf; post_deciles; inf];
|
||||
|
||||
for jt=1:10
|
||||
indy{jt}=find( (y0>post_deciles(jt)) & (y0<=post_deciles(jt+1)));
|
||||
leg{jt}=[int2str(jt) '-dec'];
|
||||
end
|
||||
[proba, dproba] = stab_map_1(x0, indy{1}, indy{end}, [],0);
|
||||
[proba] = gsa.stability_mapping_univariate(x0, indy{1}, indy{end}, [], fname, options_, parnames, estim_params_,0);
|
||||
indmcf=find(proba<options_mcf.pvalue_ks);
|
||||
if isempty(indmcf)
|
||||
[tmp,jtmp] = sort(proba,2,'ascend');
|
||||
[~,jtmp] = sort(proba,1,'ascend');
|
||||
indmcf = jtmp(1);
|
||||
% indmcf = jtmp(1:min(2,length(proba)));
|
||||
end
|
||||
[tmp,jtmp] = sort(proba(indmcf),2,'ascend');
|
||||
[~,jtmp] = sort(proba(indmcf),1,'ascend');
|
||||
indmcf = indmcf(jtmp);
|
||||
nbr_par = length(indmcf);
|
||||
nrow=ceil(sqrt(nbr_par+1));
|
||||
|
@ -793,11 +747,15 @@ for jx=1:nbr_par
|
|||
subplot(nrow,ncol,jx)
|
||||
hold off
|
||||
for jt=1:10
|
||||
h=cumplot(x0(indy{jt},indmcf(jx)));
|
||||
h=gsa.cumplot(x0(indy{jt},indmcf(jx)));
|
||||
set(h,'color', cmap(jt,:), 'linewidth', 2)
|
||||
hold all
|
||||
end
|
||||
title(options_mcf.param_names(indmcf(jx),:),'interpreter','none')
|
||||
if options_.TeX
|
||||
title(options_mcf.param_names_tex(indmcf(jx),:),'interpreter','latex')
|
||||
else
|
||||
title(options_mcf.param_names(indmcf(jx),:),'interpreter','none')
|
||||
end
|
||||
end
|
||||
hleg = legend(leg);
|
||||
aa=get(hleg,'Position');
|
||||
|
@ -824,7 +782,7 @@ if nargin<5
|
|||
end
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([figpath '.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by redform_map.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by reduced_form_mapping.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
|
@ -1,10 +1,14 @@
|
|||
function redform_screen(dirname, options_gsa_)
|
||||
%function redform_map(dirname, options_gsa_)
|
||||
% inputs (from opt_gsa structure
|
||||
% anamendo = options_gsa_.namendo;
|
||||
% anamlagendo = options_gsa_.namlagendo;
|
||||
% anamexo = options_gsa_.namexo;
|
||||
% iload = options_gsa_.load_redform;
|
||||
function reduced_form_screening(dirname, options_gsa_, estim_params_, M_, dr, options_, bayestopt_)
|
||||
% reduced_form_screening(dirname, options_gsa_, estim_params_, M_, dr, options_, bayestopt_)
|
||||
% Conduct reduced form screening
|
||||
% Inputs:
|
||||
% - dirname [string] name of the output directory
|
||||
% - options_gsa_ [structure] GSA options_
|
||||
% - estim_params [structure] describing the estimated parameters
|
||||
% - M_ [structure] describing the model
|
||||
% - dr [structure] decision rules
|
||||
% - options_ [structure] describing the options
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -28,17 +32,21 @@ function redform_screen(dirname, options_gsa_)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global M_ oo_ estim_params_ options_ bayestopt_
|
||||
|
||||
% options_gsa_ = options_.opt_gsa;
|
||||
|
||||
anamendo = options_gsa_.namendo;
|
||||
anamlagendo = options_gsa_.namlagendo;
|
||||
anamexo = options_gsa_.namexo;
|
||||
iload = options_gsa_.load_redform;
|
||||
anamendo_tex = options_gsa_.namendo_tex;
|
||||
anamlagendo_tex = options_gsa_.namlagendo_tex;
|
||||
anamexo_tex = options_gsa_.namexo_tex;
|
||||
|
||||
nliv = options_gsa_.morris_nliv;
|
||||
|
||||
pnames = M_.param_names(estim_params_.param_vals(:,1));
|
||||
if options_.TeX
|
||||
for par_iter=1:size(estim_params_.param_vals(:,1),1)
|
||||
[~,tex_names{par_iter,1}]=get_the_name(estim_params_.param_vals(par_iter,1),options_.TeX, M_, estim_params_, options_.varobs);
|
||||
end
|
||||
end
|
||||
if nargin==0
|
||||
dirname='';
|
||||
end
|
||||
|
@ -54,35 +62,45 @@ nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:)));
|
|||
|
||||
js=0;
|
||||
for j=1:size(anamendo,1)
|
||||
namendo = deblank(anamendo(j,:));
|
||||
iendo = strmatch(namendo, M_.endo_names(oo_.dr.order_var), 'exact');
|
||||
namendo = anamendo{j,:};
|
||||
namendo_tex = anamendo_tex{j,:};
|
||||
iendo = strmatch(namendo, M_.endo_names(dr.order_var), 'exact');
|
||||
iplo=0;
|
||||
ifig=0;
|
||||
for jx=1:size(anamexo,1)
|
||||
namexo = deblank(anamexo(jx,:));
|
||||
namexo = anamexo{jx};
|
||||
namexo_tex = anamexo_tex{jx};
|
||||
iexo = strmatch(namexo, M_.exo_names, 'exact');
|
||||
if ~isempty(iexo)
|
||||
y0=teff(T(iendo,iexo+nspred,:), kn, istable);
|
||||
y0=gsa.teff(T(iendo,iexo+nspred,:), kn, istable);
|
||||
if ~isempty(y0)
|
||||
if mod(iplo,9)==0
|
||||
ifig = ifig+1;
|
||||
hh_fig = dyn_figure(options_.nodisplay, 'name', [namendo,[' vs. shocks '], int2str(ifig)]);
|
||||
hh_fig = dyn_figure(options_.nodisplay, 'name', [namendo,' vs. shocks ', int2str(ifig)]);
|
||||
iplo = 0;
|
||||
end
|
||||
iplo = iplo+1;
|
||||
js = js+1;
|
||||
subplot(3, 3, iplo)
|
||||
[SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0, nliv);
|
||||
[~, SAMorris] = gsa.Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0, nliv);
|
||||
SAM = squeeze(SAMorris(nshock+1:end,1));
|
||||
SA(:,js) = SAM./(max(SAM)+eps);
|
||||
[saso, iso] = sort(-SA(:,js));
|
||||
[~, iso] = sort(-SA(:,js));
|
||||
bar(SA(iso(1:min(np,10)),js))
|
||||
set(gca,'xticklabel',' ','fontsize',10)
|
||||
set(gca,'xlim',[0.5 10.5])
|
||||
for ip=1:min(np,10)
|
||||
text(ip,-0.02,pnames(iso(ip)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,-0.02,tex_names(iso(ip)),'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,pnames(iso(ip)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
if options_.TeX
|
||||
title([namendo_tex,' vs. ',namexo_tex],'interpreter','latex')
|
||||
else
|
||||
title([namendo,' vs. ',namexo],'interpreter','none')
|
||||
end
|
||||
title([namendo,' vs. ',namexo],'interpreter','none')
|
||||
if iplo==9
|
||||
dyn_saveas(hh_fig,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],ifig,[namendo,' vs. shocks ',int2str(ifig)],[namendo,'_vs_shock'],1)
|
||||
|
@ -99,11 +117,12 @@ for j=1:size(anamendo,1)
|
|||
iplo=0;
|
||||
ifig=0;
|
||||
for je=1:size(anamlagendo,1)
|
||||
namlagendo=deblank(anamlagendo(je,:));
|
||||
ilagendo=strmatch(namlagendo, M_.endo_names(oo_.dr.order_var(M_.nstatic+1:M_.nstatic+nsok)), 'exact');
|
||||
namlagendo=anamlagendo{je};
|
||||
namlagendo_tex=anamlagendo_tex{je};
|
||||
ilagendo=strmatch(namlagendo, M_.endo_names(dr.order_var(M_.nstatic+1:M_.nstatic+nsok)), 'exact');
|
||||
|
||||
if ~isempty(ilagendo)
|
||||
y0=teff(T(iendo,ilagendo,:),kn,istable);
|
||||
y0=gsa.teff(T(iendo,ilagendo,:),kn,istable);
|
||||
if ~isempty(y0)
|
||||
if mod(iplo,9)==0
|
||||
ifig=ifig+1;
|
||||
|
@ -113,19 +132,26 @@ for j=1:size(anamendo,1)
|
|||
iplo=iplo+1;
|
||||
js=js+1;
|
||||
subplot(3,3,iplo),
|
||||
[SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv);
|
||||
[~, SAMorris] = gsa.Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv);
|
||||
SAM = squeeze(SAMorris(nshock+1:end,1));
|
||||
SA(:,js)=SAM./(max(SAM)+eps);
|
||||
[saso, iso] = sort(-SA(:,js));
|
||||
[~, iso] = sort(-SA(:,js));
|
||||
bar(SA(iso(1:min(np,10)),js))
|
||||
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
|
||||
set(gca,'xticklabel',' ','fontsize',10)
|
||||
set(gca,'xlim',[0.5 10.5])
|
||||
for ip=1:min(np,10)
|
||||
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,-0.02,tex_names(iso(ip)),'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,pnames{iso(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
|
||||
title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none')
|
||||
if options_.TeX
|
||||
title([namendo_tex,' vs. ',namlagendo_tex,'(-1)'],'interpreter','latex')
|
||||
else
|
||||
title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none')
|
||||
end
|
||||
if iplo==9
|
||||
dyn_saveas(hh_fig,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],ifig,[namendo,' vs. lagged endogenous ',int2str(ifig)],[namendo,'_vs_lags'],1)
|
||||
|
@ -140,15 +166,17 @@ for j=1:size(anamendo,1)
|
|||
end
|
||||
|
||||
hh_fig=dyn_figure(options_.nodisplay,'Name','Reduced form screening');
|
||||
%bar(SA)
|
||||
% boxplot(SA','whis',10,'symbol','r.')
|
||||
myboxplot(SA',[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
|
||||
gsa.boxplot(SA',[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:np)
|
||||
set(gca,'xlim',[0.5 np+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
set(gca,'position',[0.13 0.2 0.775 0.7])
|
||||
for ip=1:np
|
||||
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,-0.02,tex_names(ip),'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,pnames{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
xlabel(' ')
|
||||
ylabel('Elementary Effects')
|
||||
|
@ -163,7 +191,7 @@ if nargin<6
|
|||
end
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([figpath '.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by redform_screen.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by reduced_form_screening.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
|
@ -1,10 +1,19 @@
|
|||
function x0=dynare_sensitivity(options_gsa)
|
||||
function x0=run(M_,oo_,options_,bayestopt_,estim_params_,options_gsa)
|
||||
% x0=run(M_,oo_,options_,bayestopt_,estim_params_,options_gsa)
|
||||
% Frontend to the Sensitivity Analysis Toolbox for DYNARE
|
||||
% Inputs:
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
% - oo_ [structure] Matlab's structure describing the results
|
||||
% - options_ [structure] Matlab's structure describing the current options
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - options_gsa [structure] Matlab's structure describing the GSA options
|
||||
%
|
||||
% Reference:
|
||||
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
|
||||
% M. Ratto (2008), Analysing DSGE Models with Global Sensitivity Analysis,
|
||||
% Computational Economics (2008), 31, pp. 115–139
|
||||
|
||||
% Copyright © 2008-2018 Dynare Team
|
||||
% Copyright © 2008-2024 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -21,14 +30,11 @@ function x0=dynare_sensitivity(options_gsa)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global M_ options_ oo_ bayestopt_ estim_params_
|
||||
|
||||
if options_.dsge_var
|
||||
error('Identification does not support DSGE-VARs at the current stage')
|
||||
end
|
||||
|
||||
fname_ = M_.fname;
|
||||
lgy_ = M_.endo_names;
|
||||
x0=[];
|
||||
|
||||
% check user defined options
|
||||
|
@ -43,7 +49,6 @@ end
|
|||
|
||||
if isfield(options_gsa,'morris') && options_gsa.morris==1
|
||||
if isfield(options_gsa,'identification') && options_gsa.identification==0
|
||||
% options_gsa.redform=1;
|
||||
end
|
||||
if isfield(options_gsa,'ppost') && options_gsa.ppost
|
||||
error('sensitivity:: Morris is incompatible with posterior sampling')
|
||||
|
@ -89,9 +94,6 @@ if options_.order~=1
|
|||
options_.order = 1;
|
||||
end
|
||||
|
||||
original_prior_trunc = options_.prior_trunc;
|
||||
original_qz_criterium = options_.qz_criterium;
|
||||
|
||||
if ~isempty(options_gsa.datafile) || isempty(bayestopt_) || options_gsa.rmse
|
||||
if isempty(options_gsa.datafile) && options_gsa.rmse
|
||||
disp('The data file and all relevant estimation options ')
|
||||
|
@ -99,6 +101,9 @@ if ~isempty(options_gsa.datafile) || isempty(bayestopt_) || options_gsa.rmse
|
|||
disp('must be specified for RMSE analysis!');
|
||||
error('Sensitivity anaysis error!')
|
||||
end
|
||||
if isfield(options_gsa,'nobs')
|
||||
options_.nobs=options_gsa.nobs;
|
||||
end
|
||||
if ~isempty(options_.nobs) && length(options_.nobs)~=1
|
||||
error('dynare_sensitivity does not support recursive estimation. Please specify nobs as a scalar, not a vector.')
|
||||
end
|
||||
|
@ -106,9 +111,6 @@ if ~isempty(options_gsa.datafile) || isempty(bayestopt_) || options_gsa.rmse
|
|||
if isfield(options_gsa,'first_obs')
|
||||
options_.first_obs=options_gsa.first_obs;
|
||||
end
|
||||
if isfield(options_gsa,'nobs')
|
||||
options_.nobs=options_gsa.nobs;
|
||||
end
|
||||
if isfield(options_gsa,'presample')
|
||||
options_.presample=options_gsa.presample;
|
||||
end
|
||||
|
@ -130,7 +132,7 @@ if ~isempty(options_gsa.datafile) || isempty(bayestopt_) || options_gsa.rmse
|
|||
options_.mode_compute = 0;
|
||||
options_.filtered_vars = 1;
|
||||
options_.plot_priors = 0;
|
||||
[dataset_,dataset_info,xparam1,hh, M_, options_, oo_, estim_params_, bayestopt_] = ...
|
||||
[dataset_,dataset_info,~,~, M_, options_, oo_, estim_params_, bayestopt_] = ...
|
||||
dynare_estimation_init(M_.endo_names, fname_, 1, M_, options_, oo_, estim_params_, bayestopt_);
|
||||
% computes a first linear solution to set up various variables
|
||||
else
|
||||
|
@ -146,7 +148,12 @@ if M_.exo_nbr==0
|
|||
error('dynare_sensitivity does not support having no varexo in the model. As a workaround you could define a dummy exogenous variable.')
|
||||
end
|
||||
|
||||
[make,my,day,punk,oo_.dr,M_.params] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
[~,~,~,~,oo_.dr,M_.params] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
|
||||
if isfield(oo_.dr,'eigval') && any(abs(oo_.dr.eigval-1)<abs(1-options_.qz_criterium)) && options_.qz_criterium<1
|
||||
fprintf('\ngsa: The model features a unit root, but qz_criterium<1. Check whether that is intended.')
|
||||
fprintf('\ngsa: If not, use the diffuse_filter option.\n')
|
||||
end
|
||||
|
||||
options_gsa = set_default_option(options_gsa,'identification',0);
|
||||
if options_gsa.identification
|
||||
|
@ -166,7 +173,6 @@ if options_gsa.identification
|
|||
options_.options_ident.load_ident_files = options_gsa.load_ident_files;
|
||||
options_.options_ident.useautocorr = options_gsa.useautocorr;
|
||||
options_.options_ident.ar = options_gsa.ar;
|
||||
options_ident=options_.options_ident;
|
||||
else
|
||||
options_ident=[];
|
||||
options_ident = set_default_option(options_ident,'load_ident_files',options_gsa.load_ident_files);
|
||||
|
@ -193,7 +199,6 @@ options_gsa = set_default_option(options_gsa,'load_stab',0);
|
|||
options_gsa = set_default_option(options_gsa,'alpha2_stab',0);
|
||||
options_gsa = set_default_option(options_gsa,'pvalue_ks',0.001);
|
||||
options_gsa = set_default_option(options_gsa,'pvalue_corr',1.e-5);
|
||||
%options_gsa = set_default_option(options_gsa,'load_mh',0);
|
||||
% REDFORM mapping
|
||||
options_gsa = set_default_option(options_gsa,'redform',0);
|
||||
options_gsa = set_default_option(options_gsa,'load_redform',0);
|
||||
|
@ -202,8 +207,29 @@ options_gsa = set_default_option(options_gsa,'threshold_redform',[]);
|
|||
options_gsa = set_default_option(options_gsa,'ksstat_redform',0.001);
|
||||
options_gsa = set_default_option(options_gsa,'alpha2_redform',1.e-5);
|
||||
options_gsa = set_default_option(options_gsa,'namendo',{});
|
||||
options_gsa = set_default_option(options_gsa,'namlagendo',[]);
|
||||
options_gsa = set_default_option(options_gsa,'namlagendo',{});
|
||||
options_gsa = set_default_option(options_gsa,'namexo',{});
|
||||
options_gsa = set_default_option(options_gsa,'namendo_tex',{});
|
||||
options_gsa = set_default_option(options_gsa,'namlagendo_tex',{});
|
||||
options_gsa = set_default_option(options_gsa,'namexo_tex',{});
|
||||
if strmatch(':',options_gsa.namendo,'exact')
|
||||
options_gsa.namendo = M_.endo_names(1:M_.orig_endo_nbr);
|
||||
end
|
||||
if strmatch(':',options_gsa.namexo,'exact')
|
||||
options_gsa.namexo = M_.exo_names;
|
||||
end
|
||||
if strmatch(':',options_gsa.namlagendo,'exact')
|
||||
options_gsa.namlagendo = M_.endo_names(1:M_.orig_endo_nbr);
|
||||
end
|
||||
|
||||
if options_.TeX
|
||||
[~,Locb]=ismember(options_gsa.namendo,M_.endo_names);
|
||||
options_gsa.namendo_tex=cellfun(@(x) horzcat('$', x, '$'), M_.endo_names_tex(Locb), 'UniformOutput', false);
|
||||
[~,Locb]=ismember(options_gsa.namlagendo,M_.endo_names);
|
||||
options_gsa.namlagendo_tex=cellfun(@(x) horzcat('$', x, '$'), M_.endo_names_tex(Locb), 'UniformOutput', false);
|
||||
[~,Locb]=ismember(options_gsa.namexo,M_.exo_names);
|
||||
options_gsa.namexo_tex=cellfun(@(x) horzcat('$', x, '$'), M_.exo_names_tex(Locb), 'UniformOutput', false);
|
||||
end
|
||||
% RMSE mapping
|
||||
options_gsa = set_default_option(options_gsa,'load_rmse',0);
|
||||
options_gsa = set_default_option(options_gsa,'lik_only',0);
|
||||
|
@ -212,8 +238,9 @@ options_gsa = set_default_option(options_gsa,'var_rmse', options_.varobs);
|
|||
options_gsa.var_rmse_tex={};
|
||||
for ii=1:length(options_gsa.var_rmse)
|
||||
temp_name = M_.endo_names_tex{strmatch(options_gsa.var_rmse{ii}, M_.endo_names, 'exact')};
|
||||
options_gsa.var_rmse_tex = vertcat(options_gsa.var_rmse_tex, temp_name);
|
||||
options_gsa.var_rmse_tex = vertcat(options_gsa.var_rmse_tex, ['$' temp_name '$']);
|
||||
end
|
||||
options_gsa.varobs_tex = cellfun(@(x) horzcat('$', x, '$'), M_.endo_names_tex(options_.varobs_id), 'UniformOutput', false);
|
||||
options_gsa = set_default_option(options_gsa,'pfilt_rmse', 0.1);
|
||||
options_gsa = set_default_option(options_gsa,'istart_rmse', options_.presample+1);
|
||||
options_gsa = set_default_option(options_gsa,'alpha_rmse', 0.001);
|
||||
|
@ -245,31 +272,22 @@ if options_gsa.morris==1
|
|||
options_gsa.pprior=1;
|
||||
end
|
||||
options_gsa.ppost=0;
|
||||
%options_gsa.stab=1;
|
||||
options_gsa.glue=0;
|
||||
options_gsa.rmse=0;
|
||||
options_gsa.load_rmse=0;
|
||||
options_gsa.alpha2_stab=1;
|
||||
options_gsa.pvalue_ks=0;
|
||||
options_gsa.pvalue_corr=0;
|
||||
% if options_gsa.morris==3,
|
||||
% options_gsa = set_default_option(options_gsa,'Nsam',256);
|
||||
% OutputDirectoryName = CheckPath('gsa/identif',M_.dname);
|
||||
% else
|
||||
OutputDirectoryName = CheckPath('gsa/screen',M_.dname);
|
||||
% end
|
||||
else
|
||||
OutputDirectoryName = CheckPath('gsa',M_.dname);
|
||||
end
|
||||
|
||||
% options_.opt_gsa = options_gsa;
|
||||
|
||||
if (options_gsa.load_stab || options_gsa.load_rmse || options_gsa.load_redform) && options_gsa.pprior
|
||||
filetoload=[OutputDirectoryName '/' fname_ '_prior.mat'];
|
||||
if ~exist(filetoload,'file')
|
||||
disp([filetoload,' not found!'])
|
||||
disp(['You asked to load a non existent analysis'])
|
||||
%options_gsa.load_stab=0;
|
||||
disp('You asked to load a non existent analysis')
|
||||
return
|
||||
else
|
||||
if isempty(strmatch('bkpprior',who('-file', filetoload),'exact'))
|
||||
|
@ -293,7 +311,7 @@ if (options_gsa.load_stab || options_gsa.load_rmse || options_gsa.load_redform)
|
|||
end
|
||||
|
||||
if options_gsa.stab && ~options_gsa.ppost
|
||||
x0 = stab_map_(OutputDirectoryName,options_gsa);
|
||||
x0 = gsa.stability_mapping(OutputDirectoryName,options_gsa,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
if isempty(x0)
|
||||
skipline()
|
||||
disp('Sensitivity computations stopped: no parameter set provided a unique solution')
|
||||
|
@ -301,16 +319,13 @@ if options_gsa.stab && ~options_gsa.ppost
|
|||
end
|
||||
end
|
||||
|
||||
% reduced form
|
||||
% redform_map(namendo, namlagendo, namexo, icomp, pprior, ilog, threshold)
|
||||
|
||||
options_.opt_gsa = options_gsa;
|
||||
if ~isempty(options_gsa.moment_calibration) || ~isempty(options_gsa.irf_calibration)
|
||||
map_calibration(OutputDirectoryName, M_, options_, oo_, estim_params_,bayestopt_);
|
||||
gsa.map_calibration(OutputDirectoryName, M_, options_, oo_, estim_params_,bayestopt_);
|
||||
end
|
||||
|
||||
if options_gsa.identification
|
||||
map_ident_(OutputDirectoryName,options_gsa);
|
||||
gsa.map_identification(OutputDirectoryName,options_gsa,M_,oo_,options_,estim_params_,bayestopt_);
|
||||
end
|
||||
|
||||
if options_gsa.redform && ~isempty(options_gsa.namendo)
|
||||
|
@ -318,7 +333,7 @@ if options_gsa.redform && ~isempty(options_gsa.namendo)
|
|||
filnam = dir([M_.dname filesep 'metropolis' filesep '*param_irf*.mat']);
|
||||
lpmat=[];
|
||||
for j=1:length(filnam)
|
||||
load ([M_.dname filesep 'metropolis' filesep M_.fname '_param_irf' int2str(j) '.mat'])
|
||||
load ([M_.dname filesep 'metropolis' filesep M_.fname '_param_irf' int2str(j) '.mat'],'stock')
|
||||
lpmat=[lpmat; stock];
|
||||
end
|
||||
clear stock
|
||||
|
@ -336,20 +351,10 @@ if options_gsa.redform && ~isempty(options_gsa.namendo)
|
|||
save([OutputDirectoryName filesep M_.fname '_mc.mat'],'lpmat','lpmat0','istable','iunstable','iwrong','iindeterm')
|
||||
options_gsa.load_stab=1;
|
||||
|
||||
x0 = stab_map_(OutputDirectoryName,options_gsa);
|
||||
x0 = gsa.stability_mapping(OutputDirectoryName,options_gsa,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
end
|
||||
if strmatch(':',options_gsa.namendo,'exact')
|
||||
options_gsa.namendo = M_.endo_names(1:M_.orig_endo_nbr);
|
||||
end
|
||||
if strmatch(':',options_gsa.namexo,'exact')
|
||||
options_gsa.namexo = M_.exo_names;
|
||||
end
|
||||
if strmatch(':',options_gsa.namlagendo,'exact')
|
||||
options_gsa.namlagendo = M_.endo_names(1:M_.orig_endo_nbr);
|
||||
end
|
||||
% options_.opt_gsa = options_gsa;
|
||||
if options_gsa.morris==1
|
||||
redform_screen(OutputDirectoryName,options_gsa);
|
||||
gsa.reduced_form_screening(OutputDirectoryName,options_gsa, estim_params_, M_, oo_.dr, options_, bayestopt_);
|
||||
else
|
||||
% check existence of the SS_ANOVA toolbox
|
||||
if isempty(options_gsa.threshold_redform) && ~(exist('gsa_sdp','file')==6 || exist('gsa_sdp','file')==2)
|
||||
|
@ -360,11 +365,10 @@ if options_gsa.redform && ~isempty(options_gsa.namendo)
|
|||
fprintf('After obtaining the files, you need to unpack them and set a Matlab Path to those files.\n')
|
||||
error('SS-ANOVA-R Toolbox missing!')
|
||||
end
|
||||
redform_map(OutputDirectoryName,options_gsa);
|
||||
gsa.reduced_form_mapping(OutputDirectoryName,options_gsa,M_,estim_params_,options_,bayestopt_,oo_);
|
||||
end
|
||||
end
|
||||
% RMSE mapping
|
||||
% function [rmse_MC, ixx] = filt_mc_(vvarvecm, loadSA, pfilt, alpha, alpha2)
|
||||
options_.opt_gsa = options_gsa;
|
||||
if options_gsa.rmse
|
||||
if ~options_gsa.ppost
|
||||
|
@ -391,7 +395,6 @@ if options_gsa.rmse
|
|||
options_.forecast=0;
|
||||
options_.filtered_vars=0;
|
||||
end
|
||||
% dynare_MC([],OutputDirectoryName,data,rawdata,data_info);
|
||||
if options_gsa.pprior
|
||||
TmpDirectoryName = ([M_.dname filesep 'gsa' filesep 'prior']);
|
||||
else
|
||||
|
@ -408,37 +411,18 @@ if options_gsa.rmse
|
|||
delete([TmpDirectoryName filesep filparam(j).name]);
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
oo_=prior_posterior_statistics('gsa',dataset_, dataset_info,M_,oo_,options_,estim_params_,bayestopt_,'gsa::mcmc');
|
||||
if options_.bayesian_irf
|
||||
oo_=PosteriorIRF('gsa',options_,estim_params_,oo_,M_,bayestopt_,dataset_,dataset_info,'gsa::mcmc');
|
||||
end
|
||||
options_gsa.load_rmse=0;
|
||||
% else
|
||||
% if options_gsa.load_rmse==0,
|
||||
% disp('You already saved a MC filter/smoother analysis ')
|
||||
% disp('Do you want to overwrite ?')
|
||||
% pause;
|
||||
% if options_gsa.pprior
|
||||
% delete([OutputDirectoryName,'/',fname_,'_prior_*.mat'])
|
||||
% else
|
||||
% delete([OutputDirectoryName,'/',fname_,'_mc_*.mat'])
|
||||
% end
|
||||
% dynare_MC([],OutputDirectoryName);
|
||||
% options_gsa.load_rmse=0;
|
||||
% end
|
||||
|
||||
end
|
||||
end
|
||||
clear a;
|
||||
% filt_mc_(OutputDirectoryName,data_info);
|
||||
filt_mc_(OutputDirectoryName,options_gsa,dataset_,dataset_info);
|
||||
gsa.monte_carlo_filtering(OutputDirectoryName,options_gsa,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
end
|
||||
options_.opt_gsa = options_gsa;
|
||||
options_.prior_trunc=original_prior_trunc;
|
||||
options_.qz_criterium=original_qz_criterium ;
|
||||
|
||||
|
||||
if options_gsa.glue
|
||||
dr_ = oo_.dr;
|
||||
|
@ -453,11 +437,10 @@ if options_gsa.glue
|
|||
end
|
||||
end
|
||||
if ~exist('x','var')
|
||||
disp(['No RMSE analysis is available for current options'])
|
||||
disp(['No GLUE file prepared'])
|
||||
disp('No RMSE analysis is available for current options')
|
||||
disp('No GLUE file prepared')
|
||||
return,
|
||||
end
|
||||
nruns=size(x,1);
|
||||
gend = options_.nobs;
|
||||
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
|
||||
rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
|
||||
|
@ -465,28 +448,20 @@ if options_gsa.glue
|
|||
rawdata = log(rawdata);
|
||||
end
|
||||
if options_.prefilter == 1
|
||||
%data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs);
|
||||
data = transpose(rawdata-ones(gend,1)*mean(rawdata,1));
|
||||
else
|
||||
data = transpose(rawdata);
|
||||
end
|
||||
|
||||
Obs.data = data;
|
||||
Obs.time = [1:gend];
|
||||
Obs.time = 1:gend;
|
||||
Obs.num = gend;
|
||||
for j=1:length(options_.varobs)
|
||||
Obs.name{j} = options_.varobs{j};
|
||||
vj = options_.varobs{j};
|
||||
|
||||
jxj = strmatch(vj,lgy_(dr_.order_var),'exact');
|
||||
js = strmatch(vj,lgy_,'exact');
|
||||
jxj = strmatch(vj,M_.endo_names(dr_.order_var),'exact');
|
||||
if ~options_gsa.ppost
|
||||
% y0=zeros(gend+1,nruns);
|
||||
% nb = size(stock_filter,3);
|
||||
% y0 = squeeze(stock_filter(:,jxj,:)) + ...
|
||||
% kron(stock_ys(js,:),ones(size(stock_filter,1),1));
|
||||
% Out(j).data = y0';
|
||||
% Out(j).time = [1:size(y0,1)];
|
||||
Out(j).data = jxj;
|
||||
Out(j).time = [pwd,'/',OutputDirectoryName];
|
||||
else
|
||||
|
@ -500,17 +475,7 @@ if options_gsa.glue
|
|||
Lik(j).isam = 1;
|
||||
Lik(j).data = rmse_MC(:,j)';
|
||||
|
||||
if ~options_gsa.ppost
|
||||
% y0 = squeeze(stock_smooth(:,jxj,:)) + ...
|
||||
% kron(stock_ys(js,:),ones(size(stock_smooth,1),1));
|
||||
% Out1(j).name = vj;
|
||||
% Out1(j).ini = 'yes';
|
||||
% Out1(j).time = [1:size(y0,1)];
|
||||
% Out1(j).data = y0';
|
||||
Out1=Out;
|
||||
else
|
||||
Out1=Out;
|
||||
end
|
||||
Out1=Out;
|
||||
ismoo(j)=jxj;
|
||||
|
||||
end
|
||||
|
@ -520,10 +485,6 @@ if options_gsa.glue
|
|||
jsmoo=jsmoo+1;
|
||||
vj = M_.endo_names{dr_.order_var(j)};
|
||||
if ~options_gsa.ppost
|
||||
% y0 = squeeze(stock_smooth(:,j,:)) + ...
|
||||
% kron(stock_ys(j,:),ones(size(stock_smooth,1),1));
|
||||
% Out1(jsmoo).time = [1:size(y0,1)];
|
||||
% Out1(jsmoo).data = y0';
|
||||
Out1(jsmoo).data = j;
|
||||
Out1(jsmoo).time = [pwd,'/',OutputDirectoryName];
|
||||
else
|
||||
|
@ -546,36 +507,24 @@ if options_gsa.glue
|
|||
end
|
||||
Sam.name = bayestopt_.name;
|
||||
Sam.dim = [size(x) 0];
|
||||
Sam.data = [x];
|
||||
Sam.data = x;
|
||||
|
||||
Rem.id = 'Original';
|
||||
Rem.ind= [1:size(x,1)];
|
||||
Rem.ind= 1:size(x,1);
|
||||
|
||||
Info.dynare=M_.fname;
|
||||
Info.order_var=dr_.order_var;
|
||||
Out=Out1;
|
||||
if options_gsa.ppost
|
||||
% Info.dynare=M_.fname;
|
||||
% Info.order_var=dr_.order_var;
|
||||
% Out=Out1;
|
||||
Info.TypeofSample='post';
|
||||
save([OutputDirectoryName,'/',fname_,'_glue_post.mat'], 'Out', 'Sam', 'Lik', 'Obs', 'Rem','Info', 'Exo')
|
||||
%save([fname_,'_post_glue_smooth'], 'Out', 'Sam', 'Lik', 'Obs', 'Rem','Info')
|
||||
|
||||
else
|
||||
if options_gsa.pprior
|
||||
Info.TypeofSample='prior';
|
||||
save([OutputDirectoryName,'/',fname_,'_glue_prior.mat'], 'Out', 'Sam', 'Lik', 'Obs', 'Rem','Info', 'Exo')
|
||||
% save([OutputDirectoryName,'/',fname_,'_prior_glue'], 'Out', 'Sam', 'Lik', 'Obs', 'Rem')
|
||||
% Out=Out1;
|
||||
% save([OutputDirectoryName,'/',fname_,'_prior_glue_smooth'], 'Out', 'Sam', 'Lik', 'Obs', 'Rem')
|
||||
else
|
||||
Info.TypeofSample='mc';
|
||||
save([OutputDirectoryName,'/',fname_,'_glue_mc.mat'], 'Out', 'Sam', 'Lik', 'Obs', 'Rem','Info', 'Exo')
|
||||
% save([OutputDirectoryName,'/',fname_,'_mc_glue'], 'Out', 'Sam', 'Lik', 'Obs', 'Rem')
|
||||
% Out=Out1;
|
||||
% save([OutputDirectoryName,'/',fname_,'_mc_glue_smooth'], 'Out', 'Sam', 'Lik', 'Obs', 'Rem')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,4 +1,6 @@
|
|||
function indmcf = scatter_analysis(lpmat, xdata, options_scatter, options_)
|
||||
function scatter_analysis(lpmat, xdata, options_scatter, options_)
|
||||
% scatter_analysis(lpmat, xdata, options_scatter, options_)
|
||||
% Plot scatter plot analysis
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -6,7 +8,7 @@ function indmcf = scatter_analysis(lpmat, xdata, options_scatter, options_)
|
|||
%
|
||||
|
||||
% Copyright © 2017 European Commission
|
||||
% Copyright © 2017 Dynare Team
|
||||
% Copyright © 2017-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -34,7 +36,6 @@ if options_.TeX
|
|||
end
|
||||
amcf_name = options_scatter.amcf_name;
|
||||
amcf_title = options_scatter.amcf_title;
|
||||
title = options_scatter.title;
|
||||
fname_ = options_scatter.fname_;
|
||||
xparam1=[];
|
||||
if isfield(options_scatter,'xparam1')
|
||||
|
@ -48,5 +49,9 @@ if ~options_.nograph
|
|||
if ~isempty(xparam1)
|
||||
xx=xparam1;
|
||||
end
|
||||
scatter_plots(lpmat, xdata, param_names, '.', [fname_, '_', amcf_name], OutputDirectoryName, amcf_title, xx, options_)
|
||||
if options_.TeX
|
||||
gsa.scatter_plots(lpmat, xdata, param_names_tex, '.', [fname_, '_', amcf_name], OutputDirectoryName, amcf_title, xx, options_)
|
||||
else
|
||||
gsa.scatter_plots(lpmat, xdata, param_names, '.', [fname_, '_', amcf_name], OutputDirectoryName, amcf_title, xx, options_)
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function scatter_mcf(X,Y,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, options_, beha_name, non_beha_name)
|
||||
% scatter_mcf(X,Y,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, options_, beha_name, non_beha_name)
|
||||
function scatter_mcf(X,Y,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, options_, beha_name, non_beha_name, beha_name_latex, non_beha_name_latex)
|
||||
% scatter_mcf(X,Y,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, options_, beha_name, non_beha_name, beha_name_latex, non_beha_name_latex)
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -38,12 +38,6 @@ function scatter_mcf(X,Y,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, o
|
|||
|
||||
|
||||
Z=[X;Y];
|
||||
[n,p] = size(X);
|
||||
% X = X - ones(n,1)*min(Z);
|
||||
% X = X ./ (ones(n,1)*max(Z));
|
||||
[n,p] = size(Y);
|
||||
% Y = Y - ones(n,1)*min(Z);
|
||||
% Y = Y ./ (ones(n,1)*max(Z));
|
||||
[n,p] = size(Z);
|
||||
clear Z;
|
||||
|
||||
|
@ -53,8 +47,10 @@ if nargin >=3
|
|||
end
|
||||
|
||||
if nargin<4 || isempty(plotsymbol)
|
||||
if n*p<100, plotsymbol = 'o';
|
||||
else plotsymbol = '.';
|
||||
if n*p<100
|
||||
plotsymbol = 'o';
|
||||
else
|
||||
plotsymbol = '.';
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -83,7 +79,7 @@ end
|
|||
|
||||
figtitle_tex=strrep(figtitle,'_','\_');
|
||||
|
||||
fig_nam_=[fnam];
|
||||
fig_nam_=fnam;
|
||||
if ~nograph
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name',figtitle);
|
||||
end
|
||||
|
@ -100,11 +96,10 @@ for i = 1:p
|
|||
for j = 1:p
|
||||
h = axes('position',[fL(i),fL(p+1-j),ffl,ffl]);
|
||||
if i==j
|
||||
h1=cumplot(X(:,j));
|
||||
% set(h1,'color',[0 0 1], 'linestyle','--','LineWidth',1.5)
|
||||
h1=gsa.cumplot(X(:,j));
|
||||
set(h1,'color',[0 0 1],'LineWidth',1.5)
|
||||
hold on,
|
||||
h2=cumplot(Y(:,j));
|
||||
h2=gsa.cumplot(Y(:,j));
|
||||
set(h2,'color',[1 0 0],'LineWidth',1.5)
|
||||
if ~isempty(xparam1)
|
||||
hold on, plot(xparam1([j j]),[0 1],'k--')
|
||||
|
@ -126,10 +121,10 @@ for i = 1:p
|
|||
plot(X(:,i),X(:,j),[plotsymbol,'b'])
|
||||
end
|
||||
if ~isempty(xparam1)
|
||||
hold on, plot(xparam1(i),xparam1(j),'s','MarkerFaceColor',[0 0.75 0],'MarkerEdgeColor',[0 0.75 0])
|
||||
hold on
|
||||
plot(xparam1(i),xparam1(j),'s','MarkerFaceColor',[0 0.75 0],'MarkerEdgeColor',[0 0.75 0])
|
||||
end
|
||||
hold off;
|
||||
% axis([-0.1 1.1 -0.1 1.1])
|
||||
if i<p
|
||||
set(gca,'YTickLabel',[],'YTick',[]);
|
||||
else
|
||||
|
@ -144,16 +139,26 @@ for i = 1:p
|
|||
end
|
||||
if i==1
|
||||
if nflag == 1
|
||||
ylabel(vnames(j,:),'Rotation',45, ...
|
||||
'HorizontalAlignment','right','VerticalAlignment','middle');
|
||||
if options_.TeX
|
||||
ylabel(vnames(j,:),'Rotation',45, ...
|
||||
'HorizontalAlignment','right','VerticalAlignment','middle','Interpreter','latex');
|
||||
else
|
||||
ylabel(vnames(j,:),'Rotation',45, ...
|
||||
'HorizontalAlignment','right','VerticalAlignment','middle','Interpreter','none');
|
||||
end
|
||||
else
|
||||
ylabel([num2str(j),' '],'Rotation',90)
|
||||
end
|
||||
end
|
||||
if j==1
|
||||
if nflag == 1
|
||||
title(vnames(i,:),'Rotation',45, ...
|
||||
'HorizontalAlignment','left','VerticalAlignment','bottom')
|
||||
if options_.TeX
|
||||
title(vnames(i,:),'Rotation',45, ...
|
||||
'HorizontalAlignment','left','VerticalAlignment','bottom','Interpreter','latex')
|
||||
else
|
||||
title(vnames(i,:),'Rotation',45, ...
|
||||
'HorizontalAlignment','left','VerticalAlignment','bottom','Interpreter','none')
|
||||
end
|
||||
else
|
||||
title(num2str(i))
|
||||
end
|
||||
|
@ -162,8 +167,13 @@ for i = 1:p
|
|||
end
|
||||
end
|
||||
if ~isoctave
|
||||
annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center','interpreter','none');
|
||||
annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center','interpreter','none');
|
||||
if options_.TeX
|
||||
annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name_latex,'Color','Blue','horizontalalignment','center','interpreter','latex');
|
||||
annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name_latex,'Color','Red','horizontalalignment','center','interpreter','latex');
|
||||
else
|
||||
annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center','interpreter','none');
|
||||
annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center','interpreter','none');
|
||||
end
|
||||
end
|
||||
|
||||
if ~nograph
|
|
@ -1,9 +1,21 @@
|
|||
function scatter_plots(X,xp,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, options_)
|
||||
% scatter_plots(X,xp,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, options_)
|
||||
% Pairwise scatter plots of the columns of x and y after Monte Carlo filtering
|
||||
% Inputs:
|
||||
% - X [double] nxk matrix with columns containing behavioural sample
|
||||
% - xp [double] mxk matrix with columns containing non-behavioural sample
|
||||
% - vnames [char] vector of variable names (default = numeric labels 1,2,3 etc.)
|
||||
% - plotsymbol [char] plt symbol (default = '.' for npts > 100, 'o' for npts < 100
|
||||
% - fnam [char] figure name
|
||||
% - dirname [char] directory name
|
||||
% - figtitle [char] figure title
|
||||
% - xparam1 [double] parameter vector
|
||||
% - options_ [struct] option structure
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
% marco.ratto@ec.europa.eu
|
||||
%
|
||||
|
||||
|
||||
% Copyright © 2017 European Commission
|
||||
% Copyright © 2017-2023 Dynare Team
|
||||
|
@ -23,23 +35,7 @@ function scatter_plots(X,xp,vnames,plotsymbol, fnam, dirname, figtitle, xparam1,
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
% PURPOSE: Pairwise scatter plots of the columns of x and y after
|
||||
% Monte Carlo filtering
|
||||
%---------------------------------------------------
|
||||
% USAGE: scatter_mcf(x,y,vnames,pltsym,diagon)
|
||||
% or scatter_mcf(x,y) which relies on defaults
|
||||
% where:
|
||||
% x = an nxk matrix with columns containing behavioural sample
|
||||
% y = an mxk matrix with columns containing non-behavioural sample
|
||||
% vnames = a vector of variable names
|
||||
% (default = numeric labels 1,2,3 etc.)
|
||||
% pltsym = a plt symbol
|
||||
% (default = '.' for npts > 100, 'o' for npts < 100
|
||||
|
||||
|
||||
[n,p] = size(X);
|
||||
% X = X - ones(n,1)*min(Z);
|
||||
% X = X ./ (ones(n,1)*max(Z));
|
||||
|
||||
nflag = 0;
|
||||
if nargin >=3
|
||||
|
@ -47,8 +43,10 @@ if nargin >=3
|
|||
end
|
||||
|
||||
if nargin<4 || isempty(plotsymbol)
|
||||
if n*p<100, plotsymbol = 'o';
|
||||
else plotsymbol = '.';
|
||||
if n*p<100
|
||||
plotsymbol = 'o';
|
||||
else
|
||||
plotsymbol = '.';
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,7 +69,7 @@ end
|
|||
|
||||
figtitle_tex=strrep(figtitle,'_','\_');
|
||||
|
||||
fig_nam_=[fnam];
|
||||
fig_nam_=fnam;
|
||||
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name',figtitle);
|
||||
set(hh_fig,'userdata',{X,xp})
|
||||
|
@ -88,9 +86,8 @@ for i = 1:p
|
|||
for j = 1:p
|
||||
h = axes('position',[fL(i),fL(p+1-j),ffl,ffl]);
|
||||
if i==j
|
||||
h1=cumplot(X(:,j));
|
||||
h1=gsa.cumplot(X(:,j));
|
||||
set(h,'Tag','cumplot')
|
||||
% set(h1,'color',[0 0 1], 'linestyle','--','LineWidth',1.5)
|
||||
set(h1,'color',[0 0 1],'LineWidth',1.5)
|
||||
if ~isempty(xparam1)
|
||||
hold on, plot(xparam1([j j]),[0 1],'k--')
|
||||
|
@ -102,39 +99,13 @@ for i = 1:p
|
|||
end
|
||||
set(gca,'YTickLabel',[],'YTick',[]);
|
||||
else
|
||||
if j>i
|
||||
plot(X(:,i),X(:,j),[plotsymbol,'b'])
|
||||
else
|
||||
plot(X(:,i),X(:,j),[plotsymbol,'b'])
|
||||
end
|
||||
plot(X(:,i),X(:,j),[plotsymbol,'b'])
|
||||
set(h,'Tag','scatter')
|
||||
|
||||
%%
|
||||
if ~isoctave
|
||||
% Define a context menu; it is not attached to anything
|
||||
hcmenu = uicontextmenu('Callback','pick','Tag','Run viewer');
|
||||
% Define callbacks for context menu
|
||||
% items that change linestyle
|
||||
hcb1 = 'scatter_callback';
|
||||
% hcb2 = ['set(gco,''LineStyle'','':'')'];
|
||||
% hcb3 = ['set(gco,''LineStyle'',''-'')'];
|
||||
% % Define the context menu items and install their callbacks
|
||||
item1 = uimenu(hcmenu,'Label','save','Callback',hcb1,'Tag','save params');
|
||||
item2 = uimenu(hcmenu,'Label','eval','Callback',hcb1,'Tag','eval params');
|
||||
% item3 = uimenu(hcmenu,'Label','solid','Callback',hcb3);
|
||||
% Locate line objects
|
||||
hlines = findall(h,'Type','line');
|
||||
% Attach the context menu to each line
|
||||
for line = 1:length(hlines)
|
||||
set(hlines(line),'uicontextmenu',hcmenu)
|
||||
end
|
||||
end
|
||||
%%
|
||||
if ~isempty(xparam1)
|
||||
hold on, plot(xparam1(i),xparam1(j),'s','MarkerFaceColor',[0 0.75 0],'MarkerEdgeColor',[0 0.75 0])
|
||||
end
|
||||
hold off;
|
||||
% axis([-0.1 1.1 -0.1 1.1])
|
||||
if i<p
|
||||
set(gca,'YTickLabel',[],'YTick',[]);
|
||||
else
|
||||
|
@ -149,16 +120,26 @@ for i = 1:p
|
|||
end
|
||||
if i==1
|
||||
if nflag == 1
|
||||
ylabel(vnames(j,:),'Rotation',45,'interpreter','none', ...
|
||||
'HorizontalAlignment','right','VerticalAlignment','middle');
|
||||
if options_.TeX
|
||||
ylabel(vnames(j,:),'Rotation',45,'interpreter','latex', ...
|
||||
'HorizontalAlignment','right','VerticalAlignment','middle');
|
||||
else
|
||||
ylabel(vnames(j,:),'Rotation',45,'interpreter','none', ...
|
||||
'HorizontalAlignment','right','VerticalAlignment','middle');
|
||||
end
|
||||
else
|
||||
ylabel([num2str(j),' '],'Rotation',90)
|
||||
end
|
||||
end
|
||||
if j==1
|
||||
if nflag == 1
|
||||
title(vnames(i,:),'interpreter','none','Rotation',45, ...
|
||||
'HorizontalAlignment','left','VerticalAlignment','bottom')
|
||||
if options_.TeX
|
||||
title(vnames(i,:),'interpreter','latex','Rotation',45, ...
|
||||
'HorizontalAlignment','left','VerticalAlignment','bottom')
|
||||
else
|
||||
title(vnames(i,:),'interpreter','none','Rotation',45, ...
|
||||
'HorizontalAlignment','left','VerticalAlignment','bottom')
|
||||
end
|
||||
else
|
||||
title(num2str(i))
|
||||
end
|
||||
|
@ -166,10 +147,6 @@ for i = 1:p
|
|||
drawnow
|
||||
end
|
||||
end
|
||||
% if ~isoctave
|
||||
% annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center','interpreter','none');
|
||||
% annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center','interpreter','none');
|
||||
% end
|
||||
|
||||
if ~nograph
|
||||
dyn_saveas(hh_fig,[dirname,filesep,fig_nam_],options_.nodisplay,options_.graph_format);
|
|
@ -1,8 +1,16 @@
|
|||
function set_shocks_param(xparam1)
|
||||
% function set_shocks_param(xparam1)
|
||||
function M_=set_shocks_param(M_,estim_params_,xparam1)
|
||||
% function M_=set_shocks_param(M_,estim_params_,xparam1)
|
||||
% Set the structural and measurement error variances and covariances
|
||||
% Inputs
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - xparam1 [double] parameter vector
|
||||
% Outputs:
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
%
|
||||
% Notes: closely follows set_all_parameters.m
|
||||
|
||||
% Copyright © 2012-2017 Dynare Team
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -19,8 +27,6 @@ function set_shocks_param(xparam1)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global estim_params_ M_
|
||||
|
||||
nvx = estim_params_.nvx;
|
||||
ncx = estim_params_.ncx;
|
||||
nvn = estim_params_.nvn;
|
|
@ -1,11 +1,17 @@
|
|||
function s=gsa_skewness(y)
|
||||
function s=skewness(y)
|
||||
% s=skewness(y)
|
||||
% Compute normalized skewness of y
|
||||
% Inputs:
|
||||
% - y [double] input vector
|
||||
% Outputs:
|
||||
% - s [double] standardized skewness
|
||||
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
% marco.ratto@ec.europa.eu
|
||||
|
||||
% Copyright © 2012 European Commission
|
||||
% Copyright © 2012-2017 Dynare Team
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -22,8 +28,6 @@ function s=gsa_skewness(y)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
% y=stand_(y);
|
||||
% s=mean(y.^3);
|
||||
m2=mean((y-mean(y)).^2);
|
||||
m3=mean((y-mean(y)).^3);
|
||||
s=m3/m2^1.5;
|
|
@ -1,7 +1,7 @@
|
|||
function [H,prob,d] = smirnov(x1 , x2 , alpha, iflag )
|
||||
function [H,prob,d] = smirnov_test(x1 , x2 , alpha, iflag )
|
||||
% [H,prob,d] = smirnov_test(x1 , x2 , alpha, iflag )
|
||||
% Smirnov test for 2 distributions
|
||||
% [H,prob,d] = smirnov(x1 , x2 , alpha, iflag )
|
||||
%
|
||||
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
% marco.ratto@ec.europa.eu
|
||||
|
@ -34,11 +34,16 @@ end
|
|||
% empirical cdfs.
|
||||
xmix= [x1;x2];
|
||||
bin = [-inf ; sort(xmix) ; inf];
|
||||
|
||||
ncount1 = histc (x1 , bin);
|
||||
ncount1 = ncount1(:);
|
||||
ncount2 = histc (x2 , bin);
|
||||
ncount2 = ncount2(:);
|
||||
if isoctave
|
||||
ncount1 = histc(x1 , bin);
|
||||
else
|
||||
ncount1 = histcounts(x1 , bin);
|
||||
end
|
||||
if isoctave
|
||||
ncount2 = histc(x2 , bin);
|
||||
else
|
||||
ncount2 = histcounts(x2 , bin);
|
||||
end
|
||||
|
||||
cum1 = cumsum(ncount1)./sum(ncount1);
|
||||
cum1 = cum1(1:end-1);
|
|
@ -1,9 +1,22 @@
|
|||
function x0 = stab_map_(OutputDirectoryName,opt_gsa)
|
||||
% x0 = stab_map_(OutputDirectoryName,opt_gsa)
|
||||
function x0 = stability_mapping(OutputDirectoryName,opt_gsa,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
% x0 = stability_mapping(OutputDirectoryName,opt_gsa,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
% Mapping of stability regions in the prior ranges applying
|
||||
% Monte Carlo filtering techniques.
|
||||
%
|
||||
% INPUTS (from opt_gsa structure)
|
||||
% Inputs
|
||||
% - OutputDirectoryName [string] name of the output directory
|
||||
% - opt_gsa [structure] GSA options structure
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
% - oo_ [structure] Matlab's structure describing the results
|
||||
% - options_ [structure] Matlab's structure describing the current options
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
%
|
||||
% Outputs:
|
||||
% - x0 one parameter vector for which the model is stable.
|
||||
%
|
||||
%
|
||||
% Inputs from opt_gsa structure
|
||||
% Nsam = MC sample size
|
||||
% fload = 0 to run new MC; 1 to load prevoiusly generated analysis
|
||||
% alpha2 = significance level for bivariate sensitivity analysis
|
||||
|
@ -14,8 +27,6 @@ function x0 = stab_map_(OutputDirectoryName,opt_gsa)
|
|||
% _prior.mat file
|
||||
% = 0: sample from posterior ranges: sample saved in
|
||||
% _mc.mat file
|
||||
% OUTPUT:
|
||||
% x0: one parameter vector for which the model is stable.
|
||||
%
|
||||
% GRAPHS
|
||||
% 1) Pdf's of marginal distributions under the stability (dotted
|
||||
|
@ -26,7 +37,7 @@ function x0 = stab_map_(OutputDirectoryName,opt_gsa)
|
|||
% 3) Bivariate plots of significant correlation patterns
|
||||
% ( abs(corrcoef) > alpha2) under the stable and unacceptable subsets
|
||||
%
|
||||
% USES qmc_sequence, stab_map_1, stab_map_2
|
||||
% USES qmc_sequence, gsa.stability_mapping_univariate, gsa.stability_mapping_bivariate
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -50,11 +61,6 @@ function x0 = stab_map_(OutputDirectoryName,opt_gsa)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
%global bayestopt_ estim_params_ dr_ options_ ys_ fname_
|
||||
global bayestopt_ estim_params_ options_ oo_ M_
|
||||
|
||||
% opt_gsa=options_.opt_gsa;
|
||||
|
||||
Nsam = opt_gsa.Nsam;
|
||||
fload = opt_gsa.load_stab;
|
||||
alpha2 = opt_gsa.alpha2_stab;
|
||||
|
@ -82,7 +88,8 @@ nshock = nshock + estim_params_.ncn;
|
|||
lpmat0=zeros(Nsam,0);
|
||||
xparam1=[];
|
||||
|
||||
[~,~,~,lb,ub,~] = set_prior(estim_params_,M_,options_); %Prepare bounds
|
||||
%% prepare prior bounds
|
||||
[~,~,~,lb,ub] = set_prior(estim_params_,M_,options_); %Prepare bounds
|
||||
if ~isempty(bayestopt_) && any(bayestopt_.pshape > 0)
|
||||
% Set prior bounds
|
||||
bounds = prior_bounds(bayestopt_, options_.prior_trunc);
|
||||
|
@ -107,15 +114,16 @@ options_mcf.pvalue_ks = pvalue_ks;
|
|||
options_mcf.pvalue_corr = pvalue_corr;
|
||||
options_mcf.alpha2 = alpha2;
|
||||
|
||||
%% get LaTeX names
|
||||
name=cell(np,1);
|
||||
name_tex=cell(np,1);
|
||||
for jj=1:np
|
||||
if options_.TeX
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(nshock+jj,options_.TeX,M_,estim_params_,options_);
|
||||
name_tex{jj,1} = strrep(param_name_tex_temp,'$','');
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(nshock+jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
name_tex{jj,1} = param_name_tex_temp;
|
||||
name{jj,1} = param_name_temp;
|
||||
else
|
||||
param_name_temp = get_the_name(nshock+jj,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_temp = get_the_name(nshock+jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
name{jj,1} = param_name_temp;
|
||||
end
|
||||
end
|
||||
|
@ -128,19 +136,18 @@ options_mcf.fname_ = fname_;
|
|||
options_mcf.OutputDirectoryName = OutputDirectoryName;
|
||||
options_mcf.xparam1 = [];
|
||||
|
||||
opt=options_;
|
||||
options_.periods=0;
|
||||
options_.nomoments=1;
|
||||
options_.irf=0;
|
||||
options_.noprint=1;
|
||||
if fload==0
|
||||
if fload==0 %run new MC
|
||||
if isfield(dr_,'ghx')
|
||||
egg=zeros(length(dr_.eigval),Nsam);
|
||||
end
|
||||
yys=zeros(length(dr_.ys),Nsam);
|
||||
|
||||
if opt_gsa.morris == 1
|
||||
[lpmat, OutFact] = Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []);
|
||||
[lpmat] = gsa.Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []);
|
||||
lpmat = lpmat.*(nliv-1)/nliv+1/nliv/2;
|
||||
Nsam=size(lpmat,1);
|
||||
lpmat0 = lpmat(:,1:nshock);
|
||||
|
@ -158,10 +165,9 @@ if fload==0
|
|||
for j=1:np
|
||||
lpmat(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
dummy=prior_draw_gsa(1);
|
||||
gsa.prior_draw(M_,bayestopt_,options_,estim_params_,1); %initialize
|
||||
if pprior
|
||||
for j=1:nshock
|
||||
if opt_gsa.morris~=1
|
||||
|
@ -178,16 +184,16 @@ if fload==0
|
|||
lpmat(:,j)=lpmat(:,j).*(upper_bound-lower_bound)+lower_bound;
|
||||
end
|
||||
else
|
||||
xx=prior_draw_gsa(0,[lpmat0 lpmat]);
|
||||
xx=gsa.prior_draw(M_,bayestopt_,options_,estim_params_,0,[lpmat0 lpmat]);
|
||||
lpmat0=xx(:,1:nshock);
|
||||
lpmat=xx(:,nshock+1:end);
|
||||
clear xx;
|
||||
end
|
||||
else
|
||||
else %posterior analysis
|
||||
if neighborhood_width>0 && isempty(options_.mode_file)
|
||||
xparam1 = get_all_parameters(estim_params_,M_);
|
||||
else
|
||||
eval(['load ' options_.mode_file '.mat;']);
|
||||
load([options_.mode_file '.mat'],'hh','xparam1');
|
||||
end
|
||||
if neighborhood_width>0
|
||||
for j=1:nshock
|
||||
|
@ -216,8 +222,8 @@ if fload==0
|
|||
for j=1:Nsam*2
|
||||
lnprior(j) = any(lp(j,:)'<=bounds.lb | lp(j,:)'>=bounds.ub);
|
||||
end
|
||||
ireal=[1:2*Nsam];
|
||||
ireal=ireal(find(lnprior==0));
|
||||
ireal=1:2*Nsam;
|
||||
ireal=ireal(lnprior==0);
|
||||
lp=lp(ireal,:);
|
||||
Nsam=min(Nsam, length(ireal));
|
||||
lpmat0=lp(1:Nsam,1:nshock);
|
||||
|
@ -227,9 +233,9 @@ if fload==0
|
|||
end
|
||||
%
|
||||
h = dyn_waitbar(0,'Please wait...');
|
||||
istable=[1:Nsam];
|
||||
istable=1:Nsam;
|
||||
jstab=0;
|
||||
iunstable=[1:Nsam];
|
||||
iunstable=1:Nsam;
|
||||
iindeterm=zeros(1,Nsam);
|
||||
iwrong=zeros(1,Nsam);
|
||||
inorestriction=zeros(1,Nsam);
|
||||
|
@ -237,12 +243,11 @@ if fload==0
|
|||
infox=zeros(Nsam,1);
|
||||
for j=1:Nsam
|
||||
M_ = set_all_parameters([lpmat0(j,:) lpmat(j,:)]',estim_params_,M_);
|
||||
%try stoch_simul([]);
|
||||
try
|
||||
if ~ isempty(options_.endogenous_prior_restrictions.moment)
|
||||
[Tt,Rr,SteadyState,info,oo_.dr,M_.params] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
if ~isempty(options_.endogenous_prior_restrictions.moment)
|
||||
[Tt,Rr,~,info,oo_.dr,M_.params] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
else
|
||||
[Tt,Rr,SteadyState,info,oo_.dr,M_.params] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,'restrict');
|
||||
[Tt,Rr,~,info,oo_.dr,M_.params] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,'restrict');
|
||||
end
|
||||
infox(j,1)=info(1);
|
||||
if infox(j,1)==0 && ~exist('T','var')
|
||||
|
@ -250,8 +255,7 @@ if fload==0
|
|||
if prepSA
|
||||
try
|
||||
T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam);
|
||||
catch
|
||||
ME = lasterror();
|
||||
catch ME
|
||||
if strcmp('MATLAB:nomem',ME.identifier)
|
||||
prepSA=0;
|
||||
disp('The model is too large for storing state space matrices ...')
|
||||
|
@ -324,8 +328,9 @@ if fload==0
|
|||
end
|
||||
ys_=real(dr_.ys);
|
||||
yys(:,j) = ys_;
|
||||
ys_=yys(:,1);
|
||||
dyn_waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)])
|
||||
if mod(j,3)
|
||||
dyn_waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)])
|
||||
end
|
||||
end
|
||||
dyn_waitbar_close(h);
|
||||
if prepSA && jstab
|
||||
|
@ -333,13 +338,13 @@ if fload==0
|
|||
else
|
||||
T=[];
|
||||
end
|
||||
istable=istable(find(istable)); % stable params ignoring restrictions
|
||||
irestriction=irestriction(find(irestriction)); % stable params & restrictions OK
|
||||
inorestriction=inorestriction(find(inorestriction)); % stable params violating restrictions
|
||||
iunstable=iunstable(find(iunstable)); % violation of BK & restrictions & solution could not be found (whatever goes wrong)
|
||||
iindeterm=iindeterm(find(iindeterm)); % indeterminacy
|
||||
iwrong=iwrong(find(iwrong)); % dynare could not find solution
|
||||
ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong,inorestriction]))); % explosive roots
|
||||
istable=istable(istable~=0); % stable params ignoring restrictions
|
||||
irestriction=irestriction(irestriction~=0); % stable params & restrictions OK
|
||||
inorestriction=inorestriction(inorestriction~=0); % stable params violating restrictions
|
||||
iunstable=iunstable(iunstable~=0); % violation of BK & restrictions & solution could not be found (whatever goes wrong)
|
||||
iindeterm=iindeterm(iindeterm~=0); % indeterminacy
|
||||
iwrong=iwrong(iwrong~=0); % dynare could not find solution
|
||||
ixun=iunstable(~ismember(iunstable,[iindeterm,iwrong,inorestriction])); % explosive roots
|
||||
|
||||
bkpprior.pshape=bayestopt_.pshape;
|
||||
bkpprior.p1=bayestopt_.p1;
|
||||
|
@ -356,8 +361,7 @@ if fload==0
|
|||
'bkpprior','lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ...
|
||||
'egg','yys','T','nspred','nboth','nfwrd','infox')
|
||||
end
|
||||
|
||||
else
|
||||
else %~pprior
|
||||
if ~prepSA
|
||||
save([OutputDirectoryName filesep fname_ '_mc.mat'], ...
|
||||
'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ...
|
||||
|
@ -368,19 +372,18 @@ if fload==0
|
|||
'egg','yys','T','nspred','nboth','nfwrd','infox')
|
||||
end
|
||||
end
|
||||
else
|
||||
else %load old run
|
||||
if pprior
|
||||
filetoload=[OutputDirectoryName filesep fname_ '_prior.mat'];
|
||||
else
|
||||
filetoload=[OutputDirectoryName filesep fname_ '_mc.mat'];
|
||||
end
|
||||
load(filetoload,'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun','egg','yys','nspred','nboth','nfwrd','infox')
|
||||
load(filetoload,'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun','infox')
|
||||
Nsam = size(lpmat,1);
|
||||
if pprior==0 && ~isempty(options_.mode_file)
|
||||
eval(['load ' options_.mode_file '.mat;']);
|
||||
load([options_.mode_file '.mat'],'xparam1');
|
||||
end
|
||||
|
||||
|
||||
if prepSA && isempty(strmatch('T',who('-file', filetoload),'exact'))
|
||||
h = dyn_waitbar(0,'Please wait...');
|
||||
options_.periods=0;
|
||||
|
@ -392,30 +395,24 @@ else
|
|||
yys=NaN(length(ys_),ntrans);
|
||||
for j=1:ntrans
|
||||
M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(j),:)';
|
||||
%stoch_simul([]);
|
||||
[Tt,Rr,SteadyState,info,oo_.dr,M_.params] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,'restrict');
|
||||
[~,~,~,~,oo_.dr,M_.params] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,'restrict');
|
||||
if ~exist('T','var')
|
||||
T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),ntrans);
|
||||
end
|
||||
dr_ = oo_.dr;
|
||||
T(:,:,j) = [dr_.ghx dr_.ghu];
|
||||
if ~exist('nspred','var')
|
||||
nspred = dr_.nspred; %size(dr_.ghx,2);
|
||||
nboth = dr_.nboth;
|
||||
nfwrd = dr_.nfwrd;
|
||||
end
|
||||
ys_=real(dr_.ys);
|
||||
yys(:,j) = ys_;
|
||||
ys_=yys(:,1);
|
||||
dyn_waitbar(j/ntrans,h,['MC iteration ',int2str(j),'/',int2str(ntrans)])
|
||||
if mod(j,3)
|
||||
dyn_waitbar(j/ntrans,h,['MC iteration ',int2str(j),'/',int2str(ntrans)])
|
||||
end
|
||||
end
|
||||
dyn_waitbar_close(h);
|
||||
save(filetoload,'T','-append')
|
||||
elseif prepSA
|
||||
load(filetoload,'T')
|
||||
end
|
||||
end
|
||||
|
||||
%% display and save output
|
||||
if pprior
|
||||
aunstname='prior_unstable'; aunsttitle='Prior StabMap: explosiveness of solution';
|
||||
aindname='prior_indeterm'; aindtitle='Prior StabMap: Indeterminacy';
|
||||
|
@ -435,17 +432,18 @@ delete([OutputDirectoryName,filesep,fname_,'_',aindname,'.*']);
|
|||
delete([OutputDirectoryName,filesep,fname_,'_',aunstname,'.*']);
|
||||
delete([OutputDirectoryName,filesep,fname_,'_',awrongname,'.*']);
|
||||
|
||||
if length(iunstable)>0 || length(iwrong)>0
|
||||
fprintf(['%4.1f%% of the prior support gives unique saddle-path solution.\n'],length(istable)/Nsam*100)
|
||||
fprintf(['%4.1f%% of the prior support gives explosive dynamics.\n'],(length(ixun) )/Nsam*100)
|
||||
fprintf('\nSensitivity Analysis: Stability mapping:\n')
|
||||
if ~isempty(iunstable) || ~isempty(iwrong)
|
||||
fprintf('%4.1f%% of the prior support gives unique saddle-path solution.\n',length(istable)/Nsam*100)
|
||||
fprintf('%4.1f%% of the prior support gives explosive dynamics.\n',(length(ixun) )/Nsam*100)
|
||||
if ~isempty(iindeterm)
|
||||
fprintf(['%4.1f%% of the prior support gives indeterminacy.\n'],length(iindeterm)/Nsam*100)
|
||||
fprintf('%4.1f%% of the prior support gives indeterminacy.\n',length(iindeterm)/Nsam*100)
|
||||
end
|
||||
inorestriction = istable(find(~ismember(istable,irestriction))); % violation of prior restrictions
|
||||
inorestriction = istable(~ismember(istable,irestriction)); % violation of prior restrictions
|
||||
if ~isempty(iwrong) || ~isempty(inorestriction)
|
||||
skipline()
|
||||
if any(infox==49)
|
||||
fprintf(['%4.1f%% of the prior support violates prior restrictions.\n'],(length(inorestriction) )/Nsam*100)
|
||||
fprintf('%4.1f%% of the prior support violates prior restrictions.\n',(length(inorestriction) )/Nsam*100)
|
||||
end
|
||||
if ~isempty(iwrong)
|
||||
skipline()
|
||||
|
@ -486,50 +484,66 @@ if length(iunstable)>0 || length(iwrong)>0
|
|||
end
|
||||
skipline()
|
||||
if length(iunstable)<Nsam || length(istable)>1
|
||||
itot = [1:Nsam];
|
||||
isolve = itot(find(~ismember(itot,iwrong))); % dynare could find a solution
|
||||
itot = 1:Nsam;
|
||||
isolve = itot(~ismember(itot,iwrong)); % dynare could find a solution
|
||||
% Blanchard Kahn
|
||||
if neighborhood_width
|
||||
options_mcf.xparam1 = xparam1(nshock+1:end);
|
||||
end
|
||||
itmp = itot(find(~ismember(itot,istable)));
|
||||
itmp = itot(~ismember(itot,istable));
|
||||
options_mcf.amcf_name = asname;
|
||||
options_mcf.amcf_title = atitle;
|
||||
options_mcf.beha_title = 'unique Stable Saddle-Path';
|
||||
options_mcf.nobeha_title = 'NO unique Stable Saddle-Path';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'unique Stable Saddle-Path';
|
||||
options_mcf.nobeha_title_latex = 'NO unique Stable Saddle-Path';
|
||||
end
|
||||
options_mcf.title = 'unique solution';
|
||||
mcf_analysis(lpmat, istable, itmp, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(lpmat, istable, itmp, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
if ~isempty(iindeterm)
|
||||
itmp = isolve(find(~ismember(isolve,iindeterm)));
|
||||
itmp = isolve(~ismember(isolve,iindeterm));
|
||||
options_mcf.amcf_name = aindname;
|
||||
options_mcf.amcf_title = aindtitle;
|
||||
options_mcf.beha_title = 'NO indeterminacy';
|
||||
options_mcf.nobeha_title = 'indeterminacy';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'NO indeterminacy';
|
||||
options_mcf.nobeha_title_latex = 'indeterminacy';
|
||||
end
|
||||
options_mcf.title = 'indeterminacy';
|
||||
mcf_analysis(lpmat, itmp, iindeterm, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(lpmat, itmp, iindeterm, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
|
||||
if ~isempty(ixun)
|
||||
itmp = isolve(find(~ismember(isolve,ixun)));
|
||||
itmp = isolve(~ismember(isolve,ixun));
|
||||
options_mcf.amcf_name = aunstname;
|
||||
options_mcf.amcf_title = aunsttitle;
|
||||
options_mcf.beha_title = 'NO explosive solution';
|
||||
options_mcf.nobeha_title = 'explosive solution';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'NO explosive solution';
|
||||
options_mcf.nobeha_title_latex = 'explosive solution';
|
||||
end
|
||||
options_mcf.title = 'instability';
|
||||
mcf_analysis(lpmat, itmp, ixun, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(lpmat, itmp, ixun, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
|
||||
inorestriction = istable(find(~ismember(istable,irestriction))); % violation of prior restrictions
|
||||
iwrong = iwrong(find(~ismember(iwrong,inorestriction))); % what went wrong beyond prior restrictions
|
||||
inorestriction = istable(~ismember(istable,irestriction)); % violation of prior restrictions
|
||||
iwrong = iwrong(~ismember(iwrong,inorestriction)); % what went wrong beyond prior restrictions
|
||||
if ~isempty(iwrong)
|
||||
itmp = itot(find(~ismember(itot,iwrong)));
|
||||
itmp = itot(~ismember(itot,iwrong));
|
||||
options_mcf.amcf_name = awrongname;
|
||||
options_mcf.amcf_title = awrongtitle;
|
||||
options_mcf.beha_title = 'NO inability to find a solution';
|
||||
options_mcf.nobeha_title = 'inability to find a solution';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'NO inability to find a solution';
|
||||
options_mcf.nobeha_title_latex = 'inability to find a solution';
|
||||
end
|
||||
options_mcf.title = 'inability to find a solution';
|
||||
mcf_analysis(lpmat, itmp, iwrong, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis(lpmat, itmp, iwrong, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
|
||||
if ~isempty(irestriction)
|
||||
|
@ -541,11 +555,11 @@ if length(iunstable)>0 || length(iwrong)>0
|
|||
name_tex=cell(np,1);
|
||||
for jj=1:np
|
||||
if options_.TeX
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(jj,options_.TeX,M_,estim_params_,options_);
|
||||
name_tex{jj,1} = strrep(param_name_tex_temp,'$','');
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
name_tex{jj,1} = param_name_tex_temp;
|
||||
name{jj,1} = param_name_temp;
|
||||
else
|
||||
param_name_temp = get_the_name(jj,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_temp = get_the_name(jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
name{jj,1} = param_name_temp;
|
||||
end
|
||||
end
|
||||
|
@ -557,8 +571,12 @@ if length(iunstable)>0 || length(iwrong)>0
|
|||
options_mcf.amcf_title = acalibtitle;
|
||||
options_mcf.beha_title = 'prior IRF/moment calibration';
|
||||
options_mcf.nobeha_title = 'NO prior IRF/moment calibration';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'prior IRF/moment calibration';
|
||||
options_mcf.nobeha_title_latex = 'NO prior IRF/moment calibration';
|
||||
end
|
||||
options_mcf.title = 'prior restrictions';
|
||||
mcf_analysis([lpmat0 lpmat], irestriction, inorestriction, options_mcf, options_);
|
||||
gsa.monte_carlo_filtering_analysis([lpmat0 lpmat], irestriction, inorestriction, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
iok = irestriction(1);
|
||||
x0 = [lpmat0(iok,:)'; lpmat(iok,:)'];
|
||||
else
|
||||
|
@ -568,7 +586,7 @@ if length(iunstable)>0 || length(iwrong)>0
|
|||
end
|
||||
|
||||
M_ = set_all_parameters(x0,estim_params_,M_);
|
||||
[oo_.dr,info,M_.params] = resol(0,M_,options_,oo_.dr ,oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
[oo_.dr,~,M_.params] = resol(0,M_,options_,oo_.dr ,oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
else
|
||||
disp('All parameter values in the specified ranges are not acceptable!')
|
||||
x0=[];
|
||||
|
@ -578,15 +596,8 @@ else
|
|||
disp('and match prior IRF/moment restriction(s) if any!')
|
||||
x0=0.5.*(bounds.ub(1:nshock)-bounds.lb(1:nshock))+bounds.lb(1:nshock);
|
||||
x0 = [x0; lpmat(istable(1),:)'];
|
||||
|
||||
end
|
||||
skipline(1);
|
||||
|
||||
xparam1=x0;
|
||||
save([OutputDirectoryName filesep 'prior_ok.mat'],'xparam1');
|
||||
|
||||
options_.periods=opt.periods;
|
||||
if isfield(opt,'nomoments')
|
||||
options_.nomoments=opt.nomoments;
|
||||
end
|
||||
options_.irf=opt.irf;
|
||||
options_.noprint=opt.noprint;
|
|
@ -1,6 +1,20 @@
|
|||
function indcorr = stab_map_2(x,alpha2, pvalue_crit, fnam, dirname,xparam1,figtitle)
|
||||
% function stab_map_2(x, alpha2, pvalue, fnam, dirname,xparam1)
|
||||
function indcorr = stability_mapping_bivariate(x,alpha2, pvalue_crit, M_,options_,bayestopt_,estim_params_, case_name_plain, case_name_latex, dirname,xparam1,figtitle,fig_caption_latex)
|
||||
% indcorr = stability_mapping_bivariate(x,alpha2, pvalue_crit, M_,options_,bayestopt_,estim_params_, fnam, fnam_latex, dirname,xparam1,figtitle,fig_caption_latex)
|
||||
% Inputs:
|
||||
% - x
|
||||
% - alpha2
|
||||
% - pvalue_crit
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
% - options_ [structure] Matlab's structure describing the current options
|
||||
% - bayestopt_ [structure] describing the priors
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - fnam [string] file name
|
||||
% - dirnam [string] directory name
|
||||
% - xparam1 [double] parameter vector
|
||||
% - figtitle [string] figure title
|
||||
%
|
||||
% Output:
|
||||
% - indcorr
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
% marco.ratto@ec.europa.eu
|
||||
|
@ -22,29 +36,30 @@ function indcorr = stab_map_2(x,alpha2, pvalue_crit, fnam, dirname,xparam1,figti
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
%global bayestopt_ estim_params_ dr_ options_ ys_ fname_
|
||||
global bayestopt_ estim_params_ options_ oo_ M_
|
||||
|
||||
npar=size(x,2);
|
||||
nsam=size(x,1);
|
||||
ishock= npar>estim_params_.np;
|
||||
nograph = options_.nograph;
|
||||
if nargin<4
|
||||
fnam='';
|
||||
|
||||
if nargin<8
|
||||
case_name_plain='';
|
||||
end
|
||||
if nargin<5
|
||||
if nargin<9
|
||||
case_name_latex=case_name_plain;
|
||||
end
|
||||
if nargin<10
|
||||
dirname='';
|
||||
nograph=1;
|
||||
end
|
||||
if nargin<6
|
||||
if nargin<11
|
||||
xparam1=[];
|
||||
end
|
||||
if nargin<7
|
||||
figtitle=fnam;
|
||||
if nargin<12
|
||||
figtitle=case_name_plain;
|
||||
end
|
||||
if nargin<13
|
||||
fig_caption_latex=case_name_latex;
|
||||
end
|
||||
|
||||
ys_ = oo_.dr.ys;
|
||||
dr_ = oo_.dr;
|
||||
fname_ = M_.fname;
|
||||
nshock = estim_params_.nvx;
|
||||
nshock = nshock + estim_params_.nvn;
|
||||
|
@ -53,9 +68,9 @@ nshock = nshock + estim_params_.ncn;
|
|||
|
||||
[c0, pvalue] = corrcoef(x);
|
||||
c00=tril(c0,-1);
|
||||
fig_nam_=[fname_,'_',fnam,'_corr_'];
|
||||
fig_nam_tex_table=strrep([fnam,'_corr'],' ','_');
|
||||
fig_nam_=strrep(fig_nam_,' ','_');
|
||||
fig_nam_save=[fname_,'_',case_name_plain,'_corr_'];
|
||||
fig_nam_save=strrep(fig_nam_save,' ','_');
|
||||
fig_nam_tex_table_save=strrep([case_name_plain,'_corr'],' ','_');
|
||||
|
||||
ifig=0;
|
||||
j2=0;
|
||||
|
@ -67,47 +82,43 @@ if ishock==0
|
|||
else
|
||||
npar=estim_params_.np+nshock;
|
||||
end
|
||||
title_string=['Correlation analysis for ',fnam];
|
||||
title_string_tex=['Correlation analysis for ',strrep(fnam,'_','\\_')];
|
||||
title_string=['Correlation analysis for ',case_name_plain];
|
||||
title_string_tex=['Correlation analysis for ',case_name_latex];
|
||||
|
||||
indcorr = [];
|
||||
entry_iter=1;
|
||||
for j=1:npar
|
||||
i2=find(abs(c00(:,j))>alpha2);
|
||||
if length(i2)>0
|
||||
if ~isempty(i2)
|
||||
for jx=1:length(i2)
|
||||
if pvalue(j,i2(jx))<pvalue_crit
|
||||
indcorr = [indcorr; [j i2(jx)]];
|
||||
j2=j2+1;
|
||||
if ishock
|
||||
if options_.TeX
|
||||
[param_name_temp1, param_name_tex_temp1]= get_the_name(j,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_tex_temp1 = strrep(param_name_tex_temp1,'$','');
|
||||
[param_name_temp2, param_name_tex_temp2]= get_the_name(i2(jx),options_.TeX,M_,estim_params_,options_);
|
||||
param_name_tex_temp2 = strrep(param_name_tex_temp2,'$','');
|
||||
[param_name_temp1, param_name_tex_temp1]= get_the_name(j,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
[param_name_temp2, param_name_tex_temp2]= get_the_name(i2(jx),options_.TeX,M_,estim_params_,options_.varobs);
|
||||
tmp_name=(['[',param_name_temp1,',',param_name_temp2,']']);
|
||||
tmp_name_tex=(['[',param_name_tex_temp1,',',param_name_tex_temp2,']']);
|
||||
name{entry_iter,1}=tmp_name;
|
||||
name_tex{entry_iter,1}=tmp_name_tex;
|
||||
name_tex{entry_iter,1}=strrep(tmp_name_tex,'$',''); %prevent $ inside of expression for table
|
||||
else
|
||||
[param_name_temp1]= get_the_name(j,options_.TeX,M_,estim_params_,options_);
|
||||
[param_name_temp2]= get_the_name(i2(jx),options_.TeX,M_,estim_params_,options_);
|
||||
[param_name_temp1]= get_the_name(j,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
[param_name_temp2]= get_the_name(i2(jx),options_.TeX,M_,estim_params_,options_.varobs);
|
||||
tmp_name=(['[',param_name_temp1,',',param_name_temp2,']']);
|
||||
name{entry_iter,1}=tmp_name;
|
||||
end
|
||||
else
|
||||
if options_.TeX
|
||||
[param_name_temp1, param_name_tex_temp1]= get_the_name(j+nshock,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_tex_temp1 = strrep(param_name_tex_temp1,'$','');
|
||||
[param_name_temp2, param_name_tex_temp2]= get_the_name(i2(jx)+nshock,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_tex_temp2 = strrep(param_name_tex_temp2,'$','');
|
||||
[param_name_temp1, param_name_tex_temp1]= get_the_name(j+nshock,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
[param_name_temp2, param_name_tex_temp2]= get_the_name(i2(jx)+nshock,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
tmp_name=(['[',param_name_temp1,',',param_name_temp2,']']);
|
||||
tmp_name_tex=(['[',param_name_tex_temp1,',',param_name_tex_temp2,']']);
|
||||
name{entry_iter,1}=tmp_name;
|
||||
name_tex{entry_iter,1}=tmp_name_tex;
|
||||
name_tex{entry_iter,1}=strrep(tmp_name_tex,'$',''); %prevent $ inside of expression for table
|
||||
else
|
||||
[param_name_temp1]= get_the_name(j+nshock,options_.TeX,M_,estim_params_,options_);
|
||||
[param_name_temp2]= get_the_name(i2(jx)+nshock,options_.TeX,M_,estim_params_,options_);
|
||||
[param_name_temp1]= get_the_name(j+nshock,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
[param_name_temp2]= get_the_name(i2(jx)+nshock,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
tmp_name=(['[',param_name_temp1,',',param_name_temp2,']']);
|
||||
name{entry_iter,1}=tmp_name;
|
||||
end
|
||||
|
@ -121,17 +132,10 @@ for j=1:npar
|
|||
hh_fig=dyn_figure(options_.nodisplay,'name',[figtitle,' sample bivariate projection ', num2str(ifig)]);
|
||||
end
|
||||
subplot(3,4,j2-(ifig-1)*12)
|
||||
% bar(c0(i2,j)),
|
||||
% set(gca,'xticklabel',bayestopt_.name(i2)),
|
||||
% set(gca,'xtick',[1:length(i2)])
|
||||
%plot(stock_par(ixx(nfilt+1:end,i),j),stock_par(ixx(nfilt+1:end,i),i2(jx)),'.k')
|
||||
%hold on,
|
||||
plot(x(:,j),x(:,i2(jx)),'.')
|
||||
if ~isempty(xparam1)
|
||||
hold on, plot(xparam1(j),xparam1(i2(jx)),'ro')
|
||||
end
|
||||
% xlabel(deblank(estim_params_.param_names(j,:)),'interpreter','none'),
|
||||
% ylabel(deblank(estim_params_.param_names(i2(jx),:)),'interpreter','none'),
|
||||
if ishock
|
||||
xlabel(bayestopt_.name{j},'interpreter','none'),
|
||||
ylabel(bayestopt_.name{i2(jx)},'interpreter','none'),
|
||||
|
@ -141,16 +145,16 @@ for j=1:npar
|
|||
end
|
||||
title(['cc = ',num2str(c0(i2(jx),j))])
|
||||
if (mod(j2,12)==0) && j2>0
|
||||
dyn_saveas(hh_fig,[dirname,filesep,fig_nam_,int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(hh_fig,[dirname,filesep,fig_nam_save,int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([dirname,filesep,fig_nam_,int2str(ifig),'.tex'],'w');
|
||||
fidTeX = fopen([dirname,filesep,fig_nam_save,int2str(ifig),'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by stab_map_2.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s}\n',strrep([dirname,'/',fig_nam_,int2str(ifig)],'\','/'));
|
||||
fprintf(fidTeX,'\\caption{%s.}',[figtitle,' sample bivariate projection ', num2str(ifig)]);
|
||||
fprintf(fidTeX,'\\label{Fig:%s:%u}\n',fig_nam_,ifig);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s}\n',strrep([dirname,'/',fig_nam_save,int2str(ifig)],'\','/'));
|
||||
fprintf(fidTeX,'\\caption{%s.}',[fig_caption_latex,' sample bivariate projection ', num2str(ifig)]);
|
||||
fprintf(fidTeX,'\\label{Fig:%s:%u}\n',fig_nam_save,ifig);
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
fprintf(fidTeX,'%% End Of TeX file. \n');
|
||||
fclose(fidTeX);
|
||||
|
@ -162,16 +166,16 @@ for j=1:npar
|
|||
end
|
||||
end
|
||||
if ~nograph && (j==(npar)) && j2>0 && (mod(j2,12)~=0)
|
||||
dyn_saveas(hh_fig,[dirname,filesep,fig_nam_,int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(hh_fig,[dirname,filesep,fig_nam_save,int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([dirname,filesep,fig_nam_,int2str(ifig),'.tex'],'w');
|
||||
fidTeX = fopen([dirname,filesep,fig_nam_save,int2str(ifig),'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by stab_map_2.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s}\n',options_.figures.textwidth*min((j2-(ifig-1)*12)/3,1),strrep([dirname,'/',fig_nam_,int2str(ifig)],'\','/'));
|
||||
fprintf(fidTeX,'\\caption{%s.}',[figtitle,' sample bivariate projection ', num2str(ifig)]);
|
||||
fprintf(fidTeX,'\\label{Fig:%s:%u}\n',fig_nam_,ifig);
|
||||
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s}\n',options_.figures.textwidth*min((j2-(ifig-1)*12)/3,1),strrep([dirname,'/',fig_nam_save,int2str(ifig)],'\','/'));
|
||||
fprintf(fidTeX,'\\caption{%s.}',[fig_caption_latex,' sample bivariate projection ', num2str(ifig)]);
|
||||
fprintf(fidTeX,'\\label{Fig:%s:%u}\n',fig_nam_save,ifig);
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
fprintf(fidTeX,'%% End Of TeX file. \n');
|
||||
fclose(fidTeX);
|
||||
|
@ -181,7 +185,7 @@ end
|
|||
|
||||
if j2==0
|
||||
skipline();
|
||||
disp(['No correlation term with pvalue <', num2str(pvalue_crit),' and |corr. coef.| >',num2str(alpha2),' found for ',fnam])
|
||||
disp(['No correlation term with pvalue <', num2str(pvalue_crit),' and |corr. coef.| >',num2str(alpha2),' found for ',case_name_plain])
|
||||
else
|
||||
headers={'Parameters'; 'corrcoef'};
|
||||
if ~options_.noprint
|
||||
|
@ -189,7 +193,6 @@ else
|
|||
end
|
||||
dyntable(options_,title_string,headers, name, data_mat, 0, 7, 3);
|
||||
if options_.TeX
|
||||
dyn_latex_table(M_, options_, title_string_tex, fig_nam_tex_table, headers, name_tex, data_mat, 0, 7, 3);
|
||||
dyn_latex_table(M_, options_, title_string_tex, fig_nam_tex_table_save, headers, name_tex, data_mat, 0, 7, 3);
|
||||
end
|
||||
end
|
||||
%close all
|
||||
end
|
|
@ -1,20 +1,24 @@
|
|||
function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname, pcrit, atitle)
|
||||
%function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname, pcrit)
|
||||
%
|
||||
% lpmat = Monte Carlo matrix
|
||||
% ibehaviour = index of behavioural runs
|
||||
% inonbehaviour = index of non-behavioural runs
|
||||
% aname = label of the analysis
|
||||
% iplot = 1 plot cumulative distributions (default)
|
||||
% iplot = 0 no plots
|
||||
% ipar = index array of parameters to plot
|
||||
% dirname = (OPTIONAL) path of the directory where to save
|
||||
% (default: current directory)
|
||||
% pcrit = (OPTIONAL) critical value of the pvalue below which show the plots
|
||||
function [proba, dproba] = stability_mapping_univariate(lpmat, ibehaviour, inonbehaviour, aname, fname_, options_, parnames, estim_params_, iplot, ipar, dirname, pcrit, atitle)
|
||||
% [proba, dproba] = stability_mapping_univariate(lpmat, ibehaviour, inonbehaviour, aname, fname_, options_, parnames, estim_params_, iplot, ipar, dirname, pcrit, atitle)
|
||||
% Inputs:
|
||||
% - lpmat [double] Monte Carlo matrix
|
||||
% - ibehaviour [integer] index of behavioural runs
|
||||
% - inonbehaviour [integer] index of non-behavioural runs
|
||||
% - aname [string] label of the analysis
|
||||
% - fname_ [string] file name
|
||||
% - options_ [structure] options structure
|
||||
% - parnames [char] parameter name vector
|
||||
% - estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - iplot [boolean] 1 plot cumulative distributions (default)
|
||||
% 0 no plots
|
||||
% - ipar [integer] index array of parameters to plot
|
||||
% - dirname [string] (OPTIONAL) path of the directory where to save
|
||||
% (default: current directory)
|
||||
% - pcrit [double] (OPTIONAL) critical value of the pvalue below which show the plots
|
||||
%
|
||||
% Plots: dotted lines for BEHAVIOURAL
|
||||
% solid lines for NON BEHAVIOURAL
|
||||
% USES smirnov
|
||||
% USES gsa.smirnov_test.m
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -38,16 +42,13 @@ function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, i
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global estim_params_ bayestopt_ M_ options_
|
||||
|
||||
if nargin<5
|
||||
if nargin<9
|
||||
iplot=1;
|
||||
end
|
||||
fname_ = M_.fname;
|
||||
if nargin<7
|
||||
if nargin<11
|
||||
dirname='';
|
||||
end
|
||||
if nargin<9,
|
||||
if nargin<13
|
||||
atitle=aname;
|
||||
end
|
||||
|
||||
|
@ -59,49 +60,49 @@ nshock = nshock + estim_params_.ncn;
|
|||
npar=size(lpmat,2);
|
||||
ishock= npar>estim_params_.np;
|
||||
|
||||
if nargin<6
|
||||
if nargin<10
|
||||
ipar=[];
|
||||
end
|
||||
if nargin<8 || isempty(pcrit)
|
||||
if nargin<12 || isempty(pcrit)
|
||||
pcrit=1;
|
||||
end
|
||||
|
||||
% Smirnov test for Blanchard;
|
||||
% Smirnov test for Blanchard
|
||||
proba=NaN(npar,1);
|
||||
dproba=NaN(npar,1);
|
||||
for j=1:npar
|
||||
[H,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j));
|
||||
[~,P,KSSTAT] = gsa.smirnov_test(lpmat(ibehaviour,j),lpmat(inonbehaviour,j));
|
||||
proba(j)=P;
|
||||
dproba(j)=KSSTAT;
|
||||
end
|
||||
if isempty(ipar)
|
||||
% ipar=find(dproba>dcrit);
|
||||
ipar=find(proba<pcrit);
|
||||
end
|
||||
nparplot=length(ipar);
|
||||
if iplot && ~options_.nograph
|
||||
lpmat=lpmat(:,ipar);
|
||||
ftit=bayestopt_.name(ipar+nshock*(1-ishock));
|
||||
ftit=parnames(ipar+nshock*(1-ishock));
|
||||
|
||||
for i=1:ceil(nparplot/12)
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name',atitle);
|
||||
for j=1+12*(i-1):min(nparplot,12*i)
|
||||
subplot(3,4,j-12*(i-1))
|
||||
if ~isempty(ibehaviour)
|
||||
h=cumplot(lpmat(ibehaviour,j));
|
||||
h=gsa.cumplot(lpmat(ibehaviour,j));
|
||||
set(h,'color',[0 0 1], 'linestyle',':','LineWidth',1.5)
|
||||
end
|
||||
hold on
|
||||
if ~isempty(inonbehaviour)
|
||||
h=cumplot(lpmat(inonbehaviour,j));
|
||||
h=gsa.cumplot(lpmat(inonbehaviour,j));
|
||||
set(h,'color',[0 0 0],'LineWidth',1.5)
|
||||
end
|
||||
% title([ftit{j},'. D-stat ', num2str(dproba(ipar(j)),2)],'interpreter','none')
|
||||
title([ftit{j},'. p-value ', num2str(proba(ipar(j)),2)],'interpreter','none')
|
||||
end
|
||||
if nparplot>12
|
||||
dyn_saveas(hh_fig,[dirname,filesep,fname_,'_',aname,'_SA_',int2str(i)],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([dirname,filesep,fname_,'_',aname,'_SA_',int2str(i) '.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by stab_map_1.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by gsa.stability_mapping_univariate.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -116,7 +117,7 @@ if iplot && ~options_.nograph
|
|||
dyn_saveas(hh_fig,[dirname,filesep,fname_,'_',aname,'_SA'],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([dirname,filesep,fname_,'_',aname,'_SA.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by stab_map_1.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by gsa.stability_mapping_univariate.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
|
@ -1,20 +1,22 @@
|
|||
function [y, meany, stdy] = stand_(x)
|
||||
% STAND_ Standardise a matrix by columns
|
||||
function [y, meany, stdy] = standardize_columns(x)
|
||||
% [y, meany, stdy] = standardize_columns(x)
|
||||
% Standardise a matrix by columns
|
||||
%
|
||||
% [x,my,sy]=stand(y)
|
||||
%
|
||||
% y: Time series (column matrix)
|
||||
% Inputs:
|
||||
% - x: Time series (column matrix)
|
||||
%
|
||||
% x: standardised equivalent of y
|
||||
% my: Vector of mean values for each column of y
|
||||
% sy: Vector of standard deviations for each column of y
|
||||
% - y: standardised equivalent of x
|
||||
% - meany: Vector of mean values for each column of x
|
||||
% - stdy: Vector of standard deviations for each column of x
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
% marco.ratto@ec.europa.eu
|
||||
|
||||
% Copyright © 2012 European Commission
|
||||
% Copyright © 2012-2017 Dynare Team%
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
|
@ -34,9 +36,11 @@ if nargin==0
|
|||
return
|
||||
end
|
||||
|
||||
meany=NaN(size(x,2),1);
|
||||
stdy=NaN(size(x,2),1);
|
||||
y=NaN(size(x));
|
||||
for j=1:size(x,2)
|
||||
meany(j)=mean(x(find(~isnan(x(:,j))),j));
|
||||
stdy(j)=std(x(find(~isnan(x(:,j))),j));
|
||||
meany(j)=mean(x(~isnan(x(:,j)),j));
|
||||
stdy(j)=std(x(~isnan(x(:,j)),j));
|
||||
y(:,j)=(x(:,j)-meany(j))./stdy(j);
|
||||
end
|
||||
% end of m-file
|
||||
end
|
|
@ -150,4 +150,4 @@ if n<=100
|
|||
t_crit=t_crit(n,ncol);
|
||||
else
|
||||
t_crit=t_crit(end,ncol);
|
||||
end
|
||||
end
|
|
@ -37,15 +37,12 @@ if ndim==3
|
|||
[ir, ic]=(find( (tmax-tmin)>1.e-8));
|
||||
j0 = length(ir);
|
||||
yt=zeros(Nsam, j0);
|
||||
|
||||
for j=1:j0
|
||||
y0=squeeze(T(ir(j),ic(j),:));
|
||||
%y1=ones(size(lpmat,1),1)*NaN;
|
||||
y1=ones(Nsam,1)*NaN;
|
||||
y1(istable,1)=y0;
|
||||
yt(:,j)=y1;
|
||||
end
|
||||
|
||||
else
|
||||
tmax=max(T,[],2);
|
||||
tmin=min(T,[],2);
|
||||
|
@ -53,7 +50,4 @@ else
|
|||
j0 = length(ir);
|
||||
yt=NaN(Nsam, j0);
|
||||
yt(istable,:)=T(ir,:)';
|
||||
|
||||
|
||||
end
|
||||
%clear y0 y1;
|
|
@ -1,7 +1,22 @@
|
|||
function [vdec, corr, autocorr, z, zz] = th_moments(dr,var_list)
|
||||
% [vdec, corr, autocorr, z, zz] = th_moments(dr,var_list)
|
||||
function [vdec, corr, autocorr, z, zz] = th_moments(dr,options_,M_)
|
||||
% [vdec, corr, autocorr, z, zz] = th_moments(dr,options_,M_)
|
||||
% Computes theoretical moments for GSA
|
||||
%
|
||||
% INPUTS
|
||||
% - dr [structure] model information structure
|
||||
% - options_ [structure] Matlab's structure describing the current options
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
%
|
||||
% OUTPUTS
|
||||
% - vdec [double] variance decomposition matrix
|
||||
% - corr [double] correlation matrix
|
||||
% - autocorr [cell] contains autocorrelation or
|
||||
% auto- and cross-covariance matrices
|
||||
% - z [double] matrix containing mean, standard
|
||||
% deviation, and variance vector
|
||||
% - zz [double] autocorrelation matrix
|
||||
|
||||
% Copyright © 2012-2018 Dynare Team
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -18,18 +33,16 @@ function [vdec, corr, autocorr, z, zz] = th_moments(dr,var_list)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global M_ oo_ options_
|
||||
|
||||
nvar = length(var_list);
|
||||
nvar = length(options_.varobs);
|
||||
if nvar == 0
|
||||
nvar = length(dr.order_var);
|
||||
ivar = [1:nvar]';
|
||||
else
|
||||
ivar=zeros(nvar,1);
|
||||
for i=1:nvar
|
||||
i_tmp = strmatch(var_list{i}, M_.endo_names, 'exact');
|
||||
i_tmp = strmatch(options_.varobs{i}, M_.endo_names, 'exact');
|
||||
if isempty(i_tmp)
|
||||
error(['One of the variables specified does not exist']) ;
|
||||
error('th_moments: One of the variables specified does not exist');
|
||||
else
|
||||
ivar(i) = i_tmp;
|
||||
end
|
||||
|
@ -39,21 +52,11 @@ end
|
|||
[gamma_y,stationary_vars] = th_autocovariances(dr,ivar,M_, options_);
|
||||
m = dr.ys(ivar(stationary_vars));
|
||||
|
||||
|
||||
% i1 = find(abs(diag(gamma_y{1})) > 1e-12);
|
||||
i1 = [1:length(ivar)];
|
||||
i1 = 1:length(ivar);
|
||||
s2 = diag(gamma_y{1});
|
||||
sd = sqrt(s2);
|
||||
|
||||
|
||||
z = [ m sd s2 ];
|
||||
mean = m;
|
||||
var = gamma_y{1};
|
||||
|
||||
|
||||
%'THEORETICAL MOMENTS';
|
||||
%'MEAN','STD. DEV.','VARIANCE');
|
||||
z;
|
||||
|
||||
%'VARIANCE DECOMPOSITION (in percent)';
|
||||
if M_.exo_nbr>1
|
||||
|
@ -69,6 +72,7 @@ else
|
|||
corr = gamma_y{1}(i1,i1);
|
||||
end
|
||||
if options_.ar > 0
|
||||
zz=NaN(length(ivar),options_.ar);
|
||||
%'COEFFICIENTS OF AUTOCORRELATION';
|
||||
for i=1:options_.ar
|
||||
if options_.opt_gsa.useautocorr
|
|
@ -142,11 +142,11 @@ mapkeys = unique(cell2mat([keys(unanticipated_p_shocks) keys(unanticipated_t_sho
|
|||
|
||||
%% Simulation
|
||||
options_.periods = jm.periods;
|
||||
perfect_foresight_setup;
|
||||
oo_=perfect_foresight_setup(M_, options_, oo_);
|
||||
|
||||
% no surprise shocks present
|
||||
if isempty(mapkeys)
|
||||
perfect_foresight_solver;
|
||||
oo_=perfect_foresight_solver(M_, options_, oo_);
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -161,7 +161,7 @@ end
|
|||
if mapkeys(1) ~= 1
|
||||
% if first unanticipated shock is not in period 1
|
||||
% simulate until first unanticipated shock and save
|
||||
perfect_foresight_solver;
|
||||
oo_=perfect_foresight_solver(M_, options_, oo_);
|
||||
yy = [yy oo_.endo_simul(:, 2:mapkeys(1)+1)];
|
||||
end
|
||||
|
||||
|
@ -203,7 +203,7 @@ for i = 1:length(mapkeys)
|
|||
last_period = this_period;
|
||||
assert(rows(oo_.exo_simul) == oo_exo_simul_rows, 'error encountered setting oo_.exo_simul');
|
||||
oo_.endo_simul(:, 1) = yy(:, end);
|
||||
perfect_foresight_solver;
|
||||
oo_=perfect_foresight_solver(M_, options_, oo_);
|
||||
if next_period > 0
|
||||
yy = [yy oo_.endo_simul(:, 2:next_period-this_period+1)];
|
||||
else
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = identification_analysis(params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
|
||||
% [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = identification_analysis(params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
|
||||
function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
|
||||
% [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function wraps all identification analysis, i.e. it
|
||||
% (1) wraps functions for the theoretical identification analysis based on moments (Iskrev, 2010),
|
||||
|
@ -12,6 +12,11 @@ function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide
|
|||
% moments, spectrum, reduced-form solution and dynamic model derivatives
|
||||
% =========================================================================
|
||||
% INPUTS
|
||||
% * M_ [structure] describing the model
|
||||
% * options_ [structure] describing the options
|
||||
% * oo_ [structure] storing the results
|
||||
% * bayestopt_ [structure] describing the priors
|
||||
% * estim_params_ [structure] characterizing parameters to be estimated
|
||||
% * params [mc_sample_nbr by totparam_nbr]
|
||||
% parameter values for identification checks
|
||||
% * indpmodel [modparam_nbr by 1]
|
||||
|
@ -53,18 +58,18 @@ function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide
|
|||
% indicator on problems
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * dynare_identification.m
|
||||
% * identification.run
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * [M_.fname,'.dynamic']
|
||||
% * dseries
|
||||
% * dsge_likelihood.m
|
||||
% * dyn_vech
|
||||
% * ident_bruteforce
|
||||
% * identification_checks
|
||||
% * identification_checks_via_subsets
|
||||
% * identification.bruteforce
|
||||
% * identification.checks
|
||||
% * identification.checks_via_subsets
|
||||
% * isoctave
|
||||
% * get_identification_jacobians (previously getJJ)
|
||||
% * identification.get_jacobians (previously getJJ)
|
||||
% * matlab_ver_less_than
|
||||
% * prior_bounds
|
||||
% * resol
|
||||
|
@ -91,7 +96,6 @@ function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide
|
|||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
|
||||
global oo_ M_ options_ bayestopt_ estim_params_
|
||||
persistent ind_dMOMENTS ind_dREDUCEDFORM ind_dDYNAMIC
|
||||
% persistent indices are necessary, because in a MC loop the numerical threshold
|
||||
% used may provide vectors of different length, leading to crashes in MC loops
|
||||
|
@ -116,7 +120,7 @@ if ~isempty(estim_params_)
|
|||
M_ = set_all_parameters(params,estim_params_,M_);
|
||||
end
|
||||
|
||||
%get options (see dynare_identification.m for description of options)
|
||||
%get options (see identification.run.m for description of options)
|
||||
nlags = options_ident.ar;
|
||||
advanced = options_ident.advanced;
|
||||
replic = options_ident.replic;
|
||||
|
@ -138,7 +142,7 @@ error_indicator.identification_spectrum=0;
|
|||
|
||||
if info(1) == 0 %no errors in solution
|
||||
% Compute parameter Jacobians for identification analysis
|
||||
[MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_identification_jacobians(estim_params_, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
[~, ~, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = identification.get_jacobians(estim_params_, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
if isempty(dMINIMAL)
|
||||
% Komunjer and Ng is not computed if (1) minimality conditions are not fullfilled or (2) there are more shocks and measurement errors than observables, so we need to reset options
|
||||
error_indicator.identification_minimal = 1;
|
||||
|
@ -202,7 +206,7 @@ if info(1) == 0 %no errors in solution
|
|||
options_ident_local.no_identification_spectrum = 1; %do not recompute dSPECTRUM
|
||||
options_ident_local.ar = nlags; %store new lag number
|
||||
options_.ar = nlags; %store new lag number
|
||||
[~, ~, ~, ~, ~, ~, MOMENTS, dMOMENTS, ~, ~, ~, ~] = get_identification_jacobians(estim_params_, M_, options_, options_ident_local, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
[~, ~, ~, ~, ~, ~, MOMENTS, dMOMENTS] = identification.get_jacobians(estim_params_, M_, options_, options_ident_local, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
|
||||
ind_dMOMENTS = (find(max(abs(dMOMENTS'),[],1) > tol_deriv)); %new index with non-zero rows
|
||||
end
|
||||
|
@ -296,12 +300,12 @@ if info(1) == 0 %no errors in solution
|
|||
derivatives_info.no_DLIK = 1;
|
||||
bounds = prior_bounds(bayestopt_, options_.prior_trunc); %reset bounds as lb and ub must only be operational during mode-finding
|
||||
%note that for order>1 we do not provide any information on DT,DYss,DOM in derivatives_info, such that dsge_likelihood creates an error. Therefore the computation will be based on simulated_moment_uncertainty for order>1.
|
||||
[fval, info, cost_flag, DLIK, AHess, ys, trend_coeff, M_, options_, bayestopt_, oo_.dr] = dsge_likelihood(params', dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, bounds, oo_.dr, oo_.steady_state,oo_.exo_steady_state, oo_.exo_det_steady_state. derivatives_info); %non-used output variables need to be set for octave for some reason
|
||||
[~, info, ~, ~, AHess, ~, ~, M_, options_, ~, oo_.dr] = dsge_likelihood(params', dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, bounds, oo_.dr, oo_.steady_state,oo_.exo_steady_state, oo_.exo_det_steady_state. derivatives_info); %non-used output variables need to be set for octave for some reason
|
||||
%note that for the order of parameters in AHess we have: stderr parameters come first, corr parameters second, model parameters third. the order within these blocks corresponds to the order specified in the estimated_params block
|
||||
options_.analytic_derivation = analytic_derivation; %reset option
|
||||
AHess = -AHess; %take negative of hessian
|
||||
if min(eig(AHess))<-tol_rank
|
||||
error('identification_analysis: Analytic Hessian is not positive semi-definite!')
|
||||
error('identification.analysis: Analytic Hessian is not positive semi-definite!')
|
||||
end
|
||||
ide_hess.AHess = AHess; %store asymptotic Hessian
|
||||
%normalize asymptotic hessian
|
||||
|
@ -309,9 +313,9 @@ if info(1) == 0 %no errors in solution
|
|||
iflag = any((deltaM.*deltaM)==0); %check if all second-order derivatives wrt to a single parameter are nonzero
|
||||
tildaM = AHess./((deltaM)*(deltaM')); %this normalization is for numerical purposes
|
||||
if iflag || rank(AHess)>rank(tildaM)
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(AHess, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(AHess, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
else %use normalized version if possible
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
indok = find(max(ide_hess.indno,[],1)==0);
|
||||
ide_uncert_unnormaliz(indok) = sqrt(diag(inv(AHess(indok,indok))))';
|
||||
|
@ -321,7 +325,7 @@ if info(1) == 0 %no errors in solution
|
|||
diag_chh = sum(si_dREDUCEDFORM(:,ind1)'.*temp1)';
|
||||
ind1 = ind1(ind1>stderrparam_nbr+corrparam_nbr);
|
||||
cdynamic = si_dDYNAMIC(:,ind1-stderrparam_nbr-corrparam_nbr)*((AHess(ind1,ind1))\si_dDYNAMIC(:,ind1-stderrparam_nbr-corrparam_nbr)');
|
||||
flag_score = 1; %this is used for the title in plot_identification.m
|
||||
flag_score = 1; %this is used for the title in identification.plot.m
|
||||
catch
|
||||
%Asymptotic Hessian via simulation
|
||||
if options_.order > 1
|
||||
|
@ -332,7 +336,7 @@ if info(1) == 0 %no errors in solution
|
|||
options_.periods = periods+100;
|
||||
end
|
||||
replic = max([replic, length(ind_dMOMENTS)*3]);
|
||||
cmm = simulated_moment_uncertainty(ind_dMOMENTS, periods, replic,options_,M_,oo_); %covariance matrix of moments
|
||||
cmm = identification.simulated_moment_uncertainty(ind_dMOMENTS, periods, replic,options_,M_,oo_); %covariance matrix of moments
|
||||
sd = sqrt(diag(cmm));
|
||||
cc = cmm./(sd*sd');
|
||||
[VV,DD,WW] = eig(cc);
|
||||
|
@ -346,9 +350,9 @@ if info(1) == 0 %no errors in solution
|
|||
iflag = any((deltaM.*deltaM)==0);
|
||||
tildaM = MIM./((deltaM)*(deltaM'));
|
||||
if iflag || rank(MIM)>rank(tildaM)
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(MIM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(MIM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
else %use normalized version if possible
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
indok = find(max(ide_hess.indno,[],1)==0);
|
||||
ind1 = find(ide_hess.ind0);
|
||||
|
@ -359,7 +363,7 @@ if info(1) == 0 %no errors in solution
|
|||
if ~isempty(indok)
|
||||
ide_uncert_unnormaliz(indok) = (sqrt(diag(inv(tildaM(indok,indok))))./deltaM(indok))'; %sqrt(diag(inv(MIM(indok,indok))))';
|
||||
end
|
||||
flag_score = 0; %this is used for the title in plot_identification.m
|
||||
flag_score = 0; %this is used for the title in identification.plot.m
|
||||
end % end of computing sample information matrix for identification strength measure
|
||||
|
||||
ide_strength_dMOMENTS(indok) = (1./(ide_uncert_unnormaliz(indok)'./abs(params(indok)'))); %this is s_i in Ratto and Iskrev (2011, p.13)
|
||||
|
@ -371,7 +375,7 @@ if info(1) == 0 %no errors in solution
|
|||
if size(quant,1)==1
|
||||
si_dMOMENTSnorm = abs(quant).*normaliz_prior_std;
|
||||
else
|
||||
si_dMOMENTSnorm = vnorm(quant).*normaliz_prior_std;
|
||||
si_dMOMENTSnorm = identification.vnorm(quant).*normaliz_prior_std;
|
||||
end
|
||||
iy = find(diag_chh);
|
||||
ind_dREDUCEDFORM = ind_dREDUCEDFORM(iy);
|
||||
|
@ -381,7 +385,7 @@ if info(1) == 0 %no errors in solution
|
|||
if size(quant,1)==1
|
||||
si_dREDUCEDFORMnorm = abs(quant).*normaliz_prior_std;
|
||||
else
|
||||
si_dREDUCEDFORMnorm = vnorm(quant).*normaliz_prior_std;
|
||||
si_dREDUCEDFORMnorm = identification.vnorm(quant).*normaliz_prior_std;
|
||||
end
|
||||
else
|
||||
si_dREDUCEDFORMnorm = [];
|
||||
|
@ -395,7 +399,7 @@ if info(1) == 0 %no errors in solution
|
|||
if size(quant,1)==1
|
||||
si_dDYNAMICnorm = abs(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end);
|
||||
else
|
||||
si_dDYNAMICnorm = vnorm(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end);
|
||||
si_dDYNAMICnorm = identification.vnorm(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end);
|
||||
end
|
||||
else
|
||||
si_dDYNAMICnorm=[];
|
||||
|
@ -461,11 +465,11 @@ if info(1) == 0 %no errors in solution
|
|||
ide_moments.MOMENTS = MOMENTS;
|
||||
|
||||
if advanced
|
||||
% here we do not normalize (i.e. we set norm_dMOMENTS=1) as the OLS in ident_bruteforce is very sensitive to norm_dMOMENTS
|
||||
[ide_moments.pars, ide_moments.cosndMOMENTS] = ident_bruteforce(dMOMENTS(ind_dMOMENTS,:), max_dim_cova_group, options_.TeX, options_ident.name_tex, options_ident.tittxt, tol_deriv);
|
||||
% here we do not normalize (i.e. we set norm_dMOMENTS=1) as the OLS in identification.bruteforce is very sensitive to norm_dMOMENTS
|
||||
[ide_moments.pars, ide_moments.cosndMOMENTS] = identification.bruteforce(M_.dname,M_.fname,dMOMENTS(ind_dMOMENTS,:), max_dim_cova_group, options_.TeX, options_ident.name_tex, options_ident.tittxt, tol_deriv);
|
||||
end
|
||||
|
||||
%here we focus on the unnormalized S and V, which is then used in plot_identification.m and for prior_mc > 1
|
||||
%here we focus on the unnormalized S and V, which is then used in identification.plot.m and for prior_mc > 1
|
||||
[~, S, V] = svd(dMOMENTS(ind_dMOMENTS,:),0);
|
||||
if size(S,1) == 1
|
||||
S = S(1); % edge case that S is not a matrix but a row vector
|
||||
|
@ -518,9 +522,9 @@ if info(1) == 0 %no errors in solution
|
|||
|
||||
%% Perform identification checks, i.e. find out which parameters are involved
|
||||
if checks_via_subsets
|
||||
% identification_checks_via_subsets is only for debugging
|
||||
% identification.checks_via_subsets is only for debugging
|
||||
[ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = ...
|
||||
identification_checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident, error_indicator);
|
||||
identification.checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident, error_indicator);
|
||||
if ~error_indicator.identification_minimal
|
||||
ide_minimal.minimal_state_space=1;
|
||||
else
|
||||
|
@ -528,19 +532,19 @@ if info(1) == 0 %no errors in solution
|
|||
end
|
||||
else
|
||||
[ide_dynamic.cond, ide_dynamic.rank, ide_dynamic.ind0, ide_dynamic.indno, ide_dynamic.ino, ide_dynamic.Mco, ide_dynamic.Pco, ide_dynamic.jweak, ide_dynamic.jweak_pair] = ...
|
||||
identification_checks(dDYNAMIC(ind_dDYNAMIC,:)./norm_dDYNAMIC, 1, tol_rank, tol_sv, modparam_nbr);
|
||||
identification.checks(dDYNAMIC(ind_dDYNAMIC,:)./norm_dDYNAMIC, 1, tol_rank, tol_sv, modparam_nbr);
|
||||
if ~options_ident.no_identification_reducedform && ~error_indicator.identification_reducedform
|
||||
[ide_reducedform.cond, ide_reducedform.rank, ide_reducedform.ind0, ide_reducedform.indno, ide_reducedform.ino, ide_reducedform.Mco, ide_reducedform.Pco, ide_reducedform.jweak, ide_reducedform.jweak_pair] = ...
|
||||
identification_checks(dREDUCEDFORM(ind_dREDUCEDFORM,:)./norm_dREDUCEDFORM, 1, tol_rank, tol_sv, totparam_nbr);
|
||||
identification.checks(dREDUCEDFORM(ind_dREDUCEDFORM,:)./norm_dREDUCEDFORM, 1, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
if ~options_ident.no_identification_moments && ~error_indicator.identification_moments
|
||||
[ide_moments.cond, ide_moments.rank, ide_moments.ind0, ide_moments.indno, ide_moments.ino, ide_moments.Mco, ide_moments.Pco, ide_moments.jweak, ide_moments.jweak_pair] = ...
|
||||
identification_checks(dMOMENTS(ind_dMOMENTS,:)./norm_dMOMENTS, 1, tol_rank, tol_sv, totparam_nbr);
|
||||
identification.checks(dMOMENTS(ind_dMOMENTS,:)./norm_dMOMENTS, 1, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
if ~options_ident.no_identification_minimal
|
||||
if ~error_indicator.identification_minimal
|
||||
[ide_minimal.cond, ide_minimal.rank, ide_minimal.ind0, ide_minimal.indno, ide_minimal.ino, ide_minimal.Mco, ide_minimal.Pco, ide_minimal.jweak, ide_minimal.jweak_pair] = ...
|
||||
identification_checks(dMINIMAL(ind_dMINIMAL,:)./norm_dMINIMAL, 2, tol_rank, tol_sv, totparam_nbr);
|
||||
identification.checks(dMINIMAL(ind_dMINIMAL,:)./norm_dMINIMAL, 2, tol_rank, tol_sv, totparam_nbr);
|
||||
ide_minimal.minimal_state_space=1;
|
||||
else
|
||||
ide_minimal.minimal_state_space=0;
|
||||
|
@ -548,7 +552,7 @@ if info(1) == 0 %no errors in solution
|
|||
end
|
||||
if ~options_ident.no_identification_spectrum && ~error_indicator.identification_spectrum
|
||||
[ide_spectrum.cond, ide_spectrum.rank, ide_spectrum.ind0, ide_spectrum.indno, ide_spectrum.ino, ide_spectrum.Mco, ide_spectrum.Pco, ide_spectrum.jweak, ide_spectrum.jweak_pair] = ...
|
||||
identification_checks(tilda_dSPECTRUM, 3, tol_rank, tol_sv, totparam_nbr);
|
||||
identification.checks(tilda_dSPECTRUM, 3, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function [pars, cosnJ] = ident_bruteforce(J, max_dim_cova_group, TeX, name_tex, tittxt, tol_deriv)
|
||||
% function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX,tittxt)
|
||||
function [pars, cosnJ] = bruteforce(dname,fname,J, max_dim_cova_group, TeX, name_tex, tittxt, tol_deriv)
|
||||
% [pars, cosnJ] = bruteforce(dname,fname,J, max_dim_cova_group, TeX, name_tex, tittxt, tol_deriv)
|
||||
% -------------------------------------------------------------------------
|
||||
% given the Jacobian matrix J of moment derivatives w.r.t. parameters
|
||||
% computes, for each column of J, the groups of columns from 1 to n that
|
||||
|
@ -18,9 +18,9 @@ function [pars, cosnJ] = ident_bruteforce(J, max_dim_cova_group, TeX, name_tex,
|
|||
% cosnJ : cosn of each column with the selected group of columns
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_analysis.m
|
||||
% * identification.analysis.m
|
||||
% =========================================================================
|
||||
% Copyright © 2009-2019 Dynare Team
|
||||
% Copyright © 2009-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -38,20 +38,18 @@ function [pars, cosnJ] = ident_bruteforce(J, max_dim_cova_group, TeX, name_tex,
|
|||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
|
||||
global M_ options_
|
||||
|
||||
OutputDirectoryName = CheckPath('identification',M_.dname);
|
||||
OutputDirectoryName = CheckPath('identification',dname);
|
||||
|
||||
totparam_nbr = size(J,2); % number of parameters
|
||||
|
||||
if nargin<2 || isempty(max_dim_cova_group)
|
||||
if nargin<4 || isempty(max_dim_cova_group)
|
||||
max_dim_cova_group = 4; % max n-tuple
|
||||
end
|
||||
if nargin<3 || isempty(TeX)
|
||||
if nargin<5 || isempty(TeX)
|
||||
TeX = 0; % no Tex output
|
||||
tittxt='';
|
||||
end
|
||||
if nargin < 6
|
||||
if nargin < 8
|
||||
tol_deriv = 1.e-8;
|
||||
end
|
||||
|
||||
|
@ -69,7 +67,7 @@ for ll = 1:max_dim_cova_group
|
|||
cosnJ2=zeros(size(tmp2,1),1);
|
||||
b=[];
|
||||
for jj = 1:size(tmp2,1)
|
||||
[cosnJ2(jj,1), b(:,jj)] = cosn([J(:,ii),J(:,tmp2(jj,:))]);
|
||||
[cosnJ2(jj,1), b(:,jj)] = identification.cosn([J(:,ii),J(:,tmp2(jj,:))]);
|
||||
end
|
||||
cosnJ(ii,ll) = max(cosnJ2(:,1));
|
||||
if cosnJ(ii,ll)>tol_deriv
|
||||
|
@ -87,7 +85,7 @@ for ll = 1:max_dim_cova_group
|
|||
end
|
||||
dyn_waitbar_close(h);
|
||||
if TeX
|
||||
filename = [OutputDirectoryName '/' M_.fname '_collin_patterns_',tittxt1,'_' int2str(ll) '.tex'];
|
||||
filename = [OutputDirectoryName '/' fname '_collin_patterns_',tittxt1,'_' int2str(ll) '.tex'];
|
||||
fidTeX = fopen(filename,'w');
|
||||
fprintf(fidTeX,'%% TeX-table generated by ident_bruteforce (Dynare).\n');
|
||||
fprintf(fidTeX,['%% Collinearity patterns with ',int2str(ll),' parameter(s): ',tittxt,'\n']);
|
||||
|
@ -114,12 +112,12 @@ for ll = 1:max_dim_cova_group
|
|||
plist='';
|
||||
for ii=1:ll
|
||||
if ~isnan(pars{i,ll}(ii))
|
||||
plist = [plist ' $' name_tex{pars{i,ll}(ii)} '\;\; $ '];
|
||||
plist = [plist ' ' name_tex{pars{i,ll}(ii)} '\;\; '];
|
||||
else
|
||||
plist = [plist ' ---- '];
|
||||
end
|
||||
end
|
||||
fprintf(fidTeX,'$%s$ & [%s] & %7.3f \\\\ \n',...
|
||||
fprintf(fidTeX,'%s & [%s] & %7.3f \\\\ \n',...
|
||||
name_tex{i},...
|
||||
plist,...
|
||||
cosnJ(i,ll));
|
|
@ -1,5 +1,5 @@
|
|||
function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = identification_checks(X, test_flag, tol_rank, tol_sv, param_nbr)
|
||||
% function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = identification_checks(X, test_flag, tol_rank, tol_sv, param_nbr)
|
||||
function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = checks(X, test_flag, tol_rank, tol_sv, param_nbr)
|
||||
% function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = checks(X, test_flag, tol_rank, tol_sv, param_nbr)
|
||||
% -------------------------------------------------------------------------
|
||||
% Checks rank criteria of identification tests and finds out parameter sets
|
||||
% that are not identifiable via the nullspace, pairwise correlation
|
||||
|
@ -24,10 +24,10 @@ function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = identi
|
|||
% * jweak_pair [(vech) matrix] gives 1 if a couple parameters has Pco=1 (with tolerance tol_rank)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_analysis.m
|
||||
% * identification.analysis.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * cosn
|
||||
% * identification.cosn
|
||||
% * dyn_vech
|
||||
% * vnorm
|
||||
% =========================================================================
|
||||
|
@ -75,7 +75,7 @@ end
|
|||
|
||||
% find non-zero columns at machine precision
|
||||
if size(Xpar,1) > 1
|
||||
ind1 = find(vnorm(Xpar) >= eps);
|
||||
ind1 = find(identification.vnorm(Xpar) >= eps);
|
||||
else
|
||||
ind1 = find(abs(Xpar) >= eps); % if only one parameter
|
||||
end
|
||||
|
@ -86,7 +86,7 @@ else
|
|||
Xparnonzero = Xpar(:,ind1); % focus on non-zero columns
|
||||
end
|
||||
|
||||
[eu, ee2, ee1] = svd( [Xparnonzero Xrest], 0 );
|
||||
[~, ~, ee1] = svd( [Xparnonzero Xrest], 0 );
|
||||
condX = cond([Xparnonzero Xrest]);
|
||||
rankX = rank(X, tol_rank);
|
||||
icheck = 0; %initialize flag which is equal to 0 if we already found all single parameters that are not identified
|
||||
|
@ -94,7 +94,7 @@ if param_nbr > 0 && (rankX<rankrequired)
|
|||
% search for singular values associated to ONE individual parameter
|
||||
% Compute an orthonormal basis for the null space using the columns of ee1 that correspond
|
||||
% to singular values equal to zero and associated to an individual parameter
|
||||
ee0 = [rankX+1:size([Xparnonzero Xrest],2)]; %look into last columns with singular values of problematic parameter sets (except single parameters)
|
||||
ee0 = rankX+1:size([Xparnonzero Xrest],2); %look into last columns with singular values of problematic parameter sets (except single parameters)
|
||||
ind11 = ones(length(ind1),1); %initialize
|
||||
for j=1:length(ee0)
|
||||
% check if nullspace is spanned by only one parameter
|
||||
|
@ -118,7 +118,7 @@ if icheck
|
|||
else
|
||||
Xparnonzero = Xpar(:,ind1); % focus on non-zero columns
|
||||
end
|
||||
[eu, ee2, ee1] = svd( [Xparnonzero Xrest], 0 );
|
||||
[~, ~, ee1] = svd( [Xparnonzero Xrest], 0 );
|
||||
condX = cond([Xparnonzero Xrest]);
|
||||
rankX = rank(X,tol_rank);
|
||||
end
|
||||
|
@ -141,7 +141,7 @@ if test_flag == 0 || test_flag == 3 % G is a Gram matrix and hence should be a c
|
|||
else
|
||||
Mco = NaN(param_nbr,1);
|
||||
for ii = 1:size(Xparnonzero,2)
|
||||
Mco(ind1(ii),:) = cosn([Xparnonzero(:,ii) , Xparnonzero(:,find([1:1:size(Xparnonzero,2)]~=ii)), Xrest]);
|
||||
Mco(ind1(ii),:) = identification.cosn([Xparnonzero(:,ii) , Xparnonzero(:,find([1:1:size(Xparnonzero,2)]~=ii)), Xrest]);
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -151,9 +151,9 @@ if param_nbr>0 && (rankX<rankrequired || min(1-Mco)<tol_rank)
|
|||
if length(ind1)<param_nbr
|
||||
% single parameters with zero columns
|
||||
ixno = ixno + 1;
|
||||
indno(ixno,:) = (~ismember([1:param_nbr],ind1));
|
||||
indno(ixno,:) = (~ismember(1:param_nbr,ind1));
|
||||
end
|
||||
ee0 = [rankX+1:size([Xparnonzero Xrest],2)]; %look into last columns with singular values of problematic parameter sets (except single parameters)
|
||||
ee0 = rankX+1:size([Xparnonzero Xrest],2); %look into last columns with singular values of problematic parameter sets (except single parameters)
|
||||
for j=1:length(ee0)
|
||||
% linearly dependent parameters
|
||||
ixno = ixno + 1;
|
||||
|
@ -170,13 +170,13 @@ end
|
|||
jweak = zeros(1,param_nbr);
|
||||
jweak_pair = zeros(param_nbr,param_nbr);
|
||||
|
||||
if test_flag ~= 0 || test_flag ~= 0
|
||||
if test_flag ~= 0
|
||||
% these tests only apply to Jacobians, not to Gram matrices, i.e. Hessian-type or 'covariance' matrices
|
||||
Pco = NaN(param_nbr,param_nbr);
|
||||
for ii = 1:size(Xparnonzero,2)
|
||||
Pco(ind1(ii),ind1(ii)) = 1;
|
||||
for jj = ii+1:size(Xparnonzero,2)
|
||||
Pco(ind1(ii),ind1(jj)) = cosn([Xparnonzero(:,ii),Xparnonzero(:,jj),Xrest]);
|
||||
Pco(ind1(ii),ind1(jj)) = identification.cosn([Xparnonzero(:,ii),Xparnonzero(:,jj),Xrest]);
|
||||
Pco(ind1(jj),ind1(ii)) = Pco(ind1(ii),ind1(jj));
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function [ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = identification_checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident,error_indicator)
|
||||
%[ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = identification_checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident,error_indicator)
|
||||
function [ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident,error_indicator)
|
||||
%[ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident,error_indicator)
|
||||
% -------------------------------------------------------------------------
|
||||
% Finds problematic sets of paramters via checking the necessary rank condition
|
||||
% of the Jacobians for all possible combinations of parameters. The rank is
|
||||
|
@ -50,7 +50,7 @@ function [ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal]
|
|||
% * rank: [integer] rank of Jacobian
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_analysis.m
|
||||
% * identification.analysis.m
|
||||
% =========================================================================
|
||||
% Copyright © 2019-2021 Dynare Team
|
||||
%
|
||||
|
@ -161,7 +161,7 @@ end
|
|||
|
||||
% initialize for spectrum criteria
|
||||
if ~no_identification_spectrum && ~error_indicator.identification_spectrum
|
||||
dSPECTRUM = ide_spectrum.tilda_dSPECTRUM; %tilda dSPECTRUM is normalized dSPECTRUM matrix in identification_analysis.m
|
||||
dSPECTRUM = ide_spectrum.tilda_dSPECTRUM; %tilda dSPECTRUM is normalized dSPECTRUM matrix in identification.analysis.m
|
||||
%alternative normalization
|
||||
%dSPECTRUM = ide_spectrum.dSPECTRUM;
|
||||
%dSPECTRUM(ide_spectrum.ind_dSPECTRUM,:) = dSPECTRUM(ide_spectrum.ind_dSPECTRUM,:)./ide_spectrum.norm_dSPECTRUM; %normalize
|
|
@ -17,7 +17,7 @@ function [co, b, yhat] = cosn(H)
|
|||
% * y [n by 1] predicted endogenous values given ols estimation
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_checks.m
|
||||
% * identification.checks.m
|
||||
% * ident_bruteforce.m
|
||||
% =========================================================================
|
||||
% Copyright © 2008-2019 Dynare Team
|
|
@ -1,5 +1,5 @@
|
|||
function disp_identification(pdraws, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, name, options_ident)
|
||||
% disp_identification(pdraws, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, name, options_ident)
|
||||
function display(pdraws, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, name, options_ident)
|
||||
% display(pdraws, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, name, options_ident)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function displays all identification analysis to the command line
|
||||
% =========================================================================
|
||||
|
@ -26,7 +26,7 @@ function disp_identification(pdraws, ide_reducedform, ide_moments, ide_spectrum,
|
|||
% * all output is printed on the command line
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * dynare_identification.m
|
||||
% * identification.run
|
||||
% =========================================================================
|
||||
% Copyright © 2010-2021 Dynare Team
|
||||
%
|
||||
|
@ -54,7 +54,7 @@ tol_rank = options_ident.tol_rank;
|
|||
checks_via_subsets = options_ident.checks_via_subsets;
|
||||
|
||||
%% Display settings
|
||||
disp([' ']),
|
||||
disp(' '),
|
||||
fprintf('Note that differences in the criteria could be due to numerical settings,\n')
|
||||
fprintf('numerical errors or the method used to find problematic parameter sets.\n')
|
||||
fprintf('Settings:\n')
|
||||
|
@ -157,7 +157,7 @@ for jide = 1:4
|
|||
disp(' !!!WARNING!!!');
|
||||
if SampleSize>1
|
||||
if non_minimal_state_space_error
|
||||
fprintf(['\n The minimal state space could not be computed for %u out of %u cases.\n'],SampleSize-EffectiveSampleSize,SampleSize);
|
||||
fprintf('\n The minimal state space could not be computed for %u out of %u cases.\n',SampleSize-EffectiveSampleSize,SampleSize);
|
||||
end
|
||||
if jide==2
|
||||
if sum(ide.ino & ide.minimal_state_space)>0
|
||||
|
@ -207,7 +207,7 @@ for jide = 1:4
|
|||
end
|
||||
end
|
||||
|
||||
%% display problematic parameters computed by identification_checks_via_subsets
|
||||
%% display problematic parameters computed by identification.checks_via_subsets
|
||||
elseif checks_via_subsets
|
||||
if ide.rank < size(Jacob,2)
|
||||
no_warning_message_display = 0;
|
|
@ -1,5 +1,5 @@
|
|||
function fjac = fjaco(f,x,varargin)
|
||||
|
||||
% fjac = fjaco(f,x,varargin)
|
||||
% FJACO Computes two-sided finite difference Jacobian
|
||||
% USAGE
|
||||
% fjac = fjaco(f,x,P1,P2,...)
|
||||
|
@ -30,7 +30,7 @@ function fjac = fjaco(f,x,varargin)
|
|||
ff=feval(f,x,varargin{:});
|
||||
|
||||
tol = eps.^(1/3); %some default value
|
||||
if strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification_numerical_objective')
|
||||
if strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective')
|
||||
tol= varargin{4}.dynatol.x;
|
||||
end
|
||||
h = tol.*max(abs(x),1);
|
||||
|
@ -40,12 +40,12 @@ fjac = NaN(length(ff),length(x));
|
|||
for j=1:length(x)
|
||||
xx = x;
|
||||
xx(j) = xh1(j); f1=feval(f,xx,varargin{:});
|
||||
if isempty(f1) && (strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification_numerical_objective') )
|
||||
if isempty(f1) && (strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') )
|
||||
[~,info]=feval(f,xx,varargin{:});
|
||||
disp_info_error_identification_perturbation(info,j);
|
||||
end
|
||||
xx(j) = xh0(j); f0=feval(f,xx,varargin{:});
|
||||
if isempty(f0) && (strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification_numerical_objective') )
|
||||
if isempty(f0) && (strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') )
|
||||
[~,info]=feval(f,xx,varargin{:});
|
||||
disp_info_error_identification_perturbation(info,j)
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ feval(f,x,varargin{:});
|
|||
%Auxiliary functions
|
||||
function disp_info_error_identification_perturbation(info,j)
|
||||
% there are errors in the solution algorithm
|
||||
probl_par = get_the_name(j,varargin{4}.TeX,varargin{3},varargin{2},varargin{4});
|
||||
probl_par = get_the_name(j,varargin{4}.TeX,varargin{3},varargin{2},varargin{4}.varobs);
|
||||
skipline()
|
||||
message = get_error_message(info,varargin{4});
|
||||
fprintf('Parameter error in numerical two-sided difference method:\n')
|
|
@ -1,5 +1,5 @@
|
|||
function [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_identification_jacobians(estim_params, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_identification_jacobians(estim_params, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
function [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_jacobians(estim_params, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_jacobians(estim_params, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% previously getJJ.m in Dynare 4.5
|
||||
% Sets up the Jacobians needed for identification analysis
|
||||
% =========================================================================
|
||||
|
@ -84,7 +84,7 @@ function [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dM
|
|||
%
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_analysis.m
|
||||
% * identification.analysis.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * commutation
|
||||
|
@ -94,7 +94,7 @@ function [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dM
|
|||
% * fjaco
|
||||
% * get_perturbation_params_derivs (previously getH)
|
||||
% * get_all_parameters
|
||||
% * identification_numerical_objective (previously thet2tau)
|
||||
% * identification.numerical_objective (previously thet2tau)
|
||||
% * pruned_state_space_system
|
||||
% * vec
|
||||
% =========================================================================
|
||||
|
@ -153,7 +153,7 @@ obs_nbr = length(indvobs);
|
|||
d2flag = 0; % do not compute second parameter derivatives
|
||||
|
||||
% Get Jacobians (wrt selected params) of steady state, dynamic model derivatives and perturbation solution matrices for all endogenous variables
|
||||
dr.derivs = get_perturbation_params_derivs(M_, options_, estim_params, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag);
|
||||
dr.derivs = identification.get_perturbation_params_derivs(M_, options_, estim_params, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag);
|
||||
|
||||
[I,~] = find(lead_lag_incidence'); %I is used to select nonzero columns of the Jacobian of endogenous variables in dynamic model files
|
||||
yy0 = dr.ys(I); %steady state of dynamic (endogenous and auxiliary variables) in lead_lag_incidence order
|
||||
|
@ -230,7 +230,7 @@ elseif order == 3
|
|||
end
|
||||
|
||||
% Get (pruned) state space representation:
|
||||
pruned = pruned_state_space_system(M_, options_, dr, indvobs, nlags, useautocorr, 1);
|
||||
pruned = pruned_SS.pruned_state_space_system(M_, options_, dr, indvobs, nlags, useautocorr, 1);
|
||||
MEAN = pruned.E_y;
|
||||
dMEAN = pruned.dE_y;
|
||||
%storage for Jacobians used in dsge_likelihood.m for analytical Gradient and Hession of likelihood (only at order=1)
|
||||
|
@ -258,7 +258,7 @@ if ~no_identification_moments
|
|||
|
||||
if kronflag == -1
|
||||
%numerical derivative of autocovariogram
|
||||
dMOMENTS = fjaco(str2func('identification_numerical_objective'), xparam1, 1, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=1]
|
||||
dMOMENTS = identification.fjaco(str2func('identification.numerical_objective'), xparam1, 1, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=1]
|
||||
dMOMENTS = [dMEAN; dMOMENTS]; %add Jacobian of steady state of VAROBS variables
|
||||
else
|
||||
dMOMENTS = zeros(obs_nbr + obs_nbr*(obs_nbr+1)/2 + nlags*obs_nbr^2 , totparam_nbr);
|
||||
|
@ -315,7 +315,7 @@ if ~no_identification_spectrum
|
|||
IA = eye(size(pruned.A,1));
|
||||
if kronflag == -1
|
||||
%numerical derivative of spectral density
|
||||
dOmega_tmp = fjaco(str2func('identification_numerical_objective'), xparam1, 2, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=2]
|
||||
dOmega_tmp = identification.fjaco(str2func('identification.numerical_objective'), xparam1, 2, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=2]
|
||||
kk = 0;
|
||||
for ig = 1:length(freqs)
|
||||
kk = kk+1;
|
||||
|
@ -333,7 +333,7 @@ if ~no_identification_spectrum
|
|||
dC = reshape(pruned.dC,size(pruned.dC,1)*size(pruned.dC,2),size(pruned.dC,3));
|
||||
dD = reshape(pruned.dD,size(pruned.dD,1)*size(pruned.dD,2),size(pruned.dD,3));
|
||||
dVarinov = reshape(pruned.dVarinov,size(pruned.dVarinov,1)*size(pruned.dVarinov,2),size(pruned.dVarinov,3));
|
||||
K_obs_exo = commutation(obs_nbr,size(pruned.Varinov,1));
|
||||
K_obs_exo = pruned_SS.commutation(obs_nbr,size(pruned.Varinov,1));
|
||||
for ig=1:length(freqs)
|
||||
z = tneg(ig);
|
||||
zIminusA = (z*IA - pruned.A);
|
||||
|
@ -400,7 +400,7 @@ if ~no_identification_minimal
|
|||
SYS.dC = dr.derivs.dghx(pruned.indy,:,:);
|
||||
SYS.D = dr.ghu(pruned.indy,:);
|
||||
SYS.dD = dr.derivs.dghu(pruned.indy,:,:);
|
||||
[CheckCO,minnx,SYS] = get_minimal_state_representation(SYS,1);
|
||||
[CheckCO,minnx,SYS] = identification.get_minimal_state_representation(SYS,1);
|
||||
|
||||
if CheckCO == 0
|
||||
warning_KomunjerNg = 'WARNING: Komunjer and Ng (2011) failed:\n';
|
||||
|
@ -423,7 +423,7 @@ if ~no_identification_minimal
|
|||
dvechSig = dvechSig(indvechSig,:);
|
||||
Inx = eye(minnx);
|
||||
Inu = eye(exo_nbr);
|
||||
[~,Enu] = duplication(exo_nbr);
|
||||
[~,Enu] = pruned_SS.duplication(exo_nbr);
|
||||
KomunjerNg_DL = [dminA; dminB; dminC; dminD; dvechSig];
|
||||
KomunjerNg_DT = [kron(transpose(minA),Inx) - kron(Inx,minA);
|
||||
kron(transpose(minB),Inx);
|
|
@ -53,7 +53,7 @@ function [CheckCO,minns,minSYS] = get_minimal_state_representation(SYS, derivs_f
|
|||
% Jacobian (wrt to all parameters) of measurement matrix minD
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * get_identification_jacobians.m (previously getJJ.m)
|
||||
% * identification.get_jacobians.m (previously getJJ.m)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * check_minimality (embedded)
|
||||
|
@ -209,7 +209,7 @@ function [mSYS,U] = minrealold(SYS,tol)
|
|||
a = SYS.A;
|
||||
b = SYS.B;
|
||||
c = SYS.C;
|
||||
[ns,nu] = size(b);
|
||||
[ns,~] = size(b);
|
||||
[am,bm,cm,U,k] = ControllabilityStaircaseRosenbrock(a,b,c,tol);
|
||||
kk = sum(k);
|
||||
nu = ns - kk;
|
||||
|
@ -219,7 +219,7 @@ function [mSYS,U] = minrealold(SYS,tol)
|
|||
cm = cm(:,nu+1:ns);
|
||||
ns = ns - nu;
|
||||
if ns
|
||||
[am,bm,cm,t,k] = ObservabilityStaircaseRosenbrock(am,bm,cm,tol);
|
||||
[am,bm,cm,~,k] = ObservabilityStaircaseRosenbrock(am,bm,cm,tol);
|
||||
kk = sum(k);
|
||||
nu = ns - kk;
|
||||
nn = nn + nu;
|
||||
|
@ -242,8 +242,8 @@ end
|
|||
|
||||
function [abar,bbar,cbar,t,k] = ControllabilityStaircaseRosenbrock(a, b, c, tol)
|
||||
% Controllability staircase algorithm of Rosenbrock, 1968
|
||||
[ra,ca] = size(a);
|
||||
[rb,cb] = size(b);
|
||||
[ra,~] = size(a);
|
||||
[~,cb] = size(b);
|
||||
ptjn1 = eye(ra);
|
||||
ajn1 = a;
|
||||
bjn1 = b;
|
||||
|
@ -255,8 +255,8 @@ function [abar,bbar,cbar,t,k] = ControllabilityStaircaseRosenbrock(a, b, c, tol)
|
|||
tol = ra*norm(a,1)*eps;
|
||||
end
|
||||
for jj = 1 : ra
|
||||
[uj,sj,vj] = svd(bjn1);
|
||||
[rsj,csj] = size(sj);
|
||||
[uj,sj] = svd(bjn1);
|
||||
[rsj,~] = size(sj);
|
||||
%p = flip(eye(rsj),2);
|
||||
p = eye(rsj);
|
||||
p = p(:,end:-1:1);
|
||||
|
@ -264,7 +264,7 @@ function [abar,bbar,cbar,t,k] = ControllabilityStaircaseRosenbrock(a, b, c, tol)
|
|||
uj = uj*p;
|
||||
bb = uj'*bjn1;
|
||||
roj = rank(bb,tol);
|
||||
[rbb,cbb] = size(bb);
|
||||
[rbb,~] = size(bb);
|
||||
sigmaj = rbb - roj;
|
||||
sigmajn1 = sigmaj;
|
||||
k(jj) = roj;
|
|
@ -88,12 +88,13 @@ function DERIVS = get_perturbation_params_derivs(M_, options_, estim_params_, dr
|
|||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * dsge_likelihood.m
|
||||
% * get_identification_jacobians.m
|
||||
% * identification.get_jacobians.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * [fname,'.dynamic']
|
||||
% * [fname,'.dynamic_params_derivs']
|
||||
% * [fname,'.static']
|
||||
% * [fname,'.sparse.static_g1']
|
||||
% * [fname,'.sparse.static_g2']
|
||||
% * [fname,'.static_params_derivs']
|
||||
% * commutation
|
||||
% * dyn_vech
|
||||
|
@ -109,7 +110,7 @@ function DERIVS = get_perturbation_params_derivs(M_, options_, estim_params_, dr
|
|||
% * sylvester3a
|
||||
% * get_perturbation_params_derivs_numerical_objective
|
||||
% =========================================================================
|
||||
% Copyright © 2019-2020 Dynare Team
|
||||
% Copyright © 2019-2024 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -191,7 +192,7 @@ if order > 1 && analytic_derivation_mode == 1
|
|||
analytic_derivation_mode = 0; fprintf('As order > 1, reset ''analytic_derivation_mode'' to 0\n');
|
||||
end
|
||||
|
||||
numerical_objective_fname = str2func('get_perturbation_params_derivs_numerical_objective');
|
||||
numerical_objective_fname = str2func('identification.get_perturbation_params_derivs_numerical_objective');
|
||||
idx_states = nstatic+(1:nspred); %index for state variables, in DR order
|
||||
modparam_nbr = length(indpmodel); %number of selected model parameters
|
||||
stderrparam_nbr = length(indpstderr); %number of selected stderr parameters
|
||||
|
@ -295,7 +296,7 @@ if analytic_derivation_mode == -1
|
|||
% - perturbation solution matrices: dghx, dghu, dghxx, dghxu, dghuu, dghs2, dghxxx, dghxxu, dghxuu, dghuuu, dghxss, dghuss
|
||||
|
||||
%Parameter Jacobian of covariance matrix and solution matrices (wrt selected stderr, corr and model paramters)
|
||||
dSig_gh = fjaco(numerical_objective_fname, xparam1, 'perturbation_solution', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
dSig_gh = identification.fjaco(numerical_objective_fname, xparam1, 'perturbation_solution', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
ind_Sigma_e = (1:exo_nbr^2);
|
||||
ind_ghx = ind_Sigma_e(end) + (1:endo_nbr*nspred);
|
||||
ind_ghu = ind_ghx(end) + (1:endo_nbr*exo_nbr);
|
||||
|
@ -348,7 +349,7 @@ if analytic_derivation_mode == -1
|
|||
end
|
||||
|
||||
%Parameter Jacobian of dynamic model derivatives (wrt selected model parameters only)
|
||||
dYss_g = fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
dYss_g = identification.fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
ind_Yss = 1:endo_nbr;
|
||||
if options_.discretionary_policy || options_.ramsey_policy
|
||||
ind_g1 = ind_Yss(end) + (1:M_.eq_nbr*yy0ex0_nbr);
|
||||
|
@ -374,7 +375,7 @@ if analytic_derivation_mode == -1
|
|||
% Hessian (wrt paramters) of steady state and first-order solution matrices ghx and Om
|
||||
% note that hessian_sparse.m (contrary to hessian.m) does not take symmetry into account, but focuses already on unique values
|
||||
options_.order = 1; %make sure only first order
|
||||
d2Yss_KalmanA_Om = hessian_sparse(numerical_objective_fname, xparam1, gstep, 'Kalman_Transition', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
d2Yss_KalmanA_Om = identification.hessian_sparse(numerical_objective_fname, xparam1, gstep, 'Kalman_Transition', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
options_.order = order; %make sure to set back
|
||||
ind_KalmanA = ind_Yss(end) + (1:endo_nbr^2);
|
||||
DERIVS.d2KalmanA = d2Yss_KalmanA_Om(ind_KalmanA, indp2tottot2); %only unique elements
|
||||
|
@ -394,7 +395,7 @@ if analytic_derivation_mode == -2
|
|||
% The parameter derivatives of perturbation solution matrices are computed analytically below (analytic_derivation_mode=0)
|
||||
if order == 3
|
||||
[~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1);
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr);
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr);
|
||||
elseif order == 2
|
||||
[~, g1, g2] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1);
|
||||
elseif order == 1
|
||||
|
@ -405,7 +406,7 @@ if analytic_derivation_mode == -2
|
|||
% computation of d2Yss and d2g1
|
||||
% note that hessian_sparse does not take symmetry into account, i.e. compare hessian_sparse.m to hessian.m, but focuses already on unique values, which are duplicated below
|
||||
options_.order = 1; %d2flag requires only first order
|
||||
d2Yss_g1 = hessian_sparse(numerical_objective_fname, modparam1, gstep, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); % d2flag requires only first-order
|
||||
d2Yss_g1 = identification.hessian_sparse(numerical_objective_fname, modparam1, gstep, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); % d2flag requires only first-order
|
||||
options_.order = order; %make sure to set back the order
|
||||
d2Yss = reshape(full(d2Yss_g1(1:endo_nbr,:)), [endo_nbr modparam_nbr modparam_nbr]); %put into tensor notation
|
||||
for j=1:endo_nbr
|
||||
|
@ -431,7 +432,7 @@ if analytic_derivation_mode == -2
|
|||
end
|
||||
|
||||
%Parameter Jacobian of dynamic model derivatives (wrt selected model parameters only)
|
||||
dYss_g = fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
dYss_g = identification.fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
ind_Yss = 1:endo_nbr;
|
||||
ind_g1 = ind_Yss(end) + (1:endo_nbr*yy0ex0_nbr);
|
||||
dYss = dYss_g(ind_Yss,:); %in tensor notation, wrt selected model parameters only
|
||||
|
@ -447,20 +448,23 @@ if analytic_derivation_mode == -2
|
|||
clear dYss_g
|
||||
|
||||
elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1)
|
||||
%% Analytical computation of Jacobian and Hessian (wrt selected model parameters) of steady state, i.e. dYss and d2Yss
|
||||
[~, g1_static] = feval([fname,'.static'], ys, exo_steady_state', params); %g1_static is [endo_nbr by endo_nbr] first-derivative (wrt all endogenous variables) of static model equations f, i.e. df/dys, in declaration order
|
||||
try
|
||||
rp_static = feval([fname,'.static_params_derivs'], ys, exo_steady_state', params); %rp_static is [endo_nbr by param_nbr] first-derivative (wrt all model parameters) of static model equations f, i.e. df/dparams, in declaration order
|
||||
catch
|
||||
if ~exist(['+' fname filesep 'static_params_derivs.m'],'file')
|
||||
error('For analytical parameter derivatives ''static_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
if ~exist(['+' fname filesep 'dynamic_params_derivs.m'],'file')
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
%% Analytical computation of Jacobian and Hessian (wrt selected model parameters) of steady state, i.e. dYss and d2Yss
|
||||
[g1_static, T_order_static, T_static] = feval([fname,'.sparse.static_g1'], ys, exo_steady_state', params, M_.static_g1_sparse_rowval, M_.static_g1_sparse_colval, M_.static_g1_sparse_colptr); %g1_static is [endo_nbr by endo_nbr] first-derivative (wrt all endogenous variables) of static model equations f, i.e. df/dys, in declaration order
|
||||
rp_static = feval([fname,'.static_params_derivs'], ys, exo_steady_state', params); %rp_static is [endo_nbr by param_nbr] first-derivative (wrt all model parameters) of static model equations f, i.e. df/dparams, in declaration order
|
||||
dys = -g1_static\rp_static; %use implicit function theorem (equation 5 of Ratto and Iskrev (2012) to compute [endo_nbr by param_nbr] first-derivative (wrt all model parameters) of steady state for all endogenous variables analytically, note that dys is in declaration order
|
||||
d2ys = zeros(endo_nbr, param_nbr, param_nbr); %initialize in tensor notation, note that d2ys is only needed for d2flag, i.e. for g1pp
|
||||
if d2flag
|
||||
[~, ~, g2_static] = feval([fname,'.static'], ys, exo_steady_state', params); %g2_static is [endo_nbr by endo_nbr^2] second derivative (wrt all endogenous variables) of static model equations f, i.e. d(df/dys)/dys, in declaration order
|
||||
g2_static_v = feval([fname,'.sparse.static_g2'], ys, exo_steady_state', params, T_order_static, T_static);
|
||||
g2_static = build_two_dim_hessian(M_.static_g2_sparse_indices, g2_static_v, endo_nbr, endo_nbr); %g2_static is [endo_nbr by endo_nbr^2] second derivative (wrt all endogenous variables) of static model equations f, i.e. d(df/dys)/dys, in declaration order
|
||||
if order < 3
|
||||
[~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1); %note that g3 does not contain symmetric elements
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3
|
||||
else
|
||||
T = NaN(sum(dynamic_tmp_nbr(1:5)));
|
||||
T = feval([fname, '.dynamic_g4_tt'], T, ys(I), exo_steady_state', params, ys, 1);
|
||||
|
@ -468,20 +472,16 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1)
|
|||
g2 = feval([fname, '.dynamic_g2'], T, ys(I), exo_steady_state', params, ys, 1, false); %g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g3 = feval([fname, '.dynamic_g3'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g3 does not contain symmetric elements
|
||||
g4 = feval([fname, '.dynamic_g4'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g4 does not contain symmetric elements
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g4 = unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g4 = identification.unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
end
|
||||
%g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
try
|
||||
[~, g1p_static, rpp_static] = feval([fname,'.static_params_derivs'], ys, exo_steady_state', params);
|
||||
%g1p_static is [endo_nbr by endo_nbr by param_nbr] first derivative (wrt all model parameters) of first-derivative (wrt all endogenous variables) of static model equations f, i.e. (df/dys)/dparams, in declaration order
|
||||
%rpp_static is [#second_order_residual_terms by 4] and contains nonzero values and corresponding indices of second derivatives (wrt all model parameters) of static model equations f, i.e. d(df/dparams)/dparams, in declaration order, where
|
||||
% column 1 contains equation number; column 2 contains first parameter; column 3 contains second parameter; column 4 contains value of derivative
|
||||
catch
|
||||
error('For analytical parameter derivatives ''static_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
[~, g1p_static, rpp_static] = feval([fname,'.static_params_derivs'], ys, exo_steady_state', params);
|
||||
%g1p_static is [endo_nbr by endo_nbr by param_nbr] first derivative (wrt all model parameters) of first-derivative (wrt all endogenous variables) of static model equations f, i.e. (df/dys)/dparams, in declaration order
|
||||
%rpp_static is [#second_order_residual_terms by 4] and contains nonzero values and corresponding indices of second derivatives (wrt all model parameters) of static model equations f, i.e. d(df/dparams)/dparams, in declaration order, where
|
||||
% column 1 contains equation number; column 2 contains first parameter; column 3 contains second parameter; column 4 contains value of derivative
|
||||
rpp_static = get_all_resid_2nd_derivs(rpp_static, endo_nbr, param_nbr); %make full matrix out of nonzero values and corresponding indices
|
||||
%rpp_static is [endo_nbr by param_nbr by param_nbr] second derivatives (wrt all model parameters) of static model equations, i.e. d(df/dparams)/dparams, in declaration order
|
||||
if isempty(find(g2_static))
|
||||
|
@ -507,7 +507,7 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1)
|
|||
end
|
||||
%handling of steady state for nonstationary variables
|
||||
if any(any(isnan(dys)))
|
||||
[U,T] = schur(g1_static);
|
||||
[U,T] = schur(full(g1_static));
|
||||
e1 = abs(ordeig(T)) < qz_criterium-1;
|
||||
k = sum(e1); % Number of non stationary variables.
|
||||
% Number of stationary variables: n = length(e1)-k
|
||||
|
@ -525,58 +525,42 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1)
|
|||
end
|
||||
|
||||
if d2flag
|
||||
try
|
||||
if order < 3
|
||||
[~, g1p, ~, g1pp, g2p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
else
|
||||
[~, g1p, ~, g1pp, g2p, g3p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
end
|
||||
catch
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
if order < 3
|
||||
[~, g1p, ~, g1pp, g2p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
else
|
||||
[~, g1p, ~, g1pp, g2p, g3p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
end
|
||||
%g1pp are nonzero values and corresponding indices of second-derivatives (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dparam)/dparam, rows are in declaration order, first column in declaration order
|
||||
d2Yss = d2ys(order_var,indpmodel,indpmodel); %[endo_nbr by mod_param_nbr by mod_param_nbr], put into DR order and focus only on selected model parameters
|
||||
else
|
||||
if order == 1
|
||||
try
|
||||
[~, g1p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
catch
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
[~, g1p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
[~, g1, g2 ] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1);
|
||||
%g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g2 is [endo_nbr by yy0ex0_nbr^2] second derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
elseif order == 2
|
||||
try
|
||||
[~, g1p, ~, ~, g2p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
%g2p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of second-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first and second column in declaration order
|
||||
catch
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
[~, g1p, ~, ~, g2p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
%g2p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of second-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first and second column in declaration order
|
||||
[~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1); %note that g3 does not contain symmetric elements
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3
|
||||
%g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
elseif order == 3
|
||||
try
|
||||
[~, g1p, ~, ~, g2p, g3p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
%g2p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of second-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first and second column in declaration order
|
||||
%g3p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of third-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first, second and third column in declaration order
|
||||
catch
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
[~, g1p, ~, ~, g2p, g3p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
%g2p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of second-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first and second column in declaration order
|
||||
%g3p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of third-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first, second and third column in declaration order
|
||||
T = NaN(sum(dynamic_tmp_nbr(1:5)));
|
||||
T = feval([fname, '.dynamic_g4_tt'], T, ys(I), exo_steady_state', params, ys, 1);
|
||||
g1 = feval([fname, '.dynamic_g1'], T, ys(I), exo_steady_state', params, ys, 1, false); %g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g2 = feval([fname, '.dynamic_g2'], T, ys(I), exo_steady_state', params, ys, 1, false); %g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g3 = feval([fname, '.dynamic_g3'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g3 does not contain symmetric elements
|
||||
g4 = feval([fname, '.dynamic_g4'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g4 does not contain symmetric elements
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g4 = unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g4 = identification.unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
end
|
||||
end
|
||||
% Parameter Jacobian of steady state in different orderings, note dys is in declaration order
|
||||
|
@ -801,7 +785,7 @@ if analytic_derivation_mode == 1
|
|||
dghu = [zeros(endo_nbr*exo_nbr, stderrparam_nbr+corrparam_nbr) dghu];
|
||||
|
||||
% Compute dOm = dvec(ghu*Sigma_e*ghu') from expressions 34 in Iskrev (2010) Appendix A
|
||||
dOm = kron(I_endo,ghu*Sigma_e)*(commutation(endo_nbr, exo_nbr)*dghu)...
|
||||
dOm = kron(I_endo,ghu*Sigma_e)*(pruned_SS.commutation(endo_nbr, exo_nbr)*dghu)...
|
||||
+ kron(ghu,ghu)*reshape(dSigma_e, exo_nbr^2, totparam_nbr) + kron(ghu*Sigma_e,I_endo)*dghu;
|
||||
|
||||
% Put into tensor notation
|
|
@ -95,7 +95,7 @@ if strcmp(outputflag,'dynamic_model')
|
|||
out = [Yss; g1(:); g2(:)];
|
||||
elseif options_.order == 3
|
||||
[~, g1, g2, g3] = feval([M_.fname,'.dynamic'], ys(I), exo_steady_state', M_.params, ys, 1);
|
||||
g3 = unfold_g3(g3, length(ys(I))+M_.exo_nbr);
|
||||
g3 = identification.unfold_g3(g3, length(ys(I))+M_.exo_nbr);
|
||||
out = [Yss; g1(:); g2(:); g3(:)];
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function out = identification_numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% out = identification_numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state)
|
||||
function out = numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% out = numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% -------------------------------------------------------------------------
|
||||
% Objective function to compute numerically the Jacobians used for identification analysis
|
||||
% Previously this function was called thet2tau.m
|
||||
|
@ -22,7 +22,7 @@ function out = identification_numerical_objective(params, outputflag, estim_para
|
|||
% OUTPUTS
|
||||
% out: dependent on outputflag
|
||||
% * 0: out = [Yss; vec(A); vec(B); dyn_vech(Sig_e)]; of indvar variables only, in DR order. This is needed to compute dTAU and Komunjer and Ng's D.
|
||||
% Note that Jacobian of Om is computed in get_identification_Jacobians.m (previously getJJ.m) or get_first_order_solution_params_deriv.m (previously getH.m) from Jacobian of B and Sigma_e, because this is more efficient due to some testing with analytical derivatives from An and Schorfheide model
|
||||
% Note that Jacobian of Om is computed in identification.get_jacobians.m (previously getJJ.m) or get_first_order_solution_params_deriv.m (previously getH.m) from Jacobian of B and Sigma_e, because this is more efficient due to some testing with analytical derivatives from An and Schorfheide model
|
||||
% * 1: out = [vech(cov(Y_t,Y_t)); vec(cov(Y_t,Y_{t-1}); ...; vec(cov(Y_t,Y_{t-nlags})] of indvar variables, in DR order. This is needed to compute Iskrev's J.
|
||||
% * 2: out = vec(spectral density) with dimension [var_nbr^2*grid_nbr,1] Spectral density of indvar variables evaluated at (grid_nbr/2+1) discretized points in the interval [0;pi]. This is needed for Qu and Tkachenko's G.
|
||||
% * -1: out = g1(:); of all variables, in DR order. This is needed to compute dLRE.
|
||||
|
@ -32,7 +32,7 @@ function out = identification_numerical_objective(params, outputflag, estim_para
|
|||
% Jacobian of the dynamic model equations, and Y_t selected variables
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * get_identification_jacobians.m (previously getJJ.m)
|
||||
% * identification.get_jacobians.m (previously getJJ.m)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * [M_.fname,'.dynamic']
|
||||
|
@ -78,9 +78,9 @@ else
|
|||
end
|
||||
|
||||
%% compute Kalman transition matrices and steady state with updated parameters
|
||||
[dr,info,M_.params] = compute_decision_rules(M_,options_,dr, steady_state, exo_steady_state, exo_det_steady_state);
|
||||
[dr,~,M_.params] = compute_decision_rules(M_,options_,dr, steady_state, exo_steady_state, exo_det_steady_state);
|
||||
options_ = rmfield(options_,'options_ident');
|
||||
pruned = pruned_state_space_system(M_, options_, dr, indvar, nlags, useautocorr, 0);
|
||||
pruned = pruned_SS.pruned_state_space_system(M_, options_, dr, indvar, nlags, useautocorr, 0);
|
||||
|
||||
%% out = [vech(cov(Y_t,Y_t)); vec(cov(Y_t,Y_{t-1}); ...; vec(cov(Y_t,Y_{t-nlags})] of indvar variables, in DR order. This is Iskrev (2010)'s J matrix.
|
||||
if outputflag == 1
|
|
@ -1,7 +1,8 @@
|
|||
function plot_identification(params, idemoments, idehess, idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName, tit_TeX, name_tex)
|
||||
% function plot_identification(params,idemoments,idehess,idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName)
|
||||
function plot(M_, params, idemoments, idehess, idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName, fname, options_, estim_params_, bayestopt_, tit_TeX, name_tex)
|
||||
% plot(M_, params,idemoments,idehess,idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName, fname, options_, estim_params_, bayestopt_, tit_TeX, name_tex)
|
||||
%
|
||||
% INPUTS
|
||||
% o M_ [structure] model
|
||||
% o params [array] parameter values for identification checks
|
||||
% o idemoments [structure] identification results for the moments
|
||||
% o idehess [structure] identification results for the Hessian
|
||||
|
@ -9,10 +10,15 @@ function plot_identification(params, idemoments, idehess, idemodel, idelre, adva
|
|||
% o idelre [structure] identification results for the LRE model
|
||||
% o advanced [integer] flag for advanced identification checks
|
||||
% o tittxt [char] name of the results to plot
|
||||
% o name [char] list of names
|
||||
% o name [char] list of parameter names
|
||||
% o IdentifDirectoryName [char] directory name
|
||||
% o fname [char] file name
|
||||
% o options_ [structure] structure describing the current options
|
||||
% o estim_params_ [structure] characterizing parameters to be estimated
|
||||
% o bayestopt_ [structure] describing the priors
|
||||
% o tittxt [char] TeX-name of the results to plot
|
||||
% o name_tex [char] TeX-names of the parameters
|
||||
%
|
||||
% OUTPUTS
|
||||
% None
|
||||
%
|
||||
|
@ -36,14 +42,12 @@ function plot_identification(params, idemoments, idehess, idemodel, idelre, adva
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global M_ options_
|
||||
|
||||
if nargin <10 || isempty(tit_TeX)
|
||||
if nargin <14 || isempty(tit_TeX)
|
||||
tit_TeX=tittxt;
|
||||
end
|
||||
|
||||
if nargin <11
|
||||
name_TeX=name;
|
||||
if nargin <15
|
||||
name_tex=name;
|
||||
end
|
||||
|
||||
[SampleSize, nparam]=size(params);
|
||||
|
@ -54,20 +58,19 @@ si_dLREnorm = idelre.si_dDYNAMICnorm;
|
|||
tittxt1=regexprep(tittxt, ' ', '_');
|
||||
tittxt1=strrep(tittxt1, '.', '');
|
||||
if SampleSize == 1
|
||||
si_dMOMENTS = idemoments.si_dMOMENTS;
|
||||
hh_fig = dyn_figure(options_.nodisplay,'Name',[tittxt, ' - Identification using info from observables']);
|
||||
subplot(211)
|
||||
mmm = (idehess.ide_strength_dMOMENTS);
|
||||
[ss, is] = sort(mmm);
|
||||
[~, is] = sort(mmm);
|
||||
if ~all(isnan(idehess.ide_strength_dMOMENTS_prior)) ...
|
||||
&& ~(nparam == 1 && ~isoctave && matlab_ver_less_than('9.7')) % MATLAB < R2019b does not accept bar(1, [2 3])
|
||||
bar(1:nparam,log([idehess.ide_strength_dMOMENTS(:,is)' idehess.ide_strength_dMOMENTS_prior(:,is)']))
|
||||
else
|
||||
bar(1:nparam,log([idehess.ide_strength_dMOMENTS(:,is)' ]))
|
||||
bar(1:nparam,log(idehess.ide_strength_dMOMENTS(:,is)'))
|
||||
end
|
||||
hold on
|
||||
plot((1:length(idehess.ide_strength_dMOMENTS(:,is)))-0.15,log([idehess.ide_strength_dMOMENTS(:,is)']),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
|
||||
plot((1:length(idehess.ide_strength_dMOMENTS_prior(:,is)))+0.15,log([idehess.ide_strength_dMOMENTS_prior(:,is)']),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
|
||||
plot((1:length(idehess.ide_strength_dMOMENTS(:,is)))-0.15,log(idehess.ide_strength_dMOMENTS(:,is)'),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
|
||||
plot((1:length(idehess.ide_strength_dMOMENTS_prior(:,is)))+0.15,log(idehess.ide_strength_dMOMENTS_prior(:,is)'),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
|
||||
if any(isinf(log(idehess.ide_strength_dMOMENTS(idehess.identified_parameter_indices))))
|
||||
%-Inf, i.e. 0 strength
|
||||
inf_indices=find(isinf(log(idehess.ide_strength_dMOMENTS(idehess.identified_parameter_indices))) & log(idehess.ide_strength_dMOMENTS(idehess.identified_parameter_indices))<0);
|
||||
|
@ -92,7 +95,11 @@ if SampleSize == 1
|
|||
set(gca,'xticklabel','')
|
||||
dy = get(gca,'ylim');
|
||||
for ip=1:nparam
|
||||
text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,dy(1),name_tex{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
if ~all(isnan(idehess.ide_strength_dMOMENTS_prior))
|
||||
legend('relative to param value','relative to prior std','Location','Best')
|
||||
|
@ -113,8 +120,8 @@ if SampleSize == 1
|
|||
bar(1:nparam, log([idehess.deltaM(is)]))
|
||||
end
|
||||
hold on
|
||||
plot((1:length(idehess.deltaM(is)))-0.15,log([idehess.deltaM(is)']),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
|
||||
plot((1:length(idehess.deltaM_prior(is)))+0.15,log([idehess.deltaM_prior(is)']),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
|
||||
plot((1:length(idehess.deltaM(is)))-0.15,log(idehess.deltaM(is)'),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
|
||||
plot((1:length(idehess.deltaM_prior(is)))+0.15,log(idehess.deltaM_prior(is)'),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
|
||||
inf_pos=find(isinf(log(idehess.deltaM)));
|
||||
if ~isempty(inf_pos)
|
||||
inf_indices=~ismember(inf_pos,idehess.sensitivity_zero_pos);
|
||||
|
@ -131,7 +138,11 @@ if SampleSize == 1
|
|||
set(gca,'xticklabel','')
|
||||
dy = get(gca,'ylim');
|
||||
for ip=1:nparam
|
||||
text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,dy(1),name_tex{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
if ~all(isnan(idehess.deltaM_prior))
|
||||
legend('relative to param value','relative to prior std','Location','Best')
|
||||
|
@ -144,19 +155,19 @@ if SampleSize == 1
|
|||
title('Sensitivity component with moments Information matrix (log-scale)')
|
||||
end
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([IdentifDirectoryName '/' M_.fname '_ident_strength_' tittxt1,'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fidTeX = fopen([IdentifDirectoryName '/' fname '_ident_strength_' tittxt1,'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_strength_%s}\n',[IdentifDirectoryName '/' M_.fname],tittxt1);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_strength_%s}\n',[IdentifDirectoryName '/' fname],tittxt1);
|
||||
fprintf(fidTeX,'\\caption{%s - Identification using info from observables.}',tit_TeX);
|
||||
fprintf(fidTeX,'\\label{Fig:ident:%s}\n',deblank(tittxt));
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
fprintf(fidTeX,'%% End Of TeX file. \n');
|
||||
fclose(fidTeX);
|
||||
end
|
||||
dyn_saveas(hh_fig,[IdentifDirectoryName '/' M_.fname '_ident_strength_' tittxt1],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(hh_fig,[IdentifDirectoryName '/' fname '_ident_strength_' tittxt1],options_.nodisplay,options_.graph_format);
|
||||
|
||||
if advanced
|
||||
if ~options_.nodisplay
|
||||
|
@ -181,18 +192,22 @@ if SampleSize == 1
|
|||
set(gca,'xticklabel','')
|
||||
dy = get(gca,'ylim');
|
||||
for ip=1:nparam
|
||||
text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,dy(1),name_tex{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
legend('Moments','Model','LRE model','Location','Best')
|
||||
title('Sensitivity bars using derivatives (log-scale)')
|
||||
dyn_saveas(hh_fig,[IdentifDirectoryName '/' M_.fname '_sensitivity_' tittxt1 ],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(hh_fig,[IdentifDirectoryName '/' fname '_sensitivity_' tittxt1 ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([IdentifDirectoryName '/' M_.fname '_sensitivity_' tittxt1,'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fidTeX = fopen([IdentifDirectoryName '/' fname '_sensitivity_' tittxt1,'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_sensitivity_%s}\n',[IdentifDirectoryName '/' M_.fname],tittxt1);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_sensitivity_%s}\n',[IdentifDirectoryName '/' fname],tittxt1);
|
||||
fprintf(fidTeX,'\\caption{%s - Sensitivity plot.}',tit_TeX);
|
||||
fprintf(fidTeX,'\\label{Fig:sensitivity:%s}\n',deblank(tittxt));
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
|
@ -203,9 +218,6 @@ if SampleSize == 1
|
|||
% identificaton patterns
|
||||
for j=1:size(idemoments.cosndMOMENTS,2)
|
||||
pax=NaN(nparam,nparam);
|
||||
% fprintf('\n')
|
||||
% disp(['Collinearity patterns with ', int2str(j) ,' parameter(s)'])
|
||||
% fprintf('%-15s [%-*s] %10s\n','Parameter',(15+1)*j,' Expl. params ','cosn')
|
||||
for i=1:nparam
|
||||
namx='';
|
||||
for in=1:j
|
||||
|
@ -213,19 +225,27 @@ if SampleSize == 1
|
|||
if isnan(dumpindx)
|
||||
namx=[namx ' ' sprintf('%-15s','--')];
|
||||
else
|
||||
namx=[namx ' ' sprintf('%-15s',name{dumpindx})];
|
||||
if options_.TeX
|
||||
namx=[namx ' ' sprintf('%-15s',name_tex{dumpindx})];
|
||||
else
|
||||
namx=[namx ' ' sprintf('%-15s',name{dumpindx})];
|
||||
end
|
||||
pax(i,dumpindx)=idemoments.cosndMOMENTS(i,j);
|
||||
end
|
||||
end
|
||||
% fprintf('%-15s [%s] %10.3f\n',name{i},namx,idemoments.cosndMOMENTS(i,j))
|
||||
end
|
||||
hh_fig = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Collinearity patterns with ', int2str(j) ,' parameter(s)']);
|
||||
imagesc(pax,[0 1]);
|
||||
set(gca,'xticklabel','')
|
||||
set(gca,'yticklabel','')
|
||||
for ip=1:nparam
|
||||
text(ip,(0.5),name{ip},'rotation',90,'HorizontalAlignment','left','interpreter','none')
|
||||
text(0.5,ip,name{ip},'rotation',0,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,(0.5),name_tex{ip},'rotation',90,'HorizontalAlignment','left','interpreter','latex')
|
||||
text(0.5,ip,name_tex{ip},'rotation',0,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,(0.5),name{ip},'rotation',90,'HorizontalAlignment','left','interpreter','none')
|
||||
text(0.5,ip,name{ip},'rotation',0,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
colorbar;
|
||||
colormap('jet');
|
||||
|
@ -239,14 +259,14 @@ if SampleSize == 1
|
|||
set(gca,'xgrid','on')
|
||||
set(gca,'ygrid','on')
|
||||
xlabel([tittxt,' - Collinearity patterns with ', int2str(j) ,' parameter(s)'],'interpreter','none')
|
||||
dyn_saveas(hh_fig,[ IdentifDirectoryName '/' M_.fname '_ident_collinearity_' tittxt1 '_' int2str(j) ],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(hh_fig,[ IdentifDirectoryName '/' fname '_ident_collinearity_' tittxt1 '_' int2str(j) ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' M_.fname '_ident_collinearity_' tittxt1 '_' int2str(j),'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_ident_collinearity_' tittxt1 '_' int2str(j),'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_collinearity_%s_%u}\n',[IdentifDirectoryName '/' M_.fname],tittxt1,j);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_collinearity_%s_%u}\n',[IdentifDirectoryName '/' fname],tittxt1,j);
|
||||
fprintf(fidTeX,'\\caption{%s - Collinearity patterns with %u parameter(s).}',tit_TeX,j);
|
||||
fprintf(fidTeX,'\\label{Fig:collinearity:%s:%u_pars}\n',deblank(tittxt),j);
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
|
@ -255,7 +275,7 @@ if SampleSize == 1
|
|||
end
|
||||
end
|
||||
skipline()
|
||||
[U,S,V]=svd(idehess.AHess,0);
|
||||
[~,S,V]=svd(idehess.AHess,0);
|
||||
S=diag(S);
|
||||
if idehess.flag_score
|
||||
if nparam<5
|
||||
|
@ -268,8 +288,6 @@ if SampleSize == 1
|
|||
tex_tit_2=[tittxt,' - Identification patterns (Information matrix): HIGHEST SV'];
|
||||
end
|
||||
else
|
||||
% S = idemoments.S;
|
||||
% V = idemoments.V;
|
||||
if nparam<5
|
||||
f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Identification patterns (moments Information matrix)']);
|
||||
tex_tit_1=[tittxt,' - Identification patterns (moments Information matrix)'];
|
||||
|
@ -299,19 +317,23 @@ if SampleSize == 1
|
|||
set(gca,'xticklabel','')
|
||||
if j==4 || j==nparam || j==8
|
||||
for ip=1:nparam
|
||||
text(ip,-0.02,name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,-0.02,name_tex{ip},'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
end
|
||||
title(['Singular value ',num2str(Stit)])
|
||||
end
|
||||
dyn_saveas(f1,[ IdentifDirectoryName '/' M_.fname '_ident_pattern_' tittxt1 '_1' ],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(f1,[ IdentifDirectoryName '/' fname '_ident_pattern_' tittxt1 '_1' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' M_.fname '_ident_pattern_' tittxt1 '_1','.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_ident_pattern_' tittxt1 '_1','.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_pattern_%s_1}\n',[IdentifDirectoryName '/' M_.fname],tittxt1);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_pattern_%s_1}\n',[IdentifDirectoryName '/' fname],tittxt1);
|
||||
fprintf(fidTeX,'\\caption{%s.}',tex_tit_1);
|
||||
fprintf(fidTeX,'\\label{Fig:ident_pattern:%s:1}\n',tittxt1);
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
|
@ -319,14 +341,14 @@ if SampleSize == 1
|
|||
fclose(fidTeX);
|
||||
end
|
||||
if nparam>4
|
||||
dyn_saveas(f2,[ IdentifDirectoryName '/' M_.fname '_ident_pattern_' tittxt1 '_2' ],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(f2,[ IdentifDirectoryName '/' fname '_ident_pattern_' tittxt1 '_2' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' M_.fname '_ident_pattern_' tittxt1 '_2.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_ident_pattern_' tittxt1 '_2.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_pattern_%s_2}\n',[IdentifDirectoryName '/' M_.fname],tittxt1);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_pattern_%s_2}\n',[IdentifDirectoryName '/' fname],tittxt1);
|
||||
fprintf(fidTeX,'\\caption{%s.}',tex_tit_2);
|
||||
fprintf(fidTeX,'\\label{Fig:ident_pattern:%s:2}\n',tittxt1);
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
|
@ -337,10 +359,10 @@ if SampleSize == 1
|
|||
end
|
||||
|
||||
else
|
||||
hh_fig = dyn_figure(options_.nodisplay,'Name',['MC sensitivities']);
|
||||
hh_fig = dyn_figure(options_.nodisplay,'Name','MC sensitivities');
|
||||
subplot(211)
|
||||
mmm = (idehess.ide_strength_dMOMENTS);
|
||||
[ss, is] = sort(mmm);
|
||||
[~, is] = sort(mmm);
|
||||
mmm = mean(si_dMOMENTSnorm)';
|
||||
mmm = mmm./max(mmm);
|
||||
if advanced
|
||||
|
@ -357,20 +379,24 @@ else
|
|||
set(gca,'xticklabel','')
|
||||
dy = get(gca,'ylim');
|
||||
for ip=1:nparam
|
||||
text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,dy(1),name_tex{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
if advanced
|
||||
legend('Moments','Model','LRE model','Location','Best')
|
||||
end
|
||||
title('MC mean of sensitivity measures')
|
||||
dyn_saveas(hh_fig,[ IdentifDirectoryName '/' M_.fname '_MC_sensitivity' ],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(hh_fig,[ IdentifDirectoryName '/' fname '_MC_sensitivity' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' M_.fname '_MC_sensitivity.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_MC_sensitivity.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_sensitivity}\n',[IdentifDirectoryName '/' M_.fname]);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_sensitivity}\n',[IdentifDirectoryName '/' fname]);
|
||||
fprintf(fidTeX,'\\caption{MC mean of sensitivity measures}');
|
||||
fprintf(fidTeX,'\\label{Fig:_MC_sensitivity}\n');
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
|
@ -379,57 +405,62 @@ else
|
|||
end
|
||||
|
||||
if advanced
|
||||
if ~options_.nodisplay,
|
||||
if ~options_.nodisplay
|
||||
skipline()
|
||||
disp('Displaying advanced diagnostics')
|
||||
end
|
||||
% options_.nograph=1;
|
||||
hh_fig = dyn_figure(options_.nodisplay,'Name','MC Condition Number');
|
||||
subplot(221)
|
||||
hist(log10(idemodel.cond))
|
||||
if isoctave
|
||||
hist(log10(idemodel.cond))
|
||||
else
|
||||
histogram(log10(idemodel.cond))
|
||||
end
|
||||
title('log10 of Condition number in the model')
|
||||
subplot(222)
|
||||
hist(log10(idemoments.cond))
|
||||
if isoctave
|
||||
hist(log10(idemoments.cond))
|
||||
else
|
||||
histogram(log10(idemoments.cond))
|
||||
end
|
||||
title('log10 of Condition number in the moments')
|
||||
subplot(223)
|
||||
hist(log10(idelre.cond))
|
||||
if isoctave
|
||||
hist(log10(idelre.cond))
|
||||
else
|
||||
histogram(log10(idelre.cond))
|
||||
end
|
||||
title('log10 of Condition number in the LRE model')
|
||||
dyn_saveas(hh_fig,[IdentifDirectoryName '/' M_.fname '_ident_COND' ],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(hh_fig,[IdentifDirectoryName '/' fname '_ident_COND' ],options_.nodisplay,options_.graph_format);
|
||||
options_mcf.pvalue_ks = 0.1;
|
||||
options_mcf.pvalue_corr = 0.001;
|
||||
options_mcf.alpha2 = 0;
|
||||
options_mcf.param_names = name;
|
||||
options_mcf.param_names_tex = name_tex;
|
||||
options_mcf.fname_ = M_.fname;
|
||||
options_mcf.fname_ = fname;
|
||||
options_mcf.OutputDirectoryName = IdentifDirectoryName;
|
||||
options_mcf.beha_title = 'LOW condition nbr';
|
||||
options_mcf.nobeha_title = 'HIGH condition nbr';
|
||||
if options_.TeX
|
||||
options_mcf.beha_title_latex = 'LOW condition nbr';
|
||||
options_mcf.nobeha_title_latex = 'HIGH condition nbr';
|
||||
end
|
||||
options_mcf.amcf_name = 'MC_HighestCondNumberLRE';
|
||||
options_mcf.amcf_title = 'MC Highest Condition Number LRE Model';
|
||||
options_mcf.title = 'MC Highest Condition Number LRE Model';
|
||||
ncut=floor(SampleSize/10*9);
|
||||
[dum,is]=sort(idelre.cond);
|
||||
mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_);
|
||||
[~,is]=sort(idelre.cond);
|
||||
gsa.monte_carlo_filtering_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
options_mcf.amcf_name = 'MC_HighestCondNumberModel';
|
||||
options_mcf.amcf_title = 'MC Highest Condition Number Model Solution';
|
||||
options_mcf.title = 'MC Highest Condition Number Model Solution';
|
||||
[dum,is]=sort(idemodel.cond);
|
||||
mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_);
|
||||
[~,is]=sort(idemodel.cond);
|
||||
gsa.monte_carlo_filtering_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
options_mcf.amcf_name = 'MC_HighestCondNumberMoments';
|
||||
options_mcf.amcf_title = 'MC Highest Condition Number Model Moments';
|
||||
options_mcf.title = 'MC Highest Condition Number Model Moments';
|
||||
[dum,is]=sort(idemoments.cond);
|
||||
mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_);
|
||||
% [proba, dproba] = stab_map_1(idemoments.Mco', is(1:ncut), is(ncut+1:end), 'HighestCondNumberMoments_vs_Mco', 1, [], IdentifDirectoryName);
|
||||
% for j=1:nparam,
|
||||
% % ibeh=find(idemoments.Mco(j,:)<0.9);
|
||||
% % inonbeh=find(idemoments.Mco(j,:)>=0.9);
|
||||
% % if ~isempty(ibeh) && ~isempty(inonbeh)
|
||||
% % [proba, dproba] = stab_map_1(params, ibeh, inonbeh, ['HighestMultiCollinearity_',name{j}], 1, [], IdentifDirectoryName);
|
||||
% % end
|
||||
% [~,is]=sort(idemoments.Mco(:,j));
|
||||
% [proba, dproba] = stab_map_1(params, is(1:ncut), is(ncut+1:end), ['MC_HighestMultiCollinearity_',name{j}], 1, [], IdentifDirectoryName, 0.15);
|
||||
% end
|
||||
[~,is]=sort(idemoments.cond);
|
||||
gsa.monte_carlo_filtering_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
if nparam<5
|
||||
f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - MC Identification patterns (moments): HIGHEST SV']);
|
||||
|
@ -459,8 +490,10 @@ else
|
|||
SSS = idemoments.S(:,jj);
|
||||
end
|
||||
subplot(nsubplo,1,jj)
|
||||
post_median=NaN(1,nparam);
|
||||
hpd_interval=NaN(nparam,2);
|
||||
for i=1:nparam
|
||||
[post_mean, post_median(:,i), post_var, hpd_interval(i,:), post_deciles] = posterior_moments(VVV(:,i),0,0.9);
|
||||
[~, post_median(:,i), ~, hpd_interval(i,:)] = posterior_moments(VVV(:,i),0.9);
|
||||
end
|
||||
bar(post_median)
|
||||
hold on, plot(hpd_interval,'--*r'),
|
||||
|
@ -469,19 +502,23 @@ else
|
|||
set(gca,'xticklabel','')
|
||||
if j==4 || j==nparam || j==8
|
||||
for ip=1:nparam
|
||||
text(ip,-0.02,name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
if options_.TeX
|
||||
text(ip,-0.02,name_tex{ip},'rotation',90,'HorizontalAlignment','right','interpreter','latex')
|
||||
else
|
||||
text(ip,-0.02,name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
|
||||
end
|
||||
end
|
||||
end
|
||||
title(['MEAN Singular value ',num2str(Stit)])
|
||||
end
|
||||
dyn_saveas(f1,[IdentifDirectoryName '/' M_.fname '_MC_ident_pattern_1' ],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(f1,[IdentifDirectoryName '/' fname '_MC_ident_pattern_1' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([IdentifDirectoryName '/' M_.fname '_MC_ident_pattern_1.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fidTeX = fopen([IdentifDirectoryName '/' fname '_MC_ident_pattern_1.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_ident_pattern_1}\n',[IdentifDirectoryName '/' M_.fname]);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_ident_pattern_1}\n',[IdentifDirectoryName '/' fname]);
|
||||
fprintf(fidTeX,'\\caption{%s.}',tex_tit_1);
|
||||
fprintf(fidTeX,'\\label{Fig:MC_ident_pattern:1}\n');
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
||||
|
@ -489,14 +526,14 @@ else
|
|||
fclose(fidTeX);
|
||||
end
|
||||
if nparam>4
|
||||
dyn_saveas(f2,[ IdentifDirectoryName '/' M_.fname '_MC_ident_pattern_2' ],options_.nodisplay,options_.graph_format);
|
||||
dyn_saveas(f2,[ IdentifDirectoryName '/' fname '_MC_ident_pattern_2' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' M_.fname '_MC_ident_pattern_2.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_MC_ident_pattern_2.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_ident_pattern_2}\n',[IdentifDirectoryName '/' M_.fname]);
|
||||
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_ident_pattern_2}\n',[IdentifDirectoryName '/' fname]);
|
||||
fprintf(fidTeX,'\\caption{%s.}',tex_tit_2);
|
||||
fprintf(fidTeX,'\\label{Fig:MC_ident_pattern:2}\n');
|
||||
fprintf(fidTeX,'\\end{figure}\n\n');
|
|
@ -1,5 +1,5 @@
|
|||
function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = dynare_identification(options_ident, pdraws0)
|
||||
%function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = dynare_identification(options_ident, pdraws0)
|
||||
function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = run(M_,oo_,options_,bayestopt_,estim_params_,options_ident, pdraws0)
|
||||
% [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = run(options_ident, pdraws0)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called, when the user specifies identification(...); in the mod file. It prepares all identification analysis:
|
||||
% (1) set options, local and persistent variables for a new identification
|
||||
|
@ -11,6 +11,11 @@ function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, ST
|
|||
% to put identification in your mod file, otherwise the preprocessor won't provide all necessary objects
|
||||
% =========================================================================
|
||||
% INPUTS
|
||||
% * M_ [structure] Matlab's structure describing the model
|
||||
% * oo_ [structure] Matlab's structure describing the results
|
||||
% * options_ [structure] Matlab's structure describing the current options
|
||||
% * bayestopt_ [structure] describing the priors
|
||||
% * estim_params_ [structure] characterizing parameters to be estimated
|
||||
% * options_ident [structure] identification options
|
||||
% * pdraws0 [SampleSize by totparam_nbr] optional: matrix of MC sample of model parameters
|
||||
% -------------------------------------------------------------------------
|
||||
|
@ -27,19 +32,19 @@ function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, ST
|
|||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * driver.m
|
||||
% * map_ident_.m
|
||||
% * gsa.map_identification.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * checkpath
|
||||
% * disp_identification
|
||||
% * identification.display
|
||||
% * dyn_waitbar
|
||||
% * dyn_waitbar_close
|
||||
% * get_all_parameters
|
||||
% * get_posterior_parameters
|
||||
% * get_the_name
|
||||
% * identification_analysis
|
||||
% * identification.analysis
|
||||
% * isoctave
|
||||
% * plot_identification
|
||||
% * identification.plot
|
||||
% * dprior.draw
|
||||
% * set_default_option
|
||||
% * set_prior
|
||||
|
@ -65,22 +70,6 @@ function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, ST
|
|||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
|
||||
global M_ options_ oo_ bayestopt_ estim_params_
|
||||
|
||||
% The TeX option crashes MATLAB R2014a run with "-nodisplay" option
|
||||
% (as is done from the testsuite).
|
||||
% Since we can’t directly test whether "-nodisplay" has been passed,
|
||||
% we test for the "source_root" environment variable, which is set
|
||||
% by the testsuite.
|
||||
% Note that it was not tested whether the crash happens with more
|
||||
% recent MATLAB versions, so when OLD_MATLAB_VERSION is increased,
|
||||
% one should make a test before removing this workaround.
|
||||
if options_.TeX && ~isoctave && matlab_ver_less_than('8.4') && ~isempty(getenv('source_root'))
|
||||
warning('Disabling TeX option due to a bug in MATLAB R2014a with -nodisplay')
|
||||
options_.TeX = false;
|
||||
end
|
||||
|
||||
store_options_ = options_; % store options to restore them at the end
|
||||
fname = M_.fname; %model name
|
||||
dname = M_.dname; %model name
|
||||
|
||||
|
@ -106,7 +95,7 @@ end
|
|||
options_ident = set_default_option(options_ident,'gsa_sample_file',0);
|
||||
% 0: do not use sample file
|
||||
% 1: triggers gsa prior sample
|
||||
% 2: triggers gsa Monte-Carlo sample (i.e. loads a sample corresponding to pprior=0 and ppost=0 in dynare_sensitivity options)
|
||||
% 2: triggers gsa Monte-Carlo sample (i.e. loads a sample corresponding to pprior=0 and ppost=0 in sensitivity.run options)
|
||||
% FILENAME: use sample file in provided path
|
||||
options_ident = set_default_option(options_ident,'parameter_set','prior_mean');
|
||||
% 'calibration': use values in M_.params and M_.Sigma_e to update estimated stderr, corr and model parameters (get_all_parameters)
|
||||
|
@ -151,7 +140,7 @@ options_ident = set_default_option(options_ident,'tol_rank','robust');
|
|||
options_ident = set_default_option(options_ident,'tol_deriv',1.e-8);
|
||||
% tolerance level for selecting columns of non-zero derivatives
|
||||
options_ident = set_default_option(options_ident,'tol_sv',1.e-3);
|
||||
% tolerance level for selecting non-zero singular values in identification_checks.m
|
||||
% tolerance level for selecting non-zero singular values in identification.checks.m
|
||||
options_ident = set_default_option(options_ident,'schur_vec_tol',1e-11);
|
||||
% tolerance level used to find nonstationary variables in Schur decomposition of the transition matrix.
|
||||
|
||||
|
@ -192,7 +181,7 @@ if (isfield(options_ident,'no_identification_strength') && options_ident.no_ide
|
|||
options_ident.no_identification_moments = 0;
|
||||
end
|
||||
|
||||
%overwrite setting, as dynare_sensitivity does not make use of spectrum and minimal system
|
||||
%overwrite setting, as sensitivity.run does not make use of spectrum and minimal system
|
||||
if isfield(options_,'opt_gsa') && isfield(options_.opt_gsa,'identification') && options_.opt_gsa.identification == 1
|
||||
options_ident.no_identification_minimal = 1;
|
||||
options_ident.no_identification_spectrum = 1;
|
||||
|
@ -268,11 +257,11 @@ if options_ident.gsa_sample_file
|
|||
end
|
||||
pdraws0 = [lpmatx lpmat(istable,:)];
|
||||
clear lpmat lpmat0 istable;
|
||||
elseif nargin==1
|
||||
elseif nargin==6
|
||||
pdraws0=[];
|
||||
end
|
||||
external_sample=0;
|
||||
if nargin==2 || ~isempty(pdraws0)
|
||||
if nargin==7 || ~isempty(pdraws0)
|
||||
% change settings if there is an external sample provided as input argument
|
||||
options_ident.prior_mc = size(pdraws0,1);
|
||||
options_ident.load_ident_files = 0;
|
||||
|
@ -313,18 +302,18 @@ options_.mode_compute = 0;
|
|||
options_.plot_priors = 0;
|
||||
options_.smoother = 1;
|
||||
options_.options_ident = [];
|
||||
[dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, bayestopt_, bounds] = dynare_estimation_init(M_.endo_names, fname, 1, M_, options_, oo_, estim_params_, bayestopt_);
|
||||
[~, dataset_info, ~, ~, M_, options_, oo_, estim_params_, bayestopt_] = dynare_estimation_init(M_.endo_names, fname, 1, M_, options_, oo_, estim_params_, bayestopt_);
|
||||
|
||||
% set method to compute identification Jacobians (kronflag). Default:0
|
||||
options_ident = set_default_option(options_ident,'analytic_derivation_mode', options_.analytic_derivation_mode); % if not set by user, inherit default global one
|
||||
% 0: efficient sylvester equation method to compute analytical derivatives as in Ratto & Iskrev (2012)
|
||||
% 1: kronecker products method to compute analytical derivatives as in Iskrev (2010) (only for order=1)
|
||||
% -1: numerical two-sided finite difference method to compute numerical derivatives of all identification Jacobians using function identification_numerical_objective.m (previously thet2tau.m)
|
||||
% -1: numerical two-sided finite difference method to compute numerical derivatives of all identification Jacobians using function identification.numerical_objective.m (previously thet2tau.m)
|
||||
% -2: numerical two-sided finite difference method to compute numerically dYss, dg1, dg2, dg3, d2Yss and d2g1, the identification Jacobians are then computed analytically as with 0
|
||||
|
||||
if options_.discretionary_policy || options_.ramsey_policy
|
||||
if options_ident.analytic_derivation_mode~=-1
|
||||
fprintf('dynare_identification: discretionary_policy and ramsey_policy require analytic_derivation_mode=-1. Resetting the option.')
|
||||
fprintf('identification.run: discretionary_policy and ramsey_policy require analytic_derivation_mode=-1. Resetting the option.')
|
||||
options_ident.analytic_derivation_mode=-1;
|
||||
end
|
||||
end
|
||||
|
@ -374,11 +363,11 @@ if prior_exist % use estimated_params block
|
|||
name_tex = cell(totparam_nbr,1); %initialize cell for TeX parameter names
|
||||
for jj=1:totparam_nbr
|
||||
if options_.TeX
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(jj,options_.TeX,M_,estim_params_,options_);
|
||||
name_tex{jj,1} = strrep(param_name_tex_temp,'$',''); %ordering corresponds to estimated_params
|
||||
[param_name_temp, param_name_tex_temp]= get_the_name(jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
name_tex{jj,1} =param_name_tex_temp;
|
||||
name{jj,1} = param_name_temp; %ordering corresponds to estimated_params
|
||||
else
|
||||
param_name_temp = get_the_name(jj,options_.TeX,M_,estim_params_,options_);
|
||||
param_name_temp = get_the_name(jj,options_.TeX,M_,estim_params_,options_.varobs);
|
||||
name{jj,1} = param_name_temp; %ordering corresponds to estimated_params
|
||||
end
|
||||
end
|
||||
|
@ -392,10 +381,10 @@ else % no estimated_params block, choose all model parameters and all stderr par
|
|||
totparam_nbr = modparam_nbr+stderrparam_nbr;
|
||||
name = cellfun(@(x) horzcat('SE_', x), M_.exo_names, 'UniformOutput', false); %names for stderr parameters
|
||||
name = vertcat(name, M_.param_names);
|
||||
name_tex = cellfun(@(x) horzcat('$ SE_{', x, '} $'), M_.exo_names, 'UniformOutput', false);
|
||||
name_tex = vertcat(name_tex, M_.param_names_tex);
|
||||
name_tex = cellfun(@(x) horzcat('$ SE_{', x, '} $'), M_.exo_names_tex, 'UniformOutput', false);
|
||||
name_tex = vertcat(name_tex, cellfun(@(x) horzcat('$ ', x, ' $'), M_.param_names_tex, 'UniformOutput', false));
|
||||
if ~isequal(M_.H,0)
|
||||
fprintf('\ndynare_identification:: Identification does not support measurement errors (yet) and will ignore them in the following. To test their identifiability, instead define them explicitly as varexo and provide measurement equations in the model definition.\n')
|
||||
fprintf('\nidentification.run:: Identification does not support measurement errors (yet) and will ignore them in the following. To test their identifiability, instead define them explicitly as varexo and provide measurement equations in the model definition.\n')
|
||||
end
|
||||
end
|
||||
options_ident.name_tex = name_tex;
|
||||
|
@ -413,13 +402,13 @@ end
|
|||
% settings dependent on number of parameters
|
||||
options_ident = set_default_option(options_ident,'max_dim_cova_group',min([2,totparam_nbr-1]));
|
||||
options_ident.max_dim_cova_group = min([options_ident.max_dim_cova_group,totparam_nbr-1]);
|
||||
% In brute force search (ident_bruteforce.m) when advanced=1 this option sets the maximum dimension of groups of parameters that best reproduce the behavior of each single model parameter
|
||||
% In brute force search (identification.bruteforce.m) when advanced=1 this option sets the maximum dimension of groups of parameters that best reproduce the behavior of each single model parameter
|
||||
|
||||
options_ident = set_default_option(options_ident,'checks_via_subsets',0);
|
||||
% 1: uses identification_checks_via_subsets.m to compute problematic parameter combinations
|
||||
% 0: uses identification_checks.m to compute problematic parameter combinations [default]
|
||||
% 1: uses identification.checks_via_subsets.m to compute problematic parameter combinations
|
||||
% 0: uses identification.checks.m to compute problematic parameter combinations [default]
|
||||
options_ident = set_default_option(options_ident,'max_dim_subsets_groups',min([4,totparam_nbr-1]));
|
||||
% In identification_checks_via_subsets.m, when checks_via_subsets=1, this option sets the maximum dimension of groups of parameters for which the corresponding rank criteria is checked
|
||||
% In identification.checks_via_subsets.m, when checks_via_subsets=1, this option sets the maximum dimension of groups of parameters for which the corresponding rank criteria is checked
|
||||
|
||||
|
||||
% store identification options
|
||||
|
@ -481,8 +470,8 @@ if iload <=0
|
|||
end
|
||||
options_ident.tittxt = parameters; %title text for graphs and figures
|
||||
% perform identification analysis for single point
|
||||
[ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, derivatives_info_point, info, error_indicator_point] = ...
|
||||
identification_analysis(params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end implies initialization of persistent variables
|
||||
[ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, ~, info, error_indicator_point] = ...
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end implies initialization of persistent variables
|
||||
if info(1)~=0
|
||||
% there are errors in the solution algorithm
|
||||
message = get_error_message(info,options_);
|
||||
|
@ -498,8 +487,8 @@ if iload <=0
|
|||
params = Prior.draw();
|
||||
options_ident.tittxt = 'Random_prior_params'; %title text for graphs and figures
|
||||
% perform identification analysis
|
||||
[ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, derivatives_info_point, info, error_indicator_point] = ...
|
||||
identification_analysis(params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
|
||||
[ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, ~, info, error_indicator_point] = ...
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
|
||||
end
|
||||
end
|
||||
if info(1)
|
||||
|
@ -524,10 +513,11 @@ if iload <=0
|
|||
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_moments_point', 'ide_spectrum_point', 'ide_minimal_point', 'ide_hess_point', 'ide_reducedform_point', 'ide_dynamic_point', 'store_options_ident');
|
||||
save([IdentifDirectoryName '/' fname '_' parameters '_identif.mat'], 'ide_moments_point', 'ide_spectrum_point', 'ide_minimal_point', 'ide_hess_point', 'ide_reducedform_point', 'ide_dynamic_point', 'store_options_ident');
|
||||
% display results of identification analysis
|
||||
disp_identification(params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
|
||||
identification.display(params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
|
||||
if ~options_ident.no_identification_strength && ~options_.nograph && ~error_indicator_point.identification_strength && ~error_indicator_point.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the moment information matrix and (ii) plot advanced analysis graphs
|
||||
plot_identification(params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, IdentifDirectoryName, parameters_TeX, name_tex);
|
||||
identification.plot(M_,params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, parameters_TeX, name_tex);
|
||||
end
|
||||
|
||||
if SampleSize > 1
|
||||
|
@ -539,7 +529,7 @@ if iload <=0
|
|||
file_index = 0; % initialize counter for files (if options_.MaxNumberOfBytes is reached, we store results in files)
|
||||
options_MC = options_ident; %store options structure for Monte Carlo analysis
|
||||
options_MC.advanced = 0; %do not run advanced checking in a Monte Carlo analysis
|
||||
options_ident.checks_via_subsets = 0; % for Monte Carlo analysis currently only identification_checks and not identification_checks_via_subsets is supported
|
||||
options_ident.checks_via_subsets = 0; % for Monte Carlo analysis currently only identification.checks and not identification.checks_via_subsets is supported
|
||||
else
|
||||
iteration = 1; % iteration equals SampleSize and we are finished
|
||||
pdraws = []; % to have output object otherwise map_ident.m may crash
|
||||
|
@ -552,8 +542,8 @@ if iload <=0
|
|||
end
|
||||
options_ident.tittxt = []; % clear title text for graphs and figures
|
||||
% run identification analysis
|
||||
[ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, ide_derivatives_info, info, error_indicator] = ...
|
||||
identification_analysis(params, indpmodel, indpstderr, indpcorr, options_MC, dataset_info, prior_exist, 0); % the 0 implies that we do not initialize persistent variables anymore
|
||||
[ide_moments, ide_spectrum, ide_minimal, ~, ide_reducedform, ide_dynamic, ~, info, error_indicator] = ...
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_MC, dataset_info, prior_exist, 0); % the 0 implies that we do not initialize persistent variables anymore
|
||||
|
||||
if iteration==0 && info(1)==0 % preallocate storage in the first admissable run
|
||||
delete([IdentifDirectoryName '/' fname '_identif_*.mat']) % delete previously saved results
|
||||
|
@ -746,7 +736,7 @@ if iload <=0
|
|||
end
|
||||
run_index = 0; % reset index
|
||||
end
|
||||
if SampleSize > 1
|
||||
if SampleSize > 1 && mod(iteration,3)
|
||||
dyn_waitbar(iteration/SampleSize, h, ['MC identification checks ', int2str(iteration), '/', int2str(SampleSize)]);
|
||||
end
|
||||
end
|
||||
|
@ -796,28 +786,41 @@ if iload <=0
|
|||
else
|
||||
maxrun_dMINIMAL = 0;
|
||||
end
|
||||
si_dDYNAMICnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_si_dDYNAMIC,2));
|
||||
if ~options_MC.no_identification_reducedform
|
||||
si_dREDUCEDFORMnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_si_dREDUCEDFORM,2));
|
||||
end
|
||||
if ~options_MC.no_identification_moments
|
||||
si_dMOMENTSnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_si_dMOMENTS,2));
|
||||
end
|
||||
if ~options_MC.no_identification_spectrum
|
||||
dSPECTRUMnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_dSPECTRUM,2));
|
||||
end
|
||||
if ~options_MC.no_identification_minimal
|
||||
dMINIMALnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_dMINIMAL,2));
|
||||
end
|
||||
for irun=1:max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL])
|
||||
iter=iter+1;
|
||||
% note that this is not the same si_dDYNAMICnorm as computed in identification_analysis
|
||||
% note that this is not the same si_dDYNAMICnorm as computed in identification.analysis
|
||||
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
|
||||
si_dDYNAMICnorm(iter,:) = vnorm(STO_si_dDYNAMIC(:,:,irun)./repmat(normalize_STO_DYNAMIC,1,totparam_nbr-(stderrparam_nbr+corrparam_nbr))).*normaliz1((stderrparam_nbr+corrparam_nbr)+1:end);
|
||||
si_dDYNAMICnorm(iter,:) = identification.vnorm(STO_si_dDYNAMIC(:,:,irun)./repmat(normalize_STO_DYNAMIC,1,totparam_nbr-(stderrparam_nbr+corrparam_nbr))).*normaliz1((stderrparam_nbr+corrparam_nbr)+1:end);
|
||||
if ~options_MC.no_identification_reducedform && ~isempty(STO_si_dREDUCEDFORM)
|
||||
% note that this is not the same si_dREDUCEDFORMnorm as computed in identification_analysis
|
||||
% note that this is not the same si_dREDUCEDFORMnorm as computed in identification.analysis
|
||||
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
|
||||
si_dREDUCEDFORMnorm(iter,:) = vnorm(STO_si_dREDUCEDFORM(:,:,irun)./repmat(normalize_STO_REDUCEDFORM,1,totparam_nbr)).*normaliz1;
|
||||
si_dREDUCEDFORMnorm(iter,:) = identification.vnorm(STO_si_dREDUCEDFORM(:,:,irun)./repmat(normalize_STO_REDUCEDFORM,1,totparam_nbr)).*normaliz1;
|
||||
end
|
||||
if ~options_MC.no_identification_moments && ~isempty(STO_si_dMOMENTS)
|
||||
% note that this is not the same si_dMOMENTSnorm as computed in identification_analysis
|
||||
% note that this is not the same si_dMOMENTSnorm as computed in identification.analysis
|
||||
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
|
||||
si_dMOMENTSnorm(iter,:) = vnorm(STO_si_dMOMENTS(:,:,irun)./repmat(normalize_STO_MOMENTS,1,totparam_nbr)).*normaliz1;
|
||||
si_dMOMENTSnorm(iter,:) = identification.vnorm(STO_si_dMOMENTS(:,:,irun)./repmat(normalize_STO_MOMENTS,1,totparam_nbr)).*normaliz1;
|
||||
end
|
||||
if ~options_MC.no_identification_spectrum && ~isempty(STO_dSPECTRUM)
|
||||
% note that this is not the same dSPECTRUMnorm as computed in identification_analysis
|
||||
dSPECTRUMnorm(iter,:) = vnorm(STO_dSPECTRUM(:,:,irun)); %not yet used
|
||||
% note that this is not the same dSPECTRUMnorm as computed in identification.analysis
|
||||
dSPECTRUMnorm(iter,:) = identification.vnorm(STO_dSPECTRUM(:,:,irun)); %not yet used
|
||||
end
|
||||
if ~options_MC.no_identification_minimal && ~isempty(STO_dMINIMAL)
|
||||
% note that this is not the same dMINIMALnorm as computed in identification_analysis
|
||||
dMINIMALnorm(iter,:) = vnorm(STO_dMINIMAL(:,:,irun)); %not yet used
|
||||
% note that this is not the same dMINIMALnorm as computed in identification.analysis
|
||||
dMINIMALnorm(iter,:) = identification.vnorm(STO_dMINIMAL(:,:,irun)); %not yet used
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -844,7 +847,7 @@ else
|
|||
options_.options_ident = options_ident;
|
||||
end
|
||||
|
||||
%% if dynare_identification is called as it own function (not through identification command) and if we load files
|
||||
%% if identification.run is called as it own function (not through identification command) and if we load files
|
||||
if nargout>3 && iload
|
||||
filnam = dir([IdentifDirectoryName '/' fname '_identif_*.mat']);
|
||||
STO_si_dDYNAMIC = [];
|
||||
|
@ -873,10 +876,11 @@ end
|
|||
if iload
|
||||
%if previous analysis is loaded
|
||||
fprintf(['Testing %s\n',parameters]);
|
||||
disp_identification(ide_hess_point.params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
|
||||
identification.display(ide_hess_point.params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
|
||||
if ~options_.nograph && ~error_indicator_point.identification_strength && ~error_indicator_point.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(ide_hess_point.params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, IdentifDirectoryName, [], name_tex);
|
||||
identification.plot(M_,ide_hess_point.params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, [], name_tex);
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -886,11 +890,12 @@ if SampleSize > 1
|
|||
%print results to console but make sure advanced=0
|
||||
advanced0 = options_ident.advanced;
|
||||
options_ident.advanced = 0;
|
||||
disp_identification(pdraws, IDE_REDUCEDFORM, IDE_MOMENTS, IDE_SPECTRUM, IDE_MINIMAL, name, options_ident);
|
||||
identification.display(pdraws, IDE_REDUCEDFORM, IDE_MOMENTS, IDE_SPECTRUM, IDE_MINIMAL, name, options_ident);
|
||||
options_ident.advanced = advanced0; % reset advanced setting
|
||||
if ~options_.nograph && isfield(ide_hess_point,'ide_strength_dMOMENTS')
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(pdraws, IDE_MOMENTS, ide_hess_point, IDE_REDUCEDFORM, IDE_DYNAMIC, options_ident.advanced, 'MC sample ', name, IdentifDirectoryName, [], name_tex);
|
||||
identification.plot(M_, pdraws, IDE_MOMENTS, ide_hess_point, IDE_REDUCEDFORM, IDE_DYNAMIC, options_ident.advanced, 'MC sample ', name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, [], name_tex);
|
||||
end
|
||||
%advanced display and plots for MC Sample, i.e. look at draws with highest/lowest condition number
|
||||
if options_ident.advanced
|
||||
|
@ -906,16 +911,17 @@ if SampleSize > 1
|
|||
fprintf('\nTesting %s.\n',tittxt);
|
||||
if ~iload
|
||||
options_ident.tittxt = tittxt; %title text for graphs and figures
|
||||
[ide_moments_max, ide_spectrum_max, ide_minimal_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, derivatives_info_max, info_max, error_indicator_max] = ...
|
||||
identification_analysis(pdraws(jmax,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes some persistent variables
|
||||
[ide_moments_max, ide_spectrum_max, ide_minimal_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, ~, ~, error_indicator_max] = ...
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jmax,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes some persistent variables
|
||||
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_hess_max', 'ide_moments_max', 'ide_spectrum_max', 'ide_minimal_max','ide_reducedform_max', 'ide_dynamic_max', 'jmax', '-append');
|
||||
end
|
||||
advanced0 = options_ident.advanced; options_ident.advanced = 1; % make sure advanced setting is on
|
||||
disp_identification(pdraws(jmax,:), ide_reducedform_max, ide_moments_max, ide_spectrum_max, ide_minimal_max, name, options_ident);
|
||||
identification.display(pdraws(jmax,:), ide_reducedform_max, ide_moments_max, ide_spectrum_max, ide_minimal_max, name, options_ident);
|
||||
options_ident.advanced = advanced0; %reset advanced setting
|
||||
if ~options_.nograph && ~error_indicator_max.identification_strength && ~error_indicator_max.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(pdraws(jmax,:), ide_moments_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, 1, tittxt, name, IdentifDirectoryName, tittxt, name_tex);
|
||||
identification.plot(M_, pdraws(jmax,:), ide_moments_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, 1, tittxt, name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt, name_tex);
|
||||
end
|
||||
|
||||
% SMALLEST condition number
|
||||
|
@ -924,16 +930,17 @@ if SampleSize > 1
|
|||
fprintf('Testing %s.\n',tittxt);
|
||||
if ~iload
|
||||
options_ident.tittxt = tittxt; %title text for graphs and figures
|
||||
[ide_moments_min, ide_spectrum_min, ide_minimal_min, ide_hess_min, ide_reducedform_min, ide_dynamic_min, derivatives_info_min, info_min, error_indicator_min] = ...
|
||||
identification_analysis(pdraws(jmin,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes persistent variables
|
||||
[ide_moments_min, ide_spectrum_min, ide_minimal_min, ide_hess_min, ide_reducedform_min, ide_dynamic_min, ~, ~, error_indicator_min] = ...
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jmin,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes persistent variables
|
||||
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_hess_min', 'ide_moments_min','ide_spectrum_min','ide_minimal_min','ide_reducedform_min', 'ide_dynamic_min', 'jmin', '-append');
|
||||
end
|
||||
advanced0 = options_ident.advanced; options_ident.advanced = 1; % make sure advanced setting is on
|
||||
disp_identification(pdraws(jmin,:), ide_reducedform_min, ide_moments_min, ide_spectrum_min, ide_minimal_min, name, options_ident);
|
||||
identification.display(pdraws(jmin,:), ide_reducedform_min, ide_moments_min, ide_spectrum_min, ide_minimal_min, name, options_ident);
|
||||
options_ident.advanced = advanced0; %reset advanced setting
|
||||
if ~options_.nograph && ~error_indicator_min.identification_strength && ~error_indicator_min.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(pdraws(jmin,:),ide_moments_min,ide_hess_min,ide_reducedform_min,ide_dynamic_min,1,tittxt,name,IdentifDirectoryName,tittxt,name_tex);
|
||||
identification.plot(M_, pdraws(jmin,:),ide_moments_min,ide_hess_min,ide_reducedform_min,ide_dynamic_min,1,tittxt,name,...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt,name_tex);
|
||||
end
|
||||
% reset nodisplay option
|
||||
options_.nodisplay = store_nodisplay;
|
||||
|
@ -947,14 +954,15 @@ if SampleSize > 1
|
|||
if ~iload
|
||||
options_ident.tittxt = tittxt; %title text for graphs and figures
|
||||
[ide_moments_(j), ide_spectrum_(j), ide_minimal_(j), ide_hess_(j), ide_reducedform_(j), ide_dynamic_(j), derivatives_info_(j), info_resolve, error_indicator_j] = ...
|
||||
identification_analysis(pdraws(jcrit(j),:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jcrit(j),:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
|
||||
end
|
||||
advanced0 = options_ident.advanced; options_ident.advanced = 1; %make sure advanced setting is on
|
||||
disp_identification(pdraws(jcrit(j),:), ide_reducedform_(j), ide_moments_(j), ide_spectrum_(j), ide_minimal_(j), name, options_ident);
|
||||
identification.display(pdraws(jcrit(j),:), ide_reducedform_(j), ide_moments_(j), ide_spectrum_(j), ide_minimal_(j), name, options_ident);
|
||||
options_ident.advanced = advanced0; % reset advanced
|
||||
if ~options_.nograph && ~error_indicator_j.identification_strength && ~error_indicator_j.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(pdraws(jcrit(j),:), ide_moments_(j), ide_hess_(j), ide_reducedform_(j), ide_dynamic_(j), 1, tittxt, name, IdentifDirectoryName, tittxt, name_tex);
|
||||
identification.plot(M_, pdraws(jcrit(j),:), ide_moments_(j), ide_hess_(j), ide_reducedform_(j), ide_dynamic_(j), 1, tittxt, name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt, name_tex);
|
||||
end
|
||||
end
|
||||
if ~iload
|
||||
|
@ -971,5 +979,3 @@ end
|
|||
warning_config;
|
||||
|
||||
fprintf('\n==== Identification analysis completed ====\n\n')
|
||||
|
||||
options_ = store_options_; %restore options set
|
|
@ -12,7 +12,7 @@ function [cmm, mm] = simulated_moment_uncertainty(indx, periods, replic,options_
|
|||
% - cmm: [n_moments by n_moments] covariance matrix of simulated moments
|
||||
% - mm: [n_moments by replic] matrix of moments
|
||||
|
||||
% Copyright © 2009-2018 Dynare Team
|
||||
% Copyright © 2009-2024 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -60,15 +60,10 @@ end
|
|||
|
||||
oo_.dr=set_state_space(oo_.dr,M_);
|
||||
|
||||
|
||||
if options_.logged_steady_state %if steady state was previously logged, undo this
|
||||
oo_.dr.ys=exp(oo_.dr.ys);
|
||||
oo_.steady_state=exp(oo_.steady_state);
|
||||
options_.logged_steady_state=0;
|
||||
logged_steady_state_indicator=1;
|
||||
evalin('base','options_.logged_steady_state=0;')
|
||||
else
|
||||
logged_steady_state_indicator=0;
|
||||
end
|
||||
|
||||
[oo_.dr,info,M_.params] = compute_decision_rules(M_,options_,oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
|
@ -92,7 +87,6 @@ else
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
for j=1:replic
|
||||
[ys, oo_.exo_simul] = simult(y0,oo_.dr,M_,options_);%do simulation
|
||||
oo_=disp_moments(ys, options_.varobs,M_,options_,oo_); %get moments
|
||||
|
@ -106,8 +100,5 @@ for j=1:replic
|
|||
end
|
||||
dyn_waitbar_close(h);
|
||||
|
||||
if logged_steady_state_indicator
|
||||
evalin('base','options_.logged_steady_state=1;') %reset base workspace option to conform to base oo_
|
||||
end
|
||||
cmm = cov(mm');
|
||||
disp('Simulated moment uncertainty ... done!')
|
|
@ -1,22 +1,28 @@
|
|||
function oo_ = Jtest(xparam, objective_function, Woptflag, oo_, options_mom_, bayestopt_, Bounds, estim_params_, M_, nobs)
|
||||
% function oo_ = Jtest(xparam, objective_function, Woptflag, oo_, options_mom_, bayestopt_, Bounds, estim_params_, M_, nobs)
|
||||
function J_test = Jtest(xparam, objective_function, Q, model_moments, m_data, data_moments, weighting_info, options_mom_, M_, estim_params_, bayestopt_, BoundsInfo, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% J_test = Jtest(xparam, objective_function, Q, model_moments, m_data, data_moments, weighting_info, options_mom_, M_, estim_params_, bayestopt_, BoundsInfo, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% -------------------------------------------------------------------------
|
||||
% Computes the J-test statistic and p-value given a GMM/SMM estimation
|
||||
% -------------------------------------------------------------------------
|
||||
% Computes the J-test statistic and p-value for a GMM/SMM estimation
|
||||
% =========================================================================
|
||||
% INPUTS
|
||||
% xparam: [vector] estimated parameter vector
|
||||
% objective_function: [function handle] objective function
|
||||
% Woptflag: [logical] flag if optimal weighting matrix has already been computed
|
||||
% oo_: [struct] results
|
||||
% options_mom_: [struct] options
|
||||
% bayestopt_: [struct] information on priors
|
||||
% Bounds: [struct] bounds on parameters
|
||||
% estim_params_: [struct] information on estimated parameters
|
||||
% M_: [struct] information on the model
|
||||
% nobs: [scalar] number of observations
|
||||
% xparam: [vector] estimated parameter vector
|
||||
% objective_function: [function handle] objective function
|
||||
% Q: [scalar] value of moments distance criterion
|
||||
% model_moments: [vector] model moments
|
||||
% m_data: [matrix] selected empirical moments at each point in time
|
||||
% data_moments: [vector] empirical moments
|
||||
% weighting_info: [struct] information on weighting matrix
|
||||
% options_mom_: [struct] options
|
||||
% M_: [struct] model information
|
||||
% estim_params_: [struct] estimated parameters
|
||||
% bayestopt_: [struct] info on prior distributions
|
||||
% BoundsInfo: [struct] info bounds on parameters
|
||||
% dr: [struct] reduced form model
|
||||
% endo_steady_state: [vector] steady state of endogenous variables (initval)
|
||||
% exo_steady_state: [vector] steady state of exogenous variables (initval)
|
||||
% exo_det_steady_state: [vector] steady state of deterministic exogenous variables (initval)
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUT
|
||||
% oo_: [struct] updated results
|
||||
% J_test: [struct] results of J test
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% o mom.run
|
||||
|
@ -24,7 +30,8 @@ function oo_ = Jtest(xparam, objective_function, Woptflag, oo_, options_mom_, ba
|
|||
% This function calls
|
||||
% o mom.objective_function
|
||||
% o mom.optimal_weighting_matrix
|
||||
% =========================================================================
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
|
@ -41,27 +48,26 @@ function oo_ = Jtest(xparam, objective_function, Woptflag, oo_, options_mom_, ba
|
|||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
|
||||
|
||||
if options_mom_.mom.mom_nbr > length(xparam)
|
||||
% Get optimal weighting matrix for J test, if necessary
|
||||
if ~Woptflag
|
||||
W_opt = mom.optimal_weighting_matrix(oo_.mom.m_data, oo_.mom.model_moments, options_mom_.mom.bartlett_kernel_lag);
|
||||
oo_J = oo_;
|
||||
oo_J.mom.Sw = chol(W_opt);
|
||||
fval = feval(objective_function, xparam, Bounds, oo_J, estim_params_, M_, options_mom_);
|
||||
if ~weighting_info.Woptflag
|
||||
W_opt = mom.optimal_weighting_matrix(m_data, model_moments, options_mom_.mom.bartlett_kernel_lag);
|
||||
weighting_info.Sw = chol(W_opt);
|
||||
fval = feval(objective_function, xparam, data_moments, weighting_info, options_mom_, M_, estim_params_, bayestopt_, BoundsInfo, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
else
|
||||
fval = oo_.mom.Q;
|
||||
fval = Q;
|
||||
end
|
||||
% Compute J statistic
|
||||
if strcmp(options_mom_.mom.mom_method,'SMM')
|
||||
Variance_correction_factor = options_mom_.mom.variance_correction_factor;
|
||||
variance_correction_factor = options_mom_.mom.variance_correction_factor;
|
||||
elseif strcmp(options_mom_.mom.mom_method,'GMM')
|
||||
Variance_correction_factor = 1;
|
||||
variance_correction_factor = 1;
|
||||
end
|
||||
oo_.mom.J_test.j_stat = nobs*Variance_correction_factor*fval/options_mom_.mom.weighting_matrix_scaling_factor;
|
||||
oo_.mom.J_test.degrees_freedom = length(oo_.mom.model_moments)-length(xparam);
|
||||
oo_.mom.J_test.p_val = 1-chi2cdf(oo_.mom.J_test.j_stat, oo_.mom.J_test.degrees_freedom);
|
||||
fprintf('\nValue of J-test statistic: %f\n',oo_.mom.J_test.j_stat);
|
||||
fprintf('p-value of J-test statistic: %f\n',oo_.mom.J_test.p_val);
|
||||
J_test.j_stat = options_mom_.nobs*variance_correction_factor*fval/options_mom_.mom.weighting_matrix_scaling_factor;
|
||||
J_test.degrees_freedom = length(model_moments)-length(xparam);
|
||||
J_test.p_val = 1-chi2cdf(J_test.j_stat, J_test.degrees_freedom);
|
||||
fprintf('\nValue of J-test statistic: %f\n',J_test.j_stat);
|
||||
fprintf('p-value of J-test statistic: %f\n',J_test.p_val);
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
function [irf_matching_file_name, irf_matching_file_path] = check_irf_matching_file(irf_matching_file)
|
||||
% [irf_matching_file_name, irf_matching_file_path] = check_irf_matching_file(irf_matching_file)
|
||||
% -------------------------------------------------------------------------
|
||||
% Check if the provided irf_matching_file is a valid MATLAB function with
|
||||
% .m extension and return name, path and extension of the file.
|
||||
% -------------------------------------------------------------------------
|
||||
% INPUTS
|
||||
% - irf_matching_file: [string] user provided name (with possible path and extension)
|
||||
% of the MATLAB function that transforms model IRFs
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUTS
|
||||
% - irf_matching_file_name: [string] name of the MATLAB function (without extension)
|
||||
% - irf_matching_file_path: [string] path to irf_matching_file_name
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% - mom.run
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
if isempty(irf_matching_file)
|
||||
% no irf_matching_file provided, so no transformations will be done
|
||||
irf_matching_file_name = '';
|
||||
irf_matching_file_path = '';
|
||||
else
|
||||
[irf_matching_file_path, irf_matching_file_name, irf_matching_file_ext] = fileparts(irf_matching_file);
|
||||
% make sure file is a MATLAB function with .m extension
|
||||
if ~strcmp(irf_matching_file_ext,'.m')
|
||||
if strcmp(irf_matching_file_ext,'')
|
||||
irf_matching_file_ext = '.m';
|
||||
else
|
||||
error('method_of_moments: ''irf_matching_file'' needs to point towards a MATLAB function with extension ''.m''!');
|
||||
end
|
||||
end
|
||||
if isempty(irf_matching_file_path)
|
||||
irf_matching_file_path = '.';
|
||||
end
|
||||
if exist([irf_matching_file_path filesep irf_matching_file_name irf_matching_file_ext],'file') ~= 2
|
||||
error('method_of_moments: Could not find a ''irf_matching_file'' called ''%s''!',[irf_matching_file_path filesep irf_matching_file_name irf_matching_file_ext]);
|
||||
end
|
||||
end
|
|
@ -1,33 +1,33 @@
|
|||
function options_mom_ = default_option_mom_values(options_mom_, options_, dname, doBayesianEstimation)
|
||||
% function options_mom_ = default_option_mom_values(options_mom_, options_, dname, doBayesianEstimation)
|
||||
|
||||
% Returns structure containing the options for method_of_moments command
|
||||
|
||||
% options_mom_ is local and contains default and user-specified values for
|
||||
% all settings needed for the method of moments estimation. Some options,
|
||||
% though, are set by the preprocessor into options_ and we copy these over.
|
||||
% The idea is to be independent of options_ and have full control of the
|
||||
% estimation instead of possibly having to deal with options chosen somewhere
|
||||
% else in the mod file.
|
||||
|
||||
% =========================================================================
|
||||
function options_mom_ = default_option_mom_values(options_mom_, options_, dname, do_bayesian_estimation)
|
||||
% options_mom_ = default_option_mom_values(options_mom_, options_, dname, do_bayesian_estimation)
|
||||
% -------------------------------------------------------------------------
|
||||
% Returns structure containing the options for method_of_moments command.
|
||||
% Note 1: options_mom_ is local and contains default and user-specified
|
||||
% values for all settings needed for the method of moments estimation.
|
||||
% Some options, though, are set by the preprocessor into options_ and we
|
||||
% copy these over. The idea is to be independent of options_ and have full
|
||||
% control of the estimation instead of possibly having to deal with options
|
||||
% chosen somewhere else in the mod file.
|
||||
% Note 2: we call a "mode" the minimum of the objective function, i.e.
|
||||
% the parameter vector that minimizes the distance between the moments/IRFs
|
||||
% computed from the model and the moments/IRFs computed from the data.
|
||||
% -------------------------------------------------------------------------
|
||||
% INPUTS
|
||||
% o options_mom_: [structure] information about all (user-specified and updated) settings used in estimation (options_mom_)
|
||||
% o options_: [structure] information on global options
|
||||
% o dname: [string] name of directory to store results
|
||||
% o doBayesianEstimation [boolean] indicator whether we do Bayesian estimation
|
||||
% o options_mom_: [structure] all user-specified settings (from the method_of_moments command)
|
||||
% o options_: [structure] global options
|
||||
% o dname: [string] default name of directory to store results
|
||||
% o do_bayesian_estimation [boolean] indicator whether we do Bayesian estimation
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUTS
|
||||
% o oo_: [structure] storage for results (oo_)
|
||||
% o options_mom_: [structure] information about all (user-specified and updated) settings used in estimation (options_mom_)
|
||||
% o options_mom_: [structure] all user-specified and updated settings required for method_of_moments estimation
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% o mom.run
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% o set_default_option
|
||||
% o user_has_matlab_license
|
||||
% o user_has_octave_forge_package
|
||||
% o set_default_option
|
||||
% o user_has_matlab_license
|
||||
% o user_has_octave_forge_package
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
|
@ -46,34 +46,43 @@ function options_mom_ = default_option_mom_values(options_mom_, options_, dname,
|
|||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
|
||||
|
||||
mom_method = options_mom_.mom.mom_method; % this is a required option
|
||||
|
||||
|
||||
% -------------------------------------------------------------------------
|
||||
% LIMITATIONS
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
if options_.logged_steady_state || options_.loglinear
|
||||
error('method_of_moments: The loglinear option is not supported. Please append the required logged variables as auxiliary equations.')
|
||||
error('method_of_moments: The loglinear option is not supported. Please append the required logged variables as auxiliary equations.');
|
||||
else
|
||||
options_mom_.logged_steady_state = 0;
|
||||
options_mom_.loglinear = false;
|
||||
end
|
||||
options_mom_.hessian.use_penalized_objective = false; % penalized objective not yet
|
||||
% options related to variable declarations
|
||||
if isfield(options_,'trend_coeffs')
|
||||
error('method_of_moments: %s does not allow for trend in data',mom_method)
|
||||
if isfield(options_mom_,'hessian') && options_mom_.hessian.use_penalized_objective
|
||||
warning('method_of_moments: The ''use_penalized_objective_for_hessian'' option is not supported yet and will be skipped.');
|
||||
end
|
||||
options_mom_.hessian.use_penalized_objective = false; % penalized objective not yet supported
|
||||
if isfield(options_,'trend_coeffs')
|
||||
error('method_of_moments: %s does not allow for trend in data',mom_method);
|
||||
end
|
||||
% options related to endogenous prior restrictions are not supported
|
||||
if ~isempty(options_.endogenous_prior_restrictions.irf) && ~isempty(options_.endogenous_prior_restrictions.moment)
|
||||
fprintf('method_of_moments: Endogenous prior restrictions are not supported yet and will be skipped.\n')
|
||||
warning('method_of_moments: Endogenous prior restrictions are not supported yet and will be skipped.');
|
||||
end
|
||||
options_mom_.endogenous_prior_restrictions.irf = {};
|
||||
options_mom_.endogenous_prior_restrictions.moment = {};
|
||||
|
||||
options_mom_.mom.analytic_jacobian_optimizers = [1, 3, 4, 13, 101]; % these are currently supported optimizers that are able to use the analytical_jacobian option
|
||||
if isfield(options_mom_,'bayesian_irf') && options_mom_.bayesian_irf % do we need this at all??
|
||||
warning('method_of_moments: The ''bayesian_irf'' option is not supported yet and will be skipped.');
|
||||
end
|
||||
options_mom_.bayesian_irf = false;
|
||||
if strcmp(mom_method,'IRF_MATCHING')
|
||||
if isfield(options_mom_.mom,'penalized_estimator') && options_mom_.mom.penalized_estimator
|
||||
warning('method_of_moments: The ''penalized_estimator'' option is not supported yet for IRF_MATCHING and will be ignored.');
|
||||
end
|
||||
options_mom_.mom.penalized_estimator = false;
|
||||
end
|
||||
|
||||
% -------------------------------------------------------------------------
|
||||
% OPTIONS POSSIBLY SET BY THE USER
|
||||
|
@ -87,8 +96,7 @@ options_mom_ = set_default_option(options_mom_,'nograph',false); % do no
|
|||
options_mom_ = set_default_option(options_mom_,'noprint',false); % do not print output to console
|
||||
options_mom_ = set_default_option(options_mom_,'TeX',false); % print TeX tables and graphics
|
||||
options_mom_.mom = set_default_option(options_mom_.mom,'verbose',false); % display and store intermediate estimation results
|
||||
%options_mom_ = set_default_option(options_mom_,'verbosity',false); %
|
||||
if doBayesianEstimation
|
||||
if do_bayesian_estimation
|
||||
options_mom_ = set_default_option(options_mom_,'plot_priors',true); % control plotting of priors
|
||||
options_mom_ = set_default_option(options_mom_,'prior_trunc',1e-10); % probability of extreme values of the prior density that is ignored when computing bounds for the parameters
|
||||
end
|
||||
|
@ -111,6 +119,16 @@ end
|
|||
if strcmp(mom_method,'GMM')
|
||||
options_mom_.mom = set_default_option(options_mom_.mom,'analytic_standard_errors',false); % compute standard errors numerically (0) or analytically (1). Analytical derivatives are only available for GMM.
|
||||
end
|
||||
if strcmp(mom_method,'IRF_MATCHING')
|
||||
if ~isfield(options_mom_.mom,'irf_matching_file')
|
||||
options_mom_.mom.irf_matching_file = []; % irf_matching file enables to transform model IRFs before matching them to data IRFs
|
||||
end
|
||||
options_mom_.mom.irf_matching_file = set_default_option(options_mom_.mom.irf_matching_file,'name','');
|
||||
options_mom_.mom = set_default_option(options_mom_.mom,'simulation_method','STOCH_SIMUL'); % simulation method used to compute IRFs
|
||||
options_mom_ = set_default_option(options_mom_,'add_tiny_number_to_cholesky',1e-14); % add tiny number to Cholesky factor to avoid numerical problems when computing IRFs
|
||||
options_mom_ = set_default_option(options_mom_,'drop',100); % truncation / burnin for order>1 irf simulations
|
||||
options_mom_ = set_default_option(options_mom_,'relative_irf',false); % requests the computation of normalized IRFs
|
||||
end
|
||||
|
||||
% data related options
|
||||
if strcmp(mom_method,'GMM') || strcmp(mom_method,'SMM')
|
||||
|
@ -123,12 +141,14 @@ if strcmp(mom_method,'GMM') || strcmp(mom_method,'SMM')
|
|||
end
|
||||
|
||||
% optimization related
|
||||
if (isoctave && user_has_octave_forge_package('optim')) || (~isoctave && user_has_matlab_license('optimization_toolbox'))
|
||||
if strcmp(mom_method,'GMM') || strcmp(mom_method,'SMM')
|
||||
if strcmp(mom_method,'GMM') || strcmp(mom_method,'SMM')
|
||||
if (isoctave && user_has_octave_forge_package('optim')) || (~isoctave && user_has_matlab_license('optimization_toolbox'))
|
||||
options_mom_ = set_default_option(options_mom_,'mode_compute',13); % specifies lsqnonlin as default optimizer for minimization
|
||||
else
|
||||
options_mom_ = set_default_option(options_mom_,'mode_compute',5); % specifies newrat as fallback default option for minimization
|
||||
end
|
||||
else
|
||||
options_mom_ = set_default_option(options_mom_,'mode_compute',4); % specifies csminwel as fallback default option for minimization
|
||||
elseif strcmp(mom_method,'IRF_MATCHING')
|
||||
options_mom_ = set_default_option(options_mom_,'mode_compute',5); % specifies newrat as fallback default option for minimization
|
||||
end
|
||||
options_mom_ = set_default_option(options_mom_,'additional_optimizer_steps',[]); % vector of additional mode-finders run after mode_compute
|
||||
options_mom_ = set_default_option(options_mom_,'optim_opt',[]); % a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute
|
||||
|
@ -136,9 +156,20 @@ options_mom_ = set_default_option(options_mom_,'silent_optimizer',false);
|
|||
options_mom_ = set_default_option(options_mom_,'huge_number',1e7); % value for replacing the infinite bounds on parameters by finite numbers. Used by some optimizers for numerical reasons
|
||||
options_mom_.mom = set_default_option(options_mom_.mom,'analytic_jacobian',false); % use analytic Jacobian in optimization, only available for GMM and gradient-based optimizers
|
||||
options_mom_.optimizer_vec = [options_mom_.mode_compute;num2cell(options_mom_.additional_optimizer_steps)];
|
||||
options_mom_.mom.analytic_jacobian_optimizers = [1, 3, 4, 13, 101]; % these are currently supported optimizers that are able to use the analytic_jacobian option
|
||||
options_mom_.analytic_derivation = 0; % force to 0 as we check this seperately in dynare_minimize_objective.m
|
||||
options_mom_ = set_default_option(options_mom_,'mode_file',''); % name of the file containing initial values for the mode
|
||||
options_mom_ = set_default_option(options_mom_,'cova_compute',true); % 1: computed covariance via Hessian after the computation of the mode, 0: turn off computation of covariance matrix
|
||||
|
||||
% perturbation related
|
||||
options_mom_ = set_default_option(options_mom_,'order',1); % order of Taylor approximation in perturbation
|
||||
if strcmp(mom_method,'IRF_MATCHING') % number of simulated series used to compute IRFs
|
||||
if options_mom_.order == 1
|
||||
options_mom_ = set_default_option(options_mom_,'replic',1);
|
||||
else
|
||||
options_mom_ = set_default_option(options_mom_,'replic',50);
|
||||
end
|
||||
end
|
||||
options_mom_ = set_default_option(options_mom_,'pruning',false); % use pruned state space system at order>1
|
||||
options_mom_ = set_default_option(options_mom_,'aim_solver',false); % use AIM algorithm to compute perturbation approximation instead of mjdgges
|
||||
options_mom_ = set_default_option(options_mom_,'k_order_solver',false); % use k_order_perturbation instead of mjdgges
|
||||
|
@ -160,15 +191,122 @@ options_mom_ = set_default_option(options_mom_,'lyapunov_srs',false);
|
|||
options_mom_ = set_default_option(options_mom_,'lyapunov_complex_threshold',1e-15); % complex block threshold for the upper triangular matrix in symmetric Lyapunov equation solver
|
||||
options_mom_ = set_default_option(options_mom_,'lyapunov_fixed_point_tol',1e-10); % convergence criterion used in the fixed point Lyapunov solver
|
||||
options_mom_ = set_default_option(options_mom_,'lyapunov_doubling_tol',1e-16); % convergence criterion used in the doubling algorithm
|
||||
options_mom_ = set_default_option(options_mom_,'sylvester_fp',false); % determines whether to use fixed point algorihtm to solve Sylvester equation (gensylv_fp), faster for large scale models
|
||||
options_mom_ = set_default_option(options_mom_,'sylvester_fixed_point_tol',1e-12); % convergence criterion used in the fixed point Sylvester solver
|
||||
|
||||
% mode check plot
|
||||
% Bayesian MCMC related
|
||||
if do_bayesian_estimation
|
||||
options_mom_ = set_default_option(options_mom_,'mh_replic',0); % number of draws in Metropolis-Hastings and slice samplers
|
||||
options_mom_ = set_default_option(options_mom_,'mh_posterior_mode_estimation',false); % skip optimizer-based mode-finding and instead compute the mode based on a run of a MCMC
|
||||
options_mom_ = set_default_option(options_mom_,'load_mh_file',false); % add to previous Metropolis-Hastings or slice simulations instead of starting from scratch
|
||||
options_mom_ = set_default_option(options_mom_,'load_results_after_load_mh',false); % load the previously computed convergence diagnostics, marginal data density, and posterior statistics from an existing mom_results file instead of recomputing them
|
||||
|
||||
if options_mom_.mh_replic > 0 || options_mom_.load_mh_file
|
||||
options_mom_ = set_default_option(options_mom_,'sub_draws',[]);
|
||||
options_mom_ = set_default_option(options_mom_,'posterior_max_subsample_draws',1200);
|
||||
options_mom_ = set_default_option(options_mom_,'mh_nblck',2); % number of parallel chains for Metropolis-Hastings or slice algorithm
|
||||
options_mom_ = set_default_option(options_mom_,'mh_drop',0.5); % fraction of initially generated parameter vectors to be dropped as a burn-in before using posterior simulations
|
||||
options_mom_ = set_default_option(options_mom_,'mh_conf_sig',0.9); % confidence/HPD interval used for the computation of prior and posterior statistics
|
||||
options_mom_ = set_default_option(options_mom_,'mh_recover',false); % attempts to recover a Metropolis-Hastings simulation that crashed prematurely
|
||||
options_mom_ = set_default_option(options_mom_,'MCMC_jumping_covariance','hessian'); % which covariance to use for the proposal density of the MCMC sampler
|
||||
if ~isfield(options_mom_,'mh_initialize_from_previous_mcmc')
|
||||
options_mom_.mh_initialize_from_previous_mcmc.status = false; % pick initial values for new MCMC from a previous one
|
||||
end
|
||||
options_mom_.mh_initialize_from_previous_mcmc = set_default_option(options_mom_.mh_initialize_from_previous_mcmc,'directory',''); % pick initial values for new MCMC from a previous one: directory
|
||||
options_mom_.mh_initialize_from_previous_mcmc = set_default_option(options_mom_.mh_initialize_from_previous_mcmc,'record',''); % pick initial values for new MCMC from a previous one: record file name
|
||||
options_mom_.mh_initialize_from_previous_mcmc = set_default_option(options_mom_.mh_initialize_from_previous_mcmc,'prior',''); % pick initial values for new MCMC from a previous one: prior file name
|
||||
if ~isfield(options_mom_,'posterior_sampler_options')
|
||||
options_mom_.posterior_sampler_options = [];
|
||||
end
|
||||
options_mom_.posterior_sampler_options = set_default_option(options_mom_.posterior_sampler_options,'posterior_sampling_method','random_walk_metropolis_hastings'); % selects the sampler used to sample from the posterior distribution during Bayesian estimation
|
||||
options_mom_.posterior_sampler_options = set_default_option(options_mom_.posterior_sampler_options,'sampling_opt',[]); % used to set options for the posterior sampling methods
|
||||
switch options_mom_.posterior_sampler_options.posterior_sampling_method
|
||||
case 'random_walk_metropolis_hastings'
|
||||
if ~isfield(options_mom_.posterior_sampler_options,'rwmh')
|
||||
options_mom_.posterior_sampler_options.rwmh = [];
|
||||
end
|
||||
options_mom_.posterior_sampler_options.rwmh = set_default_option(options_mom_.posterior_sampler_options.rwmh,'proposal_distribution','rand_multivariate_normal');
|
||||
options_mom_.posterior_sampler_options.rwmh = set_default_option(options_mom_.posterior_sampler_options.rwmh,'student_degrees_of_freedom',3);
|
||||
options_mom_.posterior_sampler_options.rwmh = set_default_option(options_mom_.posterior_sampler_options.rwmh,'use_mh_covariance_matrix',false);
|
||||
options_mom_.posterior_sampler_options.rwmh = set_default_option(options_mom_.posterior_sampler_options.rwmh,'save_tmp_file',false);
|
||||
case 'tailored_random_block_metropolis_hastings'
|
||||
if ~isfield(options_mom_.posterior_sampler_options,'tarb')
|
||||
options_mom_.posterior_sampler_options.tarb = [];
|
||||
end
|
||||
options_mom_.posterior_sampler_options.tarb = set_default_option(options_mom_.posterior_sampler_options.tarb,'proposal_distribution','rand_multivariate_normal');
|
||||
options_mom_.posterior_sampler_options.tarb = set_default_option(options_mom_.posterior_sampler_options.tarb,'student_degrees_of_freedom',3);
|
||||
options_mom_.posterior_sampler_options.tarb = set_default_option(options_mom_.posterior_sampler_options.tarb,'mode_compute',4);
|
||||
options_mom_.posterior_sampler_options.tarb = set_default_option(options_mom_.posterior_sampler_options.tarb,'new_block_probability',0.25);
|
||||
options_mom_.posterior_sampler_options.tarb = set_default_option(options_mom_.posterior_sampler_options.tarb,'optim_opt','');
|
||||
options_mom_.posterior_sampler_options.tarb = set_default_option(options_mom_.posterior_sampler_options.tarb,'save_tmp_file',true);
|
||||
case 'slice'
|
||||
if ~isfield(options_mom_.posterior_sampler_options,'slice')
|
||||
options_mom_.posterior_sampler_options.slice = [];
|
||||
end
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'proposal_distribution','');
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'rotated',0);
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'slice_initialize_with_mode',false); % must be used with rotated
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'use_mh_covariance_matrix',false); % must be used with rotated
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'WR',[]);
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'mode_files',[]);
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'mode',[]);
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'initial_step_size',0.8);
|
||||
options_mom_.posterior_sampler_options.slice = set_default_option(options_mom_.posterior_sampler_options.slice,'save_tmp_file',true);
|
||||
case 'independent_metropolis_hastings'
|
||||
if ~isfield(options_mom_.posterior_sampler_options,'imh')
|
||||
options_mom_.posterior_sampler_options.imh = [];
|
||||
end
|
||||
options_mom_.posterior_sampler_options.imh = set_default_option(options_mom_.posterior_sampler_options.imh,'proposal_distribution','rand_multivariate_normal');
|
||||
options_mom_.posterior_sampler_options.imh = set_default_option(options_mom_.posterior_sampler_options.imh,'use_mh_covariance_matrix',false);
|
||||
options_mom_.posterior_sampler_options.imh = set_default_option(options_mom_.posterior_sampler_options.imh,'save_tmp_file',false);
|
||||
end
|
||||
if ~strcmp(options_mom_.posterior_sampler_options.posterior_sampling_method,'slice')
|
||||
options_mom_ = set_default_option(options_mom_,'mh_init_scale_factor',2);
|
||||
options_mom_ = set_default_option(options_mom_,'mh_jscale',[]);
|
||||
end
|
||||
|
||||
% mh_tune_jscale options
|
||||
if strcmp(options_mom_.posterior_sampler_options.posterior_sampling_method,'random_walk_metropolis_hastings')
|
||||
if ~isfield(options_mom_,'mh_tune_jscale')
|
||||
options_mom_.mh_tune_jscale = [];
|
||||
end
|
||||
options_mom_.mh_tune_jscale = set_default_option(options_mom_.mh_tune_jscale,'status',false);
|
||||
options_mom_.mh_tune_jscale = set_default_option(options_mom_.mh_tune_jscale,'target',0.33);
|
||||
options_mom_.mh_tune_jscale = set_default_option(options_mom_.mh_tune_jscale,'guess',[]);
|
||||
options_mom_.mh_tune_jscale.maxiter = options_.mh_tune_jscale.maxiter;
|
||||
options_mom_.mh_tune_jscale.rho = options_.mh_tune_jscale.rho;
|
||||
options_mom_.mh_tune_jscale.stepsize = options_.mh_tune_jscale.stepsize;
|
||||
options_mom_.mh_tune_jscale.c1 = options_.mh_tune_jscale.c1;
|
||||
options_mom_.mh_tune_jscale.c2 = options_.mh_tune_jscale.c2;
|
||||
options_mom_.mh_tune_jscale.c3 = options_.mh_tune_jscale.c3;
|
||||
end
|
||||
|
||||
% convergence diagnostics
|
||||
options_mom_ = set_default_option(options_mom_,'nodiagnostic',false);
|
||||
if ~isfield(options_mom_,'convergence')
|
||||
options_mom_.convergence = [];
|
||||
end
|
||||
if ~isfield(options_mom_.convergence,'geweke')
|
||||
options_mom_.convergence.geweke = [];
|
||||
end
|
||||
if ~isfield(options_mom_.convergence,'rafterylewis')
|
||||
options_mom_.convergence.rafterylewis = [];
|
||||
end
|
||||
if ~isfield(options_mom_.convergence,'brooksgelman')
|
||||
options_mom_.convergence.brooksgelman = [];
|
||||
end
|
||||
options_mom_.convergence.geweke = set_default_option(options_mom_.convergence.geweke,'taper_steps', [4 8 15]);
|
||||
options_mom_.convergence.geweke = set_default_option(options_mom_.convergence.geweke,'geweke_interval', [0.2 0.5]);
|
||||
options_mom_.convergence.rafterylewis = set_default_option(options_mom_.convergence.rafterylewis,'indicator', false);
|
||||
options_mom_.convergence.rafterylewis = set_default_option(options_mom_.convergence.rafterylewis,'qrs', [0.025 0.005 0.95]);
|
||||
options_mom_.convergence.brooksgelman = set_default_option(options_mom_.convergence.brooksgelman,'plotrows',3);
|
||||
end
|
||||
end
|
||||
|
||||
% mode check plot options
|
||||
options_mom_.mode_check.nolik = false; % we don't do likelihood (also this initializes mode_check substructure)
|
||||
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'status',false); % plot the target function for values around the computed minimum for each estimated parameter in turn. This is helpful to diagnose problems with the optimizer.
|
||||
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'neighbourhood_size',.5); % width of the window around the computed minimum to be displayed on the diagnostic plots. This width is expressed in percentage deviation. The Inf value is allowed, and will trigger a plot over the entire domain
|
||||
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'symmetric_plots',true); % ensure that the check plots are symmetric around the minimum. A value of 0 allows to have asymmetric plots, which can be useful if the minimum is close to a domain boundary, or in conjunction with neighbourhood_size = Inf when the domain is not the entire real line
|
||||
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'number_of_points',20); % number of points around the minimum where the target function is evaluated (for each parameter)
|
||||
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'status',false); % plot the target function for values around the computed mode for each estimated parameter in turn. This is helpful to diagnose problems with the optimizer.
|
||||
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'neighbourhood_size',.5); % width of the window around the computed mode to be displayed on the diagnostic plots. This width is expressed in percentage deviation. The Inf value is allowed, and will trigger a plot over the entire domain
|
||||
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'symmetric_plots',true); % ensure that the check plots are symmetric around the mode. A value of 0 allows to have asymmetric plots, which can be useful if the mode is close to a domain boundary, or in conjunction with neighbourhood_size = Inf when the domain is not the entire real line
|
||||
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'number_of_points',20); % number of points around the mode where the target function is evaluated (for each parameter)
|
||||
|
||||
|
||||
% -------------------------------------------------------------------------
|
||||
|
@ -182,8 +320,12 @@ options_mom_.obs_nbr = length(options_mom_.varobs); % number of observed variabl
|
|||
|
||||
% related to call of dynare
|
||||
options_mom_.console_mode = options_.console_mode;
|
||||
if options_mom_.console_mode
|
||||
options_mom_.nodisplay = true;
|
||||
end
|
||||
options_mom_.parallel = options_.parallel;
|
||||
options_mom_.parallel_info = options_.parallel_info;
|
||||
options_mom_.debug = options_.debug; % debug option is needed by some functions, e.g. check_plot
|
||||
|
||||
% related to estimated_params and estimated_params_init blocks
|
||||
options_mom_.use_calibration_initialization = options_.use_calibration_initialization;
|
||||
|
@ -252,19 +394,82 @@ end
|
|||
options_mom_.gstep = options_.gstep; % needed by hessian.m
|
||||
options_mom_.trust_region_initial_step_bound_factor = options_.trust_region_initial_step_bound_factor; % used in dynare_solve for trust_region
|
||||
|
||||
% other
|
||||
% miscellaneous
|
||||
options_mom_.threads = options_.threads;
|
||||
options_mom_.MaxNumberOfBytes = options_.MaxNumberOfBytes;
|
||||
%options_mom_.MaximumNumberOfMegaBytes = options_.MaximumNumberOfMegaBytes;
|
||||
options_mom_.marginal_data_density = options_.marginal_data_density;
|
||||
|
||||
|
||||
% -------------------------------------------------------------------------
|
||||
% DEFAULT VALUES
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
options_mom_.analytic_derivation = 0;
|
||||
options_mom_.mom.compute_derivs = false; % flag to compute derivs in objective function (might change for GMM with either analytic_standard_errors or analytic_jacobian (dependent on optimizer))
|
||||
options_mom_.mom.vector_output = false; % specifies whether the objective function returns a vector
|
||||
options_mom_.analytic_derivation_mode = 0; % needed by get_perturbation_params_derivs.m, ie use efficient sylvester equation method to compute analytical derivatives as in Ratto & Iskrev (2012)
|
||||
options_mom_.initialize_estimated_parameters_with_the_prior_mode = 0; % needed by set_prior.m
|
||||
options_mom_.figures = options_.figures; % needed by plot_priors.m
|
||||
options_mom_.ramsey_policy = false; % needed by evaluate_steady_state
|
||||
options_mom_.risky_steadystate = false; % needed by resol
|
||||
options_mom_.jacobian_flag = true; % needed by dynare_solve
|
||||
options_mom_.figures = options_.figures; % needed by plot_priors.m
|
||||
options_mom_.ramsey_policy = false; % needed by evaluate_steady_state
|
||||
options_mom_.risky_steadystate = false; % needed by resol
|
||||
options_mom_.jacobian_flag = true; % needed by dynare_solve
|
||||
options_mom_.use_mh_covariance_matrix = false; % needed by posterior_sampler, get's overwritten by same option in options_mom_.posterior_sampler_options
|
||||
|
||||
|
||||
% -------------------------------------------------------------------------
|
||||
% CHECKS ON SETTINGS
|
||||
% -------------------------------------------------------------------------
|
||||
if strcmp(mom_method,'GMM') || strcmp(mom_method,'SMM')
|
||||
if numel(options_mom_.nobs) > 1
|
||||
error('method_of_moments: Recursive estimation is not supported. Please set an integer as ''nobs''!');
|
||||
end
|
||||
if numel(options_mom_.first_obs) > 1
|
||||
error('method_of_moments: Recursive estimation is not supported. Please set an integer as ''first_obs''!');
|
||||
end
|
||||
end
|
||||
if options_mom_.order < 1
|
||||
error('method_of_moments: The order of the Taylor approximation cannot be 0!')
|
||||
end
|
||||
if options_mom_.order > 2
|
||||
fprintf('Dynare will use ''k_order_solver'' as the order>2\n');
|
||||
options_mom_.k_order_solver = true;
|
||||
end
|
||||
if strcmp(mom_method,'SMM')
|
||||
if options_mom_.mom.simulation_multiple < 1
|
||||
fprintf('The simulation horizon is shorter than the data. Dynare resets the simulation_multiple to 7.\n')
|
||||
options_mom_.mom.simulation_multiple = 7;
|
||||
end
|
||||
end
|
||||
if strcmp(mom_method,'GMM')
|
||||
% require pruning with GMM at higher order
|
||||
if options_mom_.order > 1 && ~options_mom_.pruning
|
||||
fprintf('GMM at higher order only works with pruning, so we set pruning option to 1.\n');
|
||||
options_mom_.pruning = true;
|
||||
end
|
||||
if options_mom_.order > 3
|
||||
error('method_of_moments: Perturbation orders higher than 3 are not implemented for GMM estimation, try using SMM!');
|
||||
end
|
||||
end
|
||||
if strcmp(mom_method,'IRF_MATCHING') && do_bayesian_estimation
|
||||
if isfield(options_mom_,'mh_tune_jscale') && options_mom_.mh_tune_jscale.status && (options_mom_.mh_tune_jscale.maxiter<options_mom_.mh_tune_jscale.stepsize)
|
||||
warning('method_of_moments: You specified mh_tune_jscale, but the maximum number of iterations is smaller than the step size. No update will take place.')
|
||||
end
|
||||
if options_mom_.load_results_after_load_mh
|
||||
if ~exist([options_mom_.dirname filesep 'method_of_moments' filesep M_.fname '_mom_results.mat'],'file')
|
||||
fprintf('\nYou specified the ''load_results_after_load_mh'' option, but no ''%s_mom_results.mat'' file\n',M_.fname);
|
||||
fprintf('was found in the folder %s%smethod_of_moments.\n',options_mom_.dirname,filesep);
|
||||
fprintf('Results will be recomputed and option ''load_results_after_load_mh'' is reset to false.\n');
|
||||
options_mom_.load_results_after_load_mh = false;
|
||||
end
|
||||
end
|
||||
if options_mom_.mh_replic>0 && options_mom_.mh_nblck<1
|
||||
error('method_of_moments: Bayesian MCMC estimation cannot be conducted with ''mh_nblocks''=0!')
|
||||
end
|
||||
end
|
||||
if options_mom_.mom.analytic_jacobian && ~strcmp(mom_method,'GMM')
|
||||
options_mom_.mom.analytic_jacobian = false;
|
||||
fprintf('\n''analytic_jacobian'' option will be dismissed as it only works with GMM.\n');
|
||||
end
|
||||
if strcmp(options_mom_.mom.mom_method,'IRF_MATCHING')
|
||||
if any(cellfun(@(x) isnumeric(x) && any(x == 13), options_mom_.optimizer_vec))
|
||||
error('method_of_moments: lsqnonlin (mode_compute=13) is not yet supported for IRF matching!');
|
||||
end
|
||||
end
|
|
@ -1,74 +0,0 @@
|
|||
function display_comparison_moments(M_, options_mom_, data_moments, model_moments)
|
||||
% function display_comparison_moments(M_, options_mom_, data_moments, model_moments)
|
||||
% -------------------------------------------------------------------------
|
||||
% Displays and saves to disk the comparison of the data moments and the model moments
|
||||
% =========================================================================
|
||||
% INPUTS
|
||||
% M_: [structure] model information
|
||||
% options_mom_: [structure] method of moments options
|
||||
% data_moments: [vector] data moments
|
||||
% model_moments: [vector] model moments
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUT
|
||||
% No output, just displays and saves to disk the comparison of the data moments and the model moments
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% o mom.run
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% o dyn_latex_table
|
||||
% o dyntable
|
||||
% o cellofchararraymaxlength
|
||||
% =========================================================================
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
|
||||
titl = ['Comparison of matched data moments and model moments (',options_mom_.mom.mom_method,')'];
|
||||
headers = {'Moment','Data','Model'};
|
||||
for jm = 1:size(M_.matched_moments,1)
|
||||
lables_tmp = 'E[';
|
||||
lables_tmp_tex = 'E \left[ ';
|
||||
for jvar = 1:length(M_.matched_moments{jm,1})
|
||||
lables_tmp = [lables_tmp M_.endo_names{M_.matched_moments{jm,1}(jvar)}];
|
||||
lables_tmp_tex = [lables_tmp_tex, '{', M_.endo_names_tex{M_.matched_moments{jm,1}(jvar)}, '}'];
|
||||
if M_.matched_moments{jm,2}(jvar) ~= 0
|
||||
lables_tmp = [lables_tmp, '(', num2str(M_.matched_moments{jm,2}(jvar)), ')'];
|
||||
lables_tmp_tex = [lables_tmp_tex, '_{t', num2str(M_.matched_moments{jm,2}(jvar)), '}'];
|
||||
else
|
||||
lables_tmp_tex = [lables_tmp_tex, '_{t}'];
|
||||
end
|
||||
if M_.matched_moments{jm,3}(jvar) > 1
|
||||
lables_tmp = [lables_tmp, '^', num2str(M_.matched_moments{jm,3}(jvar))];
|
||||
lables_tmp_tex = [lables_tmp_tex, '^{', num2str(M_.matched_moments{jm,3}(jvar)) '}'];
|
||||
end
|
||||
if jvar == length(M_.matched_moments{jm,1})
|
||||
lables_tmp = [lables_tmp, ']'];
|
||||
lables_tmp_tex = [lables_tmp_tex, ' \right]'];
|
||||
else
|
||||
lables_tmp = [lables_tmp, '*'];
|
||||
lables_tmp_tex = [lables_tmp_tex, ' \times '];
|
||||
end
|
||||
end
|
||||
labels{jm,1} = lables_tmp;
|
||||
labels_TeX{jm,1} = lables_tmp_tex;
|
||||
end
|
||||
data_mat = [data_moments model_moments];
|
||||
dyntable(options_mom_, titl, headers, labels, data_mat, cellofchararraymaxlength(labels)+2, 10, 7);
|
||||
if options_mom_.TeX
|
||||
dyn_latex_table(M_, options_mom_, titl, ['comparison_moments_', options_mom_.mom.mom_method], headers, labels_TeX, data_mat, cellofchararraymaxlength(labels)+2, 10, 7);
|
||||
end
|
|
@ -0,0 +1,96 @@
|
|||
function display_comparison_moments_irfs(M_, options_mom_, data_moments, model_moments)
|
||||
% display_comparison_moments_irfs(M_, options_mom_, data_moments, model_moments)
|
||||
% -------------------------------------------------------------------------
|
||||
% Displays and saves to disk the comparison of the data moments/IRFs and the model moments/IRFs
|
||||
% -------------------------------------------------------------------------
|
||||
% INPUTS
|
||||
% M_: [structure] model information
|
||||
% options_mom_: [structure] method of moments options
|
||||
% data_moments: [vector] data moments
|
||||
% model_moments: [vector] model moments
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUT
|
||||
% No output, just displays and saves to disk the comparison of the data moments and the model moments
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% o mom.run
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% o dyn_latex_table
|
||||
% o dyntable
|
||||
% o cellofchararraymaxlength
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
if strcmp(options_mom_.mom.mom_method,'IRF_MATCHING')
|
||||
titl = upper('Comparison of matched data IRFs and model IRFs');
|
||||
headers = {'IRF','Data','Model'};
|
||||
idx = 1;
|
||||
for jj = 1:size(M_.matched_irfs,1)
|
||||
irf_varname = M_.matched_irfs{jj,1};
|
||||
irf_shockname = M_.matched_irfs{jj,2};
|
||||
% note that periods can span over multiple rows
|
||||
IRF_PERIODS = [];
|
||||
for kk = 1:size(M_.matched_irfs{jj,3},1)
|
||||
irf_periods = M_.matched_irfs{jj,3}{kk,1};
|
||||
IRF_PERIODS = [IRF_PERIODS; irf_periods(:)];
|
||||
end
|
||||
for hh = 1:length(IRF_PERIODS)
|
||||
labels{idx,1} = sprintf('%s %s (%u)',irf_varname,irf_shockname,IRF_PERIODS(hh));
|
||||
labels_TeX{idx,1} = sprintf('%s %s (%u)',M_.endo_names_tex{ismember(M_.endo_names,irf_varname)},M_.exo_names_tex{ismember(M_.exo_names,irf_shockname)},IRF_PERIODS(hh));
|
||||
idx = idx+1;
|
||||
end
|
||||
end
|
||||
else
|
||||
titl = ['Comparison of matched data moments and model moments (',options_mom_.mom.mom_method,')'];
|
||||
headers = {'Moment','Data','Model'};
|
||||
for jm = 1:size(M_.matched_moments,1)
|
||||
lables_tmp = 'E[';
|
||||
lables_tmp_tex = 'E \left[ ';
|
||||
for jvar = 1:length(M_.matched_moments{jm,1})
|
||||
lables_tmp = [lables_tmp M_.endo_names{M_.matched_moments{jm,1}(jvar)}];
|
||||
lables_tmp_tex = [lables_tmp_tex, '{', M_.endo_names_tex{M_.matched_moments{jm,1}(jvar)}, '}'];
|
||||
if M_.matched_moments{jm,2}(jvar) ~= 0
|
||||
lables_tmp = [lables_tmp, '(', num2str(M_.matched_moments{jm,2}(jvar)), ')'];
|
||||
lables_tmp_tex = [lables_tmp_tex, '_{t', num2str(M_.matched_moments{jm,2}(jvar)), '}'];
|
||||
else
|
||||
lables_tmp_tex = [lables_tmp_tex, '_{t}'];
|
||||
end
|
||||
if M_.matched_moments{jm,3}(jvar) > 1
|
||||
lables_tmp = [lables_tmp, '^', num2str(M_.matched_moments{jm,3}(jvar))];
|
||||
lables_tmp_tex = [lables_tmp_tex, '^{', num2str(M_.matched_moments{jm,3}(jvar)) '}'];
|
||||
end
|
||||
if jvar == length(M_.matched_moments{jm,1})
|
||||
lables_tmp = [lables_tmp, ']'];
|
||||
lables_tmp_tex = [lables_tmp_tex, ' \right]'];
|
||||
else
|
||||
lables_tmp = [lables_tmp, '*'];
|
||||
lables_tmp_tex = [lables_tmp_tex, ' \times '];
|
||||
end
|
||||
end
|
||||
labels{jm,1} = lables_tmp;
|
||||
labels_TeX{jm,1} = lables_tmp_tex;
|
||||
end
|
||||
end
|
||||
data_mat = [data_moments model_moments];
|
||||
dyntable(options_mom_, titl, headers, labels, data_mat, cellofchararraymaxlength(labels)+2, 10, 7);
|
||||
if options_mom_.TeX
|
||||
dyn_latex_table(M_, options_mom_, titl, ['comparison_moments_', options_mom_.mom.mom_method], headers, labels_TeX, data_mat, cellofchararraymaxlength(labels)+2, 10, 7);
|
||||
end
|
|
@ -1,7 +1,8 @@
|
|||
function [dataMoments, m_data] = get_data_moments(data, obs_var, inv_order_var, matched_moments_, options_mom_)
|
||||
% [dataMoments, m_data] = get_data_moments(data, obs_var, inv_order_var, matched_moments_, options_mom_)
|
||||
% This function computes the user-selected empirical moments from data
|
||||
% =========================================================================
|
||||
function [data_moments, m_data] = get_data_moments(data, obs_var, inv_order_var, matched_moments_, options_mom_)
|
||||
% [data_moments, m_data] = get_data_moments(data, obs_var, inv_order_var, matched_moments_, options_mom_)
|
||||
% -------------------------------------------------------------------------
|
||||
% Computes the user-selected empirical moments from data
|
||||
% -------------------------------------------------------------------------
|
||||
% INPUTS
|
||||
% o data [T x varobs_nbr] data set
|
||||
% o obs_var: [integer] index of observables
|
||||
|
@ -10,13 +11,14 @@ function [dataMoments, m_data] = get_data_moments(data, obs_var, inv_order_var,
|
|||
% o options_mom_: [structure] information about all settings (specified by the user, preprocessor, and taken from global options_)
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUTS
|
||||
% o dataMoments [numMom x 1] mean of selected empirical moments
|
||||
% o data_moments [numMom x 1] mean of selected empirical moments
|
||||
% o m_data [T x numMom] selected empirical moments at each point in time
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% o mom.run
|
||||
% o mom.objective_function
|
||||
% =========================================================================
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Copyright © 2020-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
|
@ -33,15 +35,11 @@ function [dataMoments, m_data] = get_data_moments(data, obs_var, inv_order_var,
|
|||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% -------------------------------------------------------------------------
|
||||
% Author(s):
|
||||
% o Willi Mutschler (willi@mutschler.eu)
|
||||
% o Johannes Pfeifer (johannes.pfeifer@unibw.de)
|
||||
% =========================================================================
|
||||
|
||||
|
||||
% Initialization
|
||||
T = size(data,1); % Number of observations (T)
|
||||
dataMoments = NaN(options_mom_.mom.mom_nbr,1);
|
||||
data_moments = NaN(options_mom_.mom.mom_nbr,1);
|
||||
m_data = NaN(T,options_mom_.mom.mom_nbr);
|
||||
% Product moment for each time period, i.e. each row t contains y_t1(l1)^p1*y_t2(l2)^p2*...
|
||||
% note that here we already are able to treat leads and lags and any power product moments
|
||||
|
@ -60,11 +58,11 @@ for jm = 1:options_mom_.mom.mom_nbr
|
|||
end
|
||||
end
|
||||
% We replace NaN (due to leads and lags and missing values) with the corresponding mean
|
||||
if isoctave || matlab_ver_less_than('8.5')
|
||||
dataMoments(jm,1) = nanmean(m_data_tmp);
|
||||
if isoctave && octave_ver_less_than('8')
|
||||
data_moments(jm,1) = nanmean(m_data_tmp);
|
||||
else
|
||||
dataMoments(jm,1) = mean(m_data_tmp,'omitnan');
|
||||
data_moments(jm,1) = mean(m_data_tmp,'omitnan');
|
||||
end
|
||||
m_data_tmp(isnan(m_data_tmp)) = dataMoments(jm,1);
|
||||
m_data_tmp(isnan(m_data_tmp)) = data_moments(jm,1);
|
||||
m_data(:,jm) = m_data_tmp;
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
function graph_comparison_irfs(matched_irfs,irf_model_varobs,varobs_id,irf_horizon,relative_irf,endo_names,endo_names_tex,exo_names,exo_names_tex,dname,fname,graph_format,TeX,nodisplay,figures_textwidth)
|
||||
% graph_comparison_irfs(matched_irfs,irf_model_varobs,varobs_id,irf_horizon,relative_irf,endo_names,endo_names_tex,exo_names,exo_names_tex,dname,fname,graph_format,TeX,nodisplay,figures_textwidth)
|
||||
% -------------------------------------------------------------------------
|
||||
% Plots and saves to disk the comparison of the selected data IRFs and corresponding model IRfs
|
||||
% -------------------------------------------------------------------------
|
||||
% INPUTS
|
||||
% matched_irfs: [matrix] information on matched data IRFs
|
||||
% irf_model_varobs: [matrix] model IRFs for observable variables
|
||||
% varobs_id: [vector] index for observable variables in endo_names
|
||||
% irf_horizon: [scalar] maximum horizon of IRFs
|
||||
% relative_irf: [boolean] if true, plots normalized IRFs
|
||||
% endo_names: [cell] names of endogenous variables
|
||||
% endo_names_tex: [cell] names of endogenous variables in latex
|
||||
% exo_names: [cell] names of exogenous variables
|
||||
% exo_names_tex: [cell] names of exogenous variables in latex
|
||||
% dname: [string] name of the directory where to save the graphs
|
||||
% fname: [string] name of the mod file
|
||||
% graph_format: [cell] format of the graphs
|
||||
% TeX: [boolean] if true, uses latex for plots
|
||||
% nodisplay: [boolean] if true, does not display the graphs
|
||||
% figures_textwidth: [scalar] textwidth used in plots
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUT
|
||||
% No output, just displays and saves to disk the graphs
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% o mom.run
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% o dyn_figure
|
||||
% o dyn_saveas
|
||||
% o remove_fractional_xticks
|
||||
% o CheckPath
|
||||
% o pltorg
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
graph_directory_name = CheckPath('graphs',dname);
|
||||
latex_directory_name = CheckPath('latex',dname);
|
||||
if TeX && any(strcmp('eps',cellstr(graph_format)))
|
||||
fid_TeX = fopen([latex_directory_name '/' fname '_irf_matching_plot.tex'],'w');
|
||||
fprintf(fid_TeX,'%% TeX eps-loader file generated by mom.run.m (Dynare).\n');
|
||||
fprintf(fid_TeX,['%% ' datestr(now,0) '\n']);
|
||||
fprintf(fid_TeX,' \n');
|
||||
end
|
||||
unique_shock_entries = unique(matched_irfs(:, 2));
|
||||
colDarkGrey = [0.3, 0.3, 0.3]; % dark grey
|
||||
for jexo = unique_shock_entries' % loop over cell with shock names
|
||||
unique_variables = unique(matched_irfs(ismember(matched_irfs(:, 2),jexo), 1));
|
||||
[nbplt,nr,nc,lr,lc,nstar] = pltorg(length(unique_variables));
|
||||
fig = 0;
|
||||
for jvar = 1:length(unique_variables)
|
||||
% get data points, note that periods and values can span over multiple rows
|
||||
jj = ismember(matched_irfs(:,1), unique_variables(jvar)) & ismember(matched_irfs(:,2), jexo);
|
||||
IRF_PERIODS = []; IRF_VALUES = [];
|
||||
for kk = 1:size(matched_irfs{jj,3},1)
|
||||
irf_periods = matched_irfs{jj,3}{kk,1};
|
||||
irf_values = matched_irfs{jj,3}{kk,2};
|
||||
if length(irf_values)==1
|
||||
irf_values = repmat(irf_values,length(irf_periods),1);
|
||||
end
|
||||
IRF_PERIODS = [IRF_PERIODS; irf_periods(:)];
|
||||
IRF_VALUES = [IRF_VALUES; irf_values(:)];
|
||||
end
|
||||
|
||||
if jvar==1 || ~( (fig-1)*nstar<jvar && jvar<=fig*nstar )
|
||||
fig = fig+1;
|
||||
fig_irf = dyn_figure(nodisplay,'Name',['IRF matching shock to ' jexo{:} ' figure ' int2str(fig)]);
|
||||
end
|
||||
plt = jvar-(fig-1)*nstar;
|
||||
if nbplt>1 && fig==nbplt
|
||||
subplot(lr,lc,plt);
|
||||
else
|
||||
subplot(nr,nc,plt);
|
||||
end
|
||||
plt_data = plot(IRF_PERIODS,IRF_VALUES,'h', 'MarkerEdgeColor',colDarkGrey,'MarkerFaceColor',colDarkGrey,'MarkerSize',8);
|
||||
hold on
|
||||
plt_model = plot(1:irf_horizon, irf_model_varobs(:,varobs_id==find(ismember(endo_names,unique_variables(jvar))) , ismember(exo_names,jexo)),'-k','linewidth',2);
|
||||
hold on
|
||||
plot([1 irf_horizon],[0 0],'-r','linewidth',1);
|
||||
hold off
|
||||
xlim([1 irf_horizon]);
|
||||
remove_fractional_xticks
|
||||
if TeX
|
||||
title(['$' endo_names_tex{ismember(endo_names,unique_variables(jvar))} '$'],'Interpreter','latex');
|
||||
else
|
||||
title(unique_variables{jvar},'Interpreter','none');
|
||||
end
|
||||
set(gca,'FontSize',12);
|
||||
if (plt==nstar) || jvar==length(unique_variables)
|
||||
% Adding a legend at the bottom
|
||||
axes('Position',[0, 0, 1, 1],'Visible','off');
|
||||
lgd = legend([plt_data,plt_model],{'Data', 'Model'}, 'Location', 'southeast','NumColumns',2,'FontSize',14);
|
||||
if ~isoctave
|
||||
lgd.Position = [0.37 0.01 lgd.Position(3) lgd.Position(4)];
|
||||
end
|
||||
dyn_saveas(fig_irf,[graph_directory_name filesep fname '_matched_irf_' jexo{:} int2str(fig)],nodisplay,graph_format);
|
||||
if TeX && any(strcmp('eps',cellstr(graph_format)))
|
||||
fprintf(fid_TeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fid_TeX,'\\centering \n');
|
||||
fprintf(fid_TeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_matched_irf_%s%s}\n',figures_textwidth*min(plt/nc,1),[graph_directory_name '/' fname],jexo{:},int2str(fig));
|
||||
if relative_irf
|
||||
fprintf(fid_TeX,'\\caption{Relative impulse response functions (orthogonalized shock to $%s$).}', jexo{:});
|
||||
else
|
||||
fprintf(fid_TeX,'\\caption{Impulse response functions (orthogonalized shock to $%s$).}', jexo{:});
|
||||
end
|
||||
fprintf(fid_TeX,'\\label{Fig:MatchedIRF:%s:%s}\n', jexo{:},int2str(fig));
|
||||
fprintf(fid_TeX,'\\end{figure}\n');
|
||||
fprintf(fid_TeX,' \n');
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,151 @@
|
|||
function [data_irfs, weight_mat, irf_index, max_irf_horizon] = matched_irfs_blocks(matched_irfs, matched_irfs_weight, varobs_id, obs_nbr, exo_nbr, endo_names, exo_names)
|
||||
% [data_irfs, weight_mat, irf_index, max_irf_horizon] = matched_irfs_blocks(matched_irfs, matched_irfs_weight, varobs_id, obs_nbr, exo_nbr, endo_names, exo_names)
|
||||
% -------------------------------------------------------------------------
|
||||
% Checks and transforms matched_irfs and matched_irfs_weight blocks
|
||||
% for further use in the estimation.
|
||||
% -------------------------------------------------------------------------
|
||||
% INPUTS
|
||||
% matched_irfs: [cell array] original matched_irfs block
|
||||
% matched_irfs_weight: [cell array] original matched_irfs_weight block
|
||||
% varobs_id: [vector] index for observable variables in endo_names
|
||||
% obs_nbr: [scalar] number of observable variables
|
||||
% exo_nbr: [scalar] number of exogenous variables
|
||||
% endo_names: [cell array] names of endogenous variables
|
||||
% exo_names: [cell array] names of exogenous variables
|
||||
% -------------------------------------------------------------------------
|
||||
% OUTPUT
|
||||
% data_irfs: [matrix] IRFs for VAROBS as declared in matched_irfs block
|
||||
% weight_mat: [matrix] weighting matrix for IRFs as declared in matched_irfs_weight block
|
||||
% irf_index: [vector] index for selecting specific IRFs from full IRF matrix of observables
|
||||
% max_irf_horizon: [scalar] maximum IRF horizon as declared in matched_irfs block
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% o mom.run
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
% note matched_irfs block:
|
||||
% - each row in the cell contains a unique combination of var and varexo,
|
||||
% however the third column in each row is a nested cell with information
|
||||
% on periods, values and weights
|
||||
% - periods, values and weights can span several rows with different lengths of entries
|
||||
% - in some cases we need to duplicate values and/or weights
|
||||
% - at the end we want to have everything vectorized and the same length
|
||||
|
||||
% get maximum IRF horizons
|
||||
max_irf_horizon = [];
|
||||
for jj = 1:size(matched_irfs,1)
|
||||
max_irf_horizon = [max_irf_horizon; cell2mat(cellfun(@(c) c(:), matched_irfs{jj,3}(:,1), 'UniformOutput', false))];
|
||||
end
|
||||
max_irf_horizon = max(max_irf_horizon);
|
||||
|
||||
% create full matrix where 1st dimension are IRF periods, 2nd dimension are variables as declared in VAROBS, 3rd dimension are shocks
|
||||
% idea: overwrite NaN values if they are declared in matched_irfs block; at the end the remaining NaN values will be removed
|
||||
data_irfs = NaN(max_irf_horizon,obs_nbr,exo_nbr);
|
||||
% create full empirical weighting matrix, identity matrix by default, i.e. all IRFs are equally important
|
||||
% idea: first specify full matrix and then reduce it using only entries that are declared in matched_irfs block
|
||||
weight_mat = speye(max_irf_horizon*obs_nbr*exo_nbr);
|
||||
|
||||
for jj = 1:size(matched_irfs,1)
|
||||
id_var = find(ismember(endo_names,matched_irfs{jj,1}));
|
||||
id_varobs = find(varobs_id==id_var,1);
|
||||
id_shock = find(ismember(exo_names,matched_irfs{jj,2}));
|
||||
if isempty(id_varobs)
|
||||
skipline;
|
||||
error('method_of_moments: You specified an IRF matching involving variable %s, but it is not declared as a varobs!',endo_names{id_var})
|
||||
end
|
||||
IRF_PERIODS = []; IRF_VALUES = []; IRF_WEIGHTS = [];
|
||||
for kk = 1:size(matched_irfs{jj,3},1)
|
||||
irf_periods = matched_irfs{jj,3}{kk,1};
|
||||
if length(unique(irf_periods)) < length(irf_periods) % row-specific check for unique periods
|
||||
error('method_of_moments: You specified an IRF matching involving variable %s and shock %s, but there were duplicate ''periods'' in the specification!',endo_names{id_var},exo_names{id_shock});
|
||||
end
|
||||
irf_values = matched_irfs{jj,3}{kk,2};
|
||||
if length(irf_values)==1
|
||||
irf_values = repmat(irf_values,length(irf_periods),1);
|
||||
end
|
||||
if length(irf_periods) ~= length(irf_values) % row-specific check for enough values
|
||||
error('method_of_moments: You specified an IRF matching involving variable %s and shock %s, but the length of ''periods'' does not match the length of ''values''!',endo_names{id_var},exo_names{id_shock});
|
||||
end
|
||||
irf_weights = matched_irfs{jj,3}{kk,3};
|
||||
if length(irf_weights)==1
|
||||
irf_weights = repmat(irf_weights,length(irf_periods),1);
|
||||
end
|
||||
if length(irf_periods) ~= length(irf_weights) % row-specific check for enough weights
|
||||
error('method_of_moments: You specified an IRF matching involving variable %s and shock %s, but the length of ''periods'' does not match the length of ''weights''!',endo_names{id_var},exo_names{id_shock});
|
||||
end
|
||||
IRF_PERIODS = [IRF_PERIODS; irf_periods(:)];
|
||||
IRF_VALUES = [IRF_VALUES; irf_values(:)];
|
||||
IRF_WEIGHTS = [IRF_WEIGHTS; irf_weights(:)];
|
||||
end
|
||||
if length(unique(irf_periods)) < length(irf_periods) % overall check for unique periods
|
||||
error('method_of_moments: You specified an IRF matching involving variable %s and shock %s, but there were duplicate ''periods'' in the specification!',endo_names{id_var},exo_names{id_shock});
|
||||
end
|
||||
for hh = 1:length(IRF_PERIODS)
|
||||
data_irfs(IRF_PERIODS(hh),id_varobs,id_shock) = IRF_VALUES(hh);
|
||||
if IRF_WEIGHTS(hh) ~= 1
|
||||
idweight_mat = sub2ind(size(data_irfs),IRF_PERIODS(hh),id_varobs,id_shock);
|
||||
weight_mat(idweight_mat,idweight_mat) = IRF_WEIGHTS(hh);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% fine-tune weighting matrix using matched_irfs_weights
|
||||
for jj = 1:size(matched_irfs_weight,1)
|
||||
id_var1 = find(ismember(endo_names,matched_irfs_weight{jj,1}));
|
||||
id_var2 = find(ismember(endo_names,matched_irfs_weight{jj,4}));
|
||||
id_varobs1 = find(varobs_id==id_var1,1);
|
||||
id_varobs2 = find(varobs_id==id_var2,1);
|
||||
if isempty(id_varobs1)
|
||||
skipline;
|
||||
error('method_of_moments: You specified a weight for an IRF matching involving variable %s, but it is not a varobs!',endo_names{id_var1})
|
||||
end
|
||||
if isempty(id_varobs2)
|
||||
skipline;
|
||||
error('method_of_moments: You specified a weight for an IRF matching involving variable %s, but it is not a varobs!',endo_names{id_var2})
|
||||
end
|
||||
id_shock1 = find(ismember(exo_names,matched_irfs_weight{jj,3}));
|
||||
id_shock2 = find(ismember(exo_names,matched_irfs_weight{jj,6}));
|
||||
irf_periods1 = matched_irfs_weight{jj,2};
|
||||
irf_periods2 = matched_irfs_weight{jj,5};
|
||||
if length(irf_periods1) ~= length(irf_periods2)
|
||||
error('method_of_moments: You specified a ''matched_irfs_weights'' entry for an IRF matching involving %s/%s and %s/%s,\n but the horizons do not have the same length!',endo_names{id_var1},exo_names{id_shock1},endo_names{id_var2},exo_names{id_shock2});
|
||||
end
|
||||
if max([irf_periods1(:);irf_periods2(:)]) > max_irf_horizon
|
||||
error('method_of_moments: You specified a ''matched_irfs_weights'' entry for an IRF matching involving %s/%s and %s/%s,\n but the horizon is larger than the maximum one declared in the ''matched_irfs'' block!',endo_names{id_var1},exo_names{id_shock1},endo_names{id_var2},exo_names{id_shock2});
|
||||
end
|
||||
weight_mat_values = matched_irfs_weight{jj,7};
|
||||
if length(weight_mat_values)==1 && length(irf_periods1)>1
|
||||
weight_mat_values = repmat(weight_mat_values,length(irf_periods1),1);
|
||||
end
|
||||
if length(weight_mat_values) ~= length(irf_periods1)
|
||||
error('method_of_moments: You specified a ''matched_irfs_weights'' entry for an IRF matching involving %s/%s and %s/%s,\n but the horizons do not match the length of ''weights''!',endo_names{id_var1},exo_names{id_shock1},endo_names{id_var2},exo_names{id_shock2});
|
||||
end
|
||||
for hh = 1:length(irf_periods1)
|
||||
idweight_mat1 = sub2ind(size(data_irfs),irf_periods1(hh),id_varobs1,id_shock1);
|
||||
idweight_mat2 = sub2ind(size(data_irfs),irf_periods2(hh),id_varobs2,id_shock2);
|
||||
weight_mat(idweight_mat1,idweight_mat2) = weight_mat_values(hh);
|
||||
weight_mat(idweight_mat2,idweight_mat1) = weight_mat_values(hh); % symmetry
|
||||
end
|
||||
end
|
||||
|
||||
% remove non-specified IRFs
|
||||
irf_index = find(~isnan(data_irfs));
|
||||
data_irfs = data_irfs(irf_index);
|
||||
weight_mat = weight_mat(irf_index,irf_index);
|
|
@ -1,8 +1,8 @@
|
|||
function matched_moments = matched_moments_block(matched_moments, mom_method)
|
||||
% function matched_moments = matched_moments_block(matched_moments, mom_method)
|
||||
% matched_moments = matched_moments_block(matched_moments, mom_method)
|
||||
% -------------------------------------------------------------------------
|
||||
% Checks and transforms matched_moments block for further use in the estimation
|
||||
% -------------------------------------------------------------------------
|
||||
% Checks and transforms matched_moments bock for further use in the estimation
|
||||
% =========================================================================
|
||||
% INPUTS
|
||||
% matched_moments: [cell array] original matched_moments block
|
||||
% mom_method: [string] method of moments method (GMM or SMM)
|
||||
|
@ -12,7 +12,8 @@ function matched_moments = matched_moments_block(matched_moments, mom_method)
|
|||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% o mom.run
|
||||
% =========================================================================
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
|
@ -29,7 +30,7 @@ function matched_moments = matched_moments_block(matched_moments, mom_method)
|
|||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
|
||||
|
||||
matched_moments_orig = matched_moments;
|
||||
% higher-order product moments not supported yet for GMM
|
||||
|
@ -59,22 +60,22 @@ for jm = 1:size(matched_moments,1)
|
|||
end
|
||||
% find duplicate rows in cell array by making groups according to powers as we can then use cell2mat for the unique function
|
||||
powers = cellfun(@sum,matched_moments(:,3))';
|
||||
UniqueMomIdx = [];
|
||||
unique_mom_idx = [];
|
||||
for jpow = unique(powers)
|
||||
idx1 = find(powers==jpow);
|
||||
[~,idx2] = unique(cell2mat(matched_moments(idx1,:)),'rows');
|
||||
UniqueMomIdx = [UniqueMomIdx idx1(idx2)];
|
||||
unique_mom_idx = [unique_mom_idx idx1(idx2)];
|
||||
end
|
||||
% remove duplicate elements
|
||||
DuplicateMoms = setdiff(1:size(matched_moments_orig,1),UniqueMomIdx);
|
||||
if ~isempty(DuplicateMoms)
|
||||
fprintf('Duplicate declared moments found and removed in ''matched_moments'' block in rows:\n %s.\n',num2str(DuplicateMoms))
|
||||
duplicate_moms = setdiff(1:size(matched_moments_orig,1),unique_mom_idx);
|
||||
if ~isempty(duplicate_moms)
|
||||
fprintf('Duplicate declared moments found and removed in ''matched_moments'' block in rows:\n %s.\n',num2str(duplicate_moms));
|
||||
fprintf('Dynare will continue with remaining moment conditions\n');
|
||||
end
|
||||
if strcmp(mom_method, 'SMM')
|
||||
% for SMM: keep the original structure, but get rid of duplicate moments
|
||||
matched_moments = matched_moments_orig(sort(UniqueMomIdx),:);
|
||||
matched_moments = matched_moments_orig(sort(unique_mom_idx),:);
|
||||
elseif strcmp(mom_method, 'GMM')
|
||||
% for GMM we use the transformed matched_moments structure
|
||||
matched_moments = matched_moments(sort(UniqueMomIdx),:);
|
||||
matched_moments = matched_moments(sort(unique_mom_idx),:);
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue