2017-05-24 66 views
0

我試圖在兩條曲線之間找到正面區域,就像在哪裏只有更高的區域一樣。曲線是時間序列和水平線。這是它創建的情節的圖片:https://i.stack.imgur.com/ZrPH4.png。我不希望水平線更高的區域,所以我不能找到它們差異曲線下的區域。我嘗試在auc函數中使用閾值參數:如何在R中的兩條曲線之間找到正面區域

auc((1:96), STLFMondayBlock1$mean[(1:96)], thresh = 11648.93)但是我得到的值高於閾值:1035514沒有閾值,1213062有閾值。

+1

可以將區域設爲負值嗎? – tagoma

+0

請提供時間序列數據。 – G5W

+0

@edouard:它可以在微積分中 – AkselA

回答

1

用一個簡單的例子:

x1 <- c(0, 0, rep(1, 4), rep(0, 4), rep(1, 4), 0, 0, 0) 
x2 <- rep(0.5, length(x1)) 
d <- x1 - x2 

a <- cumsum(ifelse(d > 0, d, 0)) 
tail(a, 1) 
# 4 

par(mar=c(2, 2, 1, 1)) 
matplot(cbind(x1, x2, a), type="s", lwd=2, col=1:3) 
legend("topleft", legend="positive area between curves", 
    col=3, lty=3, lwd=2, bty="n") 

enter image description here
正如你所看到的,如果你把兩條曲線和總和只有正值之間的差別,你得到的兩條曲線之間的總陽性面積。