srr tags in the code
and tests (84 standards met, 39 not applicable, each with a reason).lagged_protest() gives a message when a linear time trend explains, on
average, more than 70% of the variance of the columns of X or Y,
advising to remove it: the null distributions assume stationary series.lagged_protest() gives a message when X or Y is a ts, zoo or
xts object, saying that its time attributes are not kept and that lags
are counted in rows.permutation = "cyclic", an nperm that is not NULL, NA or a
single whole number is now an error; before, it was silently ignored.plot() and autoplot() is labeled "Lag (rows)".@noRd).codemeta.json.X or Y are now an error with an informative
message; before, they stopped lagged_protest() with an internal error.
Missing values (NA, NaN) were and remain an error.difftime or
units) are used as plain numbers, with a message; list, factor and
character columns give an error that names them.plot() and residuals() methods gain examples. The documentation
states that rows must form a regular, complete series in time order,
that period and lags are counted in rows with no calendar, that
character arguments are case-sensitive, that residuals are on the scale
of the compared configurations, and how lagged_protest() relates to
vegan::protest().vegan::protest() on the varespec/varechem data.LAGPROTEST_EXTENDED_TESTS is "true" (as in the GitHub
Actions workflows) and described in CONTRIBUTING.md.First version prepared for CRAN.
Breaking change: the element n_perm of the object returned by
lagged_protest() is renamed nperm, the name of the argument and of the
column in $profile. Code that reads fit$n_perm must use fit$nperm.
The package description and the documentation of lagged_protest() cite
Jackson (1995) and Peres-Neto and Jackson (2001), the papers that
introduced and evaluated PROTEST.
The default of stat in lagged_protest() is now NULL, which uses
"minP" for the phase and free schemes and "raw" for the cyclic scheme.
With the cyclic scheme, many shifts tie at the smallest per-lag p-value,
and in simulations the "minP" global p-value could not fall below 0.05
with up to 96 time points, so the test never rejected. Requesting
stat = "minP" with the cyclic scheme now gives a warning, instead of a
message, when p < 0.05 is unattainable. Results of the cyclic scheme
without an explicit stat change accordingly. The documentation now
presents the cyclic scheme as a conservative check, notes that Holm
correction across lags is unattainable under it, and its example no
longer uses stat = "z".
lagged_protest() gains two preprocessing options, both off by default,
applied to X and Y after truncation to whole cycles and before
standardization:
deseason = "monthly" subtracts the mean of each position in the cycle
of length period (at least two whole cycles required). It restored
the Type I error of the phase scheme for shared seasonal cycles of any
shape in simulations.prewhiten = "prais" applies Prais-Winsten AR(1) prewhitening to every
column, keeping all rows; the coefficients are returned in rho. It
restored the Type I error for strongly autocorrelated non-seasonal
series, but can be liberal combined with deseason when an abrupt
cycle varies among years and the noise is strongly autocorrelated.prewhiten on a seasonal series without
deseason, and a message recalls the sinusoidal assumption of the
phase scheme when the series spans a single cycle of period.print() reports the preprocessing, and ar1 now describes the series
as analyzed. New article "Seasonality and autocorrelation".simulate_lagged_series() gains waveform, spread, amp_sd_vars and
amp_sd_cycles. The default seasonal signal (waveform = "circle",
unchanged, so earlier seeds give the same series) is a degenerate case:
its variables trace a circle, a shift in time is a rotation that
Procrustes analysis absorbs, and calibration estimated with it is a best
case. The new waveforms ("sine", "harmonics", "sawtooth", "pulse")
give each variable the same periodic shape with phase offsets set by
spread, and the amplitude can vary among variables and among cycles.
Documentation: the phase scheme assumes that a seasonal cycle shared by
X and Y is close to sinusoidal. With a shared sawtooth or pulse cycle
its Type I error was 0.10 to 0.34 in simulations; removing the mean of
each position in the cycle from both series, when they span several whole
cycles, restored it. See ?lagged_protest and the article "Simulating
lagged series", whose calibration study now uses stat = "z" (with 99
surrogates, "minP" was too conservative to show the power claimed in the
text).
Bug fix (changes results): the global test now treats the observed result and the permutations alike, so it is exact when the permutations are exchangeable with the observed series.
stat = "z", each permuted m² is now standardized by the mean and
SD of the other values at its lag, the observed among them (leave one
out). Before, every permuted value took part in its own standardization
and the observed did not, which made the test liberal. The observed z
in the profile is unchanged; Z, A and the corrected RV change
slightly, because each permutation may select a different lag.stat = "minP", each permuted m² is converted to a p-value by its
rank among the observed and permuted values, as the observed p-value
already was. Before, the observed value was left out, which made the
test conservative.permutation = "free", the full series of Y is now permuted
before lagging, as in the other schemes. Before, each permutation was
restricted to each lag's window, which made the permuted m² more
correlated across lags than the observed ones and the global test
liberal for every stat. Per-lag p-values were valid under either
version, but their values change.With independent iid series (n = 12, lags -3 to 3, free scheme, 199
permutations, 5000 replicates), the rejection rate at P < 0.05 of the
"z" scan fell from 0.056 to 0.046, for an attainable size of 0.045.
The bug was found in a critical review of the method preprint. The liver
example article, which computes the balanced global p-values by hand, was
updated in the same way; its values change only in the fourth decimal.
The documentation of nperm gives the minimum number of permutations for
stat = "minP" (100 per lag tested).
New elpa_blocks() builds monthly environment (temperature, salinity,
Secchi depth) and juvenile fish blocks for the Patos Lagoon estuary from
the PELD-ELPA beach-seine survey (1996–2016). The archive (CC BY-NC 4.0)
is read from a local copy or downloaded from the SiBBr IPT rather than
shipped with lagprotest.
Breaking: lagged_protest() gains stat = c("minP", "z", "raw"),
the scan statistic used for the global p-value and the optimal lag, with
"minP" as the new default. "minP" compares lags by their per-lag
p-values (Westfall and Young's minP), "z" by m² standardized by its
own null distribution, and "raw" by m² itself, the behavior of
earlier versions. All three use the same permutations and are valid
global tests; "raw" favors the longest lags, which rest on fewer rows,
and has less power for short lags. Use stat = "raw" to reproduce
results from version 0.6 and earlier. The liver example article keeps
"raw" to match the analysis submitted for publication.
New lakewa_blocks() builds monthly environment, phytoplankton and
zooplankton blocks for Lake Washington (1962–1994) from
lakeWAplanktonRaw in the MARSS package (now in Suggests). The data are
read from MARSS rather than shipped with lagprotest.
lagged_protest() now returns continuous measures of evidence and
strength computed from the same permutations as the p-values: per-lag z
and a in the profile, and in effect the lag of the largest z, its
standardized position Z among the permuted maxima, and the
chance-corrected A and RV coefficient. The permuted RV values are kept in
null.rv. print() and summary() show them, and
lagged_protest_pairs() adds Z and A as columns.
lagged_protest() now reports the mean lag-1 autocorrelation of each
series (ar1), raw and after removing the seasonal harmonics, as a
description of how close the data are to the conditions under which the
phase scheme was liberal in simulations.
lagged_protest() now issues a message when the smallest attainable
p-value is 0.05 or more (e.g., the cyclic scheme without mirror at
n = 12).
The documentation of lagged_protest() and the permutation-schemes
article cite Manly and Navarro Alberto (2020) for the p-value formula and
the recommended number of permutations, and pp. 83–84 for the
max-statistic adjustment of correlated tests.
The liver example article now checks the lag scan with two statistics that weigh all lags equally (minP and the standardized m²), computed from the surrogates stored in each fit. The raw minimum m² favors long lags, and the climate–histochemistry delay is weaker under the balanced statistics.
The permutation loop is about five times faster: m² and the RV
coefficient of each permuted pair are now computed directly from the
singular values of the cross-product matrix instead of calling
vegan::procrustes() for every permutation. Results with a fixed seed
are unchanged (p-values and lags identical, m² equal to floating-point
rounding); a new regression test guards them.
lagged_protest() and simulate_lagged_series() now check their
arguments and name the offending one in the error: nperm and seed must
be single whole numbers, lags must not be empty, mirror,
bidirectional and scale must be TRUE or FALSE, and the counts,
period, amplitude and noise_sd of the simulator must be valid.
Previously, nperm = 2.5 was silently truncated and an invalid seed
produced an unrelated warning.
The minimum-P message no longer suggests mirror = TRUE when the cyclic
scheme already uses it.
The fits stored by lagged_protest_pairs() now carry a call that names
the data sets and shows the values of lags, bidirectional and seed,
so print() is informative and eval(fit$call) reproduces the fit.
lagged_protest_pairs() gains the columns effect_lag (the lag to which
Z and A refer, which can differ from optimal_lag) and RV.
summary() now returns an object of class "summary.lagged_protest"
(still a data frame) whose print() method shows the global p-value,
the effect measures and the autocorrelation below the profile; before,
these were attributes that were not printed.
print() notes when the optimal lag (smallest m²) and the effect lag
(largest z) differ, and no longer runs the lines of a long call
together.
The documentation of lagged_protest(), the "Get started" vignette and
the README now explain that the smallest m² favors the longest lags
scanned, describe the effect measures and ar1, and point to
lagged_protest_pairs(), autoplot() and the liver example. Smaller
fixes: the mirror element is documented, n_perm is described as the
same at every lag, and the per-lag adjustment that
lagged_protest_pairs() cannot set is noted.
New inst/CITATION, so citation("lagprotest") gives the Zenodo DOI.
as.data.frame() method returns the lag profile in long form, with
the permutation null quantile at each lag and a flag for the optimal lag.autoplot() method draws the lag profile with ggplot2 (suggested
package), marking the optimal lag and its global p-value as plot() does.dminutus_liver: monthly means of four hepatic modules and
of climate for the treefrog Dendropsophus minutus over one annual cycle
(Franco-Belussi et al. 2026, CC BY 4.0), with a new article analyzing it
with lagged_protest_pairs().lagged_protest_pairs() runs lagged_protest() on pairs of data sets
from a named list (by default all unordered pairs, both directions through
the sign of the lag) and returns one table, with the global p-values
adjusted across pairs ("BH" by default) and the fits kept in an
attribute.plot() now circles the optimal lag, filled when the global p-value is
below alpha, and prints the global p-value above the plot
(global = FALSE restores the previous plot).period argument with the full design (1000
replicates per scenario, 12–96 time points) are summarized in the
article "Choosing a permutation scheme": after truncation the global
p-value was calibrated up to AR(1) of 0.5 and liberal with strong
autocorrelation, as for series spanning complete cycles.period argument in lagged_protest(): when the seasonal cycle does
not divide the series length, both series are truncated to their first
floor(n / period) * period rows, so that the phase and cyclic schemes,
which treat the series as periodic with period n, remain calibrated.
In simulations (24–48 time points, cycle of 0.75 n), this brought the
Type I error of the global p-value from 0.46–0.94 back to 0.04–0.05 for
AR(1) noise of 0.3. Removing the seasonal component by harmonic
regression was also tested and left the test liberal, so it was not
added.The default permutation scheme is now permutation = "phase"
(phase-randomized surrogates), which retains power for the global p-value
across lags. Use permutation = "cyclic" for the previous behavior; the
phase scheme is random, so set seed for reproducible results.
lagged_protest() now defaults to p.adjust.method = "none", because
corrections such as Holm are often unattainable with the few permutations
of the cyclic scheme. $p.value is now the raw p-value at the optimal lag;
the adjusted value is in the new $p.adjusted element, and the number of
permutations in $n_perm. print() warns when p-values are unadjusted.
lagged_protest() returns a global p-value, $p.global, for the scan
across lags. It is a max-statistic test that compares the observed minimum
m² across lags with the minimum across lags under each permutation, and
so accounts for testing several lags and selecting the optimal one.
print() reports it below the optimal lag. Simulations showed that the
raw p-value at the optimal lag rejects 10–28% of the time (21–25% on
average) when the series are independent.permutation = "phase": phase-randomized surrogates of Y
that keep the amplitude spectrum of each column and the cross-spectra
among columns. Unlike cyclic shifts, surrogates do not reproduce the
observed alignment at other lags, so the global p-value keeps its power.p.adjust.method = "maxT" gives single-step max-statistic adjusted
p-values per lag.permutation = "free" now applies each permutation jointly to all lags,
as the max-statistic requires.First public release.
lagged_protest() scans Procrustes concordance between two ordered
multivariate series across candidate lags and tests each lag by
permutation. Two schemes are available: cyclic shifts of the full
series, optionally with time reversal (default), and free row
permutation as in vegan::protest(). P-values are adjusted across lags.
Accepts matrices, data frames or dist objects (converted by PCoA).print(), summary(), plot() and residuals() methods for the
lag profile, the optimal lag and per-observation Procrustes residuals.simulate_lagged_series() generates seasonal series with AR(1) noise
and a known lag, for calibration and power studies.