TSA Using Matlab
TSA Using Matlab
Measures of Analysis of Time Series (MATS): A MATLAB Toolkit for Computation of Multiple Measures on Time Series Data Bases
Dimitris Kugiumtzis
Aristotle University of Thessaloniki
Alkiviadis Tsimpiris
Aristotle University of Thessaloniki
Abstract In many applications, such as physiology and nance, large time series data bases are to be analyzed requiring the computation of linear, nonlinear and other measures. Such measures have been developed and implemented in commercial and freeware softwares rather selectively and independently. The Measures of Analysis of Time Series (MATS) MATLAB toolkit is designed to handle an arbitrary large set of scalar time series and compute a large variety of measures on them, allowing for the specication of varying measure parameters as well. The variety of options with added facilities for visualization of the results support dierent settings of time series analysis, such as the detection of dynamics changes in long data records, resampling (surrogate or bootstrap) tests for independence and linearity with various test statistics, and discrimination power of dierent measures and for dierent combinations of their parameters. The basic features of MATS are presented and the implemented measures are briey described. The usefulness of MATS is illustrated on some empirical examples along with screenshots.
Keywords: time series analysis, data bases, nonlinear dynamics, statistical measures, MATLAB software, change detection, surrogate data.
1. Introduction
The analysis of time series involves a range of disciplines, from engineering to economics, and its development spans dierent aspects of the time series, e.g., analysis in the time and frequency domain, and under the assumption of a stochastic or deterministic process (Box, Jenkins, and Reinsel 1994; Kay 1988; Tong 1990; Kantz and Schreiber 1997). Many developed software products include standard methods of time series analysis. Commercial statistical packages, such as SPSS (SPSS Inc. 2006) and SAS (SAS Institute Inc. 2003),
have facilities on time series which are basically implementations of the classical Box-Jenkins approach on non-stationary time series. The commercial computational environments MATLAB (The MathWorks, Inc. 2007) and S-PLUS (Insightful Corp. 2003) provide a number of toolboxes or modules that deal with time series (MATLAB: Financial, Econometrics, Signal Processing, Neural Network and Wavelets; S-PLUS: FinMetrics, Wavelet, EnvironmentalStats). Less standard and more advanced tools of time series analysis can be found in a number of commercial stand-alone software packages developed for more specic uses of time series, and in a few freeware packages mostly oering a set of programs rather than an integrated software, such as the TISEAN package which includes a comprehensive set of methods of the dynamical system approach (Hegger, Kantz, and Schreiber 1999). Some open-source MATLAB toolkits oer selected methods for analyzing an input time series, such as the time series analysis toolbox TSA (Schlgl 2002). o In many applications, particularly when the system is rather complex as in seismology, climate, nance and physiology, the development of models from data can be a formidable task. There the interest is rather in compressing the information from a time series to some extracted features or measures that can be as simple as descriptive statistics or as complicated as the goodness of t of a nonlinear model involving many free parameters. Moreover, the problem at hand may involve a number of time series, e.g., multiple stock indices or consecutive segments from the split of a long physiological signal, such as an electrocardiogram (ECG) or electroencephalogram (EEG). The task of handling these problems is to characterize, discriminate or cluster the time series on the basis of the estimated measures. For example, dierent types of measures have been applied to nancial indices in order to compare international markets at dierent periods or to each other, such as the NMSE t (Alvarez D 2008) and az Shannon entropy (Risso 2009), and in segmented preictal EEG segments in order to predict the seizure onset (for a comprehensive collection of measures see e.g., Mormann, Kreuz, Rieke, Kraskov, David, Elger, and Lehnertz 2005; Kugiumtzis, Papana, Tsimpiris, Vlachos, and Larsson 2006; Kugiumtzis, Vlachos, Papana, and Larsson 2007). It appears that none of the existing commercial or freeware packages are suited to such problems and typically they provide partial facilities, e.g., computing some specic measures, and the user has to write code to complete the analysis. The Measures of Analysis of Time Series toolkit MATS is developed in MATLAB to meet the above-mentioned needs. The purpose of MATS is not only to implement well-known and welltested measures, but to introduce also other measures, which have been recently presented in the literature and may be useful in capturing properties of the time series. Moreover, MATS provides some types of pre-processing of arbitrary long sets of scalar time series. MATS exploits the graphical user interface (GUI) of MATLAB to establish a user-friendly environment and visualization facilities. In the computation of some methods, functions in the Signal Processing, System Identication and Statistics MATLAB toolboxes are called. Measures related to specic toolboxes, such as GARCH models (McCullough and Renfro 1998), neural networks and wavelets, are not implemented in MATS. In order to speed up computations when searching for neighboring points, MATS uses k-D tree data structure built in external les (.dll for Windows and .mexglx for Linux), which are supported by MATLAB versions 6.5 or later. The structure of the paper is as follows. The implemented facilities on time series preprocessing are presented in Section 2 and in Section 3 the implemented measures are briey described. Then in Section 4 the basic features of the MATLAB toolkit MATS are presented
and discussed and in Section 5 some representative real-world applications of the software are presented. Finally, further possible development of MATS and improvement of its applicability are discussed in Section 6.
When comparing measures across dierent time series, it is suggested to align the time series in terms of range or marginal distribution, so that any dierences of the computed measures on the time series cannot be assigned to dierences in the range or shape of the time series amplitudes. Four schemes of data standardization are also implemented in the facility of time series transformation. Let the input time series from the current set be {xt }N of length N t=1 and the standardized time series be {yt }N . The four standardizations are dened as follows. t=1
min . {y }N has minimum 0 and maximum 1. 1. Linear standardization: yt = xmax x t t=1 min
x 2. Normalized or z-score standardization: yt = xts , where x is the mean and sx the x N . {y }N has mean 0 and SD 1. standard deviation (SD) of {xt }t=1 t t=1 xt x
3. Uniform standardization: yt = Fx (xt ), where Fx is the sample marginal cumulative N given by the rank order of each sample x divided by density function (cdf) of {xt }t=1 t N . The marginal distribution of {yt }N is uniform in [0, 1]. t=1 4. Gaussian standardization: yt = 1 Fx (xt ) , where denotes the standard Gaussian (normal) cdf. The marginal distribution of {yt }N is standard Gaussian. t=1 The Gaussian standardization can also serve as a transform to Gaussian time series.
2.3. Resampling
When analyzing time series, it is often of interest to test an hypothesis for the underlying system to the given time series. The null hypotheses H0 considered here are that a time series {xt }N is generated by (a) an independent (white noise) process, (b) a Gaussian process and t=1 (c) a linear stochastic process. Many of the implemented measures in MATS can be used as test statistics for these tests. The resampling approach can be used to carry out the test by generating randomized or bootstrap time series. The facility of time series resampling implements a number of algorithms for the generation of a given number of resampled time series for each H0 , as follows. 1. Random permutation (RP) or shuing of {xt }N generates a time series that preserves t=1 the marginal distribution of the original time series but is otherwise independent. The RP time series is a randomized (or so-called surrogate) time series consistent to the H0 of independence. 2. It is conventionally referred to as Fourier transform (FT) algorithm because it starts with a Fourier transform of {xt }N , then the phases are randomized, and the resulting t=1 Fourier series is transformed back to the time domain to give the surrogate time series. The FT surrogate time series possesses the original power spectrum (slight inaccuracy may occur due to possible mismatch of data end-points). Note that the marginal distribution of the FT surrogate time series is always Gaussian and therefore it is consistent to the H0 of a Gaussian process (Theiler, Eubank, Longtin, and Galdrikian 1992). 3. The algorithm of amplitude adjusted Fourier transform (AAFT) rst orders a Gaussian white noise time series to match the rank order of {xt }N and derives the FT surrogate t=1 of this time series. Then {xt }N is reordered to match the ranks of the generated FT t=1
time series (Theiler et al. 1992). The AAFT time series possesses the original marginal distribution exactly and the original power spectrum (and thus the autocorrelation) approximately, but often the approximation can be very poor. Formally, AAFT is used to test the H0 of a Gaussian process undergoing a monotonic static transform. 4. The iterated AAFT (IAAFT) algorithm is an improvement of AAFT and approximates better the original power spectrum and may dier only slightly from the original one (Schreiber and Schmitz 1996). At cases, this dierence may be signicant because all generated IAAFT time series tend to give about the same power spectrum, i.e., the variance of the power spectrum is very small. The IAAFT surrogate time series is used to test the H0 of a Gaussian process undergoing a static transform (not only monotonic). 5. The algorithm of statically transformed autoregressive process (STAP) is used for the same H0 as for IAAFT and the surrogate data are statically transformed realizations of a suitably designed autoregressive (AR) process (Kugiumtzis 2002b). The STAP time series preserve exactly the original marginal distribution and approximately the original autocorrelation, so that the variance is larger than for IAAFT but there is no bias. 6. The algorithm of autoregressive model residual bootstrap (AMRB) is a model-based (or residual-based) bootstrap approach that uses a tted AR model and resamples with replacement from the model residuals to form the bootstrap time series (Politis 2003; Hjellvik and Tjstheim 1995). AMRB is also used for the same H0 as IAAFT and STAP. The AMRB time series have approximately the same marginal distribution and autocorrelation as those of the original time series, but deviations on both can be at cases signicant. For a review on surrogate data testing, see Schreiber and Schmitz (2000); Kugiumtzis (2002c). For a comparison of the algorithms of AAFT, IAAFT, STAP and AMRB in the test for nonlinearity, see Kugiumtzis (2008). The segmented, standardized and resampled time series get a specic coded name with a running index (following the name regarding the corresponding original time series) and they are stored in the current time series set. The name notation of the time series is given in Appendix A.
be superimposed to visualize the tting of the data to Gaussian and then the p value of the Kolmogorov-Smirnov test for normality is shown as well.
partial autocorrelation (the user can use the visualization facility of measure vs. parameter to assess this). The subgroup of frequency-based measures consists of the energy fraction in bands and the median frequency, computed from the standard periodogram estimate of the power spectrum. The energy fraction in a frequency band is simply the fraction of the sum of the values of the power spectrum at the discrete frequencies within the band to the energy over the entire frequency band. Up to 5 energy fractions in bands can be calculated. The median frequency is the frequency f , for which the energy fraction in the band [0, f ] is half. These frequency measures have been used particularly in the analysis of EEG (Gevins and Rmond 1987). e The standard linear models for time series are the autoregressive model and autoregressive moving average model (AR and ARMA, Box et al. 1994). Statistical measures of tting and prediction with AR or ARMA can be computed for varying model orders (for the AR part and the moving average, MA, part) and prediction steps. The dierence between the tting and prediction measures lies in the set of samples that are used to compute the statistical measure: all the samples are used for tting and the samples in the so-called test set are used for prediction. Here, the test set is the last part of the time series. For multi-step ahead prediction (respectively for t) the iterative scheme is used and the one step ahead predictions from previous steps are used to make prediction at the current step. Four standard statistical measures are encountered: the mean absolute percentage error (MAPE), the normalized mean square error (NMSE), the normalized root mean square error (NRMSE) and the correlation coecient (CC). All four measures account for the variance of the time series and this allows comparison of the measure across dierent time series.
estimates of equidistant and equiprobable binning because they are widely used in the literature (e.g., see Cellucci, Albano, and Rapp 2005; Papana and Kugiumtzis 2008). Similarly to the correlation measures, the measures of cumulative bicorrelation, cumulative equidistant mutual information and cumulative equiprobable mutual information at given maximum delays are implemented as well. The rst minimum of the mutual information function is of special interest and the respective delay can be used either as a discriminating measure or as the optimal delay for state space reconstruction, a prerequisite of nonlinear analysis of time series. This specic delay is computed for both the equidistant and the equiprobable estimate of mutual information. The bicorrelation is not a widely discussed measure, but the cumulative bicorrelation has been used in the form of the statistic of the the so-called Hinich test of linearity (or non-linearity as it is best known in the dynamical systems approach of time series analysis), under the constraint that the second delay is twice the rst delay (Hinich 1996). The bicorrelation, under the name three point autocorrelation, has been used as a simple nonlinear measure in the surrogate data test for nonlinearity (Schreiber and Schmitz 1997; Kugiumtzis 2001).
In practice, reliable estimation of is dicult since there is no clear scaling, meaning that the variance of the local slope is large. In these cases, other simpler measures derived from the correlation sum may be more useful, such as the value of the correlation sum C(r) for a given r, which is simply the cumulative density function of inter-point distances at a given inter-point distance, or the value of r that corresponds to a given C(r), which is the inverse of this cumulative density (McSharry, Smith, and Tarassenko 2003; Andrzejak, Mormann, Widman, Kreuz, Elger, and Lehnertz 2006). The embedding dimension m is an important parameter for the analysis of time series from the dynamical system approach, and determines the dimension of the Euclidean pseudo-space in which (supposedly) the attractor is reconstructed from the time series. An m that is small but suciently large to unfold the attractor is sought and a popular method to estimate it is the method of false nearest neighbors (FNN, Kennel, Brown, and Abarbanel 1992). The method evaluates a criterion of suciency for increasing m. For each reconstructed point at the examined embedding dimension m, it is checked whether its nearest neighbor falls apart with the addition of a new component, i.e., the distance increase at least by a so-called escape factor when changing the embedding dimension from m to m + 1. If this is so, the two points are called false nearest neighbors. The estimated minimum embedding dimension is the one that rst gives an insignicant percentage of false nearest neighbors. In our FNN algorithm we use the Euclidean metric of distances and two xed parameters in order to deal with the problem of occurrence of a large distance of the target point to its nearest neighbor (Hegger and Kantz 1999). The rst parameter sets a limit to this distance and the second sets a limit to the lowest percentage of target points for which a nearest neighbor could be found, in order to maintain sucient statistics. As a result the computation may fail for large embedding dimensions relative to the time series length (then the output measure value is blank). We believe that this is preferable than obtaining unreliable numerical values that can mislead the user to wrong conclusions. Though the minimum m estimated by this method is not an invariant measure, as it depends for example on the delay parameter t, it is used in some applications as a measure to discriminate dierent dynamical regimes and it is therefore included here as well. Among dierent complexity measures proposed in the literature, the approximate entropy and the algorithmic complexity are implemented here. The approximate entropy is a computationally simple and ecient estimate of entropy that measures the so-called pattern similarity in the time series (Pincus 1991). It is expressed as the logarithm of the ratio of two correlation sums (for an appropriately chosen radius r) computed for embedding dimensions m and m+1. Formally, the algorithmic complexity (also referred to as Kolmogorov complexity) quanties how complex a symbolic sequence is in terms of the length of the shortest computer program (or the set of algorithms) that is needed to completely describe the symbolic sequence. Here, we follow the approach of Lempel and Ziv who suggested a measure of the regularity of the symbolic sequence, or its resemblance to a random symbolic sequence (Lempel and Ziv 1976). Computationally, the complexity of the sequence is evaluated by the plurality of distinct words of varying length in the sequence of symbols. The algorithmic complexity measure, though dened for symbolic sequences, has been used in time series analysis, e.g., see Radhakrishnan, James, and Loizou (2000); Zhao, Small, Coward, Howell, Zhao, Ju, and Blair (2006). Similarly to the mutual information, the time series is discretized to a number of symbols assigned to the allocated bins, which are formed by equidistant and equiprobable binning. There are a number of other measures of complexity, most notably the largest Lyapunov
10
exponent, that are not implemented here. In our view the existing methods for the estimation of the largest Lyapunov exponent do not provide stable estimates as the establishment of scaling of the exponential growth of the initial perturbation requires large and noise-free time series, e.g., see the methods implemented in TISEAN (Hegger et al. 1999).
11
The tting and prediction measures from local models are the same as for the linear models, namely MAPE, NMSE, NRMSE and CC. For multi-step t or prediction, both the direct and iterative schemes are implemented. For the direct t or prediction at a lead time h, the h-step ahead mappings are used to form the estimate of the target points at a lead time h, whereas for the iterative t or prediction, the one step predictions from previous steps are used to make predictions for the current step until the h-step is reached.
12
Measures
Linear measures Select measures Nonlinear measures Other measures
Run measures
View time series 1D/2D/3D/ histogram Save / print plot Measured time series list Current measure list View measures Save measures
13
Figure 2: Screen shot of the main menu of MATS. The shot was taken after the measure calculations for the example 1 in Section 5 were completed and the measure table was saved, as denoted in the running message box at the bottom of the window.
Figure 3: Screen-shot of the GUI named Nonlinear Model Measures called in the GUI Measure Selection.
14
When the user completes the selection of measures, the user may start the execution, i.e., the computation of the selected measures on all the time series in the current time series list. At this point, the names in the current time series list are passed to the measured time series list. Further, the user may alter the current time series list, but the measured time series list is intact and can be called in order to assign the measure values to the corresponding time series for visualization or exporting purposes. Many of the considered measures in MATS are functions of one or more free parameters. It is stressed that the term measure is used in MATS to denote the specic outcome of the function for given values of the free parameters. So, the selection of one function can actually give rise to a number of measures (as large as the number of the given parameter values). Each such a measure is given a unique name consisting of the measure code name and each parameter code name followed by the corresponding parameter value. The names of the measures in the current measure list are displayed in the main window of MATS (see Figure 2). The measure values for the dierent time series constitute the second data base that is accessed from the GUI components in the same way as for the data base for the time series. An example of measure selection is given below for the nonlinear model measures and the corresponding screen-shot is shown in Figure 3. The user can select one or more of the local t and prediction measures (making use of the direct or iterative scheme). Suppose the user activates the check box of the rst model (Local Average or Linear Direct Fit with 10 character code name Loc_DirFit). Then the elds for the parameters are highlighted and the user can specify one or more of the four t error statistics, or change the default parameter values. Some parameters bear only a single value, such as q for specifying the type of local model, whereas other parameters can take a range of valid values. The validity of the given values in each eld is checked and appropriate error messages are displayed if wrong MATLAB syntax is used or the values are out of the valid range. For example, for the embedding dimension m and the prediction time h, valid values are any positive integers. So if we give in the eld for m, 1 3 5:5:20, for h, 1:5, set all the other parameters to single values and select one t error statistic, then upon execution of the selected measures, 30 measures of Loc_DirFit will be added in the current measure list.
15
Figure 4: Screen-shot of the GUI View Measures that opts for seven dierent plot types and one table. resampled time series, also the original time series is included and is given the index 0 in the plot. In addition, a parametric test (assuming normal distribution of the measure values on the resampled data) and a nonparametric test (using rank ordering of the measure values on the original and surrogate data) are performed for each measure and the p values are shown in the plots (for details, see Kugiumtzis 2002c). To assess the validity of the parametric test, the p value of the Kolmogorov-Smirnov test for normality is shown as well. The GUI that makes a plot of measure vs. parameter (2D plot) allows the user to select a parameter from the list of all parameters and mark the measures of interest from the current measure list. Even if there are irrelevant measures within the selected ones, i.e., measures that do not include the key character for the selected parameter, they will be ignored after checking for matching the parameter character in the measure name. The same applies for two parameters in the GUI for the 3D plot of measure vs. two parameters. Finally, the GUI of measure scatter plot makes a 2D scatter plot of points (each point regards a time series) for two selected measures and another GUI makes a 3D scatter plot for three selected measures. All dierent plots can be useful for particular types of time series analysis and some representative applications of MATS are given in the next Section.
5. Application of MATS
MATS toolkit can be used in various applications of time series analysis such as the following.
Detection of regime change in long data records: allowing for computing a measure on consecutive segments of a long data record and detecting on the series of measure values abrupt or smooth changes as well as trends.
16
Two examples are given below to illustrate the use of MATS. The data in the examples are from epileptic human EEG but it is obvious that MATS can be applied on any simulated or real world time series. Example 1 In the analysis of long EEG records the main interest is in detecting changes in the EEG signals that may presignify an impending event, such as seizure. This analysis is easily completed in MATS and consists of data segmentation, measure selection and computation, and nally visualization. The record in this example covers one hour of human EEG from 63 channels (system 10 10) sampled at 100 Hz and contains a seizure at 47 min and 40 sec. The name of the le is eeg.dat (in ASCII format). The rst 10 channels will be visualized and the tenth channel will be further processed for illustration of the measure proles on consecutive segments from this channel. Step 1. Data segmentation: The rst 10 channels of the record eeg.dat are loaded and passed to the current time series list. Then the displayed list in the main menu contains ten names, from eegC1 to eegC10. A plot of the ten time series using the facility View Time Series is shown in Figure 5. In all channels the seizure onset can be seen by a change in the amplitude of uctuations of the EEG. The objective here is to investigate if there is any progressive change in the EEG at the pre-ictal period and this cannot be observed by eyeball judgement in any of the 10 channels in Figure 5. We intend to investigate whether a measure prole can indicate such a change. For this we segment the data and compute measures at each segment. We choose to proceed with the 10th channel, and make consecutive non-overlapping segments of 30 sec. Using the segmentation facility and setting 3000 for the length of segment (denoted by the symbol n) and the same for the sliding step (denoted by the symbol s), 120 new time series are generated with the names eegC10n3000s3000ES1 to eegC10n3000s3000ES120, where the character E stands for the option of ignoring remaining data from the end. Finally, we delete the 10 long time series and the current time series list contains the 120 segmented time series. A plot of the time series indexed from 90 to 99 is shown in Figure 6 using again the View Time Series facility. Note that the seizure starts at segment indexed by 96. Step 2. Measure selection and computation: Using the facility Select / run measures and with appropriate selections the following measures are activated to be computed on the 120
17
Figure 5: A plot of EEG from the rst 10 channels of an hour long record sampled at 100 Hz as generated by View Time Series - 1D. Note that the seizure onset is at about 48 min, i.e., at time step 288000.
Figure 6: A plot of the segmented time series with running index from 90 to 99, as generated by View Time Series - 1D. Note that the seizure onset is about the middle of segment 96. segmented time series: energy bands, correlation sum, approximate entropy, Hjorth parameters and all feature statistics. For the correlation sum and approximate entropy, the parameters were set as follows: radius r = 0.1, delay t = 10, embedding dimension m = 5 and Theiler window g = 100. For the energy bands, the frequency intervals of the power spectrum were selected to correspond to the , , , and waves and the median frequency was computed as well (for a range of normalized frequencies from 0.005 to 0.48). These waves have been
18
extensively studied in encephalography research and are found to characterize various brain activities like sleep stages, but their role in pre-ictal activity is not established (Gevins and Rmond 1987). Hjorth parameters are easily computed measures that have also been used e in brain studies for very long (Hjorth 1970). The correlation sum and approximate entropy are used also in EEG analysis under the perspective of nonlinear dynamical systems (Pincus 1991; McSharry et al. 2003; Andrzejak et al. 2006). The statistics of oscillating features are recently introduced as simple alternatives for capturing changes in the oscillation patterns of the EEG signal (Kugiumtzis et al. 2006, 2007). For the detection of turning points, the parameter of oset for the local window (w) was set to 7 and the moving average lter order (a) was set to 1. The statistics median and inter-quartile range (IQR) were selected for all ve oscillating features. Upon completion of the computation of the measures on all 120 time series in the current time series list, the current measure list is lled as shown in the main menu window in Figure 2. It can then be saved for later use and this is actually done just before the snapshot of Figure 2 was taken, as denoted in the eld titled Running Messages. Note that the parameter settings are included in the names of the measures to avoid any confusion with regard to the application setup of the measures. For example, the rst energy band at the top of the current measure list (see Figure 2) is denoted as EnergyBndAl10u40, where the rst 10 characters denote the measure name (the last character A stands for the rst band), l10 denotes that the lower value of the frequency band is 10/1000 = 0.01, i.e., 1 Hz, and u40 denotes that the upper value of the frequency band is 40/1000 = 0.04, i.e., 4 Hz. Step 3. Measure visualization: To visualize the results on the measures, the measures vs segments plot is selected using the facility View measures, clicking the corresponding icon in the list of plotting choices (see Figure 4). A rapid change in amplitude at the time of seizure could be observed in the graphs of all the selected measures. However, a progressive change in the EEG signal could only be observed in the statistics of some features, namely local maxima, local minima and their dierence. As shown in Figure 7, a downward trend for the median of local minima and upward trend for the IQR of local minima are observed during the pre-ictal period, whereas a less signicant downward trend with large uctuations could be seen in the prole of band. The prole of correlation sum shows no trend but large uctuations at the level of the uctuations during seizure. It is notable that also in the post-ictal period (the time after seizure) the two rst measures relax at a dierent level of magnitude compared to that of the pre-ictal period. This illustration shows that using MATS one can easily compare dierent measures on long records. Example 2 The surrogate data test for nonlinearity is often suggested before further analysis with nonlinear tools is to be applied. We perform this test on the EEG segments with index 90 and 97 in the previous example regarding the late preictal state (prior to seizure onset) and ictal state (during seizure). Further, we evaluate the performance of three dierent algorithms that generate surrogate data for the null hypothesis of linear stochastic process underlying the EEG time series, i.e., AAFT, IAAFT and STAP. Note that all three algorithms generate surrogate time series that possess exactly the marginal distribution of the original data, approximate the original linear correlation structure, and are otherwise random, meaning that any nonlinear dynamics that may be present in the original data is removed from the surrogate data. To assess the preservation of the original linear correlations in the surrogate data we use as test statistic the measure of cumulative Pearson autocorrelation for a maxi-
19
Segments of type eegC10n3000s3000ES<seg index> 0.4 EnergyBndBl40u80 0.35 0.3 measure measure 0.25 0.2 0.15 0.1 0.05 0 0 20 40 60 80 segment index 100 120 0.18 0.16 0.14 0.12 0.1 0.08 0.06 0.04 0.02 0
CorrelSumrr10t10m5g100
20
40
60 80 segment index
100
Figure 7: Measure proles for the segmented time series of channel 10; top left: median of local minima, top right: IQR of local minima, bottom left: wave, bottom right: correlation sum. Each graph was generated by View measures - Measure vs segment and then using the MATLAB gure tools the vertical axis was rescaled to ease visualization and a gray (cyan online) vertical line was added at the position of the segment index regarding seizure onset. mum delay 10, i.e., sum up the magnitudes of autocorrelation for delays 1 to 10. Further, to assess the presence of nonlinear correlations in the original time series that would allow us to reject the null hypothesis, we use as test statistic the measure of cumulative mutual information computed at equiprobable binning for the same maximum delay. A valid rejection of the null hypothesis suggests that the rst linear statistic does not discriminate original from surrogate data, whereas the second nonlinear statistic does. The test is performed by MATS in the following steps. Step 1. Data resampling: We continue the rst example and delete from the current time series list all but the segmented time series with index 90 and 97. Then using the facility Resampled time series we generate 40 AAFT, IAAFT and STAP surrogates for each of the two EEG time series. For the latter surrogate type, the parameter of degree of polynomial approximation (pol) is let to the default value 5 and the order of autoregressive model (arm) is set to 50 to account for the small sampling time of the EEG data. After completion of the surrogate data generation the current time series list contains 242 names, the two rst are the original data and the rest are the surrogates. For example, the 40 AAFT surro-
20
40
40
Time series eegC10n3000s3000ES90IAAFT<index> 3 2 1 measure 0 1 2 3 4 PearsAutoct10 MutInfEqPrb0t10 0 10 20 30 resampling index (0 for the original) 40 measure 2 1 0 1 2 3 4 5 6
2 3
40
Figure 8: The statistics of cumulative Pearson autocorrelation and cumulative mutual information (equiprobable binning) for maximum delay 10 for the original time series (index 0, denoted by open circles) and 40 resampled time series of three types. For the panels across columns the original time series is the segmented time series with index 90 (prior to seizure onset) and 97 (on seizure) and across rows the resampled (surrogate) time series are from the algorithms AAFT, IAAFT and STAP from top to bottom.
Journal of Statistical Software gates for the segmented EEG time series with index 90 are eegC10n3000s3000ES90AAFT1 to eegC10n3000s3000ES90AAFT40.
21
Step 2. Measure selection and computation: Using the facility Select / run measures and Linear measures - Correlation the measure of Cumulative Pearson Autocorrelation is selected with the parameter delay (t) set to 10 and then from Nonlinear measures Correlation the measure of Cumulative mutual information with equiprobable bins is selected with the same delay. These two measures are executed on all the 242 time series in the current time series list and upon completion the current measure list contains the names of the two measures. Step 3. Measure visualization: MATS provides a plot facility under View Measures in the main menu for displaying the measure vs. resampled time series. In the corresponding GUI, the user is opted to select a surrogate type and then only the time series names matching the selected surrogate type are displayed in the time series list. Further, the user can select the names from this list to be included in the plot for the selected measure. As in any other plot facility, the user can select the graph type, i.e., line, points, or both. In order to allow the same scale for measures of dierent magnitude range the user can select to normalize the measure values. We have used this facility to make plots of the normalized linear and nonlinear measures for each original time series (with index 90 and 97) and surrogate type (AAFT, IAAFT and STAP) and the 6 plots are shown in Figure 8. The normalized measure value for the original time series is for index 0 of the x-axis and it is marked with an open circle. We note that AAFT does not preserve the linear autocorrelation of both EEG time series as the rst value for index 0 is above all other 40 values for the AAFT surrogates (rst row of Figure 8). The surrogate data test with AAFT is thus invalid and the discrimination with the nonlinear measure for the EEG time series at seizure cannot be taken as legitimate rejection of the null hypothesis since the same holds for the linear statistic. IAAFT does not have the problem of autocorrelation mismatch in the case of pre-ictal state, where no discrimination is observed also with the nonlinear measure, but the problem holds marginally for the ictal state, where no clear discrimination is observed with the nonlinear measure because the value for index 0 is the second smallest (second row of Figure 8). The STAP algorithm preserves the linear autocorrelation in both cases, which validates the test, and singles out the original mutual information value only for the EEG time series at ictal state. The above remarks are based on qualitative assessment from eye-ball judgement of the plots in Figure 8. MATS provides also quantitative test results in the same visualization facility. The user is opted to display the results of formal tests in the form of p values from the parametric and nonparametric approach (along with a note of acceptance or rejection of the KolmogorovSmirnov test for normality of the measure values on the resampled data). Further, horizontal lines at the signicance levels of = 0.01 and = 0.05 are drawn in the plot to allow for visual judgement of the test results. For the case of segment 97 and IAAFT and STAP surrogates, where the visual inspection is not clearly conclusive, the plots with test results are shown in Figure 9. It is now shown that for IAAFT, using the linear measure (cumulative Pearson autocorrelation), the parametric test asserts that the measure value on the time series of the segment at the ictal state is within the null distribution, whereas the nonparametric test gives p = 0.0244 (the smallest p value that can be obtained for a twosided test from the rank ordering of 41 values) and concludes for mismatch in the autocorrelation. On the other hand, for STAP the p values for both the parametric and nonparametric approach are large indicating the good match of autocorrelation. For the nonlinear statistic, the null hypothesis
22
normalized PearsCAutot10
40
Time series eegC10n3000s3000ES97C1IAAFT<index> pvalue: 0.0000(param,normality accepted) 0.0244(nonparam) 2 normalized MutInCEqPrb0t10 1 0 1 2 3 4 5 0 =0.05(param) =0.01(param) 10 20 30 resampling index (0 for the original) 40
normalized MutInCEqPrb0t10
Time series eegC10n3000s3000ES97C1STAP<index> pvalue: 0.0016(param,normality accepted) 0.0244(nonparam) 4 =0.05(param) 3 =0.01(param) 2 1 0 1 2 3 0 10 20 30 resampling index (0 for the original) 40
Figure 9: The plots in the rst row show the statistics of cumulative Pearson autocorrelation together with the test results. The original time series (given with index 0) is the segmented EEG time series with index 97 (on seizure onset) and the 40 resampled time series are of the IAAFT type (rst plot) and STAP type (second plot). The horizontal lines show the signicance level for the parametric test at = 0.01 and = 0.05, as given in the legend. In the second row the same results are shown for cumulative mutual information (equiprobable binning). of linear stochastic process is rejected for both surrogate types and with both the parametric and nonparametric approach, where the parametric p value is somehow larger for STAP (p = 0.0016). In all cases, the Kolmogorov-Smirnov test approves the normal distribution of the measure on the surrogate data. The test results with IAAFT and STAP are in agreement to known results in the literature about the drop of complexity of the EEG signal during seizure that allows the detection of low-dimensional nonlinear dynamics. For illustration purposes the surrogate data test was applied here only to two time series and test statistics, but it is straightforward to include many dierent measures and time series.
6. Discussion
MATS is an interactive MATLAB toolkit for analysis of scalar time series. The strength of
23
MATS is that it can process many time series in one go, which are loaded directly from les or generated using the facilities of segmentation, standardization and resampling. The user can then select among 52 measures grouped in linear, nonlinear and other measures, where most of them are dened in terms of a number of parameters. Most of the known measures of analysis of stationary time series are included and the addition of new measures is straightforward by adding a new checkbox for the new measure, with additional boxes and buttons for the parameters, or even a new group of measures in a separate GUI window. The structure of MATS is not altered by new insertion of measures as it is built on the current time series list and the current measure list, which are updated dynamically at any selected operation. Thus minimal intervention in the MATLAB code of MATS is required in order to add measures of choice. It should be noted that the computation of the selected measures can be slow when a large number of time series are selected or the length of the time series is large (or both). Also, some measures, such as the measure of the local linear model and the measure of the correlation dimension, require long computation time. The MATLAB routines are not optimized in every detail, but some eort was made on eective computation, e.g., for data point search a k-D tree structure built in C is called that is more eective than doing the same structure in MATLAB code. Still, there is space for improvement in terms of computation eciency and it is in the intention of the authors to implement a faster k-D tree structure and more ecient calculation of the correlation dimension. Running on MATLAB, MATS uses all ne MATLAB tools and especially the interactive graphic user interface (GUI) for the selection of the various operations, such as the selection of measures and their parameters, and for visualizing time series and measures in a number of dierent graph types. MATS is meant to be accessible to users with little experience on time series analysis. In addition, a number of checks are performed for each user selection giving out messages for invalid input data and minimizing the risk of stacking at any operation. MATS can be used for various types of analysis requiring minimum user interface. By selecting buttons, checking boxes and specifying parameter values, the user can perform rather complicated tasks. Two such tasks are demonstrated step by step, namely the computation of many measures on consecutive segments of a long time series, and the surrogate data test for nonlinearity on dierent time series and using dierent surrogate generating algorithms and test statistics. Further, the user can save results in tables for further processing or later use in MATS and make graphs that can also be processed using standard MATLAB gure options or stored as les of any desired format. There are dierent plug-ins one could think of integrating into this application. We are currently working on a new conguration of this toolkit that includes clustering methods, comparison of clusters, classiers and other data mining tools in order to extract information from the computed measures on the time series, an area that is known as feature-based clustering.
Acknowledgments
The authors want to thank the two anonymous referees for their constructive remarks on the manuscript and program. The work is part of the research project 03ED748 within the framework of the Reinforcement Programme of Human Research Manpower (PENED) and
24
it is co-nanced at 90% jointly by European Social Fund (75%) and the Greek Ministry of Development (25%) and at 10% by Rikshospitalet, Norway.
References
Abarbanel HDI (1996). Analysis of Observed Chaotic Data. Springer-Verlag, New York. Alvarez D M (2008). Exchange Rates Forecasting: Global or Local Methods? Applied az Economics, 40(15), 19691984. Andrzejak RG, Mormann F, Widman G, Kreuz T, Elger CE, Lehnertz K (2006). Improved Spatial Characterization of the Epileptic Brain by Focusing on Nonlinearity. Epilepsy Research, 69, 3044. Bao D, Yang Z (2008). Intelligent Stock Trading System by Turning Point Conrming and Probabilistic Reasoning. Expert Systems with Applications, 34(1), 620627. Box GEP, Cox DR (1964). An Analysis of Transformations. Journal of the Royal Statistical Society, Series B, 42, 7178. Box GEP, Jenkins GM, Reinsel GC (1994). Time Series Analysis: Forecasting and Control. 3rd edition. Prentice-Hall, New Jersey. Cellucci CJ, Albano AM, Rapp PE (2005). Statistical Validation of Mutual Information Calculations: Comparison of Alternative Numerical Algorithms. Physical Review E, 71, 066208. Edgar EP (1996). Chaos and Order in the Capital Markets: A New View of Cycles, Prices, and Market Volatility. 2nd edition. John Wiley & Sons, New York. Farmer JD, Sidorowich JJ (1987). Predicting Chaotic Time Series. Physical Review Letters, 59, 845848. Garci-Ferrer A, Queralt RA (1998). Can Univariate Models Forecast Turning Points in a Seasonal Economic Time Series? International Journal of Forecasting, 14(4), 433446. Gevins AS, Rmond A (eds.) (1987). Methods of Analysis of Brain Electrical and Magnetic e Signals, volume 1 of Handbook of Electroencephalography and Clinical Neurophysiology. Elsevier Science Publishers, New York, NY. Grassberger P, Procaccia I (1983). Measuring the Strangeness of Strange Attractors. Physica D, 9, 189208. Hallin M, Puri ML (1992). Rank Tests for Time Series Analysis: a Survey. In DR Brillinger, E Parzen, M Rosenblatt (eds.), New Directions in Time Series Analysis, pp. 112153. Springer-Verlag, New York. Hegger R, Kantz H (1999). Improved False Nearest Neighbor Method to Detect Determism in Time Series Data. Physical Review E, 60(4), 49704973.
25
Hegger R, Kantz H, Schreiber T (1999). Practical Implementation of Nonlinear Time Series Methods: The TISEAN Package. Chaos, 9, 413435. Hinich MJ (1996). Testing for Dependence in the Input to a Linear Time Series Model. Journal of Nonparametric Statistics, 6, 205221. Hjellvik V, Tjstheim D (1995). Biometrika, 82(2), 351368. Nonparametric Tests of Linearity for Time Series.
Hjorth B (1970). EEG Analysis Based on Time Domain Properties. Electroencephalography and Clinical Neurophysiology, 29, 306310. Insightful Corp (2003). S-PLUS Version 6.2. Seattle, WA. URL http://www.insightful. com/. Kantz H, Schreiber T (1997). Nonlinear Time Series Analysis. Cambridge University Press, Cambridge. Kay SM (1988). Modern Spectral Estimation: Theory and Applications. Prentice Hall, New Jersey. Kennel M, Brown R, Abarbanel HDI (1992). Determining Embedding Dimension for PhaseSpace Reconstruction Using a Geometrical Construction. Physical Review A, 45, 3403 3411. Kugiumtzis D (2001). On the Reliability of the Surrogate Data Test for Nonlinearity in the Analysis of Noisy Time Series. International Journal of Bifurcation and Chaos, 11(7), 18811896. Kugiumtzis D (2002a). State Space Local Linear Prediction. In A Soo, L Cao (eds.), Modelling and Forecasting Financial Data, Techniques of Nonlinear Dynamics, chapter 4, pp. 95113. Kluwer Academic Publishers. Kugiumtzis D (2002b). Surrogate Data Test for Nonlinearity Using Statically Transformed Autoregressive Process. Physical Review E, 66, 025201. Kugiumtzis D (2002c). Surrogate Data Test on Time Series. In A Soo, L Cao (eds.), Modelling and Forecasting Financial Data, Techniques of Nonlinear Dynamics, chapter 12, pp. 267282. Kluwer Academic Publishers. Kugiumtzis D (2008). Evaluation of Surrogate and Bootstrap Tests for Nonlinearity in Time Series. Studies in Nonlinear Dynamics & Econometrics, 12(4). Kugiumtzis D, Kehagias A, Aifantis EC, Neuhaser H (2004). Statistical Analysis of the u Extreme Values of Stress Time Series from the Portevin-Le Chtelier Eect. Physical a Review E, 70(3), 036110. Kugiumtzis D, Lingjrde OC, Christophersen N (1998). Regularized Local Linear Prediction of Chaotic Time Series. Physica D, 112, 344360. Kugiumtzis D, Papana A, Tsimpiris A, Vlachos I, Larsson PG (2006). Time Series Feature Evaluation in Discriminating Preictal EEG States. Lecture Notes in Computer Science, 4345, 298310.
26
Kugiumtzis D, Vlachos I, Papana A, Larsson PG (2007). Assessment of Measures of Scalar Time Series Analysis in Discriminating Preictal States. International Journal of Bioelectromagnetism, 9(3), 134145. Lempel A, Ziv J (1976). On the Complexity of Finite Sequences. IEEE Transactions on Information Theory, 22, 7581. Mandelbrot B (1997). Fractals and Scaling in Finance. Springer-Verlag, New York. McCullough BD, Renfro CG (1998). Benchmarks and Software Standards: A Case Study of GARCH Procedures. Journal of Economic and Social Measurement, 25, 59 71. McSharry PE, Smith LA, Tarassenko L (2003). Comparison of Predictability of Epileptic Seizures by a Linear and a Nonlinear Method. IEEE Transactions on Biomedical Engineering, 50(5), 628633. Mormann F, Kreuz T, Rieke C Andrzejak RG, Kraskov A, David P, Elger CE, Lehnertz K (2005). On the Predictability of Epileptic Seizures. Clinical Neurophysiology, 116(3), 569587. Papana A, Kugiumtzis D (2008). Evaluation of Mutual Information Estimators on Nonlinear Dynamic Systems. Complex Phenomena in Nonlinear Systems, 11(2), 225232. Peng CK, Buldyrev SV, Havlin S, Simons M, Stanley HE, Goldberger AL (1994). Mosaic Organization of DNA Nucleotides. Physical Review E, 49(2), 16851689. Pincus SM (1991). Approximate Entropy as a Measure of System Complexity. Proceedings of the National Academy of Sciences of USA, 88, 22972301. Politis DN (2003). The Impact of Bootstrap Methods on Time Series Analysis. Statistical Science, 18(2), 219230. Radhakrishnan N, James WD, Loizou PC (2000). An Alternate Partitioning Technique to Quantify the Regularity of Complex Time Series. International Journal of Bifurcation and Chaos, 10(7), 17731779. Risso WA (2009). The Informational Eciency: the Emerging Markets versus the Developed Markets. Applied Economics Letters, 16(5), 485487. SAS Institute Inc (2003). The SAS System, Version 9.1. Cary, NC. URL http://www.sas. com/. Schlgl A (2002). Time Series Analysis A Toolbox for the Use with MATLAB. Technische o Universitt Graz. URL http://www.dpmi.tu-graz.ac.at/schloegl/matlab/tsa/. a Schreiber T, Schmitz A (1996). Improved Surrogate Data for Nonlinearity Tests. Physical Review Letters, 77, 635638. Schreiber T, Schmitz A (1997). Discrimination Power of Measures for Nonlinearity in a Time Series. Physical Review E, 55(5), 54435447. Schreiber T, Schmitz A (2000). Surrogate Time Series. Physica D, 142(3-4), 346382.
27
Shechter G (2004). The k-D tree MATLAB Distribution. URL http://www.mathworks. co.uk/matlabcentral/fileexchange/4586. SPSS Inc (2006). SPSS for Windows, Release 15. SPSS Inc., Chicago, IL. URL http: //www.spss.com/. The MathWorks, Inc (2007). MATLAB The Language of Technical Computing, Version 7.5. The MathWorks, Inc., Natick, Massachusetts. URL http://www.mathworks. com/products/matlab/. Theiler J, Eubank S, Longtin A, Galdrikian B (1992). Testing for Nonlinearity in Time Series: the Method of Surrogate Data. Physica D, 58, 7794. Tong H (1990). Non-Linear Time Series: A Dynamical System Approach. Oxford University Press, New York. Zhao Y, Small M, Coward D, Howell E, Zhao CN, Ju L, Blair DG (2006). Identifying Deterministic Signals in Simulated Gravitational Wave Data: Algorithmic Complexity and Surrogate Data Method. Classical and Quantum Gravity, 23, 18011814.
28
B. Measure names
The full name of each measure in the current measure list is comprised by a 10 character string of the coded measure name, followed by the measure-specic parameter declaration (one value for each parameter). Each parameter is identied by a character, as shown in the rst column in Table 2. The parameters may bear only a single value or a range of values given in standard MATLAB syntax, e.g., 1:10 or [1 5:10 20] (see second column) and may be constrained to specic ranges (see third column). Default values for the parameters are given in column four and a brief description follows in column 5. Note that if a range of values is given for a parameter, a dierent measure name for each parameter value is listed in the current measure list.
Aliation:
Dimitris Kugiumtzis Department of Mathematical, Physical and Computational Sciences Faculty of Engineering, Aristotle University of Thessaloniki Thessaloniki 54124, Greece E-mail: [email protected] URL: http://users.auth.gr/dkugiu/
29
Facility Load time series Segment Segment Segment Segment Segment Transform Transform Transform Transform Transform Transform
Description (N = length of time series) The column of the matrix of the loaded le, takes values larger than one if multiple columns are selected The order of the time series segment in the series of segments when splitting the original time series Length of each segment when segmenting the time series Sliding step in the generation of segments, when s = n there is no overlapping of segments Residuals are taken from the beginning of the original time series after splitting to segments of length n Residuals are taken from the end of the original time series after splitting to segments of length n Linear standardization resulting in a time series with minimum 0 and maximum 1 Normalized or z-score standardization resulting in a time series with mean 0 and standard deviation 1 Uniform standardization resulting in a time series with uniform marginal distribution Gaussian standardization resulting in a time series with Gaussian marginal distribution Log-dierence transform that rst takes the natural logarithm of the data and then the rst dierences Detrending of the time series with a polynomial t of given degree. This value follows the code character (the same for the transforms below). Lag dierence of the time series for a given lag Box-Cox power transform for a given parameter Random permutation. The index of the resampling time series follows the code character (the same for the resampling types below). Fourier transform Amplitude adjusted Fourier transform Iterated amplitude adjusted Fourier transform Statically transformed autoregressive process Autoregressive model residual bootstrap
T X RP
30
Character Multiple Valid range values a yes integers > 0 b yes integers > 0
Default 1
c e f g h k l m o p q
[0, 1] integer 2 [0.1, 0.9] integer 0 integers > 0 integers > 0 [0, 0.5] integers > 0 integer 10 integers > 0 integer 0
r s t u w
moving average lter order, when smoothing the time series for the detection of turning points 0 number of bins when partitioning the time series range, if b = 0 then it is determined by the criterion b = N/5 0.5 correlation sum, given as input in order to nd the corresponding radius 10 escape factor, for assessing the false nearest neighbors 0.5 fraction for the test set, e.g., if f = 0.3 the length of the test set is 0.3N 0 Theilers window, to exclude temporally correlated points from the set of neighboring points 1 lead time for tting and prediction 1 number of nearest neighbors multiple lower band frequency, for the computation of encases ergy in frequency bands 1 embedding dimension or AR model order 100 number of radii to calculate the correlation sum and estimate the correlation dimension 1 order of the moving average part in ARMA 0 truncation parameter, q = 0 for local average map, q=m for OLS solution of the local linear model parameters, q<m for PCR solution 0.1 radius for the computation of the correlation sum (the time series is standardized in [0, 1]) 4 size of scaling window, i.e., s = r2 /r1 , where r2 r1 is the length of the scaling window 1 delay time multiple upper band frequency, for the computation of cases energy in frequency bands; u > l should hold 1 oset for the local window of length 2w + 1, used in the detection of turning points