
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.
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.
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)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.
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.
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")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.
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:
GPL (>= 3)