## Examine how the global evidence develops as finer resolutions are added.
local({
  set.seed(12345)
  n <- 360
  x <- runif(n)
  y <- sin(4 * pi * x) + rnorm(n, sd = 0.38)
  maximum_resolution <- 0:5
  path <- vapply(
    maximum_resolution,
    function(resolution) {
      fes(x, y, K1 = 4, K2 = 4, M = resolution)
    },
    numeric(4L)
  )
  print(path)

  old_parameters <- graphics::par(no.readonly = TRUE)
  old_parameters$new <- FALSE
  on.exit(graphics::par(old_parameters))
  graphics::layout(matrix(c(1, 2), nrow = 1L), widths = c(1.2, 1))

  graphics::par(mar = c(4, 4, 3.2, 1), mgp = c(2.2, 0.7, 0))
  graphics::plot(
    x,
    y,
    pch = 16,
    cex = 0.65,
    col = grDevices::adjustcolor("#2166AC", alpha.f = 0.48),
    xlab = "X",
    ylab = "Y",
    main = "Sinusoidal dependence",
    bty = "n",
    las = 1,
    panel.first = graphics::grid(col = "#ECECEC", lty = 1)
  )
  smooth <- stats::lowess(x, y, f = 0.18)
  graphics::lines(smooth, col = "#D95F02", lwd = 2.5)

  graphics::par(mar = c(4, 4, 3.2, 1), mgp = c(2.2, 0.7, 0))
  selected <- path[c("Sidak", "Bonferroni"), , drop = FALSE]
  evidence <- -log10(pmax(selected, .Machine$double.xmin))
  graphics::matplot(
    maximum_resolution,
    t(evidence),
    type = "b",
    pch = c(16, 17),
    lty = 1,
    lwd = 2,
    col = c("#2166AC", "#D95F02"),
    xlab = "Maximum resolution (M)",
    ylab = expression(-log[10](italic(p))),
    main = "Evidence by scan depth",
    bty = "n",
    las = 1,
    panel.first = graphics::grid(col = "#ECECEC", lty = 1)
  )
  graphics::abline(h = -log10(0.05), col = "#D7191C", lty = 2, lwd = 1.5)
  graphics::legend(
    "topleft",
    legend = c("Sidak", "Bonferroni"),
    col = c("#2166AC", "#D95F02"),
    pch = c(16, 17),
    lty = 1,
    lwd = 2,
    bty = "n",
    cex = 0.8
  )
})
