2016-04-21 27 views
0

我正在对R(某个产品在不同商店的销售量)的多个时间序列进行聚类分析。当在R中聚类时间序列时,咨询一阶时间相关系数CORT的值

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

的literaure(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系数的值。

那么,没有人如何看到CORT系数的值在R

在此先感谢。

回答

0

我不知道这是否是你想要的,但任何如何,这是我做过什么:

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))) 
} 

现在,我认为这是你在找什么。

+0

非常感谢你,这就是我一直在寻找的!现在,我想做30个时间序列,我想绘制'CORT'矩阵,就像我们使用'corrplot'命令一样。你知道有没有办法用'CORT'来做? –

+0

@AnaA你可以请投票答案? – user2007598

+0

我已经做到了,但是我得到的消息是:“感谢您的反馈!一旦您获得了15个声望,您的选票将改变公开显示的帖子得分” –