lack_of_fit
Performs lack-of-fit test for a univariate time series or transfer function given the appropriate correlation function.
Synopsis
#include <imsls.h>
float *imsls_lack_of_fit (int n_observations, float cf[], int lagmax, int npfree, …, 0)
Required Arguments
int n_observations (Input)
Number of observations of the stationary time series.
float cf[] (Input)
Array of length lagmax +1 containing the correlation function.
int lagmax (Input)
Maximum lag of the correlation function.
int npfree (Input)
Number of free parameters in the formulation of the time series model. npfree must be greater than or equal to zero and less than lagmax. Woodfield (1990) recommends npfree = p + q for an ARMA(p,q) model.
Return Value
Pointer to an array of length 2 with the test statistic, Q, and its p‑value, p. Under the null hypothesis, Q has an approximate chi-squared distribution with lagmax-lagmin+1-npfree degrees of freedom.
Synopsis with Optional Arguments
#include <imsls.h>
float *imsls_f_lack_of_fit (int n_observations, float cf[], int lagmax, int npfree,
IMSLS_LAGMIN, int lagmin,
IMSLS_RETURN_USER, float stat[],
0)
Optional Arguments
IMSLS_LAGMIN, int lagmin (Input)
Minimum lag of the correlation function. lagmin corresponds to the lower bound of summation in the lack of fit test statistic.
Default value is 1.
IMSLS_RETURN_USER, float stat[] (Output)
User defined array for storage of lack-of-fit statistics.
Description
Function imsls_f_lack_of_fit may be used to diagnose lack of fit in both ARMA and transfer function models. Typical arguments for these situations are:
Model | LAGMIN | LAGMAX | NPFREE |
---|
ARMA (p, q) | 1 | | p + q |
Transfer function | 0 | | r + s |
Function imsls_f_lack_of_fit performs a portmanteau lack of fit test for a time series or transfer function containing n observations given the appropriate sample correlation function
for k = L, L + 1, …, K where L = lagmin and K = lagmax.
The basic form of the test statistic Q is
with L = 1 if
is an autocorrelation function. Given that the model is adequate, Q has a chi-squared distribution with K − L + 1 − m degrees of freedom where m = npfree is the number of parameters estimated in the model. If the mean of the time series is estimated, Woodfield (1990) recommends not including this in the count of the parameters estimated in the model. Thus, for an ARMA(p, q) model set npfree= p + q regardless of whether the mean is estimated or not. The original derivation for time series models is due to Box and Pierce (1970) with the above modified version discussed by Ljung and Box (1978). The extension of the test to transfer function models is discussed by Box and Jenkins (1976, pages 394–395).
Example
Consider the Wölfer Sunspot Data (Anderson 1971, page 660) consisting of the number of sunspots observed each year from 1749 through 1924. The data set for this example consists of the number of sunspots observed from 1770 through 1869. An ARMA(2,1) with nonzero mean is fitted using function
imsls_f_arma. The autocorrelations of the residuals are estimated using function
imsls_f_autocorrelation. A portmanteau lack of fit test is computed using 10 lags with
imsls_f_lack_of_fit.
#include <imsls.h>
#include <stdio.h>
int main()
{
int p=2, q=1, i, n_observations=100, max_itereations=0, lagmin=1,
lagmax=10, npfree=4;
float data[176][2], x[100], *parameters, *correlations,
*residuals, *result;
/* Get sunspot data for 1770 through 1869, store it in x[]. */
imsls_f_data_sets(2, IMSLS_RETURN_USER, data, 0);
for (i=0;i<n_observations;i++) x[i] = data[21+i][1];
/* Get residuals from ARMA(2,1) for autocorrelation/lack of fit */
parameters = imsls_f_arma(n_observations, x, p, q,
IMSLS_LEAST_SQUARES,
IMSLS_RESIDUAL, &residuals,
0);
/* Get autocorrelations from residuals for lack of fit test */
/* NOTE: number of OBS is equal to number of residuals */
correlations = imsls_f_autocorrelation(n_observations-p+lagmax,
residuals, lagmax, 0);
/* Get lack of fit test statistic and p-value */
/* NOTE: number of OBS is equal to original number of data */
result = imsls_f_lack_of_fit(n_observations, correlations,
lagmax, npfree, 0);
/* Print parameter estimates, test statistic, and p-value */
/* NOTE: Test Statistic Q follows a Chi-squared dist. */
printf("Lack of Fit Statistic, Q = \t%3.5f\n", result[0]);
printf(" P-value of Q = \t %1.5f\n\n", result[1]);
}
Output
Lack of Fit Statistic, Q = 23.89239
P-value of Q = 0.00055