1
$\begingroup$

In an artificial dataset comprised of 1,000 timeseries with 1,000 timesteps each, let's assume there is a specific timestep at which the second coefficient of the autocorrelation function switches from positive to negative (or vice versa).

The timeseries pass the test of stationarity and the distribution of their means has a mean of close to zero with a distribution that seems like a mixture of a normal distribution and some positive outliers:

enter image description here

I can find the coefficient of the autocorrelation function for any timeseries using the acf method of the statsmodels package. I use the following code to visualize the distribution of the values of the second acf coefficient for different timesteps and I observe that I have a mixed picture instead with both negative and positive values at different timesteps but with a distribution that gradually moves towards assigning more probability mass to negative values after a certain point.

I wonder how I can estimate the exact timestep at which the transition occurs given that I am dealing apparently with noisy data. One way to go would be to calculate at each timestep the relative frequency of the second coefficients of the autocorrelation function that have positive value and decide that a regime change occurs when this number reaches its peak.

Here is the code I use and some visualizations of the distributions:

from statsmodels.tsa.stattools import acf

timesteps = np.arange(50, 1000, 20)
for i in np.arange(5):

    timesteps_temp = timesteps[i*12 : (i+1)*12 ]

    fig = plt.figure()
    fig.subplots_adjust(hspace=0.4, wspace=0.4)
    colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a','#ffff99','#b15928']

    for timestep, i in zip(timesteps_temp, np.arange(1, 13)):
        data = stationary_ts.iloc[:timestep,:]  # stationary_ts is the 1000x1000 dataframe containing as columns the 1000 timeseries
        acfs = [acf(data[col])[1] for col in data.columns]
        ax = fig.add_subplot(4, 3, i)
        sns.distplot(acfs,ax=ax, color = colors[i-1])
        ax.set_title(f'Data from beginning and up to timestep {timestep}')
    plt.show()

enter image description here

enter image description here

I can use the approach I described to find the peak of the relative frequency of the positive values of the second coefficient of the autocorrelation function with the following code:

figsize(31,16)
sns.distplot(means, bins = 100)
plt.title('Distribution of the means of the timeseries')

frequency_of_positive_examples = pd.Series(frequency_of_positive_examples_list, index = stationary_ts.index[50:])

frequency_of_positive_examples.plot()
plt.axvline(frequency_of_positive_examples[550:].argmax(), color = 'black')
plt.title('Relative frequency of positive examples')

enter image description here

Is this approach valid? Is there a better approach?

$\endgroup$

1 Answer 1

1
$\begingroup$

For each time series estimate an AR(2) model for all the 1000 values and then for different subsets e.g. 1-100 and 101-1000 ( break point 101) and perform a CHOW test for constancy of parameters (1960) . Do this say for 1-150 versus 151-1000 ( break point 151 )and perform the same test . Find the break point that provides the largest F value .

$\endgroup$
6
  • $\begingroup$ Thank you! I will try to implelment your approach and I will come back to you. $\endgroup$ Commented Dec 21, 2019 at 15:21
  • $\begingroup$ Your outliers may (probably will !) distort the CHOW TEST see stats.stackexchange.com/search?tab=newest&q=user%3a3382%20CHOW%20TEST .... I might normalize the outliers to be able to proceed with a head to head comparison of group A versus group B $\endgroup$
    – IrishStat
    Commented Dec 21, 2019 at 15:38
  • $\begingroup$ stats.stackexchange.com/… $\endgroup$
    – IrishStat
    Commented Dec 21, 2019 at 16:13
  • $\begingroup$ Thank you again! I will do so. I will let you know of the results possibly updating the post or creating a new post - depending on how things turn out. $\endgroup$ Commented Dec 21, 2019 at 16:34
  • $\begingroup$ I used the chow test and a methodology inspired from your recommendations and I ended up with a distribution of breaking points (since this was applied to multiple timeseries). The median was at one day difference from the break point I found using the method outlined in my post. $\endgroup$ Commented Dec 22, 2019 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.