Expanding the boundaries of local similarity analysis

Background Pairwise comparison of time series data for both local and time-lagged relationships is a computationally challenging problem relevant to many fields of inquiry. The Local Similarity Analysis (LSA) statistic identifies the existence of local and lagged relationships, but determining significance through a p-value has been algorithmically cumbersome due to an intensive permutation test, shuffling rows and columns and repeatedly calculating the statistic. Furthermore, this p-value is calculated with the assumption of normality -- a statistical luxury dissociated from most real world datasets. Results To improve the performance of LSA on big datasets, an asymptotic upper bound on the p-value calculation was derived without the assumption of normality. This change in the bound calculation markedly improved computational speed from O(pm2n) to O(m2n), where p is the number of permutations in a permutation test, m is the number of time series, and n is the length of each time series. The bounding process is implemented as a computationally efficient software package, FASTLSA, written in C and optimized for threading on multi-core computers, improving its practical computation time. We computationally compare our approach to previous implementations of LSA, demonstrate broad applicability by analyzing time series data from public health, microbial ecology, and social media, and visualize resulting networks using the Cytoscape software. Conclusions The FASTLSA software package expands the boundaries of LSA allowing analysis on datasets with millions of co-varying time series. Mapping metadata onto force-directed graphs derived from FASTLSA allows investigators to view correlated cliques and explore previously unrecognized network relationships. The software is freely available for download at: http://www.cmde.science.ubc.ca/hallam/fastLSA/.


Background
The exponential increase and ubiquitous use of computational technology has given rise to an era of "Big Data" that pushes the limits of conventional data analysis [1][2][3]. Techniques for analyzing big datasets often proceed by identifying patterns of co-occurrence or correlation through principal component analysis (PCA) [4], multidimensional scaling (MDS) [5], etc. However, many of these methods require significant data reduction or smoothing which makes them difficult to interpret [6]. Other methods such as multiple linear regression or Pearson's correlation coefficient (PCC) are easy to interpret as they operate on data in their native data space, without any kind of large data transformation or dimensionality reduction, but are limited in the structure that they can detect.
Though PCC is a classic and powerful technique for finding linear relationships between two variables, it is not designed for capturing lead-lag relationships seen in time series data. Local similarity analysis (LSA) [6] extends correlation calculations to include the time variable, enabling identification of local correlates. Furthermore, Ruan et al. have presented a graphical network framework in which to visualize the structure of significant LSA correlations. Unfortunately, the current implementation of LSA requires multiple runs on permuted data and a Monte Carlo statistical method known as a permutation test to evaluate a null distribution and obtain a p-value determining significance. Each iteration of this procedure has a computational complexity of O(pm 2 n), where p is the number of permutations, m is the number of covariate time series, and n is their length. Due to the number of pair-wise calculations needed, extant LSA is computationally onerous when m is large, limiting its use to datasets where the number of observed variables at each time point is small (< 100). Though there has been some improvement to its performance [7], assumptions of normality and implementation issues continue to stymie practical application of LSA on big datasets.
Here we describe a novel asymptotic upper bound on the calculation of the LSA statistic's p-value, resulting in an exponentially converging calculation to bound and check for significance of computed LSA statistics without a computationally intensive permutation test. This bound does not require a rank-vector normal transformation, promoting application to any distribution that has finite variance. As a result, this implementation of LSA can navigate big datasets with millions of co-variate time series. We demonstrate this using time-series datasets from public health [8], microbial ecology [9], and social media [10]. The implemented algorithm, named FASTLSA, is written in C and optimized for threading on multi-core computers.
Interpreting the LSA statistic LSA concerns itself with pairs of time series data. The LSA Statistic can be interpreted in a manner similar to PCC when no lag window exists between two time series. However, LSA is also capable of capturing localized correlation that is staggered or lagged. A large positive or negative LSA value indicates a correspondingly strong PCC correlation or a correlation at a time displacement within the lag window ( Figure 1). Note that if both positive and negative correlations exist between two time series, LSA will only report the strongest of the two.
LSA is advantageous on large datasets containing many time series. Results can be visualized as a graphical network where nodes represent the individual time series and the edges represent their LSA correlation statistic. When displayed using a force-directed layout in Cytoscape [11], closely related time series cluster together, visually isolating clusters of local similarity. Metadata related to experimental or environmental conditions can then be applied to the nodes, shedding insight into hierarchical network structure.

