## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>",
                      fig.width = 6, fig.height = 4.5)

## ----setup, include = FALSE---------------------------------------------------
library(sptrends)
r <- terra::rast(
  sort(list.files(
    example_data("vhp_ndvi"),
    pattern = "\\.tif$",
    full.names = TRUE
  ))
)

## -----------------------------------------------------------------------------
trend <- trend_test(r, method = "CMK", report = FALSE, verbose = FALSE)
fdr <- fdr_correction(
  trend$stats$p,
  method = c("BH", "BKY", "BY"),
  q = 0.05,
  report = FALSE,
  verbose = FALSE
)
fdr
summary(fdr)

## -----------------------------------------------------------------------------
bky <- fdr_correction(
  trend$stats$p,
  method = "BKY",
  q = 0.05,
  report = FALSE,
  verbose = FALSE
)

## ----fig.alt = "Raw uncorrected CMK significance map"-------------------------
plot(
  trend,
  which = "maps",
  panels = "significance",
  alpha = 0.05
)

## ----fig.alt = "FDR-BKY significance map"-------------------------------------
plot(bky)

## ----fig.alt = "Ordered p-values and BH and BKY rejection thresholds"---------
plot(fdr, which = "threshold")

