Finding lag at which cross correlation is maximum ccf( )

后端 未结 4 2121
野的像风
野的像风 2020-12-23 17:55

I have 2 time series and I am using ccf to find the cross correlation between them. ccf(ts1, ts2) lists the cross-correlations for all time lags. H

4条回答
  •  遥遥无期
    2020-12-23 18:50

    Posting the answer http://r.789695.n4.nabble.com/ccf-function-td2288257.html

    Find_Max_CCF<- function(a,b)
    {
     d <- ccf(a, b, plot = FALSE)
     cor = d$acf[,,1]
     lag = d$lag[,,1]
     res = data.frame(cor,lag)
     res_max = res[which.max(res$cor),]
     return(res_max)
    } 
    

提交回复
热议问题