繁体   English   中英

获取矩阵/数据帧格式的CCF输出

[英]Get the Output of CCF in Matrix / data frame format

我正在使用R中的prewhiten()计算互相关。我想以矩阵/数据帧格式导出输出,并且仅用于正滞后。 例如:

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

输出不是data.frame或矩阵格式。

我想以以下格式输出:

Lag     CCF
0       0.063
1       0.263
3       0.192

等等....

您可以这样做:

data.frame(lag=correlation$ccf$lag, CCF=correlation$ccf$acf)

但是,您可以使用str轻松检查对象的结构,这将帮助您转换为所需的结构:

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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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