In addition to the time series models discussed earlier,
several functions and tests specific to time series analysis
are available.
The TimeSeriesFunctions
defines a number of static methods that perform calculations that are common
in time series analysis.
The AutoCovarianceFunction(VectorDouble, Int32)
and AutocorrelationFunction(VectorDouble, Int32)
methods return the auto covariance function and auto-correlation function of a time series, respectively.
These methods take two arguments. The first is the time series. The second is the highest lag order to include in the function.
the methods return a vector that contains, for each lag starting at 0, the auto-covariance or autocorrelation of the series.
If more information is required, the GetAutocorrelationFunctionInfo(VectorDouble, Int32, Boolean, Double, Boolean)
method can provide it. This method returns a DataFrameR, C
with one row per lag value. In addition to the value of the ACF, the data frame may contain
columns for the lower and upper confidence intervals for the auto-correlation,
and the value of the Ljung-Box statistic, Q.
The first argument of this method is the time series for which to evaluate the autocorrelation function.
The remaining arguments are optional. The first optional argument is the lag order.
By default, values for lags up to 40 are included. The second optional argument
specifies whether columns should be included for the lower and upper bounds of
the confidence interval. The default is .
The third optional argument specifies the confidence level for the confidence intervals.
It defaults to 0.95. The fourth and final optional argument specifies
whether the Ljung-Box statistic should be included. The default is .
Given a vector that contains the auto-correlation function of a time series, the
PartialAutocorrelationFunction(VectorDouble)
method returns the corresponding partial correlation function.
DurbinWatsonStatistic(VectorDouble)
method returns the Durbin-Watson statistic for a vector of residuals. A value close to 0
indicates a positive autocorrelation between the residuals.
A value close to 4 indicates a negative autocorrelation between the residuals.
A value around 2 indicates there is no significant autocorrelation.
For other values, a table of critical values of the Durbin-Watson statistic should be consulted.
The Augmented Dickey-Fuller Test
The Augmented Dickey-Fuller (ADF) test is a hypothesis test that tests for the
presence of a unit root in a time series. The test is based on a regression
analysis of a time series model that may contain a constant term for drift and
a trend term. The number of auto-regressive terms in the regression model
may be specified, or a reasonable default value can be computed.
The ADF test is implemented by the
AugmentedDickeyFullerTest
class, which has one constructor that takes up to 3 arguments.
The first argument is a vector that contains the time series the test
is to be applied to. The second argument specifies the auto-regressive
order of the time series model. If it is omitted or negative,
then the cube root of the size of the sample, rounded down to the nearest
integer, is used.
The third argument is a
DickeyFullerTestType
value that specifies the type of regression model used. The possible values are:
Value | Description |
---|
NoConstant | A constant or trend is not included. |
Constant | A constant term (drift) is included. |
ConstantAndTrend | A constant term (drift) and a trend term are both included. |
The default is to include a constant and a trend term.
The critical values for the distribution of the Dickey-Fuller statistic are different
depending on whether drift and trend are included. The values are interpolated from
table 4.2 in Banerjee et.al.
In this example we look at consumption in Germany between 1960 and 1982.
Economic theory suggests that the log of the data may show a unit root.
var data = Extreme.Data.Stata.StataFile.ReadDataFrame("lutkepohl2.dta");
var adf = new AugmentedDickeyFullerTest(data["ln_consump"].As<double>(), 4);
Console.WriteLine("Augmented Dickey-Fuller statistic: {0:F3}", adf.Statistic);
var dist = adf.Distribution;
Console.WriteLine("Critical values:");
Console.WriteLine(" 1% : {0:F3}", dist.InverseDistributionFunction(0.01));
Console.WriteLine(" 5% : {0:F3}", dist.InverseDistributionFunction(0.05));
Console.WriteLine(" 10% : {0:F3}", dist.InverseDistributionFunction(0.10));
Dim frame = Stata.StataFile.ReadDataFrame("lutkepohl2.dta")
Dim adf = New AugmentedDickeyFullerTest(frame("ln_consump").As(Of Double)(), 4)
Console.WriteLine("Augmented Dickey-Fuller statistic: {0:F3}", adf.Statistic)
Dim dist = adf.Distribution
Console.WriteLine("Critical values:")
Console.WriteLine(" 1% : {0:F3}", dist.InverseDistributionFunction(0.01))
Console.WriteLine(" 5% : {0:F3}", dist.InverseDistributionFunction(0.05))
Console.WriteLine(" 10% : {0:F3}", dist.InverseDistributionFunction(0.1))
No code example is currently available or this language may not be supported.
let data = Extreme.Data.Stata.StataFile.ReadDataFrame("lutkepohl2.dta")
let adf = new AugmentedDickeyFullerTest(data.["ln_consump"].As<float>(), 4)
printfn "Augmented Dickey-Fuller statistic: %.3f" adf.Statistic
let dist = adf.Distribution
printfn "Critical values:"
printfn " 1%% : %.3f" (dist.InverseDistributionFunction(0.01))
printfn " 5%% : %.3f" (dist.InverseDistributionFunction(0.05))
printfn " 10%% : %.3f" (dist.InverseDistributionFunction(0.10))
The value of the test statistic is -1.318.
The critical values at the 1%, 5%, and 10% levels are
-4.060, -3.459, and -3.155, so the null hypothesis is not rejected.
A. Banerjee, J. J. Dolado, J. W. Galbraith, and D. F. Hendry (1993):
Cointegration, Error Correction, and the Econometric
Analysis of Non-Stationary Data, Oxford University Press, Oxford.
S. E. Said and D. A. Dickey (1984): Testing for Unit Roots
in Autoregressive-Moving Average Models of Unknown Order. Biometrika 71, 599–607