Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
dynare
Commits
e025d56a
Verified
Commit
e025d56a
authored
1 year ago
by
Willi Mutschler
Browse files
Options
Downloads
Patches
Plain Diff
method_of_moments: refactor J-Test
parent
07b62fe5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
matlab/+mom/Jtest.m
+67
-0
67 additions, 0 deletions
matlab/+mom/Jtest.m
matlab/+mom/run.m
+2
-27
2 additions, 27 deletions
matlab/+mom/run.m
with
69 additions
and
27 deletions
matlab/+mom/Jtest.m
0 → 100644
+
67
−
0
View file @
e025d56a
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)
% -------------------------------------------------------------------------
% 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
% -------------------------------------------------------------------------
% OUTPUT
% oo_: [struct] updated results
% -------------------------------------------------------------------------
% This function is called by
% o mom.run
% -------------------------------------------------------------------------
% This function calls
% o mom.objective_function
% o mom.optimal_weighting_matrix
% =========================================================================
% 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
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_
,
bayestopt_
);
else
fval
=
oo_
.
mom
.
Q
;
end
% Compute J statistic
if
strcmp
(
options_mom_
.
mom
.
mom_method
,
'SMM'
)
Variance_correction_factor
=
options_mom_
.
mom
.
variance_correction_factor
;
elseif
strcmp
(
options_mom_
.
mom
.
mom_method
,
'GMM'
)
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
);
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
matlab/+mom/run.m
+
2
−
27
View file @
e025d56a
...
...
@@ -569,39 +569,14 @@ if strcmp(options_mom_.mom.mom_method,'GMM') || strcmp(options_mom_.mom.mom_meth
end
% -------------------------------------------------------------------------
% Step 8: J test
% -------------------------------------------------------------------------
if
options_mom_
.
mom
.
mom_nbr
>
length
(
xparam1
)
%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
,
xparam1
,
Bounds
,
oo_j
,
estim_params_
,
M_
,
options_mom_
);
end
% Compute J statistic
if
strcmp
(
options_mom_
.
mom
.
mom_method
,
'SMM'
)
Variance_correction_factor
=
options_mom_
.
mom
.
variance_correction_factor
;
elseif
strcmp
(
options_mom_
.
mom
.
mom_method
,
'GMM'
)
Variance_correction_factor
=
1
;
end
oo_
.
mom
.
J_test
.
j_stat
=
dataset_
.
nobs
*
Variance_correction_factor
*
fval
/
options_mom_
.
mom
.
weighting_matrix_scaling_factor
;
oo_
.
mom
.
J_test
.
degrees_freedom
=
length
(
oo_
.
mom
.
model_moments
)
-
length
(
xparam1
);
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
)
end
% -------------------------------------------------------------------------
% display final estimation results
% -------------------------------------------------------------------------
if
strcmp
(
options_mom_
.
mom
.
mom_method
,
'SMM'
)
||
strcmp
(
options_mom_
.
mom
.
mom_method
,
'GMM'
)
% Store results in output structure
oo_
.
mom
=
display_estimation_results_table
(
xparam1
,
SE
,
M_
,
options_mom_
,
estim_params_
,
bayestopt_
,
oo_
.
mom
,
prior_dist_names
,
options_mom_
.
mom
.
mom_method
,
lower
(
options_mom_
.
mom
.
mom_method
));
% J test
oo_
=
mom
.
Jtest
(
xparam1
,
objective_function
,
Woptflag
,
oo_
,
options_mom_
,
bayestopt_
,
Bounds
,
estim_params_
,
M_
,
dataset_
.
nobs
);
title
=
[
'Comparison of data moments and model moments ('
,
options_mom_
.
mom
.
mom_method
,
')'
];
headers
=
{
'Moment'
,
'Data'
,
'Model'
};
for
jm
=
1
:
size
(
M_
.
matched_moments
,
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment