1 # Copyright (C) 2003,2004,2005 Michael Creel <michael.creel@uab.es>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; If not, see <http://www.gnu.org/licenses/>.
16 # usage: [theta, V, obj_value, infocrit] =
17 # mle_results(theta, data, model, modelargs, names, title, unscale, control)
20 # theta: column vector of model parameters
22 # model: name of function that computes log-likelihood
23 # modelargs: (cell) additional inputs needed by model. May be empty ("")
24 # names: vector of parameter names, e.g., use names = char("param1", "param2");
25 # title: string, describes model estimated
26 # unscale: (optional) cell that holds means and std. dev. of data (see scale_data)
27 # control: (optional) BFGS or SA controls (see bfgsmin and samin). May be empty ("").
28 # nslaves: (optional) number of slaves if executed in parallel (requires MPITB)
31 # theta: ML estimated value of parameters
32 # obj_value: the value of the log likelihood function at ML estimate
33 # conv: return code from bfgsmin (1 means success, see bfgsmin for details)
34 # iters: number of BFGS iteration used
38 ## Please see mle_example for information on how to use this
41 function [theta, V, obj_value, infocrit] = mle_results(theta, data, model, modelargs, names, mletitle, unscale, control = {-1}, nslaves = 0)
42 if nargin < 6 mletitle = "Generic MLE title"; endif
44 [theta, obj_value, convergence] = mle_estimate(theta, data, model, modelargs, control, nslaves);
45 V = mle_variance(theta, data, model, modelargs);
47 # unscale results if argument has been passed
48 # this puts coefficients into scale corresponding to the original modelargs
50 if iscell(unscale) # don't try it if unscale is simply a placeholder
51 [theta, V] = unscale_parameters(theta, V, unscale);
55 [theta, V] = delta_method("parameterize", theta, {data, model, modelargs}, V);
60 if convergence == 1 convergence="Normal convergence";
61 elseif convergence == 2 convergence="No convergence";
62 elseif convergence == -1 convergence = "Max. iters. exceeded";
64 printf("\n\n******************************************************\n");
66 printf("\nMLE Estimation Results\n");
67 printf("BFGS convergence: %s\n\n", convergence);
69 printf("Average Log-L: %f\n", obj_value);
70 printf("Observations: %d\n", n);
71 a =[theta, se, theta./se, 2 - 2*normcdf(abs(theta ./ se))];
73 clabels = char("estimate", "st. err", "t-stat", "p-value");
76 if names !=0 prettyprint(a, names, clabels);
77 else prettyprint_c(a, clabels);
80 printf("\nInformation Criteria \n");
81 caic = -2*n*obj_value + rows(theta)*(log(n)+1);
82 bic = -2*n*obj_value + rows(theta)*log(n);
83 aic = -2*n*obj_value + 2*rows(theta);
84 infocrit = [caic, bic, aic];
85 printf("CAIC : %8.4f Avg. CAIC: %8.4f\n", caic, caic/n);
86 printf(" BIC : %8.4f Avg. BIC: %8.4f\n", bic, bic/n);
87 printf(" AIC : %8.4f Avg. AIC: %8.4f\n", aic, aic/n);
88 printf("******************************************************\n");