Estimation

Estimation — estimation of regression models

Functions

Includes

#include <gretl/libgretl.h>

Description

Most libgretl functions that estimate regression models are collected here.

Please note that most of these functions return a MODEL struct -- literally a struct, not a pointer to one. To handle such a return value in C you should either (a) declare a MODEL and assign to it, or (b) allocate a MODEL "on the heap" and then assign to its content using the indirection operator. The code fragment below illustrates both approaches.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <gretl/libgretl.h>

int ols_using_gretl (const int *list, DATASET *dset,
                     PRN *prn)
{
    MODEL model;
    MODEL *pmod;
    int err;

    // method (a)
    model = lsq(list, dset, OLS, OPT_NONE);
    err = model.errcode;
    if (!err) {
        printmodel(&model, dset, OPT_NONE, prn);
    }
    clear_model(&model);

    // method (b)
    pmod = gretl_model_new();
    *pmod = lsq(list, dset, OLS, OPT_NONE);
    err = pmod->errcode;
    if (!err) {
        printmodel(pmod, dset, OPT_NONE, prn);
    }
    gretl_model_free(pmod);

    return err;
}

Functions

lsq ()

MODEL
lsq (const int *list,
     DATASET *dset,
     GretlCmdIndex ci,
     gretlopt opt);

Computes least squares estimates of the model specified by list , using an estimator determined by the value of ci .

Parameters

list

dependent variable plus list of regressors.

 

dset

dataset struct.

 

ci

one of the command indices in LSQ_MODEL.

 

opt

option flags: zero or more of the following -- OPT_R: compute robust standard errors; OPT_A: treat as auxiliary regression (don't bother checking for presence of lagged dependent var, don't augment model count); OPT_N: don't use degrees of freedom correction for standard error of regression; OPT_M: reject missing observations within sample range; OPT_Z: (internal use) suppress the automatic elimination of perfectly collinear variables. OPT_X: compute "variance matrix" as just (X'X)^{-1} OPT_I: compute Durbin-Watson p-value. OPT_U: treat null model as OK. OPT_P: (ar1 only): use Prais-Winsten. OPT_S: estimation as part of system.

 

Returns

a MODEL struct, containing the estimates.


ar_model ()

MODEL
ar_model (const int *list,
          DATASET *dset,
          gretlopt opt,
          PRN *prn);

Estimate the model given in list using the generalized Cochrane-Orcutt procedure for autoregressive errors.

Parameters

list

list of lags plus dependent variable and list of regressors.

 

dset

dataset struct.

 

opt

may contain OPT_O to print covariance matrix.

 

prn

gretl printing struct.

 

Returns

MODEL struct containing the results.


ar1_model ()

MODEL
ar1_model (const int *list,
           DATASET *dset,
           gretlopt opt,
           PRN *prn);

Parameters

list

model specification.

 

dset

dataset struct.

 

opt

option flags: may include OPT_H to use Hildreth-Lu, OPT_P to use Prais-Winsten, OPT_B to suppress Cochrane-Orcutt fine-tuning of Hildreth-Lu results, OPT_G to generate a gnuplot graph of the search in Hildreth-Lu case.

 

prn

gretl printer.

 

Returns

model struct containing the estimates.


lad_model ()

MODEL
lad_model (const int *list,
           DATASET *dset,
           gretlopt opt);

Estimate the model given in list using the method of Least Absolute Deviation (LAD).

Parameters

list

dependent variable plus list of regressors.

 

dset

dataset struct.

 

opt

may include OPT_Q for quiet operation.

 

Returns

a MODEL struct, containing the estimates.


quantreg ()

MODEL
quantreg (const gretl_matrix *tau,
          const int *list,
          DATASET *dset,
          gretlopt opt,
          PRN *prn);

Estimate the model given in list using the method of quantile regression.

Parameters

tau

vector containing one or more quantile values, in the range 0.01 to 0.99.

 

