pyhctsa.operations.scaling.fluctuation_analysis

pyhctsa.operations.scaling.fluctuation_analysis(x, q=2, wtf='rsrange', n_tau=50, k=1, lag=None)

Scaling exponents of a fluctuation function, from a single line and from a broken line.

Fluctuation analysis measures how the fluctuations F(tau) of the profile (the cumulative sum of the series) grow with the window length tau. For a scaling process F(tau) ~ tau**alpha, with alpha = H for fractional Gaussian noise with Hurst exponent H and alpha = 0.5 for any short-range correlated stationary process. The methods differ in how fluctuations are quantified in each window [1]. Much of the implementation follows the discussion of scaling methods in [1]; rescaled-range analysis goes back to Hurst [2], and DFA to Peng et al. [3] [4].

The profile is cut into non-overlapping windows of length tau, from the start and again from the end of the series, so that every sample is used [5]. With f the fluctuation in a window (set by wtf), F(tau) = mean(|f|**q)**(1/q) over the windows; for DFA, F is the q-th order fluctuation function of multifractal DFA [5]. Timescales are n_tau log-spaced values of tau, rounded to integers, with duplicates dropped. No window is shorter than tau_0 = max(5, 3p), where p is the number of parameters removed in each window (k + 1 for ‘dfa’ and ‘rsrangefit’, 2 for ‘rsrange’, 0 otherwise): a window only a few times longer than the detrending fit leaves little fluctuation, which biases F low at small tau [6].

Two fits are made to log F against log tau, each over its own range of timescales:

  • A single line from max(tau_0, 4 max(2, p) tau_c, N/50) to N/2, where tau_c is the 1/e decorrelation time of the analysed series (pyhctsa.utils.get_tau(), rule ‘ac1e’). Short-range correlation bends F(tau) over timescales up to several correlation times, so a slope fitted from small tau mixes the short-range correlation into the long-range exponent and can suggest long memory where there is none [7] [8]. Starting the fit beyond the correlation time reduces this; the remaining bias falls as the start of the range moves further beyond the correlation time, at the cost of a shorter, noisier fit [6]. The start grows with p (8 tau_c for DFA1, 12 tau_c for DFA2, 16 tau_c for DFA3) because the deviations from scaling at small tau are stronger for higher-order detrending [6]. The 1/e time does not register correlation spread thinly over many lags, as in anti-persistent series (for which tau_c = 1), so the start is also at least N/50, which keeps the fit to the largest timescales, where the long-range exponent dominates [7]. The slope is the Theil-Sen slope (pyhctsa.robust.bf_theil_sen()).

  • A continuous broken line (two slopes that meet at a breakpoint) from tau_0 to N/2, which describes series whose scaling changes across timescales, such as the short- and long-range exponents of heart-rate variability [9], or crossovers produced by trends [10] [11]. It is fitted by least squares at each candidate breakpoint, keeping the one with the smallest residual sum of squares. Candidates leave at least 0.3 decades of tau and 6 timescales on each side. If the best breakpoint is the first or last candidate, the range shows no change of slope that it can resolve, and the broken-line outputs are NaN.

References

Parameters:
x : array-like

The input time series.

q : float or int, optional

The order of the fluctuation function. The default is q = 2, which gives RMS fluctuations (standard DFA for wtf='dfa'). For wtf='dfa' any real q (including negative and non-integer values, and q = 0) gives the q-th order fluctuation function of MF-DFA [5]: with F^2(v) the variance of the detrended profile in window v, F_q = ( mean_v F^2(v)^(q/2) )^(1/q), and for q = 0 the logarithmic average F_0 = exp( mean_v ln F^2(v) / 2 ); the exponent is then the generalized Hurst exponent h(q), NaN for q < 0 if some window has zero variance. For the other methods q must be nonzero.

wtf : str, optional

What to fluctuate. Options are:

  • ’dfa’: detrended fluctuation analysis [3] [4] [6]: the mean of the series is removed before the profile is formed, and F is the RMS residual after removing a least-squares polynomial of order k in each window

  • ’rsrange’: the range after removing the straight line through the window’s end points [2]

  • ’rsrangefit’: the range after removing a least-squares polynomial of order k [2]

  • ’std’: the standard deviation in each window [1]

  • ’iqr’: the interquartile range in each window

  • ’range’: the range in each window

  • ’endptdiff’: the difference between the end points of each window

Default is 'rsrange'.

n_tau : int, optional

Number of log-spaced timescales in each range, before rounding. Default is 50.

k : int, optional

Order of the polynomial removed in each window, for ‘dfa’ and ‘rsrangefit’. Default is 1 (DFA1). k = 0 (only the window mean of the profile is removed) is not DFA proper.

lag : int or None, optional

If given, the series is decimated by this factor before the profile is formed, which analyses correlation at that lag [12]. Default is None.

Returns:

  • alpha, ssr: the slope (the scaling exponent) and the mean squared residual of the single line.

  • r1_alpha, r2_alpha, r1_ssr, r2_ssr: the slopes of the broken line over shorter (r1) and longer (r2) timescales, and the mean squared residual on each side of the breakpoint.

  • alphadiff: the change of slope, r1_alpha - r2_alpha.

alpha and ssr are NaN if tau_c is undefined, if the single-line range spans less than a factor of 1.5 (N/2 less than 1.5 times its start), or if it holds fewer than 8 distinct timescales. The broken-line outputs are NaN for fewer than 12 distinct timescales, or when no interior breakpoint is resolved. Either set is NaN if F is zero at some timescale of its range.

Return type:

dict

Notes

alpha is NaN for series that decorrelate slowly relative to their length, including strongly persistent ones, for which a long-range exponent cannot be told apart from short-range correlation. Short-range correlation still raises alpha a little, more for short series. The range-based exponents (‘rsrange’, ‘rsrangefit’) are biased upward, because in short windows the expected range grows faster than tau**0.5; the bias falls slowly with the window length, so these exponents decrease with series length [13] [14]. The methods that remove no trend in each window (‘std’, ‘iqr’, ‘range’, ‘endptdiff’, and ‘dfa’ with k = 0) mostly reflect the short-range correlation. Trends and changes in variance also change F(tau) [10] [11]. The location of the breakpoint is not returned: at typical series lengths the curve bends gradually and the breakpoint is poorly determined.