arima

   more...
Fits a univariate seasonal or non-seasonal ARIMA time series model with optional regression variables.
Synopsis
#include <imsls.h>
float *imsls_f_arima (int n_obs, float y[], int model[], ..., 0)
The type double function is imsls_d_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 + p + q + P + Q with the estimated constant, autoregressive (AR), and moving average (MA) parameters.
Synopsis with Optional Arguments
#include <imsls.h>
float *imsls_f_arima (int n_obs, float y[], int model[],
IMSLS_SEASONAL_MODEL, int sper, int seasonal_model[],
IMSLS_REGRESSION, int n_cols, float x[],
IMSLS_REGRESSION_INDICES, int n_regressors, int indices[],
IMSLS_REGRESSION_FORECASTS, float xlead[],
IMSLS_INITIAL_EST_INPUT, int n_params, float params[],
IMSLS_NO_TREND,
IMSLS_MAX_ITERATIONS, int max_iterations,
IMSLS_PRINT_LEVEL, int iprint,
IMSLS_DIFFERENCES, float ** differences,
IMSLS_DIFFERENCES_USER, float differences[],
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_SEASONAL_MODEL, int sper, int seasonal_model[] (Input)
Argument sper specifies the seasonal period, with sper 0. Argument seasonal_model is an array of length 3 containing the seasonal 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.
Default: P = D = Q = 0.
IMSLS_REGRESSION, int n_cols, float x[] (Input)
Array of length n_obs × n_cols containing the regression variables. Specific columns of x may be selected using the optional argument IMSLS_REGRESSION_INDICES.
If optional arguments IMSLS_FORECASTS and IMSLS_REGRESSION are present, then IMSLS_REGRESSION_FORECASTS is required.
Default: n_cols = 0 (No regression variables are included).
IMSLS_REGRESSION_INDICES, int n_regressors, int indices[] (Input)
Argument n_regressors 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_REGRESSION_FORECASTS, float xlead[] (Input)
Array of length n_predict × n_cols containing the regression variables to be used in obtaining forecasts. Specific columns of xlead may be selected using the optional argument IMSLS_REGRESSION_INDICES.
If optional arguments IMSLS_FORECASTS and IMSLS_REGRESSION are present, then IMSLS_REGRESSION_FORECASTS is required.
Default: Not used.
IMSLS_INITIAL_EST_INPUT, int n_params, float params[] (Input)
Array of length n_params containing initial estimates for the parameters. Note that n_params must be equal to p+q+P+Q. The order of each parameter must be as stated, i.e. first the p autoregressive (AR) and q moving average (MA) parameters, followed by the P seasonal AR and Q seasonal MA parameters.
Default: Initial estimates are set by the program.
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 trend on the model in the original, undifferenced space is polynomial of order d.
Default: The function includes a trend variable.
IMSLS_MAX_ITERATIONS, int max_iterations (Input)
Maximum number of iterations.
Default: max_iterations = 100
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_DIFFERENCES, float **differences (Output)
Address of a pointer to an internally allocated array of length n_obs ‑ model[1] ‑ seasonal_model[1]*sper containing the differenced series.
IMSLS_DIFFERENCES_USER, float differences[] (Output)
Storage for the array differences is provided by user.
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.
If optional arguments IMSLS_FORECASTS and IMSLS_REGRESSION are present, then IMSLS_REGRESSION_FORECASTS is required.
IMSLS_FORECASTS_USER, int n_predict, float forecasts[], float forecast_variances[] (Output)
Storage arrays forecasts and forecast_variances are provided by the 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+P+Q containing the standard errors of the ARMA parameter estimates, where p = model[0], q = model[2], P = seasonal_model[0] and Q = seasonal_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. For a regression-only model (p=q=P=Q=0), avar is the mean squared regression residual for w_t, the time series after applying any differencing.
IMSLS_SE_COEF, float **regcoef_std_errors (Output)
Address of a pointer to an internally allocated array of length n_regressors+ t containing the standard errors of the regression coefficients, where = 0 if IMSLS_NO_TREND is specified, otherwise = 1.
IMSLS_SE_COEF_USER, float regcoef_std_errors[] (Output)
Storage array regcoef_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 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+P containing the final autoregressive parameter estimates, and ma is an array of length q+Q containing the final moving average parameter estimates.
Description
Function imsls_f_arima fits a seasonal or non-seasonal ARIMA 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 .
First, for the non-seasonal case, 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. Note that if IMSLS_NO_TREND is specified, β0 will be 0.
To estimate the p + qK (and + 1 for trend) parameters of the specified regression ARIMA model, imsls_f_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 + 1 matrix with i-th column, , , and , 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) process with parameters and . At iteration m, the second step is then to obtain new estimates of and for the updated series, . The function then finds the maximum likelihood estimates, and , by minimizing the negative log-likelihood over the parameter vector. The log-likelihood is calculated using the innovations algorithm as described in Brockwell & Davis, Chapter 8.
The method is essentially the same for a seasonal ARIMA model. The notation for a seasonal model is ARIMA (p, d, q)x(P, D, Q)s where P is the order of the seasonal autoregressive polynomial, D (along with d) is the order of the differencing needed for stationarity, Q is the order of the seasonal moving-average polynomial, and s is the seasonal period. In particular, the seasonal ARIMA model has the form
φ(B)(Bs)wt = θ(B)Θ(Bs)at
where wt = (1  B)d (1 Bs), d,D0 are the difference orders, s1 is an integer specifying the seasonal period, and at is the white noise process as before. The seasonal autoregressive and moving average polynomials are given by
(Bs= 1 1Bs 2B2sp BPs
and
Θ(Bs= 1 Θ1Bs Θ2B2sΘQ BQs
respectively.
Remarks
When forecasts are requested (n_predict > 0), imsls_f_arima requires that future values of the independent variables be provided in optional argument IMSLS_REGRESSION_FORECASTS. In effect, imsls_f_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_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_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 10000’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>
#include <stdlib.h>
 
int main()
{
int nobs = 24;
int model[3] = { 1, 0, 0 };
int n_predict = 5;
float avar, llike, *result = NULL, *regcoef = NULL, *regstderr = NULL;
float *coefcovar = NULL, *armastderr = NULL, *fcst = NULL;
float *fcst_var = NULL;
 
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] = { 22722.4681, 22946.5714, 23166.4458,
23379.1990, 23582.4902, 23792.3795, 24013.2887,
24228.8918, 24449.8982, 24681.923, 24962.2814,
25298.0941, 25651.4224, 25991.8588, 26312.5821,
26627.8393, 26939.4284, 27264.6925, 27585.4104,
27904.0168, 28217.1936, 28503.9803, 28772.6647,
29021.0914, 29289.2127, 29556.0549, 29836.2973,
30129.0332, 30405.9724
};
 
result = imsls_f_arima(nobs, y, model,
IMSLS_REGRESSION, 1, regX,
IMSLS_REGRESSION_FORECASTS, &regX[nobs],
IMSLS_FORECASTS, n_predict, &fcst, &fcst_var,
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);
 
if (result) imsls_free(result);
if (fcst) imsls_free(fcst);
if (fcst_var) imsls_free(fcst_var);
if (regcoef) imsls_free(regcoef);
if (regstderr) imsls_free(regstderr);
if (coefcovar) imsls_free(coefcovar);
if (armastderr) imsls_free(armastderr);
}
 
Output
 
Final results for ARIMA model (p,d,q)x(P,D,Q)_s = (1,0,0)x(0,0,0)_0
 
Final AR parameter estimates/ std errors
0.56471 0.13500
 
-2*ln(maximum log likelihood) = 299.944427
 
White noise variance = 15425.566406
 
Regression estimates:
 
COEFFICIENTS Regression STD Errors
0 -3480.87573 689.33929
1 0.54236 0.02674
 
Forecasts with standard deviation
 
T Y fcst Y fcst std dev
24 12368.37207 124.19970
25 12524.92871 142.63528
26 12683.60254 148.03239
27 12846.14355 149.71263
28 12998.47363 150.24451
 
Example 2
The data set consists of simulated weekly observations containing a strong annual seasonality. The seasonal variables are constructed and sent into imsls_f_arima as regression variables.
 
#include <imsls.h>
#include <math.h>
#include <stdlib.h>
 
int main()
{
int nobs = 100, n_predict = 4, n_regressors = 2;
int i, model[3] = { 2, 0, 0 };
float PI, *coefcovar = NULL, *regcoef = NULL, *regstderr = NULL;
float *result = NULL, *armastderr = NULL, *fcst = NULL;
float *fcstvar = NULL;
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.78081, 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 = acos(-1.0);
 
for (i = 0; i < nobs + n_predict; i++)
{
x[i][0] = sin(2.0 * PI * i / 52.0);
x[i][1] = cos(2.0 * PI * i / 52.0);
}
 
result = imsls_f_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);
 
if (coefcovar) imsls_free(coefcovar);
if (regcoef) imsls_free(regcoef);
if (regstderr) imsls_free(regstderr);
if (result) imsls_free(result);
if (armastderr) imsls_free(armastderr);
if (fcst) imsls_free(fcst);
if (fcstvar) imsls_free(fcstvar);
}
 
 
Output
 
