Performs lack-of-fit test for a univariate time series or transfer function given the appropriate correlation function.
#include <imsls.h>
float
imsls_lack_of_fit (int n_observations, float cf[],
int
lagmax, int npfree,..., 0)
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.
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.
#include <imsls.h>
float
*imsls_f_lack_of_fit (int n_observations, float cf[], int
lagmax,
int npfree,
IMSLS_RETURN_USER, float
stat[],
IMSLS_LAGMIN, int lagmin,
0)
IMSLS_RETURN_USER,
float stat[]
(Input)
User defined array for storage of lack-of-fit statistics.
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.
Routine 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).
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 routine
imsls_f_arma. The autocorrelations of the residuals
are estimated using routine imsls_f_autocorrelation. A portmanteau
lack of fit test is computed using 10 lags with imsls_f_lack_of_fit.
The warning message from imsls_f_arma in the output can be ignored.
(See
the example for routine imsls_f_arma for a full explanation of the warning
message.)
#include <imsls.h>
#include <stdio.h>
void main()
{
int p = 2;
int q = 1;
int i;
int n_observations = 100;
int max_itereations = 0;
int lagmin = 1;
int lagmax = 10;
int npfree = 4;
float data[176][2], x[100];
float *parameters;
float *correlations;
float *residuals;
float tolerance = 0.125;
float *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_CONVERGENCE_TOLERANCE, tolerance,
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 P-value of Q
= \t %1.5f\n\n",result[0], result[1]);
}
***WARNING ERROR IMSLS_LEAST_SQUARES_FAILED from imsls_f_arma. Least
*** squares estimation of the parameters has failed to converge.
*** Increase “length” and/or “tolerence” and/or
*** “convergence_tolerence”. The estimates of the parameters at
*** the last
iteration may be used as new starting values.
Lack of Fit statistic (Q)
=
14.572
P-value (PVALUE)
= 0.9761
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |