Reputation: 271
I am calculating cross correlation using prewhiten()
in R. I want to export the output in matrix/ data frame format and for positive lag only . For example:
x<-c(12,14,22,23,25,26,28,30,32,27,36,44,22,15,8,18)
y<-c(1,2,5,2,4,4,5,6,8,9,10,3,4,8,8,9)
x_model<-auto.arima(x)
correlation<-prewhiten(x,y,x.model=x_model,plot=FALSE)
correlation$ccf
The output is not in data.frame or matrix format.
I want to have output in the following format:
Lag CCF
0 0.063
1 0.263
3 0.192
and so on....
Upvotes: 0
Views: 1995
Reputation: 18323
You could do:
data.frame(lag=correlation$ccf$lag, CCF=correlation$ccf$acf)
But, you can easily check how an object is structure with str
, which will help you convert to the structure that you want:
str(correlation$ccf)
# List of 6
# $ acf : num [1:19, 1, 1] -0.1702 0.1041 -0.0985 0.1238 0.0107 ...
# $ type : chr "correlation"
# $ n.used: int 16
# $ lag : num [1:19, 1, 1] -9 -8 -7 -6 -5 -4 -3 -2 -1 0 ...
# $ series: chr "X"
# $ snames: chr "x & y"
# - attr(*, "class")= chr "acf"
Upvotes: 1