Final results for ARIMA model (p,d,q)x(P,D,Q)_s = (2,0,0)x(0,0,0)_0
 
Final AR parameter estimates/ std errors
0.71727 0.09837
-0.26694 0.09828
 
-2*ln(maximum log likelihood) = 270.166840
 
White noise variance = 0.868012
 
Regression estimates:
 
COEFFICIENTS Regression STD Errors
0 24.81011 0.17172
1 8.91972 0.24034
2 6.84813 0.24701
 
Forecasts with standard deviation
 
T Y fcst Y fcst std dev
100 26.74694 0.93167
101 28.07994 1.14655
102 29.33769 1.16952
103 30.53127 1.16959
 
 
Example 3
The data set consists of the number of monthly accidental deaths in the USA from 1973 to 1978 (Brockwell & Davis, 2006). The following example fits a (0,1,1)x(0,1,1) ARIMA model with seasonal period = 12. With monthly data, a seasonal period of 12 corresponds to an annual seasonal cycle.
 
#include <imsls.h>
#include <stdlib.h>
 
int main()
{
int nobs = 72, iprint = 1;
int model[3] = { 0, 1, 1 };
int seas_model[3] = { 0, 1, 1 };
int sper = 12;
int n_predict = 24;
float params[2] = { .25, .25 };
float avar, llike;
float *ses = NULL, *result = NULL;
 
float deaths[72] = {
9007, 8106, 8928, 9137, 10017, 10826, 11317, 10744, 9713, 9938,
9161, 8927, 7750, 6981, 8038, 8422, 8714, 9512, 10120, 9823,
8743, 9129, 8710, 8680, 8162, 7306, 8124, 7870, 9387, 9556,
10093, 9620, 8285, 8433, 8160, 8034, 7717, 7461, 7776, 7925,
8634, 8945, 10078, 9179, 8037, 8488, 7874, 8647, 7792, 6957,
7726, 8106, 8890, 9299, 10625, 9302, 8314, 8850, 8265, 8796,
7836, 6892, 7791, 8129, 9115, 9434, 10484, 9827, 9110, 9070,
8633, 9240
};
 
result = imsls_f_arima(nobs, deaths, model,
IMSLS_SEASONAL_MODEL, sper, seas_model,
IMSLS_LOG_LIKELIHOOD, &llike,
IMSLS_NO_TREND,
IMSLS_INITIAL_EST_INPUT, 2, params,
IMSLS_VAR_NOISE, &avar,
IMSLS_PRINT_LEVEL, iprint,
IMSLS_SE_ARMA, &ses, 0);
 
if (result) imsls_free(result);
if (ses) imsls_free(ses);
}
Output
 
 
Final results for ARIMA model (p,d,q)x(P,D,Q)_s = (0,1,1)x(0,1,1)_12
 
Final MA parameter estimates/ std errors
0.42643 0.11604
 
Final Seasonal MA parameter estimates/ std errors
0.55822 0.13508
 
-2*ln(maximum log likelihood) = 851.065125
 
White noise variance = 99502.765625