From 24c817afa7a5b67e548cf6538de966ca5569c315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Ry=C3=BBk=29?= Date: Fri, 17 Dec 2021 18:02:24 +0100 Subject: [PATCH] Add integration tests for NLS estimation. --- tests/Makefile.am | 5 +- .../univariate/nls/dynamicmodel.mod | 48 ++++++++++++++++++ .../estimation/univariate/nls/staticmodel.mod | 46 +++++++++++++++++ .../univariate/nls/staticmodelx.mod | 49 +++++++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 tests/estimation/univariate/nls/dynamicmodel.mod create mode 100644 tests/estimation/univariate/nls/staticmodel.mod create mode 100644 tests/estimation/univariate/nls/staticmodelx.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 37fecb676..d2f378f3e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -82,6 +82,8 @@ MODFILES = \ estimation/system_prior_restriction/Gali_2015.mod \ estimation/no_init_estimation_check_first_obs/fs2000_init_check.mod \ estimation/example_nls.mod \ + estimation/univariate/nls/staticmodel.mod \ + estimation/univariate/nls/dynamicmodel.mod \ moments/example1_var_decomp.mod \ moments/example1_bp_test.mod \ moments/test_AR1_spectral_density.mod \ @@ -632,7 +634,8 @@ XFAIL_MODFILES = ramst_xfail.mod \ estimation/tune_mh_jscale/fs2000_2_xfail.mod \ estimation/no_init_estimation_check_first_obs/fs2000_init_check_XFAIL.mod \ estimation/no_init_estimation_check_first_obs/fs2000_init_check_XFAIL2.mod \ - var-expectations/1-with-time-shift-b/example1.mod + var-expectations/1-with-time-shift-b/example1.mod \ + estimation/univariate/nls/staticmodelx.mod MFILES = histval_initval_file/ramst_initval_file_data.m diff --git a/tests/estimation/univariate/nls/dynamicmodel.mod b/tests/estimation/univariate/nls/dynamicmodel.mod new file mode 100644 index 000000000..591adab6c --- /dev/null +++ b/tests/estimation/univariate/nls/dynamicmodel.mod @@ -0,0 +1,48 @@ +// --+ options: json=compute, stochastic +-- + +var y x z; + +varexo ey ex ez; + +parameters gamma rho; + +gamma = .3; +rho = .9; + +model; + + [name='eqx'] + x = x(-1)^.8*exp(ex) ; + + [name='eqz'] + z = exp(ez); + + [name='eqy'] + y = x^(1-gamma)*z^gamma*abs(y(-1))^rho + ey; + +end; + +histval; + x(0) = 0.1; + z(0) = 0.5; +end; + +shocks; + var ex = .05; + var ez = .05; + var ey = .01; +end; + +// Simulate a sample. +simulations = simul_backward_model([], 5000); + +// Set residuals in the estimated equation to NaNs. +simulations.ey = dseries(NaN); + +// Set initial guess for the estimated parameter. +clear('eparams') +eparams.gamma = 0.6; +eparams.rho = 0.3; + +// Call estimation routine. +estimate.nls('eqy', eparams, simulations, 1001Y:5000Y, 'annealing') diff --git a/tests/estimation/univariate/nls/staticmodel.mod b/tests/estimation/univariate/nls/staticmodel.mod new file mode 100644 index 000000000..f7b532af2 --- /dev/null +++ b/tests/estimation/univariate/nls/staticmodel.mod @@ -0,0 +1,46 @@ +// --+ options: json=compute, stochastic +-- + +var y x z; + +varexo ey ex ez; + +parameters theta gamma; + +gamma = .3; + +model; + + [name='eqx'] + x = x(-1)^.8*exp(ex) ; + + [name='eqz'] + z = exp(ez); + + [name='eqy'] + y = x^(1-gamma)*z^gamma + ey; + +end; + +histval; + x(0) = 0.1; + z(0) = 0.5; +end; + +shocks; + var ex = .05; + var ez = .05; + var ey = .01; +end; + +// Simulate a sample. +simulations = simul_backward_model([], 5000); + +// Set residuals in the estimated equation to NaNs. +simulations.ey = dseries(NaN); + +// Set initial guess for the estimated parameter. +clear('eparams') +eparams.gamma = 0.6; + +// Call estimation routine. +estimate.nls('eqy', eparams, simulations, 1001Y:5000Y, 'annealing') diff --git a/tests/estimation/univariate/nls/staticmodelx.mod b/tests/estimation/univariate/nls/staticmodelx.mod new file mode 100644 index 000000000..321a0c117 --- /dev/null +++ b/tests/estimation/univariate/nls/staticmodelx.mod @@ -0,0 +1,49 @@ +// --+ options: json=compute, stochastic +-- + +var y x z; + +varexo ey ex ez; + +parameters theta gamma; + +gamma = .3; + +model; + + [name='eqx'] + x = x(-1)^.8*exp(ex) ; + + [name='eqz'] + z = exp(ez); + + [name='eqy'] + y = x^(1-gamma)*z^gamma + ey; + +end; + +histval; + x(0) = 0.1; + z(0) = 0.5; +end; + +shocks; + var ex = .05; + var ez = .05; + var ey = .01; +end; + +// Simulate a sample. +simulations = simul_backward_model([], 5000); + +// Set residuals in the estimated equation to NaNs. +simulations.ey = dseries(NaN); + +// Add a missing NaN in the database, this should trigger an error in estimate.nls. +simulations.z(1002Y) = NaN; + +// Set initial guess for the estimated parameter. +clear('eparams') +eparams.gamma = 0.6; + +// Call estimation routine. +estimate.nls('eqy', eparams, simulations, 1001Y:5000Y, 'annealing')