bhhh_max

bhhh_max —

Synopsis




enum        BHHH_opts;
            model_info;
int         (*LL_FUNC)                      (double*,
                                             const double**,
                                             double**,
                                             model_info*,
                                             ...);
void        model_info_free                 (model_info *minfo);
model_info* model_info_new                  (int k,
                                             int t1,
                                             int t2,
                                             int bign,
                                             double tol);
MODEL*      model_info_capture_OPG_model    (model_info *minfo);
gretl_matrix* model_info_get_VCV            (model_info *minfo);
double*     model_info_get_theta            (model_info *minfo);
int         model_info_get_t1               (const model_info *minfo);
int         model_info_get_t2               (const model_info *minfo);
int         model_info_get_n                (const model_info *minfo);
int         model_info_get_iters            (const model_info *minfo);
void*       model_info_get_extra_info       (model_info *minfo);
double      model_info_get_ll               (const model_info *minfo);
double**    model_info_get_series           (const model_info *minfo);
void        model_info_set_extra_info       (model_info *minfo,
                                             void *extra);
void        model_info_set_n_series         (model_info *minfo,
                                             int n);
int         model_info_get_k                (model_info *minfo);
void        model_info_set_opts             (model_info *minfo,
                                             unsigned char opts);
void        model_info_set_ll               (model_info *minfo,
                                             double ll,
                                             int do_score);
int         bhhh_max                        (LL_FUNC loglik,
                                             const double **X,
                                             const double *init_coeff,
                                             model_info *minfo,
                                             PRN *prn);

Description

Details

enum BHHH_opts

typedef enum {
    PRESERVE_OPG_MODEL = 1 << 0,  
    FULL_VCV_MATRIX    = 1 << 1
} BHHH_opts;


model_info

typedef struct _model_info model_info;


LL_FUNC ()

int         (*LL_FUNC)                      (double*,
                                             const double**,
                                             double**,
                                             model_info*,
                                             ...);

Param1 :
Param2 :
Param3 :
Param4 :
... :
Returns :

model_info_free ()

void        model_info_free                 (model_info *minfo);

Frees the dynamically allocated members of minfo, then frees minfo itself.

minfo : model info pointer.

model_info_new ()

model_info* model_info_new                  (int k,
                                             int t1,
                                             int t2,
                                             int bign,
                                             double tol);

Creates the basic information structure required by bhhh_max(). Within that function, iteration is terminated when the difference in the log-likelihood from one round to the next falls below tol. Note that t1 and t2 are zero-based.

k : number of parameters to be estimated.
t1 : starting observation of estimation range.
t2 : ending observation of estimation range.
bign : total obserations in current dataset.
tol : tolerance for assessing convergence.
Returns : pointer to newly allocated model_info, or NULL on failure.

model_info_capture_OPG_model ()

MODEL*      model_info_capture_OPG_model    (model_info *minfo);

minfo : model info pointer.
Returns : pointer to a gretl MODEL, which contains the results of the OPG (Outer Product of the Gradient) regression associated with minfo, if the preservation of this model has been flagged by use of the option PRESERVE_OPG_MODEL: see see model_info_set_opts(). Otherwise returns NULL.

model_info_get_VCV ()

gretl_matrix* model_info_get_VCV            (model_info *minfo);

minfo : model info pointer.
Returns : pointer to the covariance matrix of minfo, if the creation of this matrix has been flagged by use of the option FULL_VCV_MATRIX: see model_info_set_opts(). Otherwise returns NULL.

model_info_get_theta ()

double*     model_info_get_theta            (model_info *minfo);

minfo : model info pointer.
Returns : the parameter vector theta from minfo. This array is freed when minfo is freed, so if the results are wanted by the caller, they should be copied.

model_info_get_t1 ()

int         model_info_get_t1               (const model_info *minfo);

minfo : model info pointer.
Returns : the (zero-based) start of the sample range for minfo.

model_info_get_t2 ()

int         model_info_get_t2               (const model_info *minfo);

minfo : model info pointer.
Returns : the end of the sample range for minfo.

model_info_get_n ()

int         model_info_get_n                (const model_info *minfo);

minfo : model info pointer.
Returns : the length of the data series used in minfo.

model_info_get_iters ()

int         model_info_get_iters            (const model_info *minfo);

minfo : model info pointer.
Returns : the number of iterations taken in estimating the model in minfo.

