简体   繁体   English

时间序列 - 相关和滞后时间

[英]Time series - correlation and lag time

I am studying the correlation between a set of input variables and a response variable, price. 我正在研究一组输入变量和响应变量price之间的相关性。 These are all in time series. 这些都是时间序列。

1) Is it necessary that I smooth out the curve where the input variable is cyclical (autoregressive)? 1)是否有必要平滑输入变量为周期性(自回归) 的曲线 If so, how? 如果是这样,怎么样?

2) Once a correlation is established, I would like to quantify exactly how the input variable affects the response variable. 2)一旦建立了相关性,我想准确量化输入变量如何影响响​​应变量。 Eg: "Once X increases >10% then there is an 2% increase in y 6 months later." 例如:“一旦X增加> 10%,那么6个月后y增加2%。”

Which python libraries should I be looking at to implement this - in particular to figure out the lag time between two correlated occurrences ? 我应该考虑哪些python库来实现这一点 - 特别是要弄清楚两个相关事件之间的滞后时间

Example: 例: 在此输入图像描述

I already looked at: statsmodels.tsa.ARMA but it seems to deal with predicting only one variable over time. 我已经看过: statsmodels.tsa.ARMA但它似乎只能预测一个变量。 In scipy the covariance matrix can tell me about the correlation, but does not help with figuring out the lag time. scipy中 ,协方差矩阵可以告诉我相关性,但无助于计算延迟时间。

While part of the question is more statistics based, the bit about how to do it in Python seems at home here. 虽然问题的一部分是基于更多的统计数据,但有关如何在Python中执行此操作的内容似乎在这里。 I see that you've since decided to do this in R from looking at your question on Cross Validated, but in case you decide to move back to Python, or for the benefit of anyone else finding this question: 我看到你已经决定在R中通过查看关于Cross Validated的问题来做这个,但是如果你决定回到Python,或者为了其他人发现这个问题的利益:

I think you were in the right area looking at statsmodels.tsa, but there's a lot more to it than just the ARMA package: 我认为你在正确的区域看statsmodels.tsa,但它还有很多东西,而不仅仅是ARMA包:

http://statsmodels.sourceforge.net/devel/tsa.html http://statsmodels.sourceforge.net/devel/tsa.html

In particular, have a look at statsmodels.tsa.vector_ar for modelling multivariate time series. 特别是,请查看statsmodels.tsa.vector_ar以建模多变量时间序列。 The documentation for it is available here: 它的文档可在此处获得:

http://statsmodels.sourceforge.net/devel/vector_ar.html http://statsmodels.sourceforge.net/devel/vector_ar.html


The page above specifies that it's for working with stationary time series - I presume this means removing both trend and any seasonality or periodicity. 上面的页面指出它是用于处理固定时间序列 - 我认为这意味着删除趋势和任何季节性或周期性。 The following link is ultimately readying a model for forecasting, but it discusses the Box-Jenkins approach for building a model, including making it stationary: 以下链接最终准备好预测模型,但它讨论了用于构建模型的Box-Jenkins方法,包括使其静止:

http://www.colorado.edu/geography/class_homepages/geog_4023_s11/Lecture16_TS3.pdf http://www.colorado.edu/geography/class_homepages/geog_4023_s11/Lecture16_TS3.pdf

You'll notice that link discusses looking for autocorrelations (ACF) and partial autocorrelations (PACF), and then using the Augmented Dickey-Fuller test to test whether the series is now stationary. 你会注意到该链接讨论了寻找自相关(ACF)和部分自相关(PACF),然后使用Augmented Dickey-Fuller测试来测试该系列是否现在是静止的。 Tools for all three can be found in statsmodels.tsa.stattools. 这三种工具都可以在statsmodels.tsa.stattools中找到。 Likewise, statsmodels.tsa.arma_process has ACF and PACF. 同样,statsmodels.tsa.arma_process有ACF和PACF。

The above link also discusses using metrics like AIC to determine the best model; 上述链接还讨论了使用像AIC这样的指标来确定最佳模型; both statsmodels.tsa.var_model and statsmodels.tsa.ar_model include AIC (amongst other measures). statsmodels.tsa.var_model和statsmodels.tsa.ar_model都包括AIC(以及其他措施)。 The same measures seem to be used for calculating lag order in var_model, using select_order. 使用select_order,似乎使用相同的度量来计算var_model中的滞后顺序。


In addition, the pandas library is at least partially integrated into statsmodels and has a lot of time series and data analysis functionality itself, so will probably be of interest. 此外,pandas库至少部分集成到statsmodels中,并且本身具有大量的时间序列和数据分析功能,因此可能会引起人们的兴趣。 The time series documentation is located here: 时间序列文档位于:

http://pandas.pydata.org/pandas-docs/stable/timeseries.html http://pandas.pydata.org/pandas-docs/stable/timeseries.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM