Skip to main content

A Package for nonlinearity test of nuivariate and multivariate time series

Project description

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]=4y[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-aheny[t-1,0]**2+bheny[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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nlntest-1.0.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

nlntest-1.0.0-py2-none-any.whl (10.7 kB view details)

Uploaded Python 2

File details

Details for the file nlntest-1.0.0.tar.gz.

File metadata

  • Download URL: nlntest-1.0.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for nlntest-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8e4422163c9f1cc281bd1e7fd8259c546df30131fbca9df193830b59a5692ee7
MD5 fd8f0d0f54441b3f99f149feeb6392f6
BLAKE2b-256 bd1a03028db7f79e9cf2ca8591386c639ce6f9132dfcb9a8ca15c1229943b24a

See more details on using hashes here.

File details

Details for the file nlntest-1.0.0-py2-none-any.whl.

File metadata

  • Download URL: nlntest-1.0.0-py2-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for nlntest-1.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 14940121834df324779c6b715139487837e32eab17b8297166c6586cac1a86b2
MD5 66f78cfd490e4f2a7634b1850841725c
BLAKE2b-256 0480f868decfe9c3e9fdb2e664f1f0124d5435d3433287b68b4272af4e673016

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page