计算时间序列曲线下的正(零以上)区域

时间:2018-09-01 02:10:19

标签: r dplyr time-series auc

我有以下数据系列,其中包括每月进行的一系列测量。

library(dplyr)
library(flux)
library(ModelMetrics)

date = c("2016-01-10","2016-02-10","2016-03-10","2016-04-10","2016-05-10", 
     "2016-06-10","2016-07-10","2016-08-10","2016-09-10","2016-10-10", 
     "2016-11-10","2016-12-10","2017-01-10","2017-02-10","2017-03-10", 
     "2017-04-10","2017-05-10","2017-06-10","2017-07-10","2017-08-10", 
     "2017-09-10","2017-10-10","2017-11-10","2017-12-10")
date = as.POSIXlt(date)
value <- c(0.1, 0.6, 0.3, 0.35, -0.37, -0.35, 0.3, 0.1, -0.5, -.6, -0.4, 0.2,
0.1, 0.2, 0.3, 0.35, 0.32, 0.31, 0.28, 0.1, -0.1, -.3, -0.38, 0.15)
df = data.frame(date, value)
df$year <- format(df$date,format="%Y")

数据如下:

enter image description here

我需要计算每年曲线下的总面积大于零(即,仅正数或曲线的零部分以上)。我一直在尝试在函数flux中使用包thresh和'auc'自变量,但无法使其正常工作。任何帮助将不胜感激。

df %>% 
  group_by(year) %>% 
    summarize(auc = auc(value, thresh=0))

0 个答案:

没有答案