Description of the LSA algorithm
In this section we reproduce the algorithm from [6] to compute LSA statistics and their corresponding p-values between pairs of time series in a dataset. We assume as input a set of time series vectors of equal length. Let us denote the number of time series by m and their length as n. Let us denote the time series dataset as X where X ij denotes the jth element of the ith time series, with i = 1, 2, ..., m and j = 1, 2, ..., n, and assume that the X ij are real numbers. We also assume that there are no missing values in the dataset X, and realize that practical use will require interpolation or filtering.
In Figure 2 we present the algorithm for computing the LSA statistic for a pair of time series, where the length of the time series is assumed to be equally spaced in time. We have modified the presentation of the LSA algorithm by [6] to highlight our analysis and derivation of a bound on the tail distribution of the LSA statistic. Specifically we calculate the LSA statistic for a pair of time series, X and Y. Two-dimensional arrays P i, j and N i, j are used to store the positive and negative partial sums (truncated if less than 0) of the pairwise product of time series values. We also assume a suitable bound on the maximum time lag considered while computing the LSA statistic, denoted by D.
The algorithm first initializes the arrays P j,0 , N j, 0 , P 0, i , and N 0,i for all i, j = 1, ..., n, with a maximum absolute difference of D. Next it considers the time series pairs for each possible lag, up to a maximum of D, and then computes the progressive sum of the pair-wise products of the time-series values from the low to high index of the arrays. During the computation, the progression of the partial sum is reset to 0 if the sum is below 0. After partial sums have been computed, the values of N and P are calculated by taking the maximum of the corresponding values of the arrays N and P. Finally, the LSA statistic is estimated as

Calculating the upper bound
In this section we derive the asymptotic upper bound on the p-value for the cumulative probability distribution of the LSA statistic without the need of a normality assumption. Our derivation is based on distributional results of the maximum cumulative sum of independent random variables known in the literature from probability theory [12][13][14][15]. We begin by stating our assumptions about the dataset, isolate target calculations from the LSA algorithm, and from our referenced mathematical results, derive and prove important lemmas. These lemmas will serve as the building blocks as we logically construct a theorem which will form the basis of our LSA p-value upper bound. We begin by making certain assumptions about the probability model used to derive the bounds. First, each P i, j or N i, j is considered individually. We assume that the time series values X i , Y j for i, j = 1, ..., n are independent of one another. This assumption can be made when weak dependence exists because it is near the truth and effective, much like the Naive Bayes assumption. This assumption is also enabling, as it allows us to invoke the distributions of partial sums of independent random variables and continue in a mathematically straightforward way. Further, we assume independence between each time time series as a null hypothesis, and as it is subject to rejection upon obtaining a statistically significant LSA value. Consider lines 5 and 7 of the LSA algorithm ( Figure 2), P i+k+1,j+k+1 max{0, P i+k, j+k + X i+k * Y j+k } and P ← max {(i,j):|i−j|≤D} P i,j . For any pair of i and j let us define the sequence random variables as Z k = X i+k Y j+k for k = 0, ..., min{n -i, n -j} -1, and the sequence of random variables ζ k = Z 1 + ... + Z k for k = 0, ..., min{n -i, n -j} -1 supposing ζ 0 = 0. Using the above ζ k 's, we define random variables η * k as η * k = max {ζ 1 , ζ 2 , · · · , ζ k } for the same values of k = 0, ..., min{n -i, n -j} -1.
We also define the set of random variables h 1 , h 2 , ..., h k by the recurrence formula h k+1 = max{0, h k + Z k+1 }. Note that the random variables P i+k, j+k and the h k have the same distribution. It is shown in [12,13] that the random variables η * k and h k also have the same distribution. As a result, now we can analyze the cumulative distribution of P i+k, j+k as a distribution for η * k , and use the results by Nevzorov and Petrov [14] on P i+k, j+k to derive tail probability bounds. We also assume that the random variables Z k have the first two moments, although such assumptions are not required for the results of [14], we use them to derive simpler bounds.
We now consider a few useful lemmas that we will use to construct our p-value upper bound. The first step is to simplify the tail event (which we will later connect to pvalue) into simpler terms. The following lemma expresses the tail event for LSA {|LSA| >x} and any x ∈ R in terms of the tail events of {P i, j >x} and {N i, j >x}, the positive and negative LSA calculations for the same x, the bound on our test statistic (the target p-value).
Proof. The result is clear from the following: In the LSA algorithm, we have maximums P ij = max {0, P i-1, j-1 + X i-1 Y j-1 } and N ij = max{0, P i-1,j-1 -X i-1, j-1 }, which complicates their theoretical analysis. Fortunately, equivalence have been demonstrated in the literature [12], and we restate these in the following lemma for clarity: the similarity of the distributions of h k and η * k , for k = 1, ..., min{n -i, n -j} -1. This will help us derive the bounds for the events {P ij >xn} and {N ij >xn}, the simpler terms we derived in the previous lemma.

Lemma 2 Let Z i be mutually independent random variables and let us denote by
In order to get a simple formula for the bound on the cumulative tail probabilities for P i, j and N i, j we reproduce below the results on partial sums of random variables due to Nevzorov and Petrov [14]. For our sequence of independent and identically distributed (iid) random variables under consideration {X n } it follows that Lindeberg's condition holds [15]. A property showing the variance of a distribution stabilizes as more variables are added, pinning the tails of it down. Thinking about this in terms of time series, as a series gets larger, the upper bound of the distribution becomes more defined and calculable. Now to build theorems upon which we will derive a formulaic p-value bound.
Theorem 3 If the random variables {X n } have zero expectation and finite variances and if Lindeberg's condition holds: k j=1 X j and V k (x) = P(X k ≤ x) In order to apply the above theorem to get a simple formulaic approximation, we assume some random variables {Z i } m 1 , each with the variance s 2 and S k = k i=1 Z i . Then by applying the above theorem, we get the following uniform convergence of distribution to that of the one-sided standard normal as Now we use the above results to get the probability estimates for our simple event terms {P ij >xn} and {N ij >xn}.
The following theorem provides us with the p-value's tail bound for LSA for any x ∈ R.
Theorem 4 For G, the one-sided normal distribution, Proof. By applying Lemma 2 we have and by Theorem 3, replacing x with y, we have Notice that k l=0 X l Y l satisfies the definition of S k , so replacing S k , √ m , and s with k l=0 X l Y l , mini-1,j-1, and as n ∞, and by change of variables to get our equation into the appropriate form as n ∞, thus It follows from Boole's inequality and Lemma 1 that Finally, we have the following tail probability bound standardizing with a mean of zero and a variance of one □ Note that this last result is asymptotic. Thus, n must be substantially large for this p-value bound to be relevant ( Figure 3 and Table 1). Similar to the normal distribution as an approximation to Student's t-distribution, this implementation of LSA requires at least 30 time points to promote confidence. Though this convergence can vary from dataset to dataset, the bound is conservative, and will not easily produce false positives if run on shorter time series.

Results
To validate versatility and effectiveness of the derived upper bound (Theorem 4), we applied the algorithm to four datasets, two sourced from biology, one from social networking, and a randomly generated control dataset. These include the Moving Pictures of the Human Microbiome [8] (MPH), the largest human microbial time series to date, a microarray hybridization dataset identifying cell cycle regulated genes in the yeast Saccharomyces cerevisiae [9] (CDC), and an online social media dataset of the volumes of the top 1000 Memetracker phrases and top 1000 twitter hash tags over an eight month period from September 2008 to August 2009 [10]. Missing data values were interpolated by averaging the two nearest temporal data points, and all analysis was performed on a Mac Pro desktop computer running Mac OSX 10.6.8 with a 2 × 2.4 Ghz Quad-Core Intel Xeon processors and 16 GB of 1066 Mhz DDR3 RAM.

