daily_response() can now detrend the aggregated
climate series of each moving window with the smoothers used by
dplR::detrend(). Besides the existing "SLD",
dc_method accepts "Spline",
"Mean", "Ar" and "Friedman",
controlled by the new arguments dc_nyrs, dc_f,
dc_difference, dc_span, dc_bass
and dc_scale.
For strictly positive series the results are identical to
dplR::detrend() in dplR 1.7.8 and later, which scales a
prewhitened ("Ar") series by the mean of the original
series. The ARSTAN safeguards that dplR applies when a fitted curve is
not strictly positive are not reproduced, because they would silently
replace the selected method for climate variables that cross zero; such
windows return NA instead.
dc_difference = FALSE (the dplR default) performs
ratio detrending and is rejected for variables with negative values,
such as temperature in degrees Celsius. Use
dc_difference = TRUE for these.
The returned object gains a $detrending element
recording the detrending method and settings that were used.
Results for dc_method = "SLD" are
unchanged.
monthly_response(),
daily_response_seascorr() and
monthly_response_seascorr() gain the same climate
detrending, with the same arguments, defaults and checks as
daily_response(), and their results gain
$detrending. Results without detrending are unchanged, and
for dc_method = "SLD" the (partial) correlation surfaces
and $optimized_return are unchanged.
In the two seascorr functions the primary and the control windows
are detrended with the same settings by default. The new argument
dc_env_data_control replaces any of them for the control
windows. For example,
dc_method = "Spline", dc_difference = TRUE, dc_env_data_control = list(dc_difference = FALSE)
detrends temperature (primary) by differences and precipitation
(control) by ratios. Their $detrending has the elements
primary and control.
In all four functions the dplR methods are fitted in
chronological order of the years in the row names, so that results do
not depend on how the rows are sorted. This matters most for
"Ar", because the seascorr functions sort the years in
descending order before the analysis, and
$optimized_return_all uses the climate data in the order
they were supplied. "SLD" keeps the row order, as before;
its residuals do not depend on the direction of time.
dc_method = "Ar" changes cor_na_use or
pcor_na_use to "pairwise.complete.obs", with a
warning, unless it already excludes missing values.
daily_response() previously switched to
"complete.obs", which stopped with “no complete element
pairs” as soon as ratio detrending left a window empty (for example a
short precipitation sum that is zero in one year) and made the cluster
filter skip. For a single window both give the same
correlation.
All four functions share one check of the dc_*
arguments, so the arguments behave identically everywhere.
New vignette “Detrending_climate_data” describes the climate detrending methods and gives examples for monthly and daily data, ratio and difference detrending, prewhitening and the seascorr functions.
New vignette “Partial_correlations_seascorr” introduces
monthly_response_seascorr() and
daily_response_seascorr(), including the partial
correlations of the control variable (pcor_control),
$variance_partitioning, significance filters and climate
detrending.
daily_response_seascorr() and
monthly_response_seascorr() gain pcor_control.
With pcor_control = TRUE they also calculate, for every
window, the partial correlation of the response with the control
variable, controlling for the primary variable. This is what a run with
the primary and control data, and their settings, swapped returns. These
partial correlations are filtered with the same significance method and
settings as the primary ones, with the permutation methods against the
same permutations, and returned as $calculations_control
with $boot_lower_control, $boot_upper_control,
$significance_filter_control and a heatmap,
plot(x, type = 3). summary() adds the
strongest of them, its window and the value in the optimal window of the
primary variable. The primary results do not change.
The seascorr functions return $variance_partitioning
for the optimal window: the three simple correlations, both partial
correlations, the variance of the response explained by both climate
variables together, and how it splits into parts unique to each variable
and a shared part.
The significance filters of the two seascorr functions now share one implementation. Their results are unchanged.
aggregate_function = "SPEI" is a new option in
daily_response() and monthly_response(), and
for the primary and the control variable of
daily_response_seascorr() and
monthly_response_seascorr(). It calculates the Standardized
Precipitation-Evapotranspiration Index (SPEI) of every window from the
climatic water balance in the climate data, i.e. precipitation minus
potential evapotranspiration. The water balance is summed over the
window and standardised with a log-logistic distribution fitted by
unbiased probability weighted moments, the default of
SPEI::spei(). Each window is standardised against all years
of the climate data, before they are matched with the response. A
monthly window of K months ending in month m therefore has the value of
SPEI::spei(scale = K) in month m, the SPEI of a year does
not depend on the analysed years, and a window in a previous year is
standardised as the same window in the current year. Previous years,
climate detrending (by differences only), the significance filters, the
bootstrap and pcor_control work with SPEI as with the other
aggregations. Unlike them, SPEI does not skip missing values: a window
that includes a missing day or month is NA in that year,
with a warning, and cor_na_use or pcor_na_use
is changed to "pairwise.complete.obs" unless it already
excludes missing values. DOY 366 of non-leap years is skipped. The SPEI
package is not needed.
New function water_balance() calculates the daily or
monthly climatic water balance from precipitation and minimum and
maximum temperatures, with potential evapotranspiration from the
Hargreaves equation. Daily data use the extraterrestrial radiation of
each day of year; for monthly data the values are those of
SPEI::hargreaves().
New datasets from the black pine (Pinus nigra) site
Sežana in Slovenia (Izmir et al. 2024, Dendrochronologia 88, 126236):
SEZ_rwl, the raw ring widths of 41 cores from 21 trees
(1882–2021), and SEZ_daily_tmin,
SEZ_daily_tavg, SEZ_daily_tmax and
SEZ_daily_psum, the daily minimum, mean and maximum
temperatures and precipitation sums from E-OBS (1950–2020).
New vignette “SPEI_drought_index” shows, with the data from
Sežana, how to calculate the climatic water balance with
water_balance() and how to use
aggregate_function = "SPEI" with monthly and daily data,
subsets of years, climate detrending and partial correlations.
boot = TRUE, all four functions now report the
coefficient of the observed data (correlation, partial correlation, R
squared or adjusted R squared), as with boot = FALSE. This
value enters $calculations, the plots and the choice of the
optimal window. Earlier versions reported the mean of the bootstrap
replicates, which differs from the coefficient of the observed data and
depends on the random resamples. The confidence intervals in
$boot_lower and $boot_upper are unchanged.
Results with boot = TRUE therefore change, and the optimal
window can change with them.dc_method = "SLD" no longer recycles fitted values
when the climate series contains missing values. This now also applies
to monthly_response(),
daily_response_seascorr() and
monthly_response_seascorr().
$optimized_return_all keeps its year row names when
detrending is applied. This now also applies to
monthly_response(), daily_response_seascorr()
and monthly_response_seascorr(). In the seascorr functions,
dc_method = "SLD" previously also matched the primary and
control series of $optimized_return_all by row position
instead of by year and sorted the rows as text (“1”, “10”, “100”, …), so
values from different years were paired. They are now merged by
year.
With dc_method = "SLD",
$aggregated_climate (and
$aggregated_climate_primary and
$aggregated_climate_control) is now a matrix, as documented
and as without detrending. It used to be a data frame. The values are
unchanged.
Warnings about missing values, in all four functions, are no
longer triggered by scattered gaps that the window aggregation removes,
such as DOY 366 in non-leap years, or by gaps in years that are not
analysed, such as an incomplete recent year after the end of the
tree-ring record. They now report only the analysed years containing a
gap at least as long as the shortest window width, and name those years.
The seascorr functions report them separately for
env_data_primary and
env_data_control.
With aggregate_function = "sum", a window without
any value in a year is now NA, in all four functions. It
used to be 0, i.e. a dry window that was never observed. In
daily_response() and
daily_response_seascorr(), "min" and
"max" returned Inf and -Inf for
such windows, with a warning, and now also return NA.
Windows with some values are aggregated over the available days or
months, as before. Results for data without such gaps are
unchanged.
Without detrending, results are again exactly those of 1.2.17:
integer climate data aggregated with "sum",
"min", "max" or "median" were
returned as doubles in $optimized_return and
$aggregated_climate of daily_response(). The
values were unchanged.
remove_insignificant_method = "sidak" (all four
functions) estimated the effective number of tests only from windows
without a missing year. After dc_method = "Ar", which
removes the first years of nearly every window, that left a handful of
windows (3 to 41 in the examples tested), so the number of tests was
underestimated and the filter was too permissive. A year missing in
every window removed every window and switched the filter off.
Incomplete years are now left out instead of incomplete windows, and
windows are dropped only if fewer than 10 complete years would remain.
Results for complete data are unchanged.
$cross_validation of daily_response()
and monthly_response() returned NA for every
fold that contained a year without a climate value, for example a
missing year or the first years after dc_method = "Ar".
Such years are now left out before the folds are formed. Results for
complete data are unchanged.
The p values in $temporal_stability of
daily_response_seascorr() and
monthly_response_seascorr() ignored the degree of freedom
spent on the control variable (nrow(dataset_temp - 2)
evaluated to the number of rows), so they were slightly too small. They
now use the number of complete years minus one, as
psych::corr.p() asks for partial correlations. This changes
these p values for every analysis.
The p values in $temporal_stability of
monthly_response() ignored exact = FALSE,
which was misspelled in the calls to cor.test(), so for
cor_method = "kendall" and "spearman" they
were exact p values whenever the data had no ties. They are now the
asymptotic p values, as in daily_response(). Pearson
correlations are not affected.
The documentation of pcor_na_use in the seascorr
functions gave "pairwise.complete.obs" as the default. The
default is "everything", as in earlier versions.
boot_ci_type = "bca" with boot_n
smaller than the number of analysed years gave only NA
intervals without explanation, because boot::boot.ci()
cannot estimate bca intervals from so few replicates. All four functions
now give a warning that names the boot_n needed. The
documentation of boot_ci_type now lists the available
interval types; "stud" was listed but is not
available.
critical_r() derived its threshold from the Pearson
sampling distribution regardless of which coefficient was actually
computed, and the criteria that rely on it — "alpha",
"fdr_BH", "fdr_BY" and "sidak" —
inherited that assumption. Kendall’s tau has a different null
distribution, so those criteria were far too strict on tau surfaces and
discarded genuine climate responses.
critical_r() gains a cor_method argument,
accepting "pearson" (the default, unchanged),
"spearman" (which uses the same transformation applied to
ranks) and "kendall". For Kendall’s tau the critical value
now follows the normal approximation with variance 2(2n + 5) / 9n(n −
1), the same null distribution stats::cor.test() uses when
exact = FALSE. The four response functions pass their
cor_method or pcor_method through, and the
false discovery rate criteria build their p values from the matching
distribution.
Results change for anyone using
cor_method = "kendall" or
pcor_method = "kendall" together with
remove_insignificant = TRUE. More windows are now
retained, correctly so. The magnitude depends on sample size: the old
threshold was 41 per cent too strict at n = 24 and 47 per cent too
strict at n = 73. On one test surface the "sidak" threshold
fell from 0.443, which retained no windows at all, to 0.276, against
0.297 from the permutation test that had always been correct.
"maxstat" and "cluster" were never
affected, because they build their null by permuting the statistic
actually being computed and so make no distributional assumption. They
remain the most reliable choice for rank correlations, and for partial
correlations with Kendall’s tau in particular, where the
effective-sample-size adjustment used by the analytic criteria is itself
an approximation.
The logical argument remove_insignificant_boot has been
removed and replaced by remove_insignificant_method, which
selects the criterion applied when
remove_insignificant = TRUE. This keeps one switch for
whether to filter and one for how, rather than adding an argument per
method.
remove_insignificant_method accepts:
"alpha" — per-window significance threshold. This is
the default and reproduces the behaviour of earlier versions."boot" — the bootstrap confidence interval excludes
zero. Requires boot = TRUE."fdr_BY" — false discovery rate, Benjamini–Yekutieli.
Valid under arbitrary dependence between windows."fdr_BH" — false discovery rate, Benjamini–Hochberg.
Valid under positive dependence and less conservative than BY."maxstat" — max-statistic permutation test."sidak" — Šidák correction on the effective number of
tests."cluster" — cluster-extent inference.The "alpha" and "boot" criteria are applied
one window at a time and therefore do not account for how many windows
were screened. The remaining criteria do.
"maxstat" builds a null distribution of the largest
absolute correlation obtained anywhere in the search by repeatedly
shuffling the response, and retains only windows exceeding the resulting
threshold. The number of permutations is set by the new argument
perm_n (default 999). It makes no distributional
assumptions, but requires perm_n re-evaluations of the
whole search. It is available for method = "cor" and for
method = "lm" with a single predictor, but not for
method = "brnn", where the permutation would require
refitting the network at every window.
"sidak" targets the same family-wise error rate as
"maxstat" but estimates it analytically. Because
neighbouring windows overlap, the number of windows screened greatly
overstates the number of independent tests. The effective number is
obtained from the eigenvalues of the correlation matrix among the
screened windows, following Li and Ji (2005), and a Šidák correction is
applied to that number rather than to the nominal count. The correlation
matrix has rank at most the number of years, so its non-zero eigenvalues
are computed from a small years-by-years matrix; no permutations are
needed and the criterion is effectively instantaneous. It is available
for every method, including method = "brnn", where
"maxstat" cannot run.
"sidak" is an approximation to "maxstat".
Across 54 combinations of site and climate variable the two thresholds
agreed to within 0.016 on average, with a maximum discrepancy of 0.038,
for ordinary correlations; for partial correlations the corresponding
figures were 0.020 and 0.046. The approximation is close to exact for
strongly autocorrelated variables such as temperature and tends to be
slightly permissive for weakly autocorrelated variables such as daily
precipitation, because the eigenvalue approach does not represent
temporal autocorrelation. "maxstat" is therefore preferable
for final results, while "sidak" suits exploratory work and
method = "brnn".
"cluster" is cluster-extent inference, adapted from
neuroimaging. The surface is thresholded at the new argument
cluster_threshold, connected regions of supra-threshold
windows are identified, and each region’s mass, the sum of absolute
correlations inside it, is compared against the largest mass arising in
permuted surfaces. It controls the family-wise error rate over
clusters rather than over windows, so it establishes that a
region contains signal without identifying which windows within it carry
that signal. It is available for method = "cor", because
the permuted statistic has to be laid out on the same surface as the
observed one.
"cluster" has little discriminating power on tree-ring
response surfaces, and is provided mainly for completeness and
comparison. A real climate signal forms one large connected region whose
mass greatly exceeds anything the permuted surfaces produce, so on daily
surfaces every cluster that forms is retained and the permutation step
never rejects; the number of windows kept is then set by
cluster_threshold rather than by the data. On a daily
search of about 3,400 windows, raising the threshold from the nominal
critical correlation to 0.45 reduced the retained area from 95 to 40 per
cent while the max-statistic threshold on the same data stayed near
0.36. On the much smaller monthly surfaces the permutation occasionally
does reject a cluster, but not stably between runs.
"maxstat" or "sidak" are preferable when the
question is which windows carry signal.
For the seascorr functions the degrees of freedom account for the control variable throughout, and the effective number of tests is estimated from the primary windows.
Applies to daily_response(),
monthly_response(), daily_response_seascorr()
and monthly_response_seascorr().
The returned list element $boot_ci_filter has been
renamed $significance_filter. It records which method was
applied, the criterion used, and how many matrix cells were retained or
removed. "alpha", "sidak",
"maxstat" and "cluster" also report the
threshold applied, as critical_r. For
"maxstat" it additionally reports the observed maximum
(observed_max_r), the global p value
(p_global), the number of permutations, and the number of
windows searched. For "sidak" it reports the effective
number of tests (effective_tests), the per-test
significance level (alpha_per_test), and the number of
windows searched. For "cluster" it reports the forming
threshold used (forming_threshold), the critical cluster
mass (cluster_mass_critical), how many clusters formed and
how many were retained (n_clusters_formed,
n_clusters_retained), the largest observed mass, and the
max-statistic threshold from the same permutations
(maxstat_critical_r), so the two criteria can be compared
directly.
When "maxstat" removes every window, the message now
reports the global p value and states that no correlation exceeded what
the search alone would produce, rather than suggesting that the
threshold be relaxed.
Missing values are no longer handled silently. All four functions now
default to cor_na_use = "everything" or
pcor_na_use = "everything", so a window overlapping a
missing value returns NA and the user decides explicitly
how to proceed. Previously the seascorr functions defaulted to
pcor_na_use = "pairwise.complete.obs" and quietly computed
over the available years, which was inconsistent with
daily_response() and monthly_response().
All four functions now warn when the climate data contain missing
values and the chosen rule does not handle them, naming the argument to
set. Previously only daily_response() did so.
For method = "cor" and for the seascorr partial
correlations, a window whose bootstrap produces any missing replicate is
now NA in all four functions, rather than being computed
from the remaining replicates. For method = "lm" and
method = "brnn" the opposite rule applies, again in all
four functions: a missing replicate there indicates a model fit that did
not converge rather than missing data, so it is dropped and the window
is computed from the replicates that succeeded.
Windows are still aggregated with na.rm = TRUE, so a
window with a small number of missing days is aggregated from the days
that are present.
The bootstrap for method = "cor", and for the partial
correlations in the seascorr functions, is now computed by matrix
algebra rather than by resampling loops. Each replicate correlation is
obtained from weighted sums over the original observations, so a whole
window’s replicates come from a single matrix product.
Approximate speedups on a search of about 6500 windows with 1000 replicates:
| correlation | before | after |
|---|---|---|
| Pearson | ~3 min | ~4 s |
| Spearman | ~9 min | ~45 s |
| Kendall | ~19 min | ~55 s |
Confidence intervals of type "norm", "perc"
and "basic" are now computed directly from the replicates
and reproduce boot::boot.ci() exactly. The
"bca" type, and the "lm" and
"brnn" methods, are unchanged and continue to use
boot::boot().
Results will differ slightly from earlier versions even with the same seed. Resample indices are now drawn once and shared by every window, instead of being redrawn for each window. Differences are of the order of Monte Carlo error (typically below 0.02 in correlation units). The shared resamples mean all windows are evaluated on the same resampled years, so bootstrap surfaces are internally comparable rather than each window carrying independent noise.
cor_na_use and pcor_na_use are honoured by
the new code path, including "everything", under which any
replicate that draws a missing value returns NA, matching
stats::cor().
boot_ci_type = "stud" is now rejected, with a
message explaining that studentized intervals require a variance
estimate for each bootstrap replicate, which is not available for
correlation statistics. Previously this combination was accepted, ran
the full search, and then failed part way through with the uninformative
error
number of items to replace is not a multiple of replacement length.
boot_ci_type is validated once at the start of the call, so
an invalid value now fails immediately rather than after minutes of
computation.
When remove_insignificant = TRUE, the
confidence-interval matrices $boot_lower and
$boot_upper are now masked with the same criterion as
$calculations. Previously they retained values for windows
the filter had removed, so plotting intervals over a filtered surface
could suggest significance for windows that had in fact been
rejected.
Kendall, M. G. (1938). A new measure of rank correlation. Biometrika 30, 81–93.
Li, J. and Ji, L. (2005). Adjusting multiple testing in multilocus analyses using the eigenvalues of a correlation matrix. Heredity 95, 221–227.
Nichols, T. E. and Holmes, A. P. (2002). Nonparametric permutation tests for functional neuroimaging: a primer with examples. Human Brain Mapping 15, 1–25.
quantile_prob for daily_response() and
monthly_response()quantile_prob_env_data_primary and
quantile_prob_env_data_control for
daily_response_seascorr() and
monthly_response_seascorr()daily_response(),
daily_response_seascorr(), monthly_response(),
and monthly_response_seascorr().number_previous_years, which
allows users to include more than one previous year in response-function
analyses.previous_year now acts as the main switch
for previous-year analyses. If previous_year = FALSE,
previous-year settings are ignored and the analysis is performed for the
current year only.day_interval or
month_interval while previous_year = FALSE,
the interval is ignored with a warning and the analysis is performed for
the current year only.Y-3, Y-2, Y-1, and
Y, with year separators where appropriate.brnn method. Occasional
unstable BRNN model fits are now handled more safely, returning
NA for failed windows instead of interrupting the full
analysis.