Package: nlntest
The package contains three modules:1- nlntstuniv2- nlntstmultv3- annnlntstThe first module, "nlntstuniv", tests the linearity of univariate time series by Ramsey, Keenan, Tsay, and Terasvirta.
Module "nlntstmultv" uses three tests: multivariate Keenan, multivariate Tsay, and multivariate Terasvirta.
If one passes univariate time series in this module result of the test will be the same as the result of "nlntstuniv".
The last package tests linearity for univariate and multivariate time series by modified form Lee, White, and Granger(1993)
test by the artificial neural network. The details of modification are described in Mohammadi(2019).
The first version of the modules is written as MATLAB code by the author. each module has separate
description in itself, but we give here all descriptions for readability.A) nlntstuniv description:Nonlinearity test for univariate time series. The output of the code includes
following nonlinearity tests:1- Ramsey2- Keenan3- Trasvirta, Lin, and Granger(1993)4- TsayInput:
y is a univariate time series in the column vector formOutput:
The probability value of the tests. Reject linearity(H0) if pval is
smaller than 5%(or any predetermined level of significance)B) nlntstmultv description:nonlinearity test for multivariate time series. The output of the code
includes the following nonlinearity tests:1- Trasvirta, Lin, and Granger(1993)2- Tsay3- KeenanThe Matlab version of this module has been used in S. Mohammadi(2019).Input:
y is a univariate time series in the form column vector.Output:
The probability value of the tests. Reject linearity(H0) if pval is
smaller than 5%(or any predetermined level of significance).C) annnlntst description:nonlinearity test for univariate and multivariate time series.
The Matlab version of this module has been used in S. Mohammadi(2019).
The test is a generalization of Lee, White, and Granger (1993) test.
In addition to generalization to multivariate time series, some modifications
are made in Mohammadi(2019) to increase the power of Lee, White,
and Granger (1993)test in the case of a univariate
time series.Input:
y: a univariate(multivariate) time series in the form column
vector(s).Output:
The probability value of the test. Reject linearity(H0) if pval is
less than 5%(or any predetermined level of significance).#################  IMPORTANT NOTE  ################for running modules simply type.import nlntest as nlntestresults=nlntest.nlntstuniv(y)resultsmult=nlntest.nlntstmultv(y)resultsann=nlntest.annnlntst(y)Examples: these example files can be found in the package installed directoryExample: logistic map with additive noiseimport nlntest as nltimport numpy as npy=np.zeros((1000,1))y[0,0]=0.1for t in range(1,1000):y[t,0]=4y[t-1,0](1-y[t-1,0])y=y+np.random.randn(1000,1)*0.3print(' ')print('     ' 'Example: Linearity test of time series generated by the logistic map')print(' ')results=nlt.nlntstuniv(y)resultsMulti=nlt.nlntstmultv(y)resultsAnn=nlt.annnlntst(y)''' Since the logistic map is nonlinear, pvalues will be smaller than 0.05
in 95% of times that you run the modules '''.For Running This Example pls Type:from nlntest import ExLogisticExample: Unemployment Rate, Percent, Monthly,Seasonally Adjusted data in an excel file format for 1948:01-2022:08Data Source:https://fred.stlouisfed.org/series/UNRATEimport numpy as npimport pandas as pdimport pandas_datareader as pdrimport nlntest as nltprint(' ')print('         '      'Example: Linearity Test of Unemployment Rate of USA')print(' ')df=pdr.get_data_fred('UNRATE','1948-01-01','2022-08-01')print(df)y=df.valuesresults=nlt.nlntstuniv(y)resultsMulti=nlt.nlntstmultv(y)resultsAnn=nlt.annnlntst(y)''' Since the unemployment rate is a nonlinear process pvalues will be smaller
than 0.05 in 95% of times that you run the modules'''Note: For running this example you need the internet connection.For Running This Example pls Type:from nlntest import ExUnemploymentExample: Henon mapimport nlntest as nltimport numpy as npahen=1.4bhen=0.3 # Parameters of Hebnon mapy=np.zeros((1000,2))y[0,0]=0y[0,1]=0.9 # Henon map initial valluesfor t in range(1,1000):y[t,0]=1-aheny[t-1,0]**2+bheny[t-1,1]y[t,1]=y[t-1,0]y=y+np.random.randn(1000,2)*0.5print(' ')print('     ' 'Example: Linearity test of time series generated by Henon map')print(' ')resultsMulti=nlt.nlntstmultv(y)resultsAnn=nlt.annnlntst(y)''' Since the Henon map is nonlinear, pvalues will be smaller than 0.05
in 95% of times that you run the modules '''For Running This Example pls Type:from nlntest import ExHenonExample: multivariate normal random numbersimport nlntest as nltimport numpy as npy3=np.random.randn(1000,3)print(' ')print('Example: Linearity test of multivariate time series generated by the normal distribution')print(' ')resultsMulti=nlt.nlntstmultv(y3)resultsAnn=nlt.annnlntst(y3)''' Since the random series are not dependent, pvalues will greater than 0.05
in 95% of times that you run the modules '''For Running This Example pls Type:from nlntest import ExmultnormrndExapmle: normal random number which is an iid seriesimport nlntest as nltimport numpy as npy=np.random.randn(1000,1)print(' ')print('Example: Linearity test of univariate time series generated by normal distribution')print(' ')results=nlt.nlntstuniv(y)resultsMulti=nlt.nlntstmultv(y)resultsAnn=nlt.annnlntst(y)''' Since iid series are not dependent, pvalues will be greater than 0.05
in 95% of times that you run the modules'''For Running This Example pls Type:from nlntest import ExunivnormReferences:1- Mohammadi S. Neural network for univariate and multivariate nonlinearity tests. Stat Anal Data Min: The ASA DataSci Journal. 2019.
13:50-70.https://doi.org/10.1002/sam.11441.2- Tsay, R. S. Testing and modeling multivariate threshold models,
J. Amer. Statist. Assoc. 93 (1998), 1188-1202.3- Vavra, M.  Testing for nonlinearity in multivariate stochastic
processes1, Working paper NBS, 2013,http://www.nbs.sk/en/publications-issued-by-the-nbs/working-papers.4-  Keenan,D. M.(1985). A Tukey nonadditivity-type test for time series
nonlinearity, Biometrika 72, 39-44.5- Ramsey,J. B.(1969). Tests for specification errors in classical linear
least squares regression analysis, J. R. Stat. Soc B 31, 350-371.6- Terasvirta,T., C. Lin, and C. W. J. Granger(1993), Power of the neural
network linearity test, J. Time Ser. Anal. 14, 209-220. Copyright, Shapour Mohammadi2022.shmohmad@ut.ac.ir