Metadata-Version: 2.1
Name: nlntest
Version: 1.0.0
Summary: A Package for nonlinearity test of nuivariate and multivariate time series
Home-page: UNKNOWN
Author: Shapour Mohammadi
Author-email: shmohmad@ut.ac.ir
License: MIT
Keywords: python,Linearity Tests,Ramsey Linearity Test,Keenan Test,Tsay Test,Terasvirta, Lin and Granger Test,Lee, White and Granger Test
Platform: UNKNOWN
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: pandas-datareader
Requires-Dist: statsmodels
Requires-Dist: scipy
Requires-Dist: sklearn

The package contains three modules:

1- nlntstuniv

2- nlntstmultv

3- annnlntst


The 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- Ramsey

 2- Keenan

 3- Trasvirta, Lin, and Granger(1993)

 4- Tsay

Input:
 y is a univariate time series in the column vector form

Output:
 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- Tsay

 3- Keenan

The 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 nlntest

results=nlntest.nlntstuniv(y)

resultsmult=nlntest.nlntstmultv(y)

resultsann=nlntest.annnlntst(y)



Examples: these example files can be found in the package installed directory 

-------------------------------------------------------------------------------------------------
# Example: logistic map with additive noise

import nlntest as nlt

import numpy as np

y=np.zeros((1000,1))

y[0,0]=0.1

for t in range(1,1000):

 y[t,0]=4*y[t-1,0]*(1-y[t-1,0])

y=y+np.random.randn(1000,1)*0.3

print(' ')

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 ExLogistic

-------------------------------------------------------------------------------------------------
# Example: Unemployment Rate, Percent, Monthly,
# Seasonally Adjusted data in an excel file format for 1948:01-2022:08
# Data Source: https://fred.stlouisfed.org/series/UNRATE

import numpy as np

import pandas as pd

import pandas_datareader as pdr

import nlntest as nlt

print(' ')

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.values

results=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 ExUnemployment
-------------------------------------------------------------------------------------------------

# Example: Henon map

import nlntest as nlt

import numpy as np

ahen=1.4

bhen=0.3 # Parameters of Hebnon map

y=np.zeros((1000,2))

y[0,0]=0

y[0,1]=0.9 # Henon map initial vallues

for t in range(1,1000):

 y[t,0]=1-ahen*y[t-1,0]**2+bhen*y[t-1,1]

 y[t,1]=y[t-1,0]

y=y+np.random.randn(1000,2)*0.5

print(' ')

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 ExHenon
-------------------------------------------------------------------------------------------------

# Example: multivariate normal random numbers

import nlntest as nlt

import numpy as np

y3=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 Exmultnormrnd

-------------------------------------------------------------------------------------------------
# Exapmle: normal random number which is an iid series

import nlntest as nlt

import numpy as np

y=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 Exunivnorm

-------------------------------------------------------------------------------------------------



 References:

 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 Mohammadi 2022.shmohmad@ut.ac.ir


