I want to compare two time series in R and see if they are cross-correlated (with ccf).
I believe that they have to be stationary? How that my data is stationary in R and are there any other requirements before I can do ccf?
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It only takes a minute to sign up.Sign up to join this community
The sample cross correlation function is useful to identify which variable is leading or lagging. You can learn more about it here. Note that if you have non-stationary data you may find some spurious correlation between the two series, so you must first check if this is the case.
To check if a series is stationary you can use unit root tests. The most common is the Augmented Dickey Fuller test. It can be implemented in R with the urca package using the following code:
library(urca) adf <- ur.df(x, type = "drift", lags = 10, selectlags = "AIC") summary(adf)
If the null hypothesis of unit root is rejected for both series you are good to go. If you have doubts about interpreting the ADF test results take a look at this question. If the series are non-stationary one way of addressing this is to differentiate them and do the test again until they are stationary. Note that you usually are not able to do major interpretations with the results of the cross correlation function, but it is a good tool to help you fit your model.