npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dfa-variability

v0.9.8

Published

Detrended Fluctuation Analysis for Javascript measuring time series variability.

Downloads

172

Readme

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.