1

I have 2 time series

Time No_Incidents
1     3           45
2     4           64
3     5           69
4     6           79
5     7           73
6     8           23
7     9           12
8    10           12
9    11          108
10   12           79

Time No_Changes
1     3          1
2     4          5
3     5          3
4     6         10
5     7          8
6     8          7
7     9          1
8    10          1
9    11          7
10   12         10

I need to find a correlation of the two time series to know whether certain changes cause spikes in incidents or not.I tried R's ccf function and find significant cross correlation with 2 lags.If I want to use lag plot is there any function in R to show the cross correlation for lag plot?

Also though it is showing there is negative correlation for lag=2 which means changes lead to incidents but practically does it make any sense if changes increase incidents will decrease.

Is there any way to study the correlation for these 2 time series?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Dibyajyoti
  • 11
  • 2
  • Till someone comes in with answer, you can try `plot.ts` and `ccf` functions – R.S. Dec 06 '16 at 11:46
  • Please review "How to Make a Reproducible R Example" if you hope to actually get an answer. You have not *illustrated* what you have done nor can we copy/past your code easily. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – JD Long Dec 06 '16 at 19:26
  • You may have better luck posting this question in Cross Validated – Rob Jan 30 '18 at 23:53

1 Answers1

0

For these two time series it is problematic to provide such kind of an analysis as the amount of observations is really small.

y1 <- structure(list(DN = 1:10, Time = 3:12, No_Incidents = c(45L, 
64L, 69L, 79L, 73L, 23L, 12L, 12L, 108L, 79L)), class = "data.frame", 
row.names = c(NA, -10L))

y2 <- structure(list(DN = 1:10, Time = 3:12, No_Changes = c(1L, 5L, 
3L, 10L, 8L, 7L, 1L, 1L, 7L, 10L)), class = "data.frame", row.names = 
c(NA, -10L))   

ts1 <- ts(y1$No_Incidents)
ts2 <- ts(y2$No_Changes)
acf(ts.union(ts1, ts2), ci = 0.99)

Output:

Correlogram and cross-correlogram

You can see that there are nor auto- neither cross-correlations with confidence level 99%. So lag = 2 correlation is somehow spurous. By default acf shows confidence level 95% hence 5% of "significant" correlations can be observed by chance.

Artem
  • 3,304
  • 3
  • 18
  • 41