Automatic selection and fitting of a univariate autoregressive time series model. The lag for the model is automatically selected using Akaike’s information criterion (AIC). Estimates of the autoregressive parameters for the model with minimum AIC are calculated using method of moments, method of least squares, or maximum likelihood.
#include <imsls.h>
float *imsls_f_auto_uni_ar (int n_obs, float z[], int maxlag, int *p,…,0)
The type double function is imsls_d_auto_uni_ar.
int n_obs
(Input)
Number of observations in the time
series.
float z[]
(Input)
Array of length n_obs containing the
stationary time series.
int maxlag
(Input)
Maximum number of autoregressive parameters requested. It is required
that
1≤ maxlag ≤ n_obs/2.
int *p
(Output)
Number of autoregressive parameters in the model with minimum
AIC.
Vector of length 1+ maxlag containing the estimates for the constant and the autoregressive parameters in the model with minimum AIC. The estimates are located in the first 1+ p locations of this array.
#include <imsls.h>
float
*imsls_f_auto_uni_ar (int
n_obs, float
z[],
int
maxlag, int
*p,
IMSLS_PRINT_LEVEL, int
iprint,
IMSLS_MAX_ITERATIONS, int
maxit,
IMSLS_METHOD, int
method,
IMSLS_VAR_NOISE,
float *avar,
IMSLS_AIC,
float *aic,
IMSLS_MEAN_ESTIMATE,
float *z_mean,
IMSLS_RETURN_USER,
float *constant,
float
ar[],
0)
IMSLS_PRINT_LEVEL,
int iprint
(Input)
Printing option:
0 — No
printing.
1 — Prints final results only.
2 — Prints
intermediate and final results.
Default: iprint = 0
IMSLS_MAX_ITERATIONS,
int maxit
(Input)
Maximum number of
estimation iterations.
Default: maxit = 300
IMSLS_METHOD, int
method
(Input)
Estimation method option:
0 — Method
of moments
1 — Method of least squares realized through Householder
transformations
2 — Maximum likelihood
Default: method = 1
IMSLS_VAR_NOISE,
float *avar
(Output)
Estimate of
innovation variance.
IMSLS_AIC, float
*aic
(Output)
Minimum AIC.
IMSLS_MEAN_ESTIMATE,
float *z_mean
(Input/Output)
Estimate of the mean of the time series z. On return, z_mean contains an
update of the mean.
Default: Time series z is centered about
its sample mean.
IMSLS_RETURN_USER,
float *constant, float
ar[]
(Output)
If specified, constant is the
constant parameter estimate, ar is an array of
length maxlag
containing the final autoregressive parameter estimates in its first p locations.
Function auto_uni_ar automatically selects the order of the AR model that best fits the data and then computes the AR coefficients. The algorithm used in auto_uni_ar is derived from the work of Akaike, H., et. al (1979) and Kitagawa and Akaike (1978). This code was adapted from the UNIMAR procedure published as part of the TIMSAC-78 Library.
The best fit AR model is determined by successively fitting AR models with 0, 1, 2, ..., maxlag autoregressive coefficients. For each model, Akaike’s Information Criterion (AIC) is calculated based on the formula
Function auto_uni_ar uses the approximation to this formula developed by Ozaki and Oda (1979),
where is an estimate of the residual variance of the series, commonly known in time series analysis as the innovation variance. By dropping the constant
the calculation is simplified to
The best fit model is the model with minimum AIC. If the number of parameters in this model is equal to the highest order autoregressive model fitted, i.e., p=maxlag, then a model with smaller AIC might exist for larger values of maxlag. In this case, increasing maxlag to explore AR models with additional autoregressive parameters might be warranted.
If method = 0, estimates of the autoregressive coefficients for the model with minimum AIC are calculated using method of moments. If method =1, the coefficients are determined by the method of least squares applied in the form described by Kitagawa and Akaike (1978). Otherwise, if method =2, the coefficients are estimated using maximum likelihood.
Consider the Wolfer Sunspot data (Anderson 1971, p. 660) consisting of the number of sunspots observed each year from 1770 through 1869. In this example, imsls_f_auto_uni_ar found the minimum AIC fit is an autoregressive model with 3 lags:
where
μ the sample mean of the time series . Defining the overall constant by , we obtain the following equivalent representation:
The example computes estimates for for every of the three parameter estimation methods available.
#include <imsls.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
int i;
int maxlag = 20;
int n_obs = 100;
int p;
float w[176][2];
float z[100];
float *parameters = NULL;
float avar, aic, constant;
float ar[20];
/* get wolfer sunspot data */
imsls_f_data_sets (2, IMSLS_X_COL_DIM, 2,
IMSLS_RETURN_USER, w,
0);
for (i=0; i<n_obs; i++)
z[i] = w[21+i][1];
/* Compute AR parameters for minimum AIC by method of moments */
printf("\n\nAIC Automatic Order selection\n");
printf("AR coefficients estimated using method of moments\n");
parameters = imsls_f_auto_uni_ar(n_obs, z, maxlag, &p,
IMSLS_VAR_NOISE, &avar,
IMSLS_METHOD, 0,
IMSLS_AIC, &aic,
0);
printf("Order selected: %d\n", p);
printf("AIC = %11.4f, Variance = %11.4f\n", aic, avar);
printf("Constant estimate is %11.4f.\n", parameters[0]);
imsls_f_write_matrix(
"Final AR coefficients estimated by method of moments",
p, 1, ¶meters[1], 0);
if (parameters)
{
imsls_free(parameters);
parameters = NULL;
}
/* Compute AR parameters for minimum AIC
by method of least squares */
printf("\n\nAIC Automatic Order selection\n");
printf("AR coefficients estimated using method of least squares\n");
imsls_f_auto_uni_ar(n_obs, z, maxlag, &p,
IMSLS_VAR_NOISE, &avar,
IMSLS_METHOD, 1,
IMSLS_AIC, &aic,
IMSLS_RETURN_USER, &constant, ar,
0);
printf("Order selected: %d\n", p);
printf("AIC = %11.4f, Variance = %11.4f\n", aic, avar);
printf("Constant estimate is %11.4f.\n", constant);
imsls_f_write_matrix(
"Final AR coefficients estimated by method of least squares",
p, 1, ar, 0);
/* Compute AR parameters for minimum AIC
by maximum likelihood estimation */
printf("\n\nAIC Automatic Order selection\n");
printf("AR coefficients estimated using maximum likelihood\n");
imsls_f_auto_uni_ar(n_obs, z, maxlag, &p,
IMSLS_VAR_NOISE, &avar,
IMSLS_METHOD, 2,
IMSLS_AIC, &aic,
IMSLS_RETURN_USER, &constant, ar,
0);
printf("Order selected: %d\n", p);
printf("AIC = %11.4f, Variance = %11.4f\n", aic, avar);
printf("Constant estimate is %11.4f.\n", constant);
imsls_f_write_matrix(
"Final AR coefficients estimated by maximum likelihood",
p, 1, ar, 0);
}
AIC Automatic Order selection
AR coefficients estimated using method of moments
Order selected: 3
AIC = 633.0114, Variance = 287.2694
Constant estimate is 13.7098.
Final AR coefficients estimated by method of moments
1 1.368
2 -0.738
3 0.078
AIC Automatic Order selection
AR coefficients estimated using method of least squares
Order selected: 3
AIC = 633.0114, Variance = 144.7149
Constant estimate is 9.8934.
Final AR coefficients estimated by method of least squares
1 1.604
2 -1.024
3 0.209
AIC Automatic Order selection
AR coefficients estimated using maximum likelihood
Order selected: 3
AIC = 633.0114, Variance = 218.8337
Constant estimate is 11.3902.
Final AR coefficients estimated by maximum likelihood
1 1.553
2 -1.001
3 0.205 XE "ARIMA models:method of moments estimates" \r "ARIMA"