Question

I'm pretty new in R and I'm working on a cross correlation model, I've searched for the answer but haven't been able to find it.

I have been able to prove the cross correlation(lag correlation) between 2 time series using the R function with "ccf".

Now based on the model created with ccf I want to be able to predict the next values of one of the variables based on the data of the other one. I don't seem to find information.

This is relatively easy in auto-correlation with Arima, but I don't seem to be able to do it with the cross correlation.

Any idea how can I achieve this?

Thanks Fernando

Was it helpful?

Solution

As stated in the help, the purpose of the ccf function is:

Function ccf computes the cross-correlation or cross-covariance of two univariate series

This means it's not a model as you state in your question, it's a computation. What you should do is use the ccf function for plotting and choosing a model for prediction such as ARIMA, VAR, etc. Check out the time series task in CRAN for more options regarding time series modelling.

Perhaps your question should be posted in stats.exchange rather than stackoverflow, as it's not a programming question.

This would be an example of the usage of ccf() in case this is useful for you.

df <- data.frame(date = seq(as.Date("1990-01-01"), length = 100, by = "month"),
                 x = (runif(n = 100, min = 0, max = 1000)),
                 y = rpois(n = 100, lambda = 50))

cc = with(df, ccf(x, y, type = "correlation"))

plot(cc)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top