I have a Problem with the correlation of time series. I want to calculate the correlation between two time series with different time lags to show if my time series x has prediction power for my variable y.
Correlation = corr(VariableX_t,〖PredictedVariable〗_(t+k))
Where k is the lag for the predicted variable. I used the ccf function but the results are strange. The data is structured like this:
t Value x t Value y
1 1 1 5
2 3 2 3
3 2 3 6
4 4 4 5
5 8 5 12
So I thought that I can compute the correlation in R like this for a lag with one month and with 3 months:
1 Month: cor(VariableX$ValueX[1:4], VariableY$ValueY[2:5])
3 Months: cor(VariableX$ValueX[1:2], VariableY$ValueY[4:5])
or with the ccf function like
ccf(VariableX$ValueX,VariableY$ValueY,lag=1, pl=FALSE)
The problem is that the functions give completely different results. Can someone tell me which approach is the right one for my equation? Furthermore, if the first approach is correct, is there a function in R that also lets me set a lag parameter for the "normal correlation"?
Thanks in advance and best regards