Find lag between two time series python. In this plot, time is shown on the x-axis with observation values along the y-axis. Feb 9, 2020 · In the above, α and β are both k x m matrices, ∆xₜ represents the first difference as ∆xₜ= xₜ − xₜ₋₁, Φi are the AR coefficients, and Θj are MA coefficients. You could also do some sort of cluster-based template matching, in particular if different classes of day (i. correlate(data_1, data_2, mode='same') delay = np. A two-dimensional process (Xt, Yt) reproduces a lead-lag effect if, for some time shift ϑ ∈ R, the process (Xt, Yt+ϑ) is a semi-martingale with respect to a certain filtration. In this accouts for shifted sequences, i. If you are familiar with R, then you may find the following two links on cross correlation, lagged May 31, 2021 · All you need to do is that compute cross-correlation functions on the first pair of time-series data from 1/1/2020 to 1/10/2020 and repeatedly apply the same cross-correlation function with an Nov 29, 2022 · I'm trying to compute/visualize the time lag between 2 time series (I want to know the time lag between the humidity progression of outside and inside a room). corr(ts2) Out[9]: -0. Sep 27, 2014 · Lagged correlation refers to the correlation between two time series shifted in time relative to one another. Determine a CCF maximizing lag, say optLag and unlag t1 and t2 as unlaggedTS = lag(t2,optLag) and perform a time-series union of the dataset as unionTS = ts. argmax(c) - c. We can easily calculate it with the euclidean_distances function from scikit-learn. Plotting the 2 series together, I can clearly see a shift between them: Sorry for hiding the axis. The cross correlation at lag 0 just computes a correlation like doing the Pearson correlation estimate pairing the data at the identical time points. We want to compute phase difference between these two time series. df[' lagged_values '] = df. I have tried normalizing the 2 arrays first (value-mean/SD), but the cross correlation values I get are in the thousands which doesnt seem correct. Dirk had mentioned the Autocorrelation Function, but that is meant for just one single time series and not for multivariate. 46238654, 0. bool(), a. May 31, 2015 · Lag variables in Python; and. The general linear equation looks something like this: y = B1*y(t-1) + B2*x1(t) + B3*x2(t-3) + e Jan 13, 2019 · 2. With a few lines of code, one can draw actionable insights about observed values in time series data. DataFrame(test) by using diff () method we can take first lag as expected but if I attempt diff (2) i. 0/r2d. e. The default, NULL, pads with a missing value. Take my free 7-day email course and discover how to get started (with sample code). However, the command unfortunately returned: Dec 20, 2019 · Specifically, I would like to know if my forecast model actually "learns" the underlying relation in the actual time series or if it just copies the values from the previous steps. (A very late answer) to find the time-shift between two signals: use the time-shift property of FTs, so the shifts can be shorter than the sample spacing, then compute the quadratic difference between a time-shifted waveform and the reference waveform. This function typically calculates the index at which maximum cross correlation occurs. delta_phi_true = 50. api as sm. Apr 21, 2022 · Now let’s use our knowledge of cross-correlation to synchronize the series again. Below is an example of visualizing the Pandas Series of the Minimum Daily Temperatures dataset directly as a line plot. 2000-01-11 00:00:00 -0. #plot autocorrelation function. We can similarly extract more granular features if we have the time stamp. 05 then H0 is accepted Aug 7, 2019 · You learned how to robustly analyze and model time series and applied your knowledge in two different projects. I directly cross correlate the two time series To analyse and find out if a time-series data follows any pattern, a lag plot can be employed. correlate(x, y, "full") lag = np. Feb 16, 2021 · Photo by Burak K from Pexels. tail(len(var)-1) Can anyone please give me some guidance? May 16, 2021 · As the n_lead and n_lag increases, the number of features at a particular prediction also increases. 34768587480980645. 5 * st_dev of the night time data. 0/np. A simple example of this is Sonar technology. There are two solutions: Drop those rows. This technique can be used on time series where input variables Feb 28, 2011 · put the second series in a horizontal line right underneath it. # to explicitly convert the date column to type DATETIME. This approach is only suitable for infrequently sampled data where autocorrelation is low. corrcoef. tsa. The x-axis displays the number of lags and the y-axis displays the autocorrelation at that number of lags. It is a simple and intuitive measure that calculates the distance between two time series as the straight-line distance between their corresponding points. Add a comment. Dec 3, 2013 · The cross-correlation between two time can be computed but is of little (none) value in assessing the time delay as statistical tests for the cross-correlation coefficients require normality (i. yhat = b0 + b1*X1. With NumPy in Python: Select a common set of time points for both signals t. First input size. Decomposition allows you to visualize trends in your data, which is a great way to clearly explain their behavior. in2_len int. As the name suggests, it involves computing the correlation coefficient. shift(i)) However, when using shift (50) for example, it computes the correlation between df1 and df2 that now has its 50 first lines filled Aug 30, 2022 · Granger Causality test is a statistical test that is used to determine if a given time series and it’s lags is helpful in explaining the value of another series. Where yhat is the prediction, b0 and b1 are coefficients found by optimizing the model on training data, and X is an input value. You can pick t1 or t2, or compute a linear space in the considered time range with np. data['Date'] = pd. Jul 6, 2021 · Autocorrelation (ACF) is a calculated value used to represent how similar a value within a time series is to a previous value. It will also automatically exclude NaN values! Share. If time series x is the similar to time series y then the variance of x-y should be less than the variance of x. Dec 12, 2012 · You could also read the night time data in from a large number of files, calculate the mean & standard deviation, and look for the first and last data points that exceed, say, 0. where n is the lag. correlate) between them and find the argmax of the cross-correlation function. pyplot as plt. Additionally, I would like to find the range of variance that is associated with the lag time and its respective confidence level . 06066296, -0. , sunny vs. 19352232, -0. Here are a part of my time series data. This is to test whether two time series are the same. For a data point, if the order of the lag is one, the lag is the previous data point. τdelay = argmax ((f ∗ g)(t)), τ delay = argmax ( ( f ∗ g) ( t)), this will estimate the time offset where the signals are best aligned. argmax (signal. See the documentation correlate for more information. May 11, 2016 · I've already written a function to classify the data, using sci-kit learn, but the function only uses non-lagged time-series data. r2d = 180. import numpy as np. An optional secondary vector that defines the ordering to use when applying the lag or lead to x. We have a name for it, as also pointed out in the comments: cross-covariance. T_(i-2)|T_(i-1) is the second time series of residuals which we created from steps 1 and 2 after fitting a linear model to the distribution of T_(i-2) versus T_(i-1). " How should I implement this - in particular to figure out the lag time between two correlated occurrences? Example: Calculates the lag / displacement indices array for 1D cross-correlation. Finally, forecasting allows you to anticipate future events that can aid in decision making. A regression model, such as linear regression, models an output value based on a linear combination of input values. Click to sign-up and also get a free PDF Ebook version of the course. Organizations find substantial value in time series data as it allows them to analyze both real-time and historical metrics. 0. com Mar 26, 2021 · We can calculate the cross correlation for every lag between the two time series by using the ccf () function from the statsmodels package as follows: import statsmodels. con Oct 7, 2022 · However, I am not sure how I can correctly measure the phase lag on temporal basis. Below is a function to find time-shift for maximum correlation between two timeseries df1 and df2: def time_shift(df1, df2, time_col1 = 'Time', time_col2 Jun 29, 2018 · So here is a slightly simplified version that uses more numpy functionalities, where your solution manually iterates over the outer lists:. We calculate cross-correlation, extract the point of the largest dot-product and then shift the time series May 24, 2021 · for time series approaches without caring about the prediction, just about the lag/when: use VAR/VECM with impulse response functions with the regression approach you can catch the predict better, the remaining residuals may be explained by a tree/boosting model, which needs specific lagged spending variables, probably with carryover effects. Matlab will also give you a lag value at which the cross correlation is the greatest. so if you have a daily time series, you could use df. A correlogram plots the correlation of all possible timesteps. Another possible way is to use peak Sorted by: 27. DataFrame. plot_acf () function from the statsmodels library: import matplotlib. Series x clearly lags y by 12 time periods. However, if the times in the two timeSeries do not match up exactly (they're generally off by seconds), I get Null as an answer. We will now go ahead and set this column as the index for the dataframe using the set_index () call. io/ and get yourself an API key! You’ll need it next! Oct 24, 2018 · According to the Augmented Dickey-Fuller Test (in R function adf. shift (1) to create a 1 day lag in you values of price such has. This is a sensible default. if I want to use a lag period of 2 I am not getting results as The value used to pad x back to its original size after the lag or lead has been applied. Stationary datasets are those that have a stable mean and [] Python gives me integers values > 1, whereas matlab gives actual correlation values between 0 and 1. How to make a correlation plot with a certain lag of two time series. Dec 3, 2017 · Lag is essentially delay. For example, I wrote: numpy. A first step would be to look at the cross-correlation of the two time series. The Dec 7, 2020 · downsample both series to match sampling rate between them; crop the longest series to match the shorter one; Then, there is a variety of methods to estimate similarity between the two series. df. test = {'A':[10,15,19,24,23]} test_df = pd. Dec 8, 2017 · There are 4 tests for granger non causality of 2 time series, aiming to hypothesis of causality testing (interpretation) -- & can apply either all of them or any - for approving your conclusion done H0 : X does not granger cause Y, H1 : X does granger cause Y, if p-value > 0. According to partial autocorrelation functions of the counts after differencing (in R function pacf) count1 shows significant autocorrelation of order 1 (lag=1 May 14, 2019 · python; pandas; correlation; lag; Share. Improve this answer. 49624355051. Jul 13, 2021 · 3. The following examples show how to use each method in practice. Just as correlation shows how much two timeseries are similar, autocorrelation describes how similar the time series is with itself. . drag those things to the right until they line up. As Problem1 I would like to correlate same time windows from them. Oct 7, 2019 · I'm trying to figure out how to incorporate lagged dependent variables into statsmodel or scikitlearn to forecast time series with AR terms but cannot seem to find a solution. union(t1,unlaggedTS). if the two events are not lined up vertically: select whichever instance is further to the left and everything to the right of it on that row. V ECTOR auto-regressive (VAR) integrated model comprises multiple time series and is quite a useful tool for forecasting. In [9]: ts1. Cross-correlation to measure the phase lag. to_datetime(data['Date']) data. def autocorrelate_graipher(Data): Data = np. This measure is useful for studying whether a lagged time series xt−k x t − k can be viewed as a good predictor for yt y t. A string indicating the size of the output. In case we have a time series with a clear seasonal pattern (like an increased number of passengers during summer months), we can apply Dec 28, 2021 · Phase difference of two time series. The value of the time shift ϑ is the lead-lag 4. std(A) for count in range(1, len(New_Data) // 2): i = np. Let’s start from the last row because for that one we have previous data. You should consider looking at the Box-Jenkins textbook Chapter 10 where they introduce the steps do this. Use a. Dec 9, 2019 · Feature Engineering for Time Series #2: Time-Based Features. shift(-1) will create a 1 index lag behing. var is a basic time series variable or any nx1 vector. The serial correlation or autocorrelation of lag k, ρ k, of a second order stationary time series is given by the autocovariance of the series normalised by the product of the spread. shift (1) Note that the value in the shift() function indicates the number of values to calculate the lag for. the dates in these 2 data sets do not coincide with each other but they are over the same period of time. The ACF can be used to Sep 20, 2017 · 3. Trends can result in a varying mean over time, whereas seasonality can result in a changing variance over time, both which define a time series as being non-stationary. mode str {‘full’, ‘valid’, ‘same’}, optional. Aug 4, 2021 · As I proceeded, I got to know that a time series (y) with ‘k’th lag is its version that is ‘t-k’ periods behind in time. shift(1) Note that the value in the shift () function indicates the number of values to calculate the lag for. <x>,<y>: 1-D time series. Depending on the frequency of observations, a time series may typically be hourly, daily, weekly, monthly, quarterly and annual. I need to know which predictors are important. y(t-1). I tried using the tail method for the lag, but it seems to be an inefficient way to do so. First, let’s generate some dummy time series data as it would appear “in the wild” and put it into three dataframes for illustrative purposes (all the code in one place). The following example shows how to use this Feb 13, 2019 · Time series is a sequence of observations recorded at regular time intervals. I wonder if this is possible. Second input size. find correlation between pandas time series. Using the default value of the periods argument results in a differenced series as described in the formula above. stattools. Jun 10, 2020 · The pandas function to_datetime () can help us convert a string to a proper date/time format. partly Nov 25, 2019 · You may find this article beneficial if you’re looking to use IEX Cloud, if you’re looking to do Correlation tests in Python, and if you’re interested in Time-Series data! If you’re following this and coding it yourself, go to https://iexcloud. Oct 16, 2015 · I have various time series, that I want to correlate - or rather, cross-correlate - with each other, to find out at which time lag the correlation factor is the greatest. Jan 29, 2024 · The utilization of time series visualization and analytics facilitates the extraction of insights from data, enabling the generation of forecasts and a comprehensive understanding of the information at hand. The first, and perhaps most popular, visualization for time series is the line plot. Blockquote. Dec 13, 2012 · I have 2 time series data. In case of joint stationarity, this function becomes However it is not guaranteed that by taking first lag would make time series stationary. 2. You've random processes instead of variables, in which you can calculate the covariance between samples at specific times, i. correlate result in Python. A related post suggested to look at the statsmodels. Generate an example Pandas dataframe as below. A time series with lag (k=1) is a version of the original time series that is 1 period behind in time, i. item(), a. (See an example on the image below) What I want to use is : df1. sm. The correlation of the two-time series measures how they vary with each other. Sometimes, you might have seconds and minute-wise time series as well, like, number of clicks and user visits every minute etc. , full-waveform inversion), template matching etc. To calculate the time delay between two signals, we need to find the cross-correlation between two signals and find the argmax. empty, a. Autocorrelation is a powerful analysis tool for modeling time series data. First Attempt. def detect_phase_shift(t, x, y): 1. In seismology, several applications are based on finding the time shift of one time-series relative to other such as ambient noise cross-correlation (to find the empirical Green’s functions between two recording stations), inversion for the source (e. ValueError: The truth value of a DataFrame is ambiguous. Eg: "Once X increases >10% then there is an 2% increase in y 6 months later. So if I shift the signal Y by 'lag' it should be aligned with x. argmax(correlation) - int(len(correlation)/2) Share. Such a plot is also called a correlogram. Mathematically, Cross-correlation for discrete dataset f and g is defined as: Cross-correlation function. You can implement this in Python using the statsmodels package. The index from what I understood is considered to be the time lag. 1. correlate . a time lag as well. It can be useful when you have n shifted waveforms with a multiplicity in the Aug 14, 2020 · To estimate the time delay between two signals you can use the cross-correlation ( np. The two signals are almost identical except for a very small timelag. Jul 15, 2022 · I tried using np. Note that ρ 0 = C 0 σ 2 = E [ ( x t − μ) 2] σ 2 = σ 2 σ 2 = 1. Here is an example that shows a clear peak in the cross correlation for two time shifted series: Stop learning Time Series Forecasting the slow way!. correlation = np. import matplotlib. Oct 10, 2022 · I use 'lag=np. mean(A)) / np. Hot Network Questions Jan 13, 2015 · 18. Some of those are: cross correlation: this will be affected by the amplitude and will not be able to estimate lagged correlations, prone to noise. Example 1: Calculate Lag by One Group Oct 12, 2022 · During a time series analysis in Python, you also need to perform trend decomposition and forecast future values. Jul 9, 2017 · Time series datasets may contain trends and seasonality, which may need to be removed prior to modeling. Pre-Processing Steps: Say you had two time -series t1 and t2. Jan 26, 2013 · 2000-01-10 00:00:00 1. A lag plot is drawn by representing the time series data in x-axis and the lag of the time series data point in y axis. Recover the time shift from nympy. That is, ρ k = C k σ 2. multiply(New_Data[i], New Oct 13, 2020 · The easiest way to apply differencing in Python is to use the diff method of a pd. Consider a discrete sequence of values, for lag 1, you compare your time series with a lagged time series, in other words you shift the time series by 1 before comparing it with itself. The correlation coefficient summarizes this relation in one number. ccf(marketing, revenue, adjusted=False) array([ 0. <lag>: lag option, could take different forms of <lag>: if 0 or None, compute ordinary correlation and p-value; if positive integer, compute lagged correlation with lag upto <lag>; if negative integer, compute lead correlation with lead upto <-lag>; if pass in an list or tuple or array of integers, compute lead/lag Sep 15, 2020 · This is great! How would you go about feature selection for time series using LSTM/keras. any() or a. import pandas as pd. correlate functions to compute the time delay between two time series. Here is my script with steps, I used so far for my computation: How data looks like. correlate and signal. Abstract: We propose a simple continuous time model for modeling the lead-lag effect between two financial assets. Jul 12, 2020 · Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Phenomenon captured by time series may not happen at the exact same time with some lag \(h\) between them. Consider we have two time series and for each of them , we know the phase (Phase1 and Phase2). I hope you found this article useful, and I hope you will refer back to it. tsa package. 77109358, 0. 1. If the lag is two, the lag is data point Mar 8, 2023 · The Euclidean distance is a widely used technique to measure the similarity between time series. visually identify the first correlated event. I've been playing with Pandas to try to do this. The lagged variables with the highest correlation can be considered for modeling. Parameters: in1_len int. The significance of a peak might be determined by values in the future. I need to find the time lag between this 2 variables. How can I find the lag which results in maximum correlation without manually looking at the data? Nov 30, 2017 · returns. If supplied, this must be a vector with size 1, which will be cast to the type of x. We can test this using a one sided F test for variance. But the lag is not corresponding to actual time delay that can be inferred from the graph. Notably if your data are over different sets of dates, it will compute the pairwise correlation. correlate (x,y))' where x and y are the signals. Following that, as the time-series unlagging would produce a few NA's as you lose entries by lagging, you Mar 31, 2022 · Correlation describes the relationship between two-time series and autocorrelation describes the relationship of a time series with its past values. We define the phase difference as (Phase1 - Phase2) and we wrap the results to the range of [-pi,pi]. VAR model involves multiple independent variables and therefore has more than one equations. 204383054598. It would be nice to extend the algorithm to become online by modifying the past results without sacrificing the time complexity too much. , gCAP) and structure studies (e. from scipy import signal. One can pre-whiten the "cause" series via an ARIMA model to create a surrogate x and then apply Aug 22, 2022 · Method 2: Calculate Lag by Multiple Groups. all() 2) Problem 2: Correlate between different sensors In this case I have 2 CVS files with PM values from two sensors. The time series associated with the response from the sound waves being reflected comes at some lag compared to the time series of the device emitting the initial sound waves. pandas allows you to shift your data without moving the index such has. Jun 28, 2020 · Just try to find a correlation between the last x values of that vector and the target. corr(TimeSeriesB). You could normalize them with the product of standard deviations of each signal and arrive at a lag-dependent pearson coefficient. mean(axis=0) # Average 2D array New_Data = (Data - np. In that case, there won’t be a need to deconstruct the time series into the different lag variables from t to t-12. or. To learn the latest techniques for time series analysis, checkout my complete time series forecasting course: Applied Time Series Forecasting in Python; Cheers! Jul 23, 2020 · We can plot the autocorrelation function for a time series in Python by using the tsaplots. independence of successive observations ) and more. I'm trying to get the correlation between these two sets of data. Returns: lags array Aug 22, 2022 · You can use the shift () function in pandas to create a column that displays the lagged values of another column. Nov 13, 2019 · Modeling Time-series Stochastic Data. 2) Once a correlation is established, I would like to quantify exactly how the input variable affects the response variable. I could get a decent answer Oct 12, 2022 · The 2 dataframes contain some meteorological data where the cols are the location (x,y) and the lines are one day in a year. groupby ([' group1 ', ' group2 '])[' values ']. For example: 1. Dec 29, 2015 at 19:43. By real-time data you mean a so-called online algorithm, where data points are received time after time. Stationary data is important because it allows us to apply statistical models that assume constant parameters (like the mean and standard deviation) over time, and this can improve the accuracy of our predictions. append(value) return Series(diff) We can see that the function is careful to begin the differenced dataset after the specified interval to ensure differenced values can, in fact, be calculated. Because, I am interested to measure the phase lag change with time. shift(1) will create a forward lag of 1 index. Having the same length is not essential. A default interval or lag value of 1 is defined. var-var. I've tried numpy. To calculate the autocorrelations, I extracted two time series for each column whose start and end data differed by one year and then calculated correlation coefficients with numpy. linspace. Mar 5, 2011 · I'm trying to calculate the lag between two signals in Python using cross correlation. Jan 5, 2017 · In my example the application of a window function improves the detected phase shift (within resolution of the discretization). We still have a problem with the first 4 rows because we don’t have the previous 5 rows to get the data from. This function uses the following basic syntax: df['lagged_col1'] = df['col1']. size/2 Mar 16, 2020 · I have two variables as time series, one a consequent of the other, I would like to find the average time delay it takes the dependent variable to act on the independent variable. Lag multiple variables across multiple groups — with groupby. Oct 13, 2017 · 0. ccf(ts1, ts2) lists the cross-correlations for all time lags. This is implemented in numpy. 3. Most of those videos took an example of the stock market daily prices to explain time series analysis. Difference them. corrwith(df2. Each data point of my series was taken hourly. I’m currently working on a time series problem with multiple predictors. You should consider the Cross Correlation Function as that is meant to identify the lead/lag relationship. pi # conversion factor RAD-to-DEG. Aug 14, 2020 · value = dataset[i] - dataset[i - interval] diff. arange(len(New_Data) - count) yield np. For example if we have 5 independent features at every time stamp and we conside n_lag=5 and n_lead =2, then the over all features post reframe will be 5+5*(n_lag)+5*(n_lead), which is in case 40 features. Since you work with time series, you could use the cross-correlation function between the two series. From my understanding, the predicted value at time t is highly correlated with the actual value at time t and then with the actual value of t-1 thus the model has 1. array(Data) A = Data. Apr 29, 2012 · I have 2 time series and I am using ccf to find the cross correlation between them. Jan 8, 2017 · The statsmodels library stands as a vital tool for those looking to harness the power of ARIMA for time series forecasting in Python. Let's say you have a signal with values in an array s1 at time points t1, and a signal s2 evaluate at time points t2. – Christian Hirsch. corrcoef(data[['C']][1:-1],data[['C']][2:]) (the entire DataFrame is called data). #calculate cross correlation. However, using the following code as suggested in Python cross correlation : import numpy as np c = np. The numerator of the equation calculates the covariance between these two residual time series and the denominator standardizes the covariance using the respective standard Feb 21, 2021 · The number of samples lagged can be used to calculate time-shift. Let’s see how we can easily perform differencing in Python using Pandas Jan 17, 2022 · Method 3: Using plot_acf () A plot of the autocorrelation of a time series by lag is called the AutoCorrelation Function (ACF). dtypes. Lag one variable across multiple groups — using unstack method. Sep 12, 2019 · 1 Answer. Building an ARIMA Model: A Step-by-Step Guide: Model Definition: Initialize the ARIMA model by invoking ARIMA () and specifying the p, d, and q parameters. For instance, we can determine the hour or minute of the day Feb 4, 2016 · You can use the cross correlation to find the lag that maximizes correlation between two functions. The Statsmoldels library makes calculating autocorrelation in Python very streamlined. Assuming data_1 and data_2 are samples of two signals: import numpy as np. g. That is, the Granger Causality can be used to check if a given series is a leading indicator of a series we want to Mar 4, 2023 · When working with time series data, differencing is a common technique used to make the data stationary. How to find the lag between two time series using cross-correlation. 1 Autocorrelation. cov(xt1,yt2) cov ( x t 1, y t 2), and this is a function of t1,t2 t 1, t 2. To complete the answer of Glen_b and his/her example on random walks, if you really want to use Pearson correlation on this kind of time series (St)1≤t≤T ( S t) 1 ≤ t ≤ T, you should first differentiate them, then work out the correlation coefficient on the increments ( Xt = St −St−1 X t = S t − S t − 1) which are (in the Jul 20, 2020 · 0. It can be considered an extension of the auto-regressive (AR part of ARIMA) model. order_by. correlate and scipy. test from tseries) Count1 neither count1 and count2 are stationary but they become stationary after differencing once. Time Series Line Plot. Dec 29, 2015 at 16:19. Is there a way, in Python, using sci-kit, to automatically lag all of these time-series to find what time-series (if any) tend to lag other data? Macro's point is correct the proper way to compare for relationships between time series is by the cross-correlation function (assuming stationarity). I've created two timeseries, and am using TimeSeriesA. Correlation of Two Time Series. I found various questions Stack Overflow See full list on forecastegy. But here, rather than computing it between two features, correlation of a time series is found with a lagging version of itself. That's why I want to know if there is any library with a function to identify the best lag :) – aabujamra. 28159595, I suggest that you could simply use a prediction task not importantly how many lags one time-series is ahead of the other one; specially this makes sense while not necessarily always the difference of lags would continue the same during the history of two time-series; In the other hand, a prediction method can model it better. jn jv hl wo fu aw bq lo tq ju