Chapter 8: Time Series and Forecasting > regression_arima

regression_arima

   

Fits a univariate ARIMA (p, d, q) time series model with the inclusion of one or more regression variables.

Synopsis

#include <imsls.h>

float *imsls_f_regression_arima (int n_obs, float y[], int model[], ..., 0)

The type double function is imsls_d_regression_arima.

Required Arguments

int n_obs   (Input)
Number of observations.

float y[]   (Input)
Array of length n_obs containing the observations.

int model[]   (Input)
Array of length 3 containing the model order parameters p, d, q.

 

Element

Description

0

Order of the autoregressive part, p, where p  0.

1

Order of the non-seasonal difference operator, d, where d  0.

2

Order of the moving average part, q, where q  0.

 

Return Value

Pointer to an array of length 1 + pq with the estimated constant, autoregressive (AR), and moving average (MA) parameters.

Synopsis with Optional Arguments

#include <imsls.h>

float *imsls_f_regression_arima (int n_obs, float y[], int model[],

IMSLS_REGRESSION, int n_regressors, float x[],

IMSLS_REGRESSION_FORECASTS, float xlead[],

IMSLS_REGRESSION_INDICES, int n_indices, int indices[],

IMSLS_NO_TREND,

IMSLS_MAX_ITERATIONS, int max_iterations,

IMSLS_PRINT_LEVEL, int iprint,

IMSLS_FORECASTS, int n_predict, float **forecastsfloat **forecast_variances,

IMSLS_FORECASTS_USER, int n_predict, float forecasts[], float forecast_variances[],

IMSLS_REGRESSION_COEF, float **coefficients,

IMSLS_REGRESSION_COEF_USER, float coefficients[],

IMSLS_SE_ARMA, float **arma_std_errors,

IMSLS_SE_ARMA_USER, float arma_std_errors[],

IMSLS_VAR_NOISE, float *avar,

IMSLS_SE_COEF, float **regcoef_std_errors,

IMSLS_SE_COEF_USER, float regcoef_std_errors[],

IMSLS_COEF_COVARIANCES, float **coef_covar,

IMSLS_COEF_COVARIANCES_USER, float coef_covar[],

IMSLS_AIC, float *aic,

IMSLS_LOG_LIKELIHOOD, float *log_likelihood,

IMSLS_RETURN_USER, float *constant, float ar[], float ma[],

0)

Optional Arguments

IMSLS_REGRESSION, int n_regressors, float x[]   (Input)
Array of length n_obs × n_regressors containing  the regression variables. Specific columns of x may be selected using the optional argument IMSLS_REGRESSION_INDICES.
Default: n_regressors = 0 (No regression variables are included.)

IMSLS_REGRESSION_FORECASTS, float xlead[]   (Input)
Array of length n_predict × n_regressors containing  the regression variables to be used in obtaining forecasts. Specific columns of xlead may be selected using the optional argument IMSLS_REGRESSION_INDICES.
Note: If optional arguments IMSLS_FORECASTS and IMSLS_REGRESSION are present, then IMSLS_REGRESSION_FORECASTS is required.
Default: Not used.

IMSLS_REGRESSION_INDICES, int n_indices, int indices[]   (Input)
Argument n_indices specifies the length of array indices and the number of regression variables to be included in the ARIMA fit.  Argument indices contains the indices of the regression variables in matrices x and xlead.
Default: All regression variables in x and xlead will be used.

IMSLS_NO_TREND, (Input)
If IMSLS_NO_TREND is specified, the function will not include a trend variable. A trend variable has the effect of fitting an intercept term in the regression. If the difference operator model[1] = d > 0, the effect of no trend on the model in the original, undifferenced space is polynomial of order d.
Default: The function will include a trend variable.

IMSLS_MAX_ITERATIONS, int max_iterations   (Input)
Maximum number of iterations.
Default: max_iterations = 50

IMSLS_PRINT_LEVEL, int iprint   (Input)
Printing option.

 

iprint

Action

0

No printing

1

Prints final results only.

2

Prints intermediate and final results.

 

            Default: iprint = 0