model_info_get_extra_info ()

void*       model_info_get_extra_info       (model_info *minfo);

Retrieves the content of the "extra" pointer member of minfo.

minfo : model info pointer.
Returns : the pointer that was set with model_info_set_extra_info(), or NULL if none was set.

model_info_get_ll ()

double      model_info_get_ll               (const model_info *minfo);

minfo : model info pointer.
Returns : the log-likelihood for minfo.

model_info_get_series ()

double**    model_info_get_series           (const model_info *minfo);

minfo : model info pointer.
Returns : the allocated two-dimensional array set on minfo using model_info_set_n_series(). This array is freed when minfo is freed, so the returned pointer itself should not be modified.

model_info_set_extra_info ()

void        model_info_set_extra_info       (model_info *minfo,
                                             void *extra);

Set the content of the "extra" pointer member of minfo. This pointer is not used within bhhh_max(), it is intended for use within the log-likelihood callback. Setting this pointer is therefore optional.

minfo : model info pointer.
extra : pointer to set on minfo.

model_info_set_n_series ()

void        model_info_set_n_series         (model_info *minfo,
                                             int n);

Sets the number of auxiliary data series needed for the calculations associated with minfo. These series are allocated within the bhhh_max() function, and are freed when minfo is freed; see model_info_free(). The length of each series is given by the n member of minfo, which is set implicitly when the start and end of the sample range are set, using model_info_new(), and which can be retrieved using model_info_get_n(). This length is in fact t2 (zero-based ending observation of sample range) plus one.

These series (if any) are not actually used within bhhh_max() itself: they are intended for use within the log-likelihood callback (serving as persistent storage, and saving the callback function from having to allocate and deallocate storage on each call). The series may be written to in that context, but the pointers themselves should not be altered in any way.

minfo : model info pointer.
n : number of auxiliary data series.

model_info_get_k ()

int         model_info_get_k                (model_info *minfo);

minfo : model info pointer.
Returns : the number of regressors in minfo.

model_info_set_opts ()

void        model_info_set_opts             (model_info *minfo,
                                             unsigned char opts);

Sets the option flags for minfo. If the option PRESERVE_OPG_MODEL is set, a pointer to the MODEL struct used internally by bhhh_max() is available on exit via model_info_capture_OPG_model(); otherwise this is freed on exit. If FULL_VCV_MATRIX is set, a pointer to the full covariance matrix from the last iteration of the OPG model is available on exit using model_info_get_VCV().

minfo : model info pointer.
opts : option flags to set, from BHHH_opts.

model_info_set_ll ()

void        model_info_set_ll               (model_info *minfo,
                                             double ll,
                                             int do_score);

Sets the log-likelihood for minfo. If do_score is non-zero, sets the primary ll value, otherwise sets the secondary value, which is used for comparison (to see if we have succeeded in increasing the likelihood by following the estimated gradient).

minfo : model info pointer.
ll : log-likehood.
do_score :

bhhh_max ()

int         bhhh_max                        (LL_FUNC loglik,
                                             const double **X,
                                             const double *init_coeff,
                                             model_info *minfo,
                                             PRN *prn);

Maximize likelihood using the BHHH conditional ML method, implemented via iteration of the Outer Product of the Gradient (OPG) regression with line search.

The minfo pointer is obtained using model_info_new(). Optional settings may be applied using model_info_set_opts(), model_info_set_n_series() and model_info_set_extra_info().

loglik is called to calculate the log-likelihood for the model in question. The parameters passed to this function are: (1) the array of estimated coefficients; (2) the primary data array X; (3) a further data array Z; (4) minfo; and (5) an integer that is 1 if the score matrix should be calculated in Z, otherwise 0. The Z array is allocated within bhhh_max and is freed on exit; it is a two-dimensional array with k + 1 members, each of length n (where k and n may be obtained using model_info_get_k() and model_info_get_n()). The first member, Z[0], represents the constant or intercept, and should not be modified.

For an example of the use of this function, see arma.c in the plugin directory of the gretl source.

loglik : pointer to function for calculating log-likelihood and score matrix; see below.
X : primary data set (not used within this function, but passed on for use by loglik).
init_coeff : starting values for coefficients.
minfo : model info struct; see below.
prn : printing struct for iteration info (or NULL).
Returns : 0 on successful completion, non-zero error code otherwise.