繁体   English   中英

R中的时间序列聚类时的一阶时间相关系数CORT的咨询值

[英]Consulting values of the first order temporal correlation coefficient CORT when clustering time series in R

我正在对R中几个时间序列(产品在不同商店中的销售)进行聚类分析。

我在包TSclust使用一阶时间相关系数CORT(S1,S2) ,其中S1S2是两个时间序列。

文学作品( https://cran.r-project.org/web/packages/TSclust/TSclust.pdf )解释了CORT属于interval [-1,1] :当CORT(S1,S2)=1两个系列表现出相似的动态行为,并且当CORT(S1,S2)=-1它们具有相反的行为。

我想知道如何查看CORT的结果,以便观察每个时间序列对的CORT值。

我们可以在TSclust包中看到下一个示例:

## Create three sample time series
x <- cumsum(rnorm(100))
y <- cumsum(rnorm(100))
z <- sin(seq(0, pi, length.out=100))

## Compute the distance and check for coherent results
diss.CORT(x, y, 2)
diss.CORT(x, z, 2)
diss.CORT(y, z, 2)

因此,使用上述代码,我们可以使用系数CORT(S1,S2)计算相异指数,但无法查询CORT系数的值。

那么,有谁能看到RCORT数值呢?

提前致谢。

我不确定这是否是您想要的,但是我不确定这是怎么做的:

View(diss.CORT)

其中R显示:

function (x, y, k = 2, deltamethod = "Euclid") 

{
  .ts.sanity.check(x, y)
  .check.equal.length.ts(x, y)
  corrt <- corrtemporder1(x, y)
  type <- (pmatch(deltamethod, c("Euclid", "Frechet", "DTW")))
  typedist <- 0
  if (is.na(type)) {
    stop(paste("Unknown method", deltamethod))
  }
  else if (type == 1) {
    typedist <- as.numeric(dist(rbind(x, y)))
  }
  else if (type == 2) {
    typedist <- diss.FRECHET(x, y)
  }
  else if (type == 3) {
    typedist <- dtw(x, y, dist.method = "Manhattan", distance.only = T)$distance
  }
  (2/(1 + exp(k * corrt))) * typedist
}

现在,如果您经历了这一点并开始阅读脚本,似乎您正在寻找的地方是corrt <- corrtemporder1(x, y) 谷歌它,你得到: https : //github.com/cran/TSclust/blob/master/R/diss.R

#############################################################################
#################   Temporal Correlation Distance   #########################
#############################################################################

##CHOUAKRIA-DOUZAL

corrtemporder1 <- function (x, y) {
    p <- length(x)
    sum((x[2:p] - x[1:(p-1)]) * (y[2:p] - y[1:(p-1)])) / ( sqrt( sum((x[2:p] - x[1:(p-1)])^2) ) * sqrt( sum((y[2:p] - y[1:(p-1)])^2) ))
}

现在,我认为这就是您想要的。

暂无
暂无

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

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