IMSLS_FORECASTS, int n_predict, float **forecasts, float **forecast_variances   (Output)
Addresses of pointers to internally allocated arrays of length n_predict containing the forecasts and forecast variances for time points n+1, n+2, …, n+n_predict, where n = n_obs.

IMSLS_FORECASTS_USER, int n_predict, float forecasts[], float forecast_variances[]   (Output)
Storage arrays forecast and forecast_variance are provided by user. See IMSLS_FORECASTS.

IMSLS_REGRESSION_COEF, float **coefficients   (Output)
Address of a pointer to an internally allocated array of length n_regressors+t containing the estimated regression coefficients, where = 0 if IMSLS_NO_TREND is specified, otherwise = 1.

IMSLS_REGRESSION_COEF_USER, float coefficients[]   (Output)
Storage array coefficients is provided by user. See IMSLS_REGRESSION_COEF.

IMSLS_SE_ARMA, float **arma_std_errors   (Output)
Address of a pointer to an internally allocated array of length p+q containing the standard errors of the ARMA parameter estimates, where p = model[0] and q = model[2].

IMSLS_SE_ARMA_USER, float arma_std_errors[]   (Output)
Storage array arma_std_errors is provided by user.  See IMSLS_SE_ARMA.

IMSLS_VAR_NOISE, float *avar   (Output)
White noise variance estimate.
Note: If model[0]+model[2]= 0 and n_regressors > 0, avar is the mean squared regression residual.

IMSLS_SE_COEF, float **regcoef_std_error   (Output)
Address of a pointer to an internally allocated array of length n_regressors+ t containing the standard errors of the ARMA parameter estimates, where= 0 if IMSLS_NO_TREND is specified, otherwise = 1.

IMSLS_SE_COEF_USER, float regcoef_std_errors[]   (Output)
Storage array reg_std_errors is provided by user. See IMSLS_SE_COEF.

IMSLS_COEF_COVARIANCES, float **coef_covar   (Output)
Address of a pointer to an internally allocated array of length
(n_regressors+t) × (n_regressors+t) containing the variances and covariances of the regression coefficients, where= 0 if IMSLS_NO_TREND is specified, otherwise = 1.

IMSLS_COEF_COVARIANCES_USER, float coef_covar[]   (Output)
Storage array coef_covar is provided by user.  See IMSLS_COEF_COVARIANCES.

IMSLS_AIC, float *aic   (Output)
Akaike’s Information Criterion for the fitted ARMA model.

IMSLS_LOG_LIKELIHOOD, float *log_likelihood   (Output)
Value of –2(ln(likelihood)) for fitted model.

IMSLS_RETURN_USER, float *constant, float ar[], float ma[]   (Output)
If specified, constant is the constant parameter estimate, ar is an array of length p containing the final autoregressive parameter estimates, and ma is an array of length q containing the final moving average parameter estimates.

Description

Function imsls_f_regression_arima fits an ARIMA(pdq) to a univariate time series with the possible inclusion of one or more regression variables.

Suppose , , is a time series such that the d-th difference is stationary. Further, suppose  is a series of uncorrelated, mean 0 random variables with variance .

The Auto-Regressive Integrated Moving Average (ARIMA) model for can be expressed as

where B is the backshift operator,

and

.

The notation for this model is ARIMA(p, d, q) where p is the order of the autoregressive polynomial , d is the order of the differencing needed to make  stationary, and q is the order of the moving-average polynomial .

The ARIMA model can be extended to include  regression variables, by using the residuals (of the multiple regression of  on ) in place of  in the above ARIMA model.

Equivalently,

where

is the differenced residual series.

To estimate the (p + qK) parameters of the specified regression ARIMA model, imsls_f_regression_arima uses the iterative generalized least squares method (IGLS) as described in Otto, Bell, and Burman (1987).

The IGLS method iterates between two steps, one step to estimate the regression parameters via generalized least squares (GLS) and the second step to estimate the ARMA parameters. In particular, at iteration m, the first step finds

 

by solving the GLS problem with weight matrix

,

where

That is,  minimizes , where ,  is an N by K matrix with i-th column, , and is an N by N weight matrix defined using the theoretical autocovariances of the series. The series is modeled as an ARMA(p,q) with parameters  and . At iteration m, the second step is then to obtain new estimates of  and  for the updated series,. To find the estimates and , imsls_f_regression_arima uses the exact likelihood method as described in Akaike, Kitagawa, Arahata and Tada (1979) and used in function, imsls_f_max_arma.

