首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R中时间序列聚类时一阶时间相关系数CORT的参考值

R中时间序列聚类时一阶时间相关系数CORT的参考值
EN

Stack Overflow用户
提问于 2016-04-21 18:27:48
回答 1查看 304关注 0票数 0

我正在对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包中看到下一个示例:

代码语言:javascript
复制
## 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系数的值。

那么,有谁知道如何在R中查看CORT系数的值

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-04-21 20:44:48

我不确定这是不是你想要的,但我是怎么做到的:

代码语言:javascript
复制
View(diss.CORT)

其中R表示:

代码语言:javascript
复制
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

代码语言:javascript
复制
#############################################################################
#################   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) ))
}

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36766808

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档