Skip to contents

lagprotest extends the Procrustean randomization test (PROTEST) to ordered multivariate series. It scans Procrustes concordance between two configurations across candidate temporal lags, tests each lag by permutation, and returns the lag profile, the lag of maximal concordance (minimum m²), a global p-value that accounts for scanning several lags and selecting the best one, and per-observation Procrustes residuals.

Three permutation schemes are available:

  • permutation = "phase" (default): phase-randomized surrogates of Y, which keep the autocorrelation of each variable and the cross-correlations among them. Recommended for the global p-value.
  • permutation = "cyclic": cyclic shifts of the full series, optionally with its time reversal, applied before lagging. Keeps temporal autocorrelation under the null, but the global p-value has low power.
  • permutation = "free": free permutation of rows within the overlapping window, as in vegan::protest(). Rows are assumed exchangeable, which autocorrelated series violate; Type I error can be severely inflated.

Installation

From r-universe:

install.packages("lagprotest",
                 repos = c("https://diogoprov.r-universe.dev",
                           "https://cloud.r-project.org"))

Or the development version from GitHub:

# install.packages("remotes")
remotes::install_github("diogoprov/lagprotest")

Example

library(lagprotest)

# Two 12-month series in which X leads Y by 2 months
sim <- simulate_lagged_series(n_times = 12, true_lag = 2, noise_sd = 0.5,
                              seed = 1)

fit <- lagged_protest(sim$X, sim$Y, lags = 0:4, seed = 1)
fit             # lag profile, optimal lag, per-lag and global p-values
plot(fit)       # m2 against lag, with the permutation null quantile
residuals(fit)  # per-observation residuals at the optimal lag

Report the global p-value (fit$p.global) for the optimal lag: it accounts for scanning several lags and selecting the best one, whereas the per-lag p-values do not.

Inputs can be matrices or data frames (rows = ordered time points, columns = variables) or dist objects, which are converted to principal coordinates.

Status

Under development. The method and its calibration are described in a manuscript in preparation.

License

MIT

Code of Conduct

Please note that the lagprotest project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.