Get the App
SLTechnology News&Howtos  ›  Development  › 

How to make the eigenvalue lag one line by Python

Shulou Source: shulou.com Published: 2022-06-01 12:53:42 09月30日 Update

This article is about how Python lags eigenvalues by one line. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

What is the lead-lag correlation

If you want to see whether the two time series are related, the simplest way is to find the correlation coefficient, but in the study of atmosphere, ocean and other scientific problems, the response of a process is often not real-time. It is possible that the a process will only occur after a period of time, and this relationship is often not represented by the correlation coefficient of the same period.

Lead-lag correlation is to see whether the occurrence and evolution of the two processes have a certain correlation in time.

For example:

There are two time series an and b, both of which are twelve months in length. The direct calculation of the correlation coefficient is a simple simultaneous correlation.

If the correlation coefficient of January-November of a to the February-December of b is the correlation of a to b one month ahead, and the correlation of February-December of a to b from January to November is called the lag correlation of a to b, and so on, the lead lag correlation of n months can be obtained, and the drawing shows the positive and negative n months along the month of October (the same period).

Implementation in python

Two time series need to be input, and the result is the sequence of lead-lag correlation coefficient of data1 to data2.

From scipy.stats import pearsonrimport numpy as np # lead lag correlation def leadlagcor (data1,data2,n): # data1 and data2 are two time series, n sets the number of time steps to do with lead lag a c=b*2+1 x=np.arange (- n journal 1) r=np.zeros ((c)) p=np.zeros ((c)) for i in range (c): if I

Tags: Time lead two sequence that is time series coefficient one line process feature eigenvalue content data more article step size good practical and so on example Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Huawei Shulou Tech Info OPPO Reno