Statistical Inference for Spatiotemporal Trends in Gridded Data

Provides a unified and reproducible framework for statistical inference of spatiotemporal trends in gridded environmental data. The framework addresses the interconnected challenges of serial correlation, spatial dependence and multiple testing that commonly arise when analysing gridded environmental time series. Its core methods support serial-correlation treatment through trend-preserving prewhitening, pixel-wise and spatially explicit trend inference, slope estimation and multiple-testing correction. These methods may be applied independently or integrated within configurable analytical workflows. Dedicated workflows are also provided to reproduce methodologies published in the scientific literature: Gutiérrez-Hernández and García (2025) for the True Significant Trends workflow, Gutiérrez-Hernández and García (2024) for the Robust Trend Analysis workflow, and Gutiérrez-Hernández and García (2025) for the adaptive false discovery rate procedure. Supporting utilities facilitate raster data import and inspection, anomaly calculation, spatial autocorrelation diagnostics, simulation studies, benchmarking, visualisation, mapping, and reporting.


sptrends sptrends logo

Statistical Inference for Spatiotemporal Trends in Gridded Data

R License: GPL v3 Lifecycle: stable DOI pkgdown

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 source package from a local archive or directory:

remotes::install_local("path/to/sptrends")

When starting from a development source directory, regenerate its help files first with roxygen2::roxygenise("path/to/sptrends"). This step is not needed for a built source tarball.

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.

  • workflow_tst() implements True Significant Trends: selective prewhitening, Contextual Mann-Kendall, Theil-Sen and adaptive FDR (Gutiérrez-Hernández and García, 2025).
  • workflow_rta() implements Robust Trend Analysis: Contextual Mann-Kendall, Theil-Sen and FDR-BH without prewhitening (Gutiérrez-Hernández and García, 2024).
  • workflow_trends() combines user-selected preprocessing, trend, slope and FDR modules through the same validated interfaces.

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

  • read_ordered_stack() and read_netcdf_stack() — raster import with temporal-order checks.
  • compute_anomalies() — deseasonalising, when the series has a known cycle.
  • prewhiten() — serial-correlation treatment, trend-preserving.
  • trend_test() — CMK with configurable odd neighbourhoods (3 by 3 by default), MK, OLS and modified MK.
  • slope_estimator() — Theil-Sen, OLS and Siegel repeated median.
  • fdr_correction() — BH, adaptive BKY and BY.
  • spatial_autocorrelation() — permutation-based spatial diagnostics.
  • sim_trend_stack(), simulation_design(), compare_detections(), benchmark_methods() and benchmark_summary() — known-truth simulation and reproducible method benchmarking, including S3 performance plots and Monte Carlo summaries (empirical FDR and FWER where applicable) across scenario factors.

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 recorded 1.5.9 local check completed in under 10 minutes with 0 errors, 0 warnings and 0 notes. Coverage was 100% across every R source file with SPTRENDS_TEST_PARALLEL=true. The recorded win-builder checks for 1.5.8 had 0 errors and 0 warnings, with submission and terminology notes. These are historical results; see cran-comments.md for the validation status of the current changes. 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 has been validated through an external battery covering the then-current 18 exported functions with correctness checks against known-truth simulations, and 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]. Zenodo. https://doi.org/10.5281/zenodo.21822842

Or, from R:

citation("sptrends")

Published workflows:

  • Gutiérrez-Hernández, O. and García, L.V. (2025). Uncovering true significant trends in global greening. Remote Sensing Applications: Society and Environment, 37, 101377. https://doi.org/10.1016/j.rsase.2024.101377
  • Gutiérrez-Hernández, O. and García, L.V. (2024). Robust Trend Analysis in Environmental Remote Sensing: A Case Study of Cork Oak Forest Decline. Remote Sensing, 16(20), 3886. https://doi.org/10.3390/rs16203886

Authors

  • Oliver Gutiérrez-Hernández (ORCID), Associate Professor, Department of Geography, University of Málaga.
  • Luis V. García (ORCID), Tenured Scientist, Institute of Natural Resources and Agrobiology of Seville (IRNAS), Spanish National Research Council (CSIC).

License

GPL (>= 3)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("sptrends")

1.6.3 by Oliver Gutiérrez-Hernández, 21 days ago


https://github.com/Olive-r/sptrends, https://olive-r.github.io/sptrends/


Report a bug at https://github.com/Olive-r/sptrends/issues


Browse source code at https://github.com/cran/sptrends


Authors: Oliver Gutiérrez-Hernández [aut, cre] (ORCID: , affiliation: Department of Geography , University of Málaga , Málaga , Spain) , Luis V. García [aut] , affiliation: Institute of Natural Resources and Agrobiology of Seville (IRNAS) , Spanish National Research Council (CSIC) , Seville , Spain)


Documentation:   PDF Manual  


GPL (>= 3) license


Imports terra, Matrix, parallel, stats, utils, graphics, grDevices, withr

Suggests fields, testthat, knitr, rmarkdown, ncdf4, Kendall, modifiedmk, rkt, robslopes, trend, zyp


See at CRAN