Remarks

When forecasts are requested (n_predict > 0), imsls_f_regression_arima requires that future values of the independent variables be provided in optional argument IMSLS_REGRESSION_FORECASTS. In effect, imsls_f_regression_arima assumes the future X’s are known without error, which is valid for any deterministic function of time such as a seasonal indicator. Also, in economics, certain factors that are considered to be leading indicators are treated as deterministic for the purpose of predicting changes in the economy. Users may consider using a more general transfer function model if this is an unreasonable assumption. Function imsls_f_regression_arima calculates forecast variances using the asymptotic result found in Fuller (1996), Theorem 2.9.4.  To obtain the standard errors of the ARMA parameters, imsls_f_regression_arima calls function imsls_f_arma for the final w series.

Examples

Example 1

The data set consists of annual mileage per passenger vehicle and annual US population (in 1000’s) spanning the years 1980 to 2006 (U.S. Energy Information Administration, 2008). Consider modeling the annual mileage using US population as a regression variable.

 

#include <imsls.h>

int main()

{

    int  nobs= 24, model[3] = {1, 0, 0};

    int  indices[1] = {0}, n_predict=5;

    float avar, llike, *result;

    float *regcoef, *regstderr, *coefcovar, *armastderr;

    float *fcst, *fcst_var;

    float y[29] = {

        9062.0, 8813.0, 8873.0, 9050.0, 9118.0,

        9248.0, 9419.0, 9464.0, 9720.0, 9972.0,

        10157.0, 10504.0, 10571.0, 10857.0, 10804.0,

        10992.0, 11203.0, 11330.0, 11581.0, 11754.0,

        11848.0, 11976.0, 11831.0, 12202.0, 12325.0,    

        12460.0, 12510.0, 12485.0, 12293.0

    };

    float regX[29][2] = {

        {22722.4681, 9062.0},

        {22946.5714, 8813.0},

        {23166.4458, 8873.0},

        {23379.1990, 9050.0},

        {23582.4902, 9118.0},

        {23792.3795, 9248.0},

        {24013.2887, 9419.0}, 

        {24228.8918, 9464.0},

        {24449.8982, 9720.0},

        {24681.923, 9972.0},

        {24962.2814, 10157.0},

        {25298.0941, 10504.0}, 

        {25651.4224, 10571.0},

        {25991.8588, 10857.0},

        {26312.5820999999, 10804.0},

        {26627.8393, 10992.0},

        {26939.4284, 11203.0},

        {27264.6925, 11330.0},

        {27585.4104, 11581.0},

        {27904.0168, 11754.0},

        {28217.1936, 11848.0},

        {28503.9803, 11976.0},

        {28772.6647, 11831.0},

        {29021.0914, 12202.0},

        {29289.2127, 12325.0},

        {29556.0549, 12460.0}, 

        {29836.2973, 12510.0},

        {30129.0332, 12485.0},

        {30405.9724, 12293.0}

    };

 

 

    result = imsls_f_regression_arima (nobs, y, model,

        IMSLS_REGRESSION,2, regX,

        IMSLS_REGRESSION_FORECASTS, &regX[24][0],

        IMSLS_FORECASTS, n_predict, &fcst, &fcst_var,

        IMSLS_REGRESSION_INDICES, 1, indices,

        IMSLS_VAR_NOISE, &avar,

        IMSLS_LOG_LIKELIHOOD, &llike,

        IMSLS_REGRESSION_COEF, &regcoef,

        IMSLS_SE_COEF, &regstderr,

        IMSLS_COEF_COVARIANCES, &coefcovar,

        IMSLS_SE_ARMA, &armastderr,

        IMSLS_PRINT_LEVEL, 1,

        0);

}

Output

 

Final results for regression ARIMA model (p,d,q) = 1, 0, 0s

 

 Final AR parameter estimates/ std errors

          0.73000               0.13498

 

