我正在对R中的几个时间序列(一个产品在不同商店的销售额)进行聚类分析。
我在TSclust软件包中使用一阶时间相关系数CORT(S1,S2),其中S1和S2是两个时间序列。
文献(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系数的值。
那么,有谁知道如何在R中查看CORT系数的值
提前谢谢。
发布于 2016-04-21 20:44:48
我不确定这是不是你想要的,但我是怎么做到的:
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) ))
}现在,我想这就是你要找的。
https://stackoverflow.com/questions/36766808
复制相似问题