0.9.8 • Published 5 months ago

dfa-variability v0.9.8

Weekly downloads
-
License
AGPLv3
Repository
github
Last release
5 months ago

Detrended Fluctuation Analysis (DFA)

Javascript port with no external dependencies

Inspired by the approach described in the Nodus Labs Fractal Variability Feedback System article.

Currently used to analyze the fractal variability of movement in EightOS practice and cognitive variability in InfraNodus tool.

If you have more use cases, please, let us know.

Based on the python script https://github.com/dokato/dfa and the polinomial script https://github.com/rfink/polyfit.js

Use

When using NPM

npm install dfa-variability

In the browser

Include the dfa.js file into your browser or a node.js app. Then use the Javascript below:

// when running on the backend (Node.Js)
let DFA = require("dfa-variability");

// When running on the frontend (via browser) or backend:
let time_series = [8, 10, 6, 9, 7, 5, 5, 11, 11, 8, 6, 7, 9, 10, 7, 9];

let dfa = new DFA(time_series);

// calculate alpha component: dfa.compute(min_window = 4, step = 0.5)

let alpha_component = dfa.compute();

console.log(alpha_component);

The object structure of the response is:

alpha_component =
  {
	    averageVariance: averageVariance,
			meanValue: meanValue,
			SDNN: SDNN,
			RMSSD: RMSSD,
			lnRMSSD: lnRMSSD,
			PNN50: PNN50,
			averageDifferences: averageDifferences,
			scales: scales,
			segments: arraySize,
			fluctuations: fluctuations,
			scales_log: scales_log,
			fluctuations_log: flucts_log,
			coefficients: coefficients,
			alpha: alpha,
			alphaScore: alphaScore,
  }

Concept

DFA is used to measure the behaviour of a time series.

An obtained alpha component (closely related to the Hurst exponent) will indicate the presence of correlations in the time series.

It is based on the relationship between the length of an observation and cumulated variability.

Algorithm:

  1. represent a time series as a one-dimensional vector

  2. transform it into cumulative sum of variances from the mean

  3. generate the scales of different window sizes for the time series — each containing the number of observations

  4. split the cumulative variance vector into those chunks

  5. for each chunk: generate polinomial in the range in a window (to detrend it)

  6. calculate RMS of the fluctuations of the original from the fit

  7. get the average RMS value for each window in the scale

  8. take the average for each squared RMS for each scale

  9. if they align along in a straight line in loglog plot, there is power law relation i.e. as observations increase in length, the amplitude of average fluctuations increases as well that is, there is an exponential growth of fluctuations when there's an exponential growth of scale (2^n) on the smaller scales the deviations are smaller. on the bigger scales they are much bigger.

Author

Created by Dmitry Paranyushkin in 2020-2021

GPL License

This open source, free software is available under the GNU Affero General Public License version 3 (AGPLv3) license. You can make modifications to this code and binaries based on it, but only on the condition that you provide access to those modifications under the same license (including remotely through a computer network). It is provided as is, with no guarantees and no liabilities. You can re-use it as long as you keep this notice inside the code.

0.9.8

5 months ago

0.9.5

5 months ago

0.9.4

8 months ago

0.9.3

8 months ago

0.9.0

8 months ago

0.8.0

8 months ago

0.9.2

8 months ago

0.9.1

8 months ago

0.7.0

8 months ago

0.6.0

8 months ago

0.5.0

3 years ago