Forecasting

Forecasting — Forecasting based on models

Functions

Types and Values

enum FcastFlags
struct FITRESID_

Includes

#include <gretl/libgretl.h>
#include <gretl/forecast.h>

Description

Write-up needed here.

Functions

free_fit_resid ()

void
free_fit_resid (FITRESID *fr);

Frees all resources associated with fr , then frees the pointer itself.

Parameters

fr

the pointer to be freed.

 

get_fit_resid ()

FITRESID *
get_fit_resid (const MODEL *pmod,
               const DATASET *dset,
               int *err);

Allocates a FITRESID structure and fills it out with the actual and predicted values of the dependent variable in pmod .

Parameters

pmod

the model for which actual and fitted values are wanted.

 

dset

dataset struct.

 

err

location to receive error code.

 

Returns

pointer to allocated structure, or NULL on failure.


get_forecast ()

FITRESID *
get_forecast (MODEL *pmod,
              int t1,
              int t2,
              int pre_n,
              DATASET *dset,
              gretlopt opt,
              int *err);

Allocates a FITRESID structure and fills it out with forecasts based on pmod , over the specified range of observations. For some sorts of models forecast standard errors are also computed (these appear in the sderr member of the structure to which a pointer is returned; otherwise the sderr member is NULL).

The calculation of forecast errors, where applicable, is based on Davidson and MacKinnon, Econometric Theory and Methods, chapter 3 (p. 104), which shows how the variance of forecast errors can be computed given the covariance matrix of the parameter estimates, provided the error term may be assumed to be serially uncorrelated.

Parameters

pmod

the model from which forecasts are wanted.

 

t1

start of forecast range.

 

t2

end of forecast range.

 

pre_n

number of pre-forecast observations to include.

 

dset

dataset struct.

 

opt

if OPT_D, force a dynamic forecast; if OPT_S, force a static forecast. By default, the forecast is static within the data range over which the model was estimated, and dynamic out of sample (in cases where a dynamic forecast is meaningful). If opt includes OPT_I, integrate the forecast (only relevant if the dependent variable in the model in question is recognized as the first difference of another variable).

 

err

location to receive error code.

 

Returns

pointer to allocated structure, or NULL on failure, in which case an error code is assigned via err .


get_system_forecast ()

FITRESID *
get_system_forecast (void *p,
                     int ci,
                     int i,
                     int t1,
                     int t2,
                     int pre_n,
                     DATASET *dset,
                     gretlopt opt,
                     int *err);

Allocates a FITRESID structure and fills it out with forecasts based on the system at location p , over the specified range of observations.

Parameters

p

pointer to the VAR or equation system from which forecasts are wanted.

 

ci

command index for system (VAR, VECM or SYSTEM)

 

i

0-based index for the variable to forecast, within the equation system.

 

t1

start of forecast range.

 

t2

end of forecast range.

 

pre_n

number of pre-forecast observations to include.

 

dset

dataset struct.

 

opt

if OPT_D, force a dynamic forecast; if OPT_S, force a static forecast. By default, the forecast is static within the data range over which the model was estimated, and dynamic out of sample.

 

err

location to receive error code.

 

Returns

pointer to allocated structure, or NULL on failure.


do_forecast ()

int
do_forecast (const char *str,
             DATASET *dset,
             gretlopt opt,
             PRN *prn);

In the case of "simple" models with an autoregressive error term (AR, AR1) the forecast values incorporate the predictable component of the error.

Parameters

str

command string, which may include a starting observation and ending observation, and/or the name of a variable for saving the forecast values.

 

dset

dataset struct.

 

opt

if OPT_D, force a dynamic forecast; if OPT_S, force a static forecast. By default, the forecast is static within the data range over which the model was estimated, and dynamic out of sample (in cases where this distinction is meaningful). OPT_R: do recursive forecast. OPT_Q: suppress printing of the forecast; OPT_P: ensure that the values are printed. OPT_U: produce gnuplot plot.

 

prn

gretl printing struct.

 

Returns

0 on success, non-zero error code on failure.


forecast_options_for_model ()

void
forecast_options_for_model (MODEL *pmod,
                            const DATASET *dset,
                            FcastFlags *flags,
                            int *dt2max,
                            int *st2max);

Examines pmod and determines which forecasting options are applicable.

Parameters

pmod

the model from which forecasts are wanted.

 

dset

dataset struct.

 

flags

location to receive flags from among FcastFlags.

 

dt2max

location to receive the last observation that can be supported for a dynamic forecast.

 

st2max

location to receive the last observation that can be supported for a static forecast.

 

get_forecast_matrix ()

gretl_matrix *
get_forecast_matrix (int idx,
                     int *err);

recursive_OLS_k_step_fcast ()

FITRESID *
recursive_OLS_k_step_fcast (MODEL *pmod,
                            DATASET *dset,
                            int t1,
                            int t2,
                            int k,
                            int pre_n,
                            int *err);

fcast_get_continuous_range ()

void
fcast_get_continuous_range (const FITRESID *fr,
                            int *pt1,
                            int *pt2);

forecast_matrix_cleanup ()

void
forecast_matrix_cleanup (void);

Types and Values

enum FcastFlags

Members

FC_AUTO_OK

   

FC_DYNAMIC_OK

   

FC_ADDOBS_OK

   

FC_INTEGRATE_OK

   

FC_MEAN_OK

   

struct FITRESID_

struct FITRESID_ {
    int model_ID;   /* ID of model on which forecast is based */
    int asymp;      /* 0/1 flag for asymptotic estimator */
    int std;        /* 0/1 flag for standardized residuals */
    int model_t1;   /* start of model estimation range */
    int method;     /* one of the ForecastMethod options */
    double *actual; /* array of values of dependent variable */
    double *fitted; /* array of fitted values */
    double *resid;  /* array of residuals */
    double *sderr;  /* array of forecast standard errors (or NULL) */
    double sigma;   /* standard error of regression */
    double alpha;   /* for confidence intervals */
    int pmax;       /* if positive, suggested number of decimal places
                       for use in printing */
    int df;         /* degrees of freedom for model */
    int t0;         /* start of pre-forecast data range */
    int t1;         /* start of forecast range */
    int t2;         /* end of forecast range */
    int k;          /* number of steps ahead (method = FC_KSTEP only) */
    int nobs;       /* length of the arrays actual, fitted, resid */
    char depvar[VNAMELEN]; /* name of dependent variable */
};