Chronology¶
Averaging detrended series into a site chronology, with optional autoregressive modelling and variance stabilization. See the Building chronologies guide.
chron¶
Build a mean-value chronology from ring-width indices.
Averages the series (detrended RWI) year by year into a standard chronology, optionally prewhitening each series with an AR model first to also produce a residual chronology. Mirrors dplR's chron().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rwi_data
|
pandas dataframe
|
detrended ring-width indices (e.g. from dpl.detrend()). |
required |
biweight
|
boolean
|
average with Tukey's biweight robust mean if True, else the arithmetic mean. |
True
|
prewhiten
|
boolean
|
prewhiten each series with an AR model to also build a residual chronology. |
False
|
plot
|
boolean
|
plot the chronology. |
True
|
ar_max
|
int
|
maximum AR order considered when prewhiten is True. To reproduce dplR's
chron() exactly, pass ar_max=floor(10*log10(n)) and first_aic_min=False.
( |
10
|
aic
|
boolean
|
when prewhiten is True, select the AR order by AIC up to ar_max; if False, fit a fixed AR of order ar_max. |
True
|
ar_method
|
(yw, burg, ols)
|
AR estimator for prewhitening (case-insensitive). "yw" (Yule-Walker) matches R's ar() default; "burg" is ARSTAN's estimator; "ols" matches R's ar(method="ols"). |
"yw"
|
first_aic_min
|
boolean
|
AR order-selection rule when aic is True. True takes the first local AIC minimum (ARSTAN's rule, dplPy's package default); False takes the global AIC minimum, which is what R's ar() and dplR's chron() do. |
True
|
backcast
|
boolean
|
when prewhiten is True, fill each series' first |
False
|
stabilize
|
(None, rbar, spline, both)
|
if set, also variance-stabilize each chronology and return the stabilized
versions in extra *_vsc columns (see Notes). Method families are as in
|
None
|
stabilize_kwargs
|
dict
|
extra keyword arguments forwarded to |
None
|
ci
|
boolean
|
also compute a bootstrap confidence interval for the standard chronology,
adding |
False
|
conf
|
float
|
confidence level, used when |
0.95
|
R
|
int
|
number of bootstrap replicates per year, used when |
100
|
seed
|
int or None
|
seed for the |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
pandas dataframe
|
a mean-value chronology indexed by year (the full year index of
|
Notes
Prewhitening. Each series is whitened with autoreg._prewhiten(), the
package-wide prewhitening (Yule-Walker, ar_max=10, first local AIC
minimum). This differs from R's ar()/dplR, which take the global AIC
minimum up to floor(10*log10(n)); pass first_aic_min=False and
ar_max accordingly to reproduce dplR.
Variance stabilization (stabilize). The standard chronology is
stabilized with the rbar of the standard RWI matrix and the residual chronology
with the rbar of the residual matrix; both restandardize to the full period
(see stabilize_chron()). For the re-reddened ARSTAN chronology, use
chron_ars() with stabilize=.
Examples:
>>> import dplpy as dpl
>>> rwi_data = dpl.detrend(dpl.readers("../tests/data/csv/file.csv"))
>>> dpl.chron(rwi_data)
>>> dpl.chron(rwi_data, prewhiten=True)
References
.. [1] https://opendendro.github.io/dplPy/reference/chronology/#chron
chron_stabilized¶
Build a variance-stabilized mean-value chronology.
Scales a mean-value chronology by the square root of the effective independent
sample size Neff = n(t) / (1 + (n(t)-1) rbar(t)), where n(t) is the sample depth
and rbar(t) the mean pairwise interseries correlation, computed over windows of
length window_length. Port of dplR's chron.stabilized().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rwi_data
|
DataFrame
|
detrended ring-width indices. |
required |
window_length
|
int
|
window length over which rbar values are calculated. ( |
50
|
min_seg_ratio
|
float
|
minimum ratio of non-NA values to window length for a series to count in an Neff calculation (⅓ matches dplR's chron.stabilized()). |
1/3
|
biweight
|
boolean
|
average with Tukey's biweight robust mean if True, else the arithmetic mean. |
True
|
running_rbar
|
boolean
|
also return the running rbar values in the output (only for method='running_rbar'). |
False
|
method
|
str
|
the variance-stabilization method (case-insensitive):
|
'running_rbar'
|
spline_period
|
(int, float or None)
|
stiffness for method='spline'. An int > 1 is a fixed spline wavelength in
years; a float in (0, 1) is a fraction of the chronology length; None uses
the 67% spline ( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
stabilized_chron |
pandas dataframe
|
a variance-stabilized mean-value chronology indexed by year, with columns
|
Notes
This function scales the departures and adds the grand mean back, as dplR
does; stabilize_chron() instead restandardizes to the input chronology's
full-period mean and SD, so the two differ slightly in level and scale.
Examples:
>>> import dplpy as dpl
>>> data = dpl.readers("../tests/data/csv/file.csv")
>>> dpl.chron_stabilized(data, window_length=60, min_seg_ratio=0.4)
References
.. [1] https://rdrr.io/cran/dplR/man/chron.stabilized.html .. [2] https://opendendro.github.io/dplPy/reference/chronology/#chron_stabilized
stabilize_chron¶
Variance-stabilize an already-built chronology.
Scales the departures of a chronology you already built with chron() or
chron_ars() (standard, residual, or ARSTAN) to remove time-varying
variance. Unlike chron_stabilized(), which takes the RWI matrix and builds
its own standard chronology, this takes the finished chronology.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chron
|
Series or DataFrame
|
the chronology to stabilize. A Series is used directly; a DataFrame (e.g.
chron()/chron_ars() output) uses |
required |
method
|
(rbar, spline, both)
|
required, explicit (case-insensitive):
|
"rbar"
|
column
|
str
|
which column to stabilize when |
"std"
|
rwi
|
DataFrame
|
the source ring-width-index matrix (for the |
None
|
rbar
|
float
|
precomputed scalar rbar (for |
None
|
running_rbar
|
array - like
|
precomputed per-year running rbar (for |
None
|
samp_depth
|
array - like
|
per-year sample depth. Taken from the DataFrame's |
None
|
rbar_mode
|
(running, constant)
|
running rbar (Frank RUNNINGr) or a single time-constant rbar (Osborn/Briffa MEANr). |
"running"
|
window_length
|
(int, float)
|
running-rbar window length (default 50; must be shorter than the
chronology) and minimum overlap ratio (as in chron_stabilized).
( |
50
|
min_seg_ratio
|
(int, float)
|
running-rbar window length (default 50; must be shorter than the
chronology) and minimum overlap ratio (as in chron_stabilized).
( |
50
|
spline_period
|
(int, float or None)
|
spline stiffness for the |
None
|
f
|
float
|
spline frequency response (50% amplitude cutoff). |
0.5
|
clip_negative
|
bool
|
clamp the stabilized chronology at >= 0. Off by default: a chronology centered at zero (difference detrending, or a residual chronology) has legitimate negative departures, and clamping them floors the series at 0. Set True only for a positive ratio/index chronology where a negative value is not meaningful. |
False
|
return_info
|
bool
|
also return the diagnostics (rbar used, N_eff, sample depth). |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
indexed by year, with the stabilized chronology in column |
Notes
Both families restandardize to the input chronology's full-period mean and SD,
so the stabilized chronology stays on the scale you already had. dplR's
chron.stabilized (ported as chron_stabilized()) instead scales the
departures by sqrt(n_eff * rbar) and adds the grand mean back, which puts
the chronology on the variance of an infinitely replicated chronology
(Osborn, Briffa & Jones 1997). The two flatten the same variance trend and
differ only by a uniform level and scale (on ca533: slope 1.11, offset -0.12,
residual below 0.002), which matters for anything read off absolute index
values but not for correlation-based uses. For the ARSTAN chronology, stabilization must precede re-reddening, so use
chron_ars(stabilize=...) rather than calling this on an already re-reddened
series.
References
Osborn, Briffa & Jones (1997) Dendrochronologia 15, 89-99. Frank, Esper & Cook (2006) TRACE 4, 56-66.
chron_ars¶
Build ARSTAN standard, residual, and re-reddened chronologies.
Produces the three ARSTAN chronologies of Cook (1985) from a set of detrended ring-width indices:
- std: the standard chronology, the (robust) mean of the RWI series with no autoregressive modeling.
- res: the residual chronology, each series prewhitened by an AR(p) model of the pooled order, averaged, then prewhitened once more to order p (near-white).
- ars: the ARSTAN chronology, the pooled red-noise persistence reintroduced
by re-reddening;
ars_methodsets how (see Notes).
The pooled AR order p is selected by AIC from an autocovariance accumulated
across all series. Analog of dplR's chron.ars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rwi_data
|
pandas dataframe
|
detrended ring-width indices (e.g. from |
required |
biweight
|
boolean
|
aggregate series with Tukey's biweight robust mean if True, else the arithmetic mean. |
True
|
ar_max
|
int
|
maximum AR lag considered when selecting the pooled AR order.
( |
10
|
first_aic_min
|
boolean
|
select the order at the first local AIC minimum (ARSTAN's and dplR's rule)
if True, else the global AIC minimum. With True, a pooled AIC that never
turns back up within |
True
|
verbose
|
boolean
|
print the pooled ACF, AR coefficients, AIC, and selected order. |
True
|
prewhiten_method
|
str
|
estimator for the per-series (and residual-chronology) AR(p) whitening,
case-insensitive: |
"ar.yw"
|
ars_method
|
str
|
how the re-reddened ARSTAN chronology is built (see Notes): |
"arstan"
|
backcast
|
boolean
|
backcast the initial values of each AR whitening and re-reddening step
(ARSTAN's |
True
|
stabilize
|
(None, rbar, spline, both)
|
if set, also variance-stabilize each chronology and return the stabilized
versions in extra |
None
|
stabilize_kwargs
|
dict
|
extra keyword arguments forwarded to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
out |
pandas dataframe indexed by year with columns 'std', 'res', 'ars', and
|
'samp_depth'. When |
Notes
ARSTAN chronology (ars_method). ARSTAN whitens every series to the
pooled order p, averages them, whitens that mean once more (the residual
chronology, albino1), and then puts the pooled persistence back into the
residual chronology (commie1): ars = redden(res, phi_pooled). That is
ars_method="arstan" (default), and also what the dplR development version
computes. Released dplR <= 1.8.0 instead re-reddened each prewhitened series
and averaged those; ars_method="dplr" reproduces it. Re-reddening and
averaging do not commute when sample depth changes through time, so the two
differ; the std and res columns, the pooled AR order, and the
prewhitening are identical either way.
Backcasting (backcast). An AR(p) filter has no data for its first p
lagged terms. With backcast=True (default) those pre-sample values are
estimated by running the model in reverse from the start of each series
(ARSTAN's bckcst), so the residual and ARSTAN chronologies are full length
(no leading NaN); the first p years of each series are model-based, so
treat them as slightly less certain. With backcast=False the first p
residuals of every series are NaN, as in dplR's chron.ars. Because series
start in different years, that changes the chronology res (and ars)
in every year where some series is within its first p years -- not only
the first p years of the chronology. dplR's postAR took its
re-reddening initials from the end of the record; dplPy follows ARSTAN here
too, so ars differs from dplR in roughly the first 10 years of each
series' contribution.
Variance stabilization (stabilize). std_vsc uses the rbar of the
standard RWI matrix; res_vsc the rbar of the residual matrix; ars_vsc
is the stabilized residual chronology re-reddened ("arstan") or the
reddened chronology stabilized with the residual rbar ("dplr"). Each
column restandardizes to its own full period (see stabilize_chron()).
Examples:
>>> import dplpy as dpl
>>> rwi = dpl.detrend(dpl.readers("../tests/data/csv/file.csv"), plot=False)
>>> dpl.chron_ars(rwi)
References
.. [1] https://rdrr.io/cran/dplR/man/chron.ars.html .. [2] Cook, E.R. (1985) A time series analysis approach to tree-ring standardization. PhD dissertation, University of Arizona. .. [3] https://opendendro.github.io/dplPy/reference/chronology/#chron_ars
autoreg¶
Fit the best-fit AR model to a series and return its parameters.
Selects the AR order up to max_lag by AIC and returns the fitted model parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Series
|
an individual series representing tree rings/widths. |
required |
ar_max
|
int
|
maximum AR order considered when selecting the model. ( |
10
|
aic
|
bool
|
select the AR order by AIC up to ar_max; if False, fit a fixed AR of order ar_max. |
True
|
method
|
(yw, burg, ols)
|
AR estimator. "yw" (Yule-Walker) is dplPy's package default and matches R's ar() default and dplR; "burg" is the estimator ARSTAN and COFECHA use; "ols" matches R's ar(method="ols"). |
"yw"
|
first_aic_min
|
bool
|
when aic is True, True takes the first local AIC minimum (ARSTAN's rule, dplPy's package default), False the global minimum. NOTE this default differs from R's ar() / dplR, which take the global minimum. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
params |
array
|
parameters of the best-fit AR model, as [intercept, phi_1, ..., phi_p]. |
Examples:
>>> import dplpy as dpl
>>> data = dpl.readers("../tests/data/csv/file.csv")
>>> dpl.autoreg(data["series name"])
References
.. [1] https://opendendro.github.io/dplPy/reference/chronology/#autoreg
ar_func¶
Prewhiten series with a best-fit AR model.
Fits each series to the best-fit autoregressive model and returns the residuals plus the series mean (the prewhitened series).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame or Series
|
ring widths from dpl.readers(), or a single series taken from one. |
required |
ar_max
|
int
|
maximum AR order considered when selecting the model. ( |
10
|
aic
|
bool
|
select the AR order by AIC up to ar_max; if False, fit a fixed AR of order ar_max. |
True
|
method
|
(yw, burg, ols)
|
AR estimator. "yw" (Yule-Walker) is dplPy's package default and matches R's ar() default and dplR; "burg" is the maximum-entropy estimator ARSTAN and COFECHA use; "ols" matches R's ar(method="ols"). |
"yw"
|
first_aic_min
|
bool
|
when aic is True, True takes the first local AIC minimum (ARSTAN's rule, dplPy's package default), False the global minimum. NOTE this default differs from R's ar() / dplR, which take the global minimum. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
res |
pandas dataframe or series
|
the prewhitened data (residuals plus mean), matching the input type. The
first |
Examples:
>>> import dplpy as dpl
>>> data = dpl.readers("../tests/data/csv/file.csv")
>>> dpl.ar_func(data["series name"])
References
.. [1] https://opendendro.github.io/dplPy/reference/chronology/#ar_func