sptrends sptrends logo

Statistical Inference for Spatiotemporal Trends in Gridded Data

sptrends provides a reproducible framework for statistical inference of spatiotemporal trends in gridded environmental data. It offers modular methods for serial-correlation treatment, trend testing, spatially explicit inference, global and local spatial-autocorrelation diagnostics, robust slope estimation, multiple-testing correction, simulation, benchmarking, visualisation, mapping, and reporting.

Installation

Install the released version from CRAN:

install.packages("sptrends")

Or install the development version from GitHub:

# remotes::install_github("Olive-r/sptrends")
install.packages("sptrends", repos = c('https://olive-r.r-universe.dev', 'https://cloud.r-project.org'))

Quick start

A bundled annual NDVI dataset is available for reproducible examples:

library(sptrends)

r <- read_ordered_stack(example_data("vhp_ndvi"))
result <- workflow_tst(r, report = FALSE, verbose = FALSE)
plot(result)

With your own data, replace the file path:

# One raster file per time step, ordered from numbers in the file names.
r <- read_ordered_stack("path/to/rasters")

# Published True Significant Trends workflow
# (Gutierrez-Hernandez and Garcia, 2025, https://doi.org/10.1016/j.rsase.2024.101377).
result <- workflow_tst(r)

print(result)
summary(result)
plot(result)

Workflows

For seasonal data, declare the temporal structure and remove the cycle before running a trend workflow. For example, for consecutive monthly layers beginning in August:

# Supply your files in chronological order; files may contain multiple layers.
monthly <- read_ordered_stack(
  files = ordered_files, cycle_type = "monthly",
  start = as.Date("2001-08-01"), report = FALSE
)
anomalies <- compute_anomalies(monthly, cycle_type = "monthly",
                               start_position = 8)
result <- workflow_tst(anomalies$anomalies, report = FALSE)

start is the first period's beginning; the default assigned date for a monthly layer is its centre. Annual layers use 1 January. Anomalies group layers by position, not by their date metadata; the user supplies the correct cycle and starting position. files plus time also supports an explicit date for every layer. See the loading guide.

Each analytical stage is also available independently:

pw <- prewhiten(r, method = "TFPW_WS")
trend <- trend_test(pw$series, method = "CMK")
slope <- slope_estimator(pw$series, method = "TS")
fdr <- fdr_correction(trend$stats$p, method = "BKY")

spatial_autocorrelation() provides independent global and local permutation inference for environmental variables, residuals, coefficients or inferential fields. Local p-value rasters can be passed to fdr_correction() for BH, BKY or BY control.

Main modules

The current calculations are vectorised and selected stages can use parallel processing, but analytical rasters are materialised in memory. Test representative dimensions before processing very large datasets.

Documentation

The function help pages describe assumptions, alternatives, computational trade-offs, references and method-specific quality assurance. The vignettes provide concise guides to preprocessing, trend tests, slope estimation, FDR correction and complete workflows:

browseVignettes("sptrends")

Quality assurance

The 1.6.3 local check completed in under 10 minutes with 0 errors, 0 warnings and 0 notes. Coverage is 100% across every R source file with SPTRENDS_TEST_PARALLEL=true. win-builder checks (R-devel, R-release, R-oldrelease) had 0 errors and 0 warnings, with only the routine submission/terminology note. See cran-comments.md for the current validation status. The 19 parallel-execution tests remain optional to keep routine checks within CRAN's time limit. Website building is a separate step. Style, spelling and link integrity are checked periodically with lintr, goodpractice, spelling and urlchecker.

Beyond the automated tests/testthat/ suite, the package's Mann-Kendall and Theil-Sen implementations have been cross-checked against five independent CRAN packages (Kendall, trend, modifiedmk, robslopes, zyp) across five test series (clear trend, no trend, tied values, short, long), with no unexplained discrepancies. The package has also undergone a comprehensive integral audit of code, citations and documentation.

trend_test(method = "CMK") has additionally been cross-checked against an installed copy of ConMK (Antiphon, GitHub, not on CRAN -- also available as a fork at geoporttishare/ConMK), the closest available external reference implementation of the contextual Mann-Kendall test. The base statistic matched to floating-point precision, and the optional continuity = TRUE argument reproduces ConMK's own p-values exactly at the specific edge case where the two implementations would otherwise be expected to diverge. Full details in ?trend_test's "External validation" section.

Every change is documented transparently in NEWS.md.

Citation

To cite the package itself:

Gutiérrez-Hernández, O., & García, L. V. (2026). sptrends: Statistical Inference for Spatiotemporal Trends in Gridded Data. R package version 1.6.3, CRAN. https://doi.org/10.32614/CRAN.package.sptrends

Archived source code snapshots for each release are also available via Zenodo: https://doi.org/10.5281/zenodo.21822842

Or, from R:

citation("sptrends")

Published workflows:

Authors

License

GPL (>= 3)