From 77ac473b81b6ac96082029d00bd2a8484a28ab80 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx,de>
Date: Tue, 1 Jul 2014 18:50:24 +0200
Subject: [PATCH] Filter out ML of model_comparison.m

Also documents that ML is not supported and adds reference for model comparison
Related to #681

(cherry picked from commit 85f336496d09615c4e0a39c9284d3ee9b6d6d62a)
---
 doc/dynare.texi           | 11 +++++++++--
 matlab/model_comparison.m | 14 +++++++++++---
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/doc/dynare.texi b/doc/dynare.texi
index ad53f775e..f8a4908f4 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -5552,8 +5552,12 @@ estimates using a higher tapering are usually more reliable.
 @descriptionhead
 
 This command computes odds ratios and estimate a posterior density
-over a collection of models. The priors over models can be specified
-as the @var{DOUBLE} values, otherwise a uniform prior is assumed.
+over a collection of models 
+(see e.g. @cite{Koop (2003), Ch. 1}). The priors over models can be specified
+as the @var{DOUBLE} values, otherwise a uniform prior over all models is assumed. 
+In contrast to frequentist econometrics, the models to be compared do not need to be nested. 
+However, as the computation of posterior odds ratios is a Bayesian technique, 
+the comparison of models estimated with maximum likelihood is not supported.
 
 @examplehead
 
@@ -11369,6 +11373,9 @@ Kim, Jinill, Sunghyun Kim, Ernst Schaumburg, and Christopher A. Sims
 discrete time dynamic equilibrium models,'' @i{Journal of Economic
 Dynamics and Control}, 32(11), 3397--3414
 
+@item
+Koop, Gary (2003), @i{Bayesian Econometrics}, John Wiley & Sons
+
 @item
 Koopman, S. J. and J. Durbin (2003): ``Filtering and Smoothing of
 State Vector for Diffuse State Space Models,'' @i{Journal of Time
diff --git a/matlab/model_comparison.m b/matlab/model_comparison.m
index 0ff60e453..43cf0cc8f 100644
--- a/matlab/model_comparison.m
+++ b/matlab/model_comparison.m
@@ -75,10 +75,18 @@ for i=1:NumberOfModels
         eval(['MarginalLogDensity(i) = mstruct.oo_.MarginalDensity.' type ';']) 
     catch
         if strcmpi(type,'LaplaceApproximation')
-            disp(['MODEL_COMPARISON: I cant''t find the Laplace approximation associated to model ' ModelNames{i}])
+            if isfield(mstruct.oo_,'mle_mode')
+                disp(['MODEL_COMPARISON: Model comparison is a Bayesian approach and does not support models estimated with ML'])
+            else
+                disp(['MODEL_COMPARISON: I cant''t find the Laplace approximation associated to model ' ModelNames{i}])
+            end
             return
         elseif strcmpi(type,'ModifiedHarmonicMean')
-            disp(['MODEL_COMPARISON: I cant''t find the modified harmonic mean estimate associated to model ' ModelNames{i}])
+            if isfield(mstruct.oo_,'mle_mode')
+                disp(['MODEL_COMPARISON: Model comparison is a Bayesian approach and does not support models estimated with ML'])
+            else
+                disp(['MODEL_COMPARISON: I cant''t find the modified harmonic mean estimate associated to model ' ModelNames{i}])
+            end
             return
         end
     end
@@ -124,7 +132,7 @@ name = modelname(idx(end)+1:end);
 function name = get_model_name_without_extension(modelname)
 idx = strfind(modelname,'.mod');
 if isempty(idx)
-    idx = strfind(modelname,'.dyn')
+    idx = strfind(modelname,'.dyn');
 end
 if isempty(idx)
     name = modelname;
-- 
GitLab