【问题标题】:Consulting values of the first order temporal correlation coefficient CORT when clustering time series in RR中时间序列聚类时一阶时间相关系数CORT的参考值
【发布时间】:2016-08-14 11:45:29
【问题描述】:

我正在对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 系数的值吗?

提前致谢。

【问题讨论】:

    标签: r time-series cluster-analysis


    【解决方案1】:

    我不确定这是否是你想要的,但无论如何这就是我所做的:

    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 &lt;- 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) ))
    }
    

    现在,我想这就是你要找的。​​p>

    【讨论】:

    • 非常感谢,这就是我要找的!现在,我想做 30 个时间序列,我想绘制 CORT 矩阵,就像我们使用命令 corrplot 一样。你知道CORT有没有办法做到这一点?
    • 我已经完成了,但我收到消息:“感谢您的反馈!一旦您总共获得 15 个声望,您的投票将改变公开显示的帖子分数”
    • @AnaA 感激不尽!谢谢
    猜你喜欢
    • 1970-01-01
    • 2013-12-13
    • 2013-03-30
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 2016-02-05
    • 2015-07-22
    相关资源
    最近更新 更多