简体   繁体   中英

custom lags acf/ccf in R

is there a way to generate a ccf plot in R using ccf but to allow it to only use negative lags? i tried changing lag.max but it still retains a symmetric shape.

EDIT: to clarify, i need lags that are larger than the standard default that gets plotted (i think the default is +-34)

I followed one of the examples in ?ccf. I created a ccf object then looked at its structure, I don't plot it yet by using plot=F :

>xccf=ccf(mdeaths,fdeaths,ylab="wtf!",lag.max=200, plot=F)
>str(xccf)

The str commmand shows that there is a there is component call lag that are a sequence of some sort, look at it with:

    > xccf$lag
, , 1

              [,1]
  [1,] -5.91666667
  [2,] -5.83333333
  [3,] -5.75000000
  [4,] -5.66666667
  [5,] -5.58333333
 ...       ...    ...
[141,]  5.75000000
[142,]  5.83333333
[143,]  5.91666667

The length of the lags will be the lag.max or the number of observations in the shorter data, whichever is lower. For this example data I set max.lag to be 200 but since there is not enough data to comput that many you only get 143. If you want only the negative ones the first 71 are they. So I pass which lags into the square brackets to subset to those. Then call plot on the thing.

plot(xccf[xccf$lag[1:71],])

which gives this plot:

哦,啊!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM