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
npm install dfa-variability
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,
}
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.
-
represent a time series as a one-dimensional vector
-
transform it into cumulative sum of variances from the mean
-
generate the scales of different window sizes for the time series — each containing the number of observations
-
split the cumulative variance vector into those chunks
-
for each chunk: generate polinomial in the range in a window (to detrend it)
-
calculate RMS of the fluctuations of the original from the fit
-
get the average RMS value for each window in the scale
-
take the average for each squared RMS for each scale
-
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.
Created by Dmitry Paranyushkin in 2020-2021
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.