简体   繁体   中英

Time series linearity test

Is there a test in python which allows to know if a time series is linear or not? I want to know which module of kalman filter I have to use in order to correct my forecast data.

You'll want to do a "linear regression". Numpy and SciPy are Python math libraries that can help.

Here's an example of a linear regression using Numpy and SciPy:

from numpy import arange
from pylab import plot,show
from scipy import stats

xi = arange(0,9)
# linearly generated sequence
y = [19, 20, 20.5, 21.5, 22, 23, 23, 25.5, 24]

slope, intercept, r_value, p_value, std_err = stats.linregress(xi,y)

print 'r-value', r_value
print 'p-value', p_value
print 'standard deviation', std_err

line = slope*xi + intercept
plot(xi,line,'r-',xi,y,'o')
show()

The closer your r-value is to 1, the more closely your data matches then calculated line. Since the linear regression produces a line, and the r-value tell you how your data fits the line, an r-value of 1 would mean your series is completely linear.

You may want to look at statsmodels.tsa and try an ARMA (auto regressive moving average) model. Specifically the kalman filter methods can be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM