stdev
Description
Computes the sample standard deviation of an Observable using [Welford's Online Algorithm]([https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)\) .
By default, it will compute the sample (rather than population) standard deviation.
Examples
import { from } from 'rxjs';
import { takeLast } from 'rxjs';
import { stdev, roundTo } from '@bottlenose/rxstats';
const stdev$ = from([600, 470, 170, 430, 300]).pipe(
stdev(),
takeLast(1),
roundTo(6)
);
stdev$.subscribe(console.log);
// Output:
// 164.71187API
stdev(
[initialState={index: 0, mean: 0, m2: null}],
[sample=true]
)Since
0.1
Parameters
None
Options
initialState: Object: Sets a warm start value so that the calculation can continue from a non-zero starting point (instead of a blank state). The initialState should have these keys:index: Number: The starting index. (The total number of items in the sample minus one.)mean: Number: The initial mean of the sample.m2: NumberThe initial m2 value for the sample. (See the source code to see how m2 is calculated.)
sample: Boolean: The default istrue. Iftrue, then it will calculate the sample variance. Otherwise, it will calculate population variance.
Returns
Number. (The current variance of the Observable.)
Arguments
None
Options
None
Last updated
Was this helpful?