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.
intn_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.
Return Value
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.
Synopsis with Optional Arguments
#include<imsls.h>
float*imsls_f_auto_uni_ar(intn_obs, float z[], int maxlag, int *p,
IMSLS_MAX_ITERATIONS, intmaxit (Input) Maximum number of estimation iterations.
Default: maxit = 300
IMSLS_METHOD, int method (Input) Estimation method option:
method
Action
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.
Description
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.
Example
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 each of the three parameter estimation methods available.
#include <imsls.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");