X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Feconometrics-1.0.8%2Fmle_results.m;fp=octave_packages%2Feconometrics-1.0.8%2Fmle_results.m;h=f931c85a7f0bc5510f2f547773cbf0696bbf157f;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/econometrics-1.0.8/mle_results.m b/octave_packages/econometrics-1.0.8/mle_results.m new file mode 100644 index 0000000..f931c85 --- /dev/null +++ b/octave_packages/econometrics-1.0.8/mle_results.m @@ -0,0 +1,89 @@ +# Copyright (C) 2003,2004,2005 Michael Creel +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; If not, see . + +# usage: [theta, V, obj_value, infocrit] = +# mle_results(theta, data, model, modelargs, names, title, unscale, control) +# +# inputs: +# theta: column vector of model parameters +# data: data matrix +# model: name of function that computes log-likelihood +# modelargs: (cell) additional inputs needed by model. May be empty ("") +# names: vector of parameter names, e.g., use names = char("param1", "param2"); +# title: string, describes model estimated +# unscale: (optional) cell that holds means and std. dev. of data (see scale_data) +# control: (optional) BFGS or SA controls (see bfgsmin and samin). May be empty (""). +# nslaves: (optional) number of slaves if executed in parallel (requires MPITB) +# +# outputs: +# theta: ML estimated value of parameters +# obj_value: the value of the log likelihood function at ML estimate +# conv: return code from bfgsmin (1 means success, see bfgsmin for details) +# iters: number of BFGS iteration used + + +## +## Please see mle_example for information on how to use this + +# report results +function [theta, V, obj_value, infocrit] = mle_results(theta, data, model, modelargs, names, mletitle, unscale, control = {-1}, nslaves = 0) + if nargin < 6 mletitle = "Generic MLE title"; endif + + [theta, obj_value, convergence] = mle_estimate(theta, data, model, modelargs, control, nslaves); + V = mle_variance(theta, data, model, modelargs); + + # unscale results if argument has been passed + # this puts coefficients into scale corresponding to the original modelargs + if (nargin > 6) + if iscell(unscale) # don't try it if unscale is simply a placeholder + [theta, V] = unscale_parameters(theta, V, unscale); + endif + endif + + [theta, V] = delta_method("parameterize", theta, {data, model, modelargs}, V); + + n = rows(data); + k = rows(V); + se = sqrt(diag(V)); + if convergence == 1 convergence="Normal convergence"; + elseif convergence == 2 convergence="No convergence"; + elseif convergence == -1 convergence = "Max. iters. exceeded"; + endif + printf("\n\n******************************************************\n"); + disp(mletitle); + printf("\nMLE Estimation Results\n"); + printf("BFGS convergence: %s\n\n", convergence); + + printf("Average Log-L: %f\n", obj_value); + printf("Observations: %d\n", n); + a =[theta, se, theta./se, 2 - 2*normcdf(abs(theta ./ se))]; + + clabels = char("estimate", "st. err", "t-stat", "p-value"); + + printf("\n"); + if names !=0 prettyprint(a, names, clabels); + else prettyprint_c(a, clabels); + endif + + printf("\nInformation Criteria \n"); + caic = -2*n*obj_value + rows(theta)*(log(n)+1); + bic = -2*n*obj_value + rows(theta)*log(n); + aic = -2*n*obj_value + 2*rows(theta); + infocrit = [caic, bic, aic]; + printf("CAIC : %8.4f Avg. CAIC: %8.4f\n", caic, caic/n); + printf(" BIC : %8.4f Avg. BIC: %8.4f\n", bic, bic/n); + printf(" AIC : %8.4f Avg. AIC: %8.4f\n", aic, aic/n); + printf("******************************************************\n"); +endfunction