-2*ln(maximum log likelihood) = 231.835464

 

 White noise variance = 15427.915039

 

 Regression estimates:

 

          COEFFICIENTS   Regression STD Errors

 0          -3483.13306       687.21167

 1              0.54244         0.02666

 

 Forecasts with standard deviation

 

 T               Y fcst                  Y fcst std dev

24          12360.51563               124.20916

25          12514.80664               153.78410

26          12673.78906               167.42434

27          12837.66895               174.25776

28          12991.60547               177.79208

Example 2

The data set consists of simulated weekly observations containing a strong annual seasonality. The seasonal variables are constructed and sent into regression_arima as regression variables.

 

#include <imsls.h>

#include <math.h>

int main()

{

    int nobs=100, n_predict=4, n_regressors=2;

    int i, model[3] = {2,0,0};

    float PI, *coefcovar, *regcoef, *regstderr, *result;

    float *armastderr, *fcst, *fcstvar;

    float avar, llike;

    float x[104][2];

    float y[104] = {

        32.27778, 32.63300, 33.13768, 34.4517, 

        34.63824, 37.31262, 37.35704, 37.03092,

        36.39894, 35.75541, 35.10829, 34.70107,

        34.69592, 32.75326, 30.85370, 31.10936,

        29.47493, 29.14361, 28.50466, 30.09714,

        28.49403, 27.23268, 23.49674, 22.71225,

        21.42798, 18.68601, 17.40035, 16.06832,

        15.31862, 14.75179, 13.40089, 13.01101,

        12.44863, 11.27890, 11.51770, 14.31982,

        14.67036, 14.76331, 15.35644, 17.04353,

        18.39931, 18.21919, 18.72777, 19.61794,

        22.31733, 23.79600, 25.41326, 25.60497,

        27.93579, 29.21765, 29.60981, 28.46994,

        28.780810, 30.96402, 35.49537, 35.75124,

        36.18933, 37.2627,  35.02454, 33.57089,

        35.00683, 34.83886, 34.19827, 33.73966,

        34.49709, 34.07127, 32.74709, 31.97856,

        31.3029,  30.21916, 27.46015, 26.78431,

        25.32815, 23.97863, 21.83837, 21.00647,

        20.58846, 19.94578, 17.38271, 17.12572,

        16.71847, 17.45425, 16.15050, 13.07448,

        12.54188, 12.42137, 13.51771, 14.84232,

        14.28870, 13.39561, 15.48938, 16.47175,

        17.62758, 16.57677, 18.20737, 20.8491, 

        20.15616, 20.93857, 23.73973, 25.30449,

        26.51106, 29.43261, 32.02672, 32.18846

    };

 

 

    /*

    *  The data are simulated weekly observations

    *  with an annual seasonal cycle

    */

    PI = imsls_f_constant("PI",0);

 

    for (i=0; i<nobs+n_predict;i++)

    {

        x[i][0] = sin(2*PI*i/ 52.0);

        x[i][1] = cos(2*PI*i/ 52.0);

    }

 

    result = imsls_f_regression_arima (nobs, y,  model,

        IMSLS_REGRESSION,2, x,

        IMSLS_REGRESSION_FORECASTS, &x[100][0],

        IMSLS_FORECASTS, n_predict, &fcst, &fcstvar,

        IMSLS_VAR_NOISE, &avar,

        IMSLS_LOG_LIKELIHOOD, &llike,

        IMSLS_REGRESSION_COEF, &regcoef,

        IMSLS_SE_COEF, &regstderr,

        IMSLS_COEF_COVARIANCES, &coefcovar,

        IMSLS_SE_ARMA, &armastderr,

        IMSLS_PRINT_LEVEL, 1,

        0);

 

}

Output

 

Final AR parameter estimates/ std errors

          0.71855               0.09838

         -0.25989               0.09828

 

-2*ln(maximum log likelihood) = -13.621020

 

 White noise variance = 0.868007

 

 Regression estimates:

 

          COEFFICIENTS   Regression STD Errors

 0             24.81011         0.17177

 1              8.91971         0.24042

 2              6.84814         0.24709

 

 Forecasts with standard deviation

 

 T               Y fcst                  Y fcst std dev

100            26.74492                 0.93167

101            28.07804                 1.14725

102            29.33707                 1.35615

103            30.53160                 1.52323


RW_logo.jpg
Contact Support