tseriesTests {fSeries} | R Documentation |
A collection of functions for testing various aspects of time series,
including unit roots, independence, normality of the distribution,
trend stationary, cointegration and neglected nonlinearities.
The family of time series tests includes the following hypothesis tests:
1 | adfTest | Augmented Dickey–Fuller test for unit roots, |
2 | bdsTest | Brock–Dechert–Scheinkman test for iid series, |
3 | jbTest | Jarque–Bera Test for normality, |
4 | kpssTest | KPSS test for level or trend stationary, |
5 | poTest | Phillips–Ouliaris test for cointegration, |
6 | ppTest | Phillips–Perron test for unit roots, |
7 | tnnTest | Teraesvirta NN test for neglected nonlinearity, |
8 | wnnTest | White NN test for neglected nonlinearity. |
adfTest(x, alternative = c("stationary", "explosive"), k) bdsTest(x, m = 3, eps = seq(0.5*sd(x), 2*sd(x), length = 4), trace = FALSE) jbTest(x) kpssTest(x, null = c("Level", "Trend"), lshort = TRUE) poTest(x, demean = TRUE, lshort = TRUE) ppTest(x, alternative = c("stationary", "explosive"), type = c("Z(alpha)", "Z(t_alpha)"), lshort = TRUE) tnnTest(x, lag = 1, type = c("Chisq", "F"), scale = TRUE, ...) wnnTest(x, lag = 1, qstar = 2, q = 10, range = 4, type = c("Chisq", "F"), scale = TRUE, ...)
alternative, null |
In the case of alternative , the argument indicates an
alternative hypothesis. The choice must be one of the elements
specified in the input vector, by default the first entry is
selected.
In the case of null , the argument indicates for the
kpssTest the null hypothesis and must be one of
"Level" (default) or "Trend" . You can specify
just the initial letter.
|
demean |
a logical indicating whether an intercept is included in the cointegration regression or not. |
eps |
a numeric vector of epsilon values for close points. The
BDS test is computed for each element of eps . It should
be set in terms of the standard deviation of x .
|
k |
the lag order to calculate the test statistic. |
lag |
an integer which specifies the model order in terms of lags. |
lshort |
a logical indicating whether the short or long version of the truncation lag parameter is used. |
m |
an integer indicating that the BDS test statistic is computed
for embedding dimensions 2 , ..., m .
|
q |
an integer representing the number of phantom hidden units used to compute the test statistic. |
qstar |
the test is conducted using qstar principal
components of the phantom hidden units. The first principal
component is omitted since in most cases it appears to be collinear
with the input vector of lagged variables. This strategy preserves
power while still conserving degrees of freedom.
|
range |
the input to hidden unit weights are initialized uniformly
over [-range/2, range/2] .
|
scale |
a logical indicating whether the data should be scaled
before computing the test statistic. The default arguments to
scale are used.
|
trace |
a logical indicating whether some informational output is traced. |
type |
indicates which variant of a test will be computed. The choice must be one of the elements specified in the input vector, by default the first entry is selected. |
x |
a numeric vector or time series. |
... |
further arguments to be passed from or to methods. |
Augmented Dickey–Fuller Test for Unit Roots:
The general regression equation which incorporates a constant and a
linear trend is used and the t-statistic for a first order
autoregressive coefficient equals one is computed. The number of lags
used in the regression is k
. The default value of
trunc((length(x)-1)^(1/3))
corresponds to the suggested upper
bound on the rate at which the number of lags, k
, should be
made to grow with the sample size for the general ARMA(p,q)
setup. Note that for k
equals zero the standard Dickey-Fuller
test is computed. The p-values are interpolated from Table 4.2, p. 103
of Banerjee et al. (1993). If the computed statistic is outside the
table of critical values, then a warning message is generated.
Note, that missing values are not allowed.
[tseries:adf.test]
Brock–Dechert–Sheinkman Test:
The bdsTest
test examines the spatial dependence of the
observed series. To do this, the series is embedded in m
-space
and the dependence of x
is examined by counting near
points. Points for which the distance is less than eps
are
called near. The BDS test statistic is asymptotically standard Normal.
Note, that missing values are not allowed.
There is a special print method for objects of class "bdsTest"
which by default uses 4 digits to format real numbers.
[tseries:bds.test]
Jarque–Bera Test:
The jbTest
evaluates the hypothesis that the series has a
normal distribution with unspecified mean and variance, against the
alternative that the series does not have a normal distribution. The
test is based on the sample skewness and kurtosis. For a true normal
distribution, the sample skewness should be near 0 and the sample
kurtosis should be near 3. The Jarque-Bera test determines whether
the sample skewness and kurtosis are unusually different than their
expected values, as measured by a chi-square statistic. The Jarque-Bera
test is an asymptotic test, and should not be used with small samples.
You may want to use the lillieTest
for small samples.
[jb.test]
Kwiatkowski–Phillips–Schmidt–Shin Test:
To estimate sigma^2
the Newey-West estimator is used.
If lshort
is TRUE
, then the truncation lag parameter is
set to trunc(3*sqrt(n)/13)
, otherwise
trunc(10*sqrt(n)/14)
is used. The p-values are interpolated
from Table 1 of Kwiatkowski et al. (1992). If the computed statistic
is outside the table of critical values, then a warning message is
generated.
[tseries:kpss.test]
Phillips–Ouliaris Test:
The poTest
Z(alpha) statistic for a unit root in the
residuals of the cointegration regression is computed, see also
ppTest
. The unit root is estimated from a regression of
the first variable (column) of x
on the remaining variables of
x
without a constant and a linear trend. To estimate
sigma^2
the Newey-West estimator is used. If lshort
is
TRUE
, then the truncation lag parameter is set to
trunc(n/100)
, otherwise trunc(n/30)
is used. The
p-values are interpolated from Table Ia and Ib, p. 189 of Phillips and
Ouliaris (1990). If the computed statistic is outside the table of
critical values, then a warning message is generated. The dimension
of x
is restricted to six variables.
[tseries:po.test]
Phillips–Perron Test:
The general regression equation which incorporates a constant and a
linear trend is used and the Z(alpha)
or Z(t_alpha)
statistic for a first order autoregressive coefficient equals one are
computed. To estimate sigma^2
the Newey-West estimator is
used. If lshort
is TRUE
, then the truncation lag
parameter is set to trunc(4*(n/100)^0.25)
, otherwise
trunc(12*(n/100)^0.25)
is used. The p-values are interpolated
from Table 4.1 and 4.2, p. 103 of Banerjee et al. (1993). If the
computed statistic is outside the table of critical values, then a
warning message is generated.
[tseries:pp.test]
Teraesvirta Neural Network Test:
The null is the hypotheses of linearity in mean
. This test
uses a Taylor series expansion of the activation function to
arrive at a suitable test statistic. If type
equals "F"
,
then the F-statistic instead of the Chi-Squared statistic
is used in analogy to the classical linear regression.
Missing values are not allowed.
[tseries:teraesvirta.test]
White Neural Network Test:
The null is the hypotheses of linearity in ``mean''. This
type of test is consistent against arbitrary nonlinearity
in mean. If type
equals "F"
, then the F-statistic
instead of the Chi-Squared statistic is used in analogy to the
classical linear regression.
[tseries:white.test]
A list with class "htest"
containing the following
components:
statistic |
the value of the test statistic. |
parameter |
the lag order. |
p.value |
the p-value of the test. |
method |
a character string indicating what type of test was performed. |
data.name |
a character string giving the name of the data. |
alternative |
a character string describing the alternative hypothesis. |
There is nothing really new in this package. The benefit you will get from this help page, that we bring together a broad collection of time series tests from several R-packages which may be of interest for economists and financial engineers.
On the other hand the user can still use the underlying function calls from the imported R-packages.
The output of the various hypothesis tests is an object of class
htest
. The associated print
method gives an unique
report about the test results.
Adrian Trapletti for the tests from R's tseries package,
Blake LeBaron for the bds
C program,
Diethelm Wuertz for this R-port.
Banerjee A., Dolado J.J., Galbraith J.W., Hendry D.F. (1993); Cointegration, Error Correction, and the Econometric Analysis of Non-Stationary Data, Oxford University Press, Oxford.
Brock, W.A., Dechert W.D., Sheinkman J.A. (1987); A Test of Independence Based on the Correlation Dimension, SSRI no. 8702, Department of Economics, University of Wisconsin, Madison.
Conover, W.J. (1980); Practical Nonparametric Statistics, New York, Wiley.
Cromwell J.B., Labys W.C., Terraza M. (1994); Univariate Tests for Time Series Models, Sage, Thousand Oaks, CA, pages 32–36.
Kwiatkowski D., Phillips P.C.B, Schmidt P., Shin Y. (1992); Testing the Null Hypothesis of Stationarity against the Alternative of a Unit Root, Journal of Econometrics 54, 159–178.
Lee T.H., White H., Granger C.W.J. (1993); Testing for neglected nonlinearity in time series models, Journal of Econometrics 56, 269–290.
Perron P. (1988); Trends and Random Walks in Macroeconomic Time Series, Journal of Economic Dynamics and Control 12, 297–332.
Phillips P.C.B., Ouliaris S. (1990); Asymptotic Properties of Residual Based Tests for Cointegration, Econometrica 58, 165–193.
Said S.E., Dickey D.A. (1984); Testing for Unit Roots in Autoregressive-Moving Average Models of Unknown Order, Biometrika 71, 599–607.
Teraesvirta T., Lin C.F., Granger C.W.J. (1993); Power of the Neural Network Linearity Test, Journal of Time Series Analysis 14, 209–220.
classicalTests
,
lmTests
.
## adfTest - xmpSeries("\nStart: Augmented Dickey-Fuller Test for Unit Roots >") # A time series which contains no unit-root: x = rnorm(1000) adfTest(x) # A time series which contains a unit-root: y = diffinv(x) adfTest(y) ## bdsTest - xmpSeries("\nNext: Brock-Dechert-Sheinkman Test for iid Series >") # iid Time Series: par(mfrow = c(3,1)) x = rnorm(100) plot(x, type = "l", main = "iid Time Series") bdsTest(x, m = 3) # Non Identically Distributed Time Series: x = c(rnorm(50), runif(50)) plot(x, type = "l", main = "Non-iid Time Series") bdsTest(x, m = 3) # Non Independent Innovations from Quadratic Map: x = rep(0.2, 100) for (i in 2:100) x[i] = 4*(1-x[i-1])*x[i-1] plot(x, type = "l", main = "Quadratic Map") bdsTest(x, m = 3) ## jbTest - xmpSeries("\nNext: Jarque-Bera Test for Normality >") # Null: x = rnorm(100) jbTest(x) # Alternative: x = runif(100) jbTest(x) ## kpssTest - xmpSeries("\nNext: KPSS test for Level or Trend Stationary >") # Time Series is Level Stationary: x = rnorm(1000) kpssTest(x) # Time Series has Unit Root: y = cumsum(x) kpssTest(y) # Time Series is Trend Stationary: x = 0.3*(1:1000)+rnorm(1000) kpssTest(x, null = "Trend") ## poTest - xmpSeries("\nNext: Phillips-Ouliaris Test for Cointegration >") # Non-Cointegrated Case: x = ts(diffinv(matrix(rnorm(2000), 1000, 2))) poTest(x) # Cointegrated Case: x = diffinv(rnorm(1000)) y = 2.0 - 3.0*x + rnorm(x, sd=5) z = ts(cbind(x, y)) poTest(z) ## ppTest - xmpSeries("\nNext: Phillips-Perron Test for Unit Roots >") # The Time Series has no Unit Root: x = rnorm(1000) ppTest(x) # The Time Series has Unit Root: y = cumsum(x) ppTest(y) ## tnnTest - xmpSeries("\nNext: Teraesvirta NN test for Neglected Nonlinearity >") # Time Series Non-linear in ``mean'' regression par(mfrow = c(2, 1)) n = 1000 x = runif(1000, -1, 1) tnnTest(x) # Generate time series which is nonlinear in ``mean'' x[1] = 0.0 for (i in (2:n)) { x[i] = 0.4*x[i-1] + tanh(x[i-1]) + rnorm (1, sd = 0.5) } plot(x, main = "Teraesvirta Test", type = "l") tnnTest(x) ## wnnTest - xmpSeries("\nNext: White NN test for Neglected Nonlinearity >") # Time Series Non-Linear in ``mean'' Regression par(mfrow = c(2, 1)) n = 1000 x = runif(1000, -1, 1) wnnTest(x) # Generate time series which is nonlinear in ``mean'' x[1] = 0.0 for (i in (2:n)) { x[i] = 0.4*x[i-1] + tanh(x[i-1]) + rnorm (1, sd = 0.5) } plot(x, main = "White Test", type = "l") wnnTest(x)