Computational complexity
The algorithm calculates in O(m 2 n) time, where m is the number of time series and n is the length of each time series. To get an idea of how long calculations take, we fixed n = 50, d = 3 and plotted log-calculation time against log-m ( Figure 4). It can be seen that LSA tests with p-values calculated by the permutation test are about 10,000 times slower than calculating p-values formulaically. Compared to direct formulaic calculation, random number generation is slow, making a repetition of 10,000 permutations for each time series pair a computationally intense operation ( Table 2). The permutation test may be able to calculate statistically significant (a = 0.001) pairs confidently, but applying a multiple test correction (Bonferroni) will require exponentially more permutations to reach the same level of confidence for the entire dataset. Pairwise comparisons for big datasets are computationally infeasible to sufficiently estimate pvalues with enough accuracy to protect against false positives. In contrast, FASTLSA directly calculates a conservative upper bound approximating the p-value, making permutation unnecessary and protecting against false positives.

Moving pictures of the human microbiome (MPH)
The MPH time series dataset [8] investigates temporal variations in the microbial community structure of two healthy human subjects, one male, one female. Samples were collected from three body parts, the gut (feces), mouth, and skin (left and right palms) daily for 15 months (male) and six months (female) with taxonomy being determined by the amplified V4 region of the small subunit ribosomal RNA (SSU or 16S rRNA) gene. The male and female samples were concatenated together resulting in a profile of 14105 taxa for 390 time points with missing values being interpolated by the average of the two nearest time points.
For a given time series, if more than 25% of time steps were zero it was removed from the analysis. Analysis took 58 minutes (7.5 minutes on 16 threads) without including output writing time which is variable. Significant (a < 0.001) LSA results revealed clusters of local similarity that corresponded well when nodes were colored by sample source ( Figure 5). The low level of mixing between local clusters reflects the large differences in taxonomic profiles across the different body environments [8].

Microarray hybridization detection cell cycle-regulated genes in yeast Saccharomyces cerevisae (CDC)
In the CDC data set [9], we focused on the cdc15 temperature sensitive mutant and the profile of 6178 genes over 24 time steps, representing gene expression for approximately three cell cycles. Analysis took 3.25 minutes (22 seconds on 16 threads) without including output writing time ( Figure 6). Applying the asymptotic bound with the small number of time steps resulted in some rather large bounds (≥ 1).
However, LSA was capable of detecting lead-lag correlation despite the periodicity of the data, demonstrating its capacity to find long correlate pairs with a large number of covariate time series. Only 800 of the 6178 gene nodes could be classified from [9] to one of the five defined cell cycle phases (G1, G2/M, S, S/G2, M/G1) so only two clusters could be inferred upon with any confidence (Figure 7).

Social media: top 1000 Twitter and Memetracker phrases (Twitter)
The data from [10] contains the volume of the top 1000 Twitter and Memetracker phrase counts over 130 time steps from September 2008 to August 2009, a spacing of approximately 2-3 days per observation. Analysis took approximately six seconds (one second on 16 threads) without including write out time. Two major clusters of related times series nodes emerged. However, attempts to label the series using existing metadata of general content or time granularity (day of the week, working hours, seasonality, etc.) did not elucidate its structure (Figure 8). We conjecture that this difference is geographical (East-West North America) or socially structured, however, additional metadata on geolocation or social connectivity associations of the nodes would be needed to better elucidate network structure.

