0

I have the following data series consisting of a series of measurements taken at monthly intervals.

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

where the data looks like:

enter image description here

I need to calculate the total area under the curve for each year that is greater than zero (i.e, only positive or above zero parts of the curve). I have been trying to use the package flux and the 'thresh' argument in the function auc, but cant get it to work. Any help will be appreciated.

df %>% 
  group_by(year) %>% 
    summarize(auc = auc(value, thresh=0))
  • C'mon dude! This is very different to the other question for two reasons. 1) I want to work out a code to summarise the AUC for each year; 2) I am only interested in the area under the curve which is above zero. I feel it is a little unfair marking this as a duplicate and preventing me from seeking an answer. – Christopher Kavazos Sep 02 '18 at 01:58
  • A third reason is that me y-axis is temporal – Christopher Kavazos Sep 02 '18 at 02:09

0 Answers0