Estimation

Estimation — estimation of regression models

Synopsis

#include <libgretl.h>

MODEL               lsq                                 (const int *list,
                                                         double **Z,
                                                         DATAINFO *pdinfo,
                                                         GretlCmdIndex ci,
                                                         gretlopt opt);
MODEL               ar_model                            (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
MODEL               ar1_model                           (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
MODEL               lad                                 (const int *list,
                                                         double **Z,
                                                         DATAINFO *pdinfo);
MODEL               quantreg                            (const gretl_matrix *tau,
                                                         const int *list,
                                                         double **Z,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
MODEL               arma                                (const int *list,
                                                         const int *pqlags,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
MODEL               garch                               (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
MODEL               mp_ols                              (const int *list,
                                                         const double **Z,
                                                         DATAINFO *pdinfo);
MODEL               panel_model                         (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
MODEL               ivreg                               (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt);
MODEL               arbond_model                        (const int *list,
                                                         const char *ispec,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
MODEL               dpd_model                           (const int *list,
                                                         const int *laglist,
                                                         const char *ispec,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
MODEL               hsk_model                           (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo);
MODEL               arch_model                          (const int *list,
                                                         int order,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
int                 whites_test                         (MODEL *pmod,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
int                 arch_test                           (MODEL *pmod,
                                                         int order,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);
int                 array_arch_test                     (const double *u,
                                                         int n,
                                                         int order,
                                                         gretlopt opt,
                                                         PRN *prn);
int                 makevcv                             (MODEL *pmod,
                                                         double sigma);
int *               augment_regression_list             (const int *orig,
                                                         int aux,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo);
double *            gretl_XTX                           (const MODEL *pmod,
                                                         const double **Z,
                                                         int *err);
int                 anova                               (const int *list,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

Description

Most libgretl functions that estimate regression models are collected here.

Please note that most of these functions return a MODEL struct. This is literally a struct, not a pointer to one. FIXME add more explanation.

Details

lsq ()

MODEL               lsq                                 (const int *list,
                                                         double **Z,
                                                         DATAINFO *pdinfo,
                                                         GretlCmdIndex ci,
                                                         gretlopt opt);

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

list :

dependent variable plus list of regressors.

Z :

data array.

pdinfo :

dataset information.

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_B: don't compute R^2. OPT_I: compute Durbin-Watson p-value. OPT_Q: use QR decomposition (not necessarily robust VCV). OPT_U: treat null model as OK.

Returns :

a MODEL struct, containing the estimates.

ar_model ()

MODEL               ar_model                            (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

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

list :

list of lags plus dependent variable and list of regressors.

pZ :

pointer to data array.

pdinfo :

dataset information.

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,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

list :

model specification.

pZ :

address of data array.

pdinfo :

dataset information.

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               lad                                 (const int *list,
                                                         double **Z,
                                                         DATAINFO *pdinfo);

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

list :

dependent variable plus list of regressors.

Z :

data array.

pdinfo :

dataset information.

Returns :

a MODEL struct, containing the estimates.

quantreg ()

MODEL               quantreg                            (const gretl_matrix *tau,
                                                         const int *list,
                                                         double **Z,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

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

tau :

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

list :

model specification: dependent var and regressors.

Z :

data array.

pdinfo :

dataset information.

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,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         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.

list :

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

pqlags :

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

Z :

data array.

pdinfo :

dataset information.

opt :

option flags.

prn :

for printing details of iterations (or NULL).

Returns :

a MODEL struct, containing the estimates.

garch ()

MODEL               garch                               (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

Calculate GARCH estimates.

list :

dependent variable plus arch and garch orders.

pZ :

pointer to data array.

pdinfo :

dataset information.

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,
                                                         const double **Z,
                                                         DATAINFO *pdinfo);

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

list :

specification of variables to use.

Z :

data array.

pdinfo :

dataset information.

Returns :

a MODEL struct, containing the estimates.

panel_model ()

MODEL               panel_model                         (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         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.

list :

regression list (dependent variable plus independent variables).

pZ :

pointer to data array.

pdinfo :

dataset information.

opt :

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

prn :

printing struct (or NULL).

Returns :

a MODEL struct, containing the estimates.

ivreg ()

MODEL               ivreg                               (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         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.

list :

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

pZ :

pointer to data array.

pdinfo :

dataset information.

opt :

option flags.

Returns :

a MODEL struct, containing the estimates.

arbond_model ()

MODEL               arbond_model                        (const int *list,
                                                         const char *ispec,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

Produces estimates of a dynamic panel-data model in the manner of Arellano and Bond. See the documentation for the "arbond" command in gretl for the construction of the list argument and also the syntax of ispec.

list :

regression list.

ispec :

may contain additional instrument specification.

Z :

data array.

pdinfo :

dataset information.

opt :

may include OPT_D to include time dummies, OPT_H to transform the dependent variable via orthogonal deviations rather than first differences, OPT_T for two-step estimation, OPT_A to force production of asymptotic standard errors rather than finite-sample corrected ones.

prn :

printing struct.

Returns :

a MODEL struct, containing the estimates.

dpd_model ()

MODEL               dpd_model                           (const int *list,
                                                         const int *laglist,
                                                         const char *ispec,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

This is at present a secret function, for testing only.

list :

regression list.

laglist :

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

ispec :

may contain additional instrument specification.

Z :

data array.

pdinfo :

dataset information.

opt :

to be hooked up.

prn :

printing struct.

Returns :

a MODEL struct, containing the estimates.

hsk_model ()

MODEL               hsk_model                           (const int *list,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo);

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

list :

dependent variable plus list of regressors.

pZ :

pointer to data array.

pdinfo :

dataset information.

Returns :

a MODEL struct, containing the estimates.

arch_model ()

MODEL               arch_model                          (const int *list,
                                                         int order,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

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.

list :

dependent variable plus list of regressors.

order :

lag order for ARCH process.

pZ :

pointer to data array.

pdinfo :

dataset information.

opt :

may contain OPT_O to print covariance matrix.

prn :

gretl printing struct.

Returns :

a MODEL struct, containing the estimates.

whites_test ()

int                 whites_test                         (MODEL *pmod,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

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

pmod :

pointer to model.

pZ :

pointer to data array.

pdinfo :

dataset information.

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.

prn :

gretl printing struct.

Returns :

0 on successful completion, error code on error.

arch_test ()

int                 arch_test                           (MODEL *pmod,
                                                         int order,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

Tests pmod for AutoRegressive Conditional Heteroskedasticity.

pmod :

model to be tested.

order :

lag order for ARCH process.

pdinfo :

dataset information.

opt :

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

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.

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,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo);

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.

orig :

list giving original regression specification.

aux :

either AUX_SQ, AUX_LOG or AUX_WHITE.

pZ :

pointer to data array.

pdinfo :

dataset information.

Returns :

the augmented list, or NULL on failure.

gretl_XTX ()

double *            gretl_XTX                           (const MODEL *pmod,
                                                         const double **Z,
                                                         int *err);

(Re-)calculates X'X, with various possible transformations of the original data depending on whether estimation of pmod involved weighting or quasi-differencing.

pmod :

reference model.

Z :

data array.

err :

location to receive error code.

Returns :

The vech of X'X or NULL on error.

anova ()

int                 anova                               (const int *list,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         gretlopt opt,
                                                         PRN *prn);

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

list :

must contain the response and treatment variables.

Z :

data array.

pdinfo :

dataset information.

opt :

unused at present.

prn :

printing struct.

Returns :

0 on success, non-zero on failure.