Null hypothesis simulated data
Finally, to identify throughput limits of FASTLSA and to simulate a large iid dataset without time dependence, three data matrices were randomly generated: (1) one hundred thousand measurements across 100 time steps, (2) one million measurements across 30 time steps, and (3) one million measurements across 100 time steps. Data were generated by random sampling from a uniform distribution. Running FASTLSA on 16 threads, the first dataset (100, 000 × 100) took one hour 54 minutes, the second (1, 000, 000 × 30) 2 days and 3 hours, and the third (1, 000, 000 × 100) had an ETA of 7 days and 23 hours without including writeout time. The asymptotic bound is conservative for shorter datasets (n ≤ 30) ( Figure 3, Table 1), the second data having 30 time points found zero false positives, despite having a Bonferroni correction of α n 2 = 10 −13 . This is likely because the software's p-value is an upper bound to the real p-value, and so is the Bonferroni correction. An inspection of a uniform random graph (a = 0.05, |LSA| < 0.4) of 1,000 random time series with 100 time steps did not generate any cliques, but only short (4-8) length chains of nodes, serving as a warning to those wanting to interpret relevant structure ( Figure 9). Given appropriate thresholds on LSA values, cliques do not seem to occur randomly.

Discussion
FASTLSA uses a novel asymptotic upper bound algorithm for calculating the LSA p-value. This is done without any normality assumption, extending implementation to untransformed data and data in violation of normality assumptions such as time series containing many zero entries. Moreover, FASTLSA replaces a computationally intensive permutation test that was previously required to calculate significance of LSA statistics with a dramatic increase on the size of datasets that can be analyzed on a single desktop machine. However, like all asymptotic bounds, a significant number of observations need to be obtained for their application. From theoretical simulation, we estimate this to be greater than 30 time points for most datasets. This is supported by our experience on the CDC and MPH datasets having 24 and 390 time series, respectively. Despite this potential operating constraint, FAS-TLSA expands the boundaries of LSA allowing time series analysis on datasets with millions of co-variate time series. The algorithm is implemented as a computationally efficient software package, FASTLSA, written in C and optimized for threading on multi-core computers using POSIX threads. Finally, we demonstrated the utility and versatility of FASTLSA using real-world and simulated time series datasets from different fields of inquiry, visualizing the resulting clusters of local similarity using the Cytoscape software. LSA statistics have been demonstrated to capture relevant local similarity structure for a number of biological datasets [16,17]. However, previous implementations were limited to relatively small datasets. FASTLSA improves the computational efficiency and statistical robustness of LSA, a necessary step in using the statistic to explore next generation time series datasets. Despite the current improvements, the structure captured by LSA is less than ideal and could be further improved. Given two vectors of time series, LSA reports the strongest statistic. However, it is unclear where this significant time window occurs, or if there are multiple small windows with large LSA values that are not reported. An inspection of time series traces in question is often required to visually check exactly how the two are similar. Another hazard is that LSA does not handle missing data effectively, and so a continuous version of the statistic would be desirable for exploratory experiments where sampling conditions could change to small degrees and analysis could be performed without imputation. Furthermore, LSA is asymmetric in nature, meaning that time reversal has the potential to produce differing LSA values. We anticipate even better performance from the statistic if these issues were addressed, perhaps through a modified version of PCC that isolates optimal windows of similarity. Clusters of local structure are observed with some example correlates of expression shown in graphs a, b, and c, indicated by solid ellipses. However, because only 800 of the approximately 6,000 genes could be classified to a cell cycle position (G1, G2/M, S, S/G2, M/G1) we could only guess at two clusters' functional characteristics. Cluster x has many G1 genes that, according to the Saccharomyces Genome Database http://www.yeastgenome.org [18], have some functionality relative to helicases and telomeres. The gene, YKR077W (*), accelerates the cell cycle initiation stage (G1) when abundant [19]. Cluster y is a set of genes encoding histone proteins [19]. Histone development is an essential part of genome replication [20] adequately describing all of cluster y as S phase genes.

Conclusions
LSA is a local similarity statistic that has recently been used to capture relevant local structure in time series datasets, particularly within the biological community. However, its use has been limited to smaller datasets due to an intensive permutation test used to calculate significance. Our derivation and direct calculation of an asymptotic upper bound using FASTLSA replaces this onerous calculation without a normality assumption, enabling LSA on time series datasets containing millions of co-variate time series. We demonstrate the utility and versatility of FAS-TLSA by analyzing time series data from public health, microbial ecology, and social media and compare these results to the previous implementation of LSA, obtaining similar results with orders of magnitude increase in throughput.