# dfa: Detrended Fluctuation Analysis In nonlinearTseries: Nonlinear Time Series Analysis

## Description

Functions for performing Detrended Fluctuation Analysis (DFA), a widely used technique for detecting long range correlations in time series. These functions are able to estimate several scaling exponents from the time series being analyzed. These scaling exponents characterize short or long-term fluctuations, depending of the range used for regression (see details).

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17``` ```dfa(time.series, window.size.range = c(10, 300), npoints = 20, do.plot = TRUE, ...) ## S3 method for class 'dfa' windowSizes(x) ## S3 method for class 'dfa' fluctuationFunction(x) ## S3 method for class 'dfa' plot(x, main = "Detrended Fluctuation Analysis", xlab = "Window size: t", ylab = "Fluctuation function: F(t)", log = "xy", ...) ## S3 method for class 'dfa' estimate(x, regression.range = NULL, do.plot = FALSE, fit.col = 2, fit.lty = 1, fit.lwd = 1, add.legend = TRUE, ...) ```

## Arguments

 `time.series` The original time series to be analyzed. `window.size.range` Range of values for the windows size that will be used to estimate the fluctuation function. Default: c(10,300). `npoints` The number of different window sizes that will be used to estimate the Fluctuation function in each zone. `do.plot` logical value. If TRUE (default value), a plot of the Fluctuation function is shown. `...` Additional graphical parameters. `x` A dfa object. `main` A title for the plot. `xlab` A title for the x axis. `ylab` A title for the y axis. `log` A character string which contains "x" if the x axis is to be logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if both axes are to be logarithmic. `regression.range` Vector with 2 components denoting the range where the function will perform linear regression. `fit.col` A colors to plot the regression line. `fit.lty` The type of line to plot the regression line. `fit.lwd` The width of the line for the regression line. `add.legend` add a legend with the resulting estmation to the plot?

## Details

The Detrended Fluctuation Analysis (DFA) has become a widely used technique for detecting long range correlations in time series. The DFA procedure may be summarized as follows:

1. Integrate the time series to be analyzed. The time series resulting from the integration will be referred to as the profile.

2. Divide the profile into N non-overlapping segments.

3. Calculate the local trend for each of the segments using least-square regression. Compute the total error for each ofi the segments.

4. Compute the average of the total error over all segments and take its root square. By repeating the previous steps for several segment sizes (let's denote it by t), we obtain the so-called Fluctuation function F(t).

5. If the data presents long-range power law correlations: F(t) proportional t^alpha and we may estimate using regression.

6. Usually, when plotting log(F(t)) Vs log(t) we may distinguish two linear regions. By regressing them separately, we obtain two scaling exponents, alpha1 (characterizing short-term fluctuations) and alpha2 (characterizing long-term fluctuations).

Steps 1-4 are performed using the dfa function. In order to obtain a estimate of some scaling exponent, the user must use the estimate function specifying the regression range (window sizes used to detrend the series).

## Value

A dfa object.

The windowSizes function returns the windows sizes used to detrend the time series.

The fluctuationFunction function returns the fluctuation function obtained in the DFA represented by the dfa object.

## Author(s)

Constantino A. Garcia

## References

Penzel, Thomas, et al. "Comparison of detrended fluctuation analysis and spectral analysis for heart rate variability in sleep and sleep apnea." Biomedical Engineering, IEEE Transactions on 50.10 (2003): 1143-1151.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29``` ```## Not run: white.noise = rnorm(5000) dfa.analysis = dfa(time.series = white.noise, npoints = 10, window.size.range=c(10,1000), do.plot=FALSE) white.estimation = estimate(dfa.analysis,do.plot=TRUE) cat("Theorical: 0.5---Estimated: ",white.estimation ,"\n") library(fArma) fgn = as.numeric(fArma::fgnSim(n = 2000, H = 0.75)) dfa.analysis = dfa(time.series = fgn, npoints = 30, window.size.range=c(10,1000), do.plot=FALSE) fgn.estimation = estimate(dfa.analysis, do.plot = TRUE, fit.col="blue",fit.lwd=2,fit.lty=2, main="Fitting DFA to fGn") cat("Theorical: 0.75---Estimated: ",fgn.estimation ,"\n") fbm = as.numeric(fArma::fbmSim(n = 2000, H = 0.25)) dfa.analysis = dfa(time.series = fbm, npoints = 50, window.size.range=c(10,300), do.plot=FALSE) fbm.estimation = estimate(dfa.analysis,do.plot = TRUE, add.legend=F, main="DFA of fBm") cat("Theorical: 1.25 ---Estimated: ",fbm.estimation ,"\n") ## End(Not run) ```

### Example output

```Attaching package: 'nonlinearTseries'

The following object is masked from 'package:grDevices':

contourLines

Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl_init' failed, running with rgl.useNULL = TRUE
call: fun(...)
Theorical: 0.5---Estimated:  0.5048641
Theorical: 0.75---Estimated:  0.7298782
Theorical: 1.25 ---Estimated:  1.306235
```

nonlinearTseries documentation built on Sept. 23, 2018, 9:03 a.m.