list

model specification: dependent var and regressors.

 

dset

dataset struct.

 

opt

may contain OPT_R for robust standard errors, OPT_I to produce confidence intervals.

 

prn

gretl printing struct.

 

Returns

a MODEL struct, containing the estimates.


arma ()

MODEL
arma (const int *list,
      const int *pqlags,
      DATASET *dset,
      gretlopt opt,
      PRN *prn);

Calculates ARMA estimates. By default the estimator is exact ML, implemented via gretl's Kalman filter in conjunction with the BFGS maximizer. Other options: if opt includes OPT_L we use L-BFGS-B rather than standard BFGS; OPT_C (incompatible with OPT_L) calls for use of conditional ML (BHHH algorithm); and OPT_X requests estimation via X-12-ARIMA rather than native code.

If pqlags is non-NULL it should take the form of two gretl sub-lists joined by LISTSEP: the first sub-list holds a set of AR lags and the second a list of MA lags. If only AR lags are specified, a single list may be given; if only MA lags are specified, use LISTSEP with a null first sub-list.

If the model specification does not include a constant this is added automatically, unless opt includes OPT_N ("no constant").

When the estimation method is native exact ML, two (mutually exclusive) flags in opt may be used to control the estimator of the covariance matrix: OPT_G specifies use of the outer product of the gradient (OPG), while OPT_H specifies use of the (numerical) Hessian. If neither of these flags is given, the default is to use the Hessian by preference, but to fall back to OPG if computation of the numerical Hessian fails. These flags are ignored if estimation is not via native exact ML.

Parameters

list

AR and MA orders, dependent variable, and any exogenous regressors.

 

pqlags

list giving specific non-seasonal AR/MA lags (or NULL).

 

dset

dataset struct.

 

opt

option flags.

 

PRN

for printing details of iterations (or NULL).

 

Returns

a MODEL struct, containing the estimates.


garch ()

MODEL
garch (const int *list,
       DATASET *dset,
       gretlopt opt,
       PRN *prn);

Calculate GARCH estimates.

Parameters

list

dependent variable plus arch and garch orders.

 

dset

dataset struct.

 

opt

can specify robust standard errors and VCV.

 

prn

for printing details of iterations (or NULL).

 

Returns

a MODEL struct, containing the estimates.


mp_ols ()

MODEL
mp_ols (const int *list,
        DATASET *dset,
        gretlopt opt);

Estimate an OLS model using multiple-precision arithmetic via the GMP library.

Parameters

list

specification of variables to use.

 

dset

dataset struct.

 

opt

maye include OPT_Q for quiet operation.

 

Returns

a MODEL struct, containing the estimates.


panel_model ()

MODEL
panel_model (const int *list,
             DATASET *dset,
             gretlopt opt,
             PRN *prn);

Calculate estimates for a panel dataset, using fixed effects (the default), random effects, or weighted least squares based on the respective variances for the cross-sectional units.

Parameters

list

regression list (dependent variable plus independent variables).

 

dset

dataset struct.

 

opt

can include OPT_Q (quiet estimation), OPT_U (random effects model), OPT_H (weights based on the error variance for the respective cross-sectional units), OPT_I (iterate, only available in conjunction with OPT_H).

 

prn

printing struct (or NULL).

 

Returns

a MODEL struct, containing the estimates.


ivreg ()

MODEL
ivreg (const int *list,
       DATASET *dset,
       gretlopt opt);

Calculate IV estimates for a linear model, by default via two-stage least squares. The option flags can include OPT_Q for quiet operation, and either OPT_L to specify estimation via Limited Information Maximum Likelihood or OPT_G for estimation via Generalized method of Moments.

Parameters

list

regression list; see the documentation for the "tsls" command.

 

dset

dataset struct.

 

opt

option flags.

 

Returns

a MODEL struct, containing the estimates.


dpd_model ()

MODEL
dpd_model (const int *list,
           const int *laglist,
           const char *ispec,
           const DATASET *dset,
           gretlopt opt,
           PRN *prn);

Implements the "dpanel" command.

Parameters

list

regression list.

 

laglist

list of specific lags of the dependent variable, or NULL.

 

ispec

may contain additional instrument specification.

 

dset

dataset struct.

 

opt

may include... see options.c.

 

prn

printing struct.

 

Returns

a MODEL struct, containing the estimates.


hsk_model ()

MODEL
hsk_model (const int *list,
           DATASET *dset,
           gretlopt opt);

Estimate the model given in list using a correction for heteroskedasticity.

Parameters

list

dependent variable plus list of regressors.

 

dset

dataset struct.

 

opt

may include OPT_N to suppress use of squares of regressors in the auxiliary regression.

 

Returns

a MODEL struct, containing the estimates.


arch_model ()

MODEL
arch_model (const int *list,
            int order,
            DATASET *dset,
            gretlopt opt);

Estimate the model given in list via weighted least squares, with the weights based on the predicted error variances from an auxiliary regression of the squared residuals on their lagged values.

Parameters

list

dependent variable plus list of regressors.

 

order

lag order for ARCH process.

 

dset

dataset struct.

 

opt

may contain OPT_O to print covariance matrix.

 

Returns

a MODEL struct, containing the estimates.


whites_test ()

int
whites_test (MODEL *pmod,
             DATASET *dset,
             gretlopt opt,
             PRN *prn);

Runs White's test for heteroskedasticity on the given model.

Parameters

pmod

pointer to model.

 

dset

dataset struct.

 

opt

if flags include OPT_S, save results to model; OPT_Q means don't print the auxiliary regression; OPT_B means do the simpler Breusch-Pagan variant; OPT_I means run silently.

 

prn

gretl printing struct.

 

Returns

0 on successful completion, error code on error.


arch_test ()

int
arch_test (MODEL *pmod,
           int order,
           const DATASET *dset,
           gretlopt opt,
           PRN *prn);

Tests pmod for AutoRegressive Conditional Heteroskedasticity.

Parameters

pmod

model to be tested.

 

order

lag order for ARCH process.

 

dset

dataset struct.

 

opt

if flags include OPT_S, save test results to model; if OPT_Q, be less verbose; if OPT_I, be silent.

 

prn

gretl printing struct.

 

Returns

0 on success, non-zero code on error.


array_arch_test ()

int
array_arch_test (const double *u,
                 int n,
                 int order,
                 gretlopt opt,
                 PRN *prn);

makevcv ()

int
makevcv (MODEL *pmod,
         double sigma);

Inverts the Cholesky-decomposed X'X and computes the coefficient covariance matrix.

Parameters

pmod

pointer to model.

 

sigma

square root of error variance, or 1.0 to produce just X'X^{-1}.

 

Returns

0 on successful completion, non-zero code on error.


augment_regression_list ()

int *
augment_regression_list (const int *orig,
                         int aux,
                         DATASET *dset,
                         int *err);

Augment the regression list orig with auxiliary terms. If aux is AUX_SQ add the squares of the original regressors; if aux is AUX_WHITE add squares and cross-products, or if aux is AUX_LOG add the natural logs of the original regressors. If they are not already present, these variables are added to the data array.

Parameters

orig

list giving original regression specification.

 

aux

either AUX_SQ, AUX_LOG or AUX_WHITE.

 

dset

dataset struct.

 

err

location to receive error code.

 

Returns

the augmented list, or NULL on failure.


anova ()

int
anova (const int *list,
       const DATASET *dset,
       gretlopt opt,
       PRN *prn);

Does one-way or two-way Analysis of Variance (prints table and F-test).

Parameters

list

must contain the response and treatment variables.

 

dset

dataset struct.

 

opt

unused at present.

 

prn

printing struct.

 

Returns

0 on success, non-zero on failure.