## ----setup, message=FALSE, warning=FALSE--------------------------------------
library(epifitter)
library(ggplot2)
library(dplyr)
library(cowplot)
theme_set(cowplot::theme_half_open(font_size = 12))

## -----------------------------------------------------------------------------
set.seed(1)

epi <- sim_logistic(
  N = 40,
  y0 = 0.01,
  dt = 5,
  r = 0.25,
  alpha = 0.2,
  n = 1
)

knitr::kable(epi, digits = 4)

## ----fig.alt="Line plot of a simulated disease progress curve showing disease intensity increasing over time."----
ggplot(epi, aes(time, y)) +
  geom_point(size = 2, color = "#15616d") +
  geom_line(linewidth = 0.9, color = "#15616d") +
  labs(
    title = "Example disease progress curve",
    x = "Time",
    y = "Disease intensity"
  )

## -----------------------------------------------------------------------------
audpc_abs <- AUDPC(
  time = epi$time,
  y = epi$y,
  y_proportion = TRUE,
  type = "absolute"
)

audpc_abs

## -----------------------------------------------------------------------------
audpc_rel <- AUDPC(
  time = epi$time,
  y = epi$y,
  y_proportion = TRUE,
  type = "relative"
)

audpc_rel

## -----------------------------------------------------------------------------
time_rep <- c(0, 0, 5, 5, 10, 10)
y_rep <- c(0.10, 0.30, 0.40, 0.60, 0.70, 0.90)

AUDPC(time = time_rep, y = y_rep)
AUDPS(time = time_rep, y = y_rep)

## -----------------------------------------------------------------------------
time_mean <- c(0, 5, 10)
y_mean <- c(mean(c(0.10, 0.30)), mean(c(0.40, 0.60)), mean(c(0.70, 0.90)))

AUDPC(time = time_mean, y = y_mean, aggregate = "none")
AUDPS(time = time_mean, y = y_mean, aggregate = "none")

## -----------------------------------------------------------------------------
AUDPC(time = time_rep, y = y_rep, aggregate = "median")
AUDPS(time = time_rep, y = y_rep, aggregate = "median")

## ----eval=FALSE---------------------------------------------------------------
#  AUDPC(time = time_rep, y = y_rep, aggregate = "none")
#  AUDPS(time = time_rep, y = y_rep, aggregate = "none")

## -----------------------------------------------------------------------------
epi_rep <- sim_logistic(
  N = 30,
  y0 = 0.01,
  dt = 5,
  r = 0.3,
  alpha = 0.2,
  n = 4
)

knitr::kable(head(epi_rep), digits = 4)

## -----------------------------------------------------------------------------
AUDPC(time = epi_rep$time, y = epi_rep$random_y)
AUDPS(time = epi_rep$time, y = epi_rep$random_y)

## -----------------------------------------------------------------------------
epi_rep %>%
  group_by(replicates) %>%
  summarise(
    audpc = AUDPC(time = time, y = random_y, aggregate = "none"),
    audps = AUDPS(time = time, y = random_y, aggregate = "none"),
    .groups = "drop"
  ) %>%
  knitr::kable(digits = 4)

## -----------------------------------------------------------------------------
audps_abs <- AUDPS(
  time = epi$time,
  y = epi$y,
  y_proportion = TRUE,
  type = "absolute"
)

audps_abs

## -----------------------------------------------------------------------------
audps_rel <- AUDPS(
  time = epi$time,
  y = epi$y,
  y_proportion = TRUE,
  type = "relative"
)

audps_rel

## -----------------------------------------------------------------------------
audpc_two_points <- AUDPC_2_points(
  time = epi$time[7],
  y0 = epi$y[1],
  yT = epi$y[7]
)

audpc_two_points

## -----------------------------------------------------------------------------
full_curve_audpc <- AUDPC(
  time = epi$time,
  y = epi$y,
  y_proportion = TRUE
)

c(
  AUDPC_full_curve = full_curve_audpc,
  AUDPC_two_points = audpc_two_points
)

