Hi all,
I have a problem concerning my understanding of the cross-correlation (ccf)
function in R.
assume a time serie as:
> t<-seq(0,6.28,by=0.01);
> my_serie<-ts(sin(t),start=0,end=6.28,deltat=0.01)
then I generate an other one shifted by 12 time points:
> my_shifted_serie<-ts(sin(t),start=0+0.12,end=6.28+0.12,deltat=0.01)
if I do the cross-correlation I get that the two series are shifted by 12
time units:
> c<-ccf(my_serie,my_shifted_serie); c[[4]][which(c[[1]]==max(c[[1]]))]
[1] -0.12
This works for all shift from 0.01 to 0.12. If I do a longer shift, like
0.13:
> my_shifted_serie<-ts(sin(t),start=0+0.13,end=6.28+0.13,deltat=0.01)
> c<-ccf(my_serie,my_shifted_serie); c[[4]][which(c[[1]]==max(c[[1]]))]
[1] -0.12
I get a wrong result, and this old for any shift greater than 0.12 (for
example with a shift of 1.01 you get a peak in the ccf function at
-0.72!!!). What I'm missing in my understanding?
If I pad with zeros the time points of my_serie which do not belong to
my_shifted_serie in my_shifted_serie, and viceversa:
> my_shifted_serie<-ts(sin(t),start=0+1.01,end=6.28+1.01,deltat=0.01)
> tmp<-ts.union(my_serie,my_shifted_serie)
> tmp[which(is.na(tmp[,1])),1]<-0
> my_serie_padded<-tmp[,1]
> tmp[which(is.na(tmp[,2])),2]<-0
> my_shifted_serie_padded<-tmp[,2]
and I ccf the resulting series:> c<-ccf(my_serie_padded,my_shifted_serie_padded,200);
c[[4]][which(c[[1]]==max(c[[1]]))]
[1] -1.01
the exact shift.
Thanks for help.
Best,
Andrea
[[alternative HTML version deleted]]