stats

stats

new stats()

Main class used for statistical analyses and data cleaning.

Source:

Methods

(static) arrchange(data) → {Array.<Object>}

Changes a m x n matrix into a n x m matrix (transpose). Mainly used for creating google charts. M != N.

Parameters:
Name Type Description
data Object

Contains: nd-JS array representing [[m],[n]] matrix.

Source:
Returns:

[[n],[m]] array.

Type
Array.<Object>
Example
hydro.analyze.stats.arrchange({data: [[someSize1],[someSize2]]})

(static) autocovarianceMatrix(data, params) → {Object}

Still needs some testing Compute the autocovariance matrix from the autocorrelation values

Parameters:
Name Type Description
data Object

array with autocorrelation values

params number

number of lags

Author:
  • riya-patil
Source:
Returns:

Autocovariance matrix

Type
Object
Example
const acTestData = [1, 0.7, 0.5, 0.3];
const lags = 2
hydro.analyze.stats.autocovarianceMatrix({params: lag, data : actestData});

(static) basicstats(data) → {Array.<Object>}

Returns an array that Contains the basic statistics of a dataset. It is used afterwards to be prompted using google graphing tools.

Parameters:
Name Type Description
data Object

1d-JS array with data arranged as [data].

Source:
Returns:

flatenned array for the dataset.

Type
Array.<Object>
Example
hydro.analyze.stats.basicstats({data: [someData]})

(static) bernoulliDist(params) → {Number}

Probability mass function (PMF) of a Bernoulli distribution

Parameters:
Name Type Description
params Object

Contains: x (value at which to compute the PMF) and p (probability of success)

Author:
  • riya-patil
Source:
Returns:

Probability mass function of the Bernoulli distribution

Type
Number

(static) binomialCoefficient(trials, s) → {Number}

Calculates the binomial coefficient (n choose k format)

Parameters:
Name Type Description
trials Number

The number of trials

s Number

The number of successes

Author:
  • riya-patil
Source:
Returns:

The binomial coefficient (trials choose s)

Type
Number

(static) binomialDist(params, args, data) → {Number}

Calculates the probability mass function (PMF) of a Binomial Distribution.

Parameters:
Name Type Description
params Object

Contains the number of trials 'n' (n >= 0) and the probability of success

args Object

Contains the number of successes 's'

data Array

Empty array as no data is needed for this calculation.

Author:
  • riya-patil
Source:
Returns:

The probability of getting exactly 's' successes in trials.

Type
Number
Example
hydro.analyze.stats.binomialDist({ params: { trials: 10, probSuccess: 0.5 }, args: { s: 3 });

(static) boxPlotDistribution(params, args) → {Array}

Generates random numbers from within a Box Plot distribution.

Parameters:
Name Type Description
params Object

Contains the parameters 'min', 'q1', 'median', 'q3', 'max'.

args Object

Contains the argument 'size' for the number of random numbers to generate.

Author:
  • riya-patil
Source:
Returns:

Array of random numbers following the Box Plot Distribution.

Type
Array
Example
hydro.analyze.stats.boxPlotDistribution({ params: { min: 1, q1: 2, median: 3, q3: 4, max: 5 }, args: { size: 100 }})

(static) breuschPaganTest(params) → {Object}

Performs the Breusch-Pagan test for heteroscedasticity.

Parameters:
Name Type Description
params Object

errors: Array of residuals, regressors: Array of regressor variables

Author:
  • riya-patil
Source:
Throws:

If the input arrays have different lengths.

Type
Error
Returns:

Object containing test statistic and p-value.

Type
Object
Example
const params = {
  errors: [1, 2, 3, 4, 5],
  regressors: [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]
};
hydro.analyze.stats.breuschPaganTest({ params });

(static) chisqCDF(x, k) → {number}

Calculates the cumulative distribution function (CDF) of the chi-square distribution NOTE: This will require revision in the future, readjusting considering lookups or fitting to a gamma distribution instead

Parameters:
Name Type Description
x number

The value at which to evaluate the CDF

k number

The degrees of freedom

Author:
  • riya-patil
Source:
Returns:

The cumulative probability

Type
number
Example
const x = 10
const df = 20
hydro.analyze.stats.chisCDF(10, 20)

(static) cleaner(data) → {Array.<Object>}

Filters out items in an array that are undefined, NaN, null, ", etc.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array with data to be cleaned as [dataValues]

Source:
Returns:

Cleaned array.

Type
Array.<Object>
Example
hydro.analyze.stats.cleaner({data: [someValues]})

(static) computeD(data) → {Number}

D-statistic Computes D-statistic from two samples to evaluate if they come from the same distribution Reference: Kottegoda & Rosso, 2008.

Parameters:
Name Type Description
data Array.<Object>

2d-JS array containing ordered as [samples_A, samples_B], with each being 1-d arrays

Author:
  • Alexander Michalek & Renato Amorim, IFC, University of Iowa.
Source:
Returns:

d-statistic of the samples

Type
Number
Example
hydro.analyze.stats.computeD({data: [samples_A, samples_B]})

(static) copydata(data) → {Object}

Makes a deep copy of original data for further manipulation.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array or object with original data.

Source:
Returns:

Deep copy of original data.

Type
Object
Example
hydro.analyze.stats.copydata({data: [someData]})

(static) correlation() → {Number}

Calculates pearson coefficient for bivariate analysis. The sets must be of the same size.

Parameters:
Name Type Description
params.data Object

An object containing the two data sets as set1 and set2.

Source:
Returns:

Pearson coefficient.

Type
Number
Example
const data = {set1: [1,2,3], set2: [2,4,6]};
const pearsonCoefficient = hydro1.analyze.stats.correlation({data})

(static) datagaps(data) → {Number}

Identifies gaps in data.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array with data as [data].

Source:
Returns:

Number of gaps in data.

Type
Number
Example
hydro.analyze.stats.datagaps({data: [someData]})

(static) dateparser(data) → {Array.<Object>}

Changes a 1d-date array into local strings. Used mainly for changing displaying into google charts.

Parameters:
Name Type Description
data Array.<Object>

Contains: 1-dJS array with date values as [dateValue].

Source:
Returns:

Array with date parsed.

Type
Array.<Object>
Example
hydro.analyze.stats.dateparser({data: [someValues]})

(static) differencing(params, data) → {Array}

Performs differencing on a time series dataset to remove trend or seasonality from the data

Parameters:
Name Type Description
params Object

Contains the order parameter

data Array

1D array of numerical values representing a time series

Author:
  • riya-patil
Source:
Throws:

If the order is invalid

Type
Error
Returns:

Differenced time series

Type
Array
Example
const order = 1;
const timeSeries = [1, 3, 6, 10, 15];
const differencedSeries = stats.differencing({ order, data: timeSeries });

(static) efficiencies(options) → {Number|Object}

Calculates different types of efficiencies for hydrological models: Nash-Sutcliffe, Coefficient of Determination and Index of Agreement. Only accepts 1D array of observed and model data within the same time resolution. Range of validity: Nash-Sutcliffe: between 0.6-0.7 is acceptable, over 0.7 is very good. Determination coefficient: between 0 and 1, 1 being the highest with no dispersion between the data sets and 0 meaning there is no correlation. Index of agrement: between 0 and 1, with more than 0.65 being considered good. All efficiencies have limitations and showcase statistically the well performance of a model, but should not be considered as only variable for evaluation.

Parameters:
Name Type Description
options Object

The options object.

Properties
Name Type Attributes Description
params Object

An object containing the type of efficiency to calculate ('NSE','determination', 'agreement', 'all').

data Object

A 2D array with values arranged as [[observed], [model]].

args Array <optional>

An optional array of additional arguments to pass to the function.

Source:
Returns:
  • A number representing the calculated metric, or an object containing multiple metrics if 'all' is specified.
Type
Number | Object
Example
// Calculate Nash-Sutcliffe efficiency:
const obs = [1, 2, 3];
const model = [1.5, 2.5, 3.5];
const NSE = hydro.analyze.stats.efficiencies({ params: { type: 'NSE' }, data: [obs, model] });

// Calculate all efficiencies:
const metrics = hydro.analyze.stats.efficiencies({ params: { type: 'all' }, data: [obs, model] });
// metrics = { NSE: 0.72, r2: 0.5, d: 0.62 }

(static) exponentialMovingAverage(args) → {Array.<number>}

Computes the Exponential Moving Average (EMA) for a given dataset.

Parameters:
Name Type Description
args Object

Contains the dataset as 'data' (1D JavaScript array) and the 'alpha' value (smoothing factor between 0 and 1)

Author:
  • riya-patil
Source:
Returns:

The Exponential Moving Average (EMA) values for the dataset

Type
Array.<number>
Example
const dataset= [1,2,3,4,5]
const params={alpha: 0.5}
hydro.analyze.stats.exponentialMovingAverage({params, data});

(static) fastfourier(data) → {Array.<Object>}

Fast fourier analysis over a 1d dataset and see if there are any patterns within the data. Should be considered to be used for small data sets.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array with data as [data]

Source:
Returns:

calculated array.

Type
Array.<Object>
Example
hydro.analyze.stats.fastfourier({data: [someData]})

(static) flatenise(params, data) → {Array.<Object>}

Helper function for preparing nd-JSarrays for charts and tables for duration/discharge.

Parameters:
Name Type Description
params Object

Contains: columns (nd-JS array with names as [someName1, someName2,...])

data Object

Contains: nd-JS array object required to be flatenned as [[somedata1, somedata2,...],[somedata1, somedata2,...],...]

Source:
Returns:

Flatenned array.

Type
Array.<Object>
Example
hydro.analyze.stats.flatenise({params:{columns: [someName1, someName2,...]},
data: [[somedata1, somedata2,...],[somedata1, somedata2,...],...]})

(static) frequency(data) → {Object}

Calculates the frequency in data.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Object with frenquency distribution.

Type
Object
Example
hydro.analyze.stats.frequency({data: [data]})

(static) gapfiller(params, data) → {Array.<Object>}

Fills data gaps (either time missig or data missing). Unfinished.

Parameters:
Name Type Description
params Object

Contains: type (time or data)

data Object

Contains: 2d-JS array with data or time gaps to be filled as [[time],[data]].

Source:
Returns:

Array with gaps filled.

Type
Array.<Object>
Example
hydro.analyze.stats.gapfiller({params: {type: 'someType'}, data: [[time1,time2...], [data1, data2,...]]})

(static) gapremoval(data) → {Number}

Remove gaps in data with an option to fill the gap.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Number of gaps found in the data.

Type
Number
Example
hydro.analyze.stats.gapremoval({data: [someData]})

(static) gaussianDist(params) → {Number}

Computes the probability density function (PDF) of a Gaussian (normal) distribution

Parameters:
Name Type Description
params Object

x (value at which to compute the PDF), mean (mean of the distribution), and stddev (standard deviation of the distribution)

Author:
  • riya-patil
Source:
Returns:

Probability density function of the Gaussian distribution

Type
Number
Example
const testData = {
    x: 2.5,
    mean: 3,
    stddev: 1.2
  };
  hydro.analyze.stats.gaussianDist({params: testData});

(static) generateRandomData(size, rangeopt) → {Array.<number>}

Generates an array of random integers within a specified range.

Parameters:
Name Type Attributes Default Description
size number

The number of elements in the array to be generated.

range number <optional>
100

The upper limit (exclusive) of the range from which the random integers will be generated.

Source:
Returns:

An array of random integers between 0 and range-1, of length size.

Type
Array.<number>
Example
hydro.analyze.stats.generateRandomDat
(10, 50) // returns [23, 48, 15, 9, 36,
28, 39, 18, 20, 22]

(static) geometricDist(params, args) → {Number}

Calculates the probability mass function (PMF) of a Geometric Distribution

Parameters:
Name Type Description
params Object

Contains the probability of success "s" (where 0 <= s <= 1) as a parameter.

args Number

Contains the number of trials until the first success trials (trials >= 1)

Author:
  • riya-patil
Source:
Returns:

The probability of getting the first success on the n-th trial

Type
Number
Example
hydro.analyze.stats.geometricDist({ params: { s: 0.5 }, args: { trials: 3 }, data: [] });
0.125

(static) getNextState(transitionMatrix, currentState) → {number}

Gets the next state based on the transition probabilities defined in the transition matrix.

Parameters:
Name Type Description
transitionMatrix Array.<Array.<number>>

transition matrix representing the probabilities of transitioning between states.

currentState number

current state of the function

Author:
  • riya-patil
Source:
Returns:

Next state selected based on the transition probabilities.

Type
number
Example
const transitionMatrix = [
  [0.2, 0.8], 
  [0.5, 0.5],
    ];
  const initialState = 0;

(static) gevDistribution(params) → {Number}

Computes the probability density function (PDF) of the Generalized Extreme Value (GEV) distribution.

Parameters:
Name Type Description
params Object

Contains: x (value at which to compute the PDF), mu (location parameter), sigma (scale parameter), xi (shape parameter).

Author:
  • riya-patil
Source:
Returns:

Probability density function of the GEV distribution.

Type
Number

(static) gumbelDist(params) → {Number}

Calculates the probability density function (PDF) of the Gumbel Distribution

Parameters:
Name Type Description
params Object

Contains the parameters 'mu' (location parameter) and 'beta' (scale parameter).

Author:
  • riya-patil
Source:
Returns:

Probability density at the given value 'x'.

Type
Number
Example
hydro.analyze.stats.gumbelDist({ params: { mu: 0, beta: 1, x: 2}})

(static) interoutliers(paramsopt, data) → {Array}

Removes interquartile outliers from an array or a set of arrays.

Parameters:
Name Type Attributes Default Description
params Object <optional>
{ q1: 0.25, q2: 0.75 }

Parameters object.

data Array

Data to filter. If a 2D array is provided, the first array will be considered as a time array.

Source:
Returns:
  • Filtered data.
Type
Array
Example
hydro.analyze.stats.interoutliers({ params: { q1: 0.25, q2: 0.75 }, data: [1, 2, 3, 100, 4, 5, 6]});

(static) itemfilter(data) → {Array.<Object>}

Filters out items in an array based on another array.

Parameters:
Name Type Description
data Object

Contains: 2d-JS array with data to be kept and removed as [[dataKept],[dataRemoved]]

Source:
Returns:

Cleaned array.

Type
Array.<Object>
Example
hydro.analyze.stats.itemfilter({data: [[dataKept], [dataRemoved]]})

(static) joinarray(data) → {Array.<Object>}

Preprocessing tool for joining arrays for table display.

Parameters:
Name Type Description
data Object

2d-JS array as [[someData1], [someData2]]

Source:
Returns:

Array for table display.

Type
Array.<Object>
Example
hydro.analyze.stats.joinarray({data: [[someData1], [someData2]]})

(static) KS_computePValue(data) → {Array.<Object>}

Kolmogorov Smirnov Two-sided Test Calculates the P value, based on the D-statistic from the function above. Reference: Kottegoda & Rosso, 2008.

Parameters:
Name Type Description
data Array.<Object>

2d-JS array containing ordered as [samples_A, samples_B], with each being 1-d arrays

Author:
  • Alexander Michalek & Renato Amorim, IFC, University of Iowa
Source:
Returns:

array with [p-Statistic, d-Statistic]

Type
Array.<Object>
Example
hydro.analyze.stats.KS_computePValue({data: [samples_A, samples_B]})

(static) KS_rejectAtAlpha(params, data) → {Number}

Reject P statistic based on a significance level alpha. Reference: Kottegoda & Rosso, 2008.

Parameters:
Name Type Description
params Object

contains {alpha: Number} with alpha being the significance level

data Array.<Object>

2d-JS array containing ordered as [samples_A, samples_B], with each being 1-d arrays

Author:
  • Alexander Michalek & Renato Amorim, IFC, University of Iowa
Source:
Returns:

rejection if p is less than the significance level

Type
Number
Example
hydro.analyze.stats.KS_rejectAtAlpha({params: {alpha: someAlpha}, data: [samples_A, samples_B]})

(static) linearMovingAverage(params, data) → {Array}

Calculates the Linear Moving Average (LMA) of a given dataset.

Parameters:
Name Type Description
params Number

Contains the windowSize parameter.

data Array

1D array of numerical values.

Author:
  • riya-patil
Source:
Throws:

If the window size is invalid.

Type
Error
Returns:

Array of moving averages.

Type
Array
Example
const windowSize = 5;
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
hydro.analyze.stats.linearMovingAverage({ windowSize, data });

(static) lognormalDist(params, args) → {Number}

Calculates the probability density function (PDF) of the Lognormal Distribution

Parameters:
Name Type Description
params Object

Contains the parameters 'mu' and 'sigma' which represent the mean and standard deviation of the associated normal distribution.

args Object

Contains the argument 'x' which represents the value at which to evaluate the PDF.

Author:
  • riya-patil
Source:
Returns:

Probability density at 'x' in the Lognormal Distribution.

Type
Number
Example
hydro.analyze.stats.lognormalDist({params: { mu: 0, sigma: 1 }, args: { x: 2 }})

(static) logPearsonTypeIII(params, size) → {Array}

Generates random numbers following a Log Pearson Type III distribution.

Parameters:
Name Type Description
params Object

Contains the parameters 'mu' 'sigma' and 'gamma'.

size Number

Number of random numbers to generate.

Author:
  • riya-patil
Source:
Returns:

Array of random numbers following the Log Pearson Type III distribution.

Type
Array
Example
hydro.analyze.stats.logPearsonTypeIII({ params: { mu: 1, sigma: 2, gamma: 3 }, args: { size: 100 } })

(static) LogSeriesDistribution(params, args) → {Number}

Calculates the probability mass function (PMF) of the Log series Distribution

Parameters:
Name Type Description
params Object

Contains the parameter 'probSuccess' which represents the probability of success in a single trial.

args Object

Contains the argument 'trials' (trials >= 1) which represents the number of trials.

Author:
  • riya-patil
Source:
Returns:

Probability of achieving the first success in # of trials.

Type
Number
Example
hydro.analyze.stats.logSeriesDist({params: {probSuccess: 0.2, trials: 3}})

(static) matrixInverse(matrix) → {Array}

Computes the inverse of a matrix

Parameters:
Name Type Description
matrix Array

Matrix to compute inverse of

Author:
  • riya-patil
Source:
Returns:

Inverse of the matrix

Type
Array
Example
const matrix = [[1, 2, 3], [4, 5, 6]];
hydro.analyze.stats.matrixInverse(matrix)

(static) max(data) → {Number}

Maximum value of an array.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Maximum value of a dataset.

Type
Number
Example
hydro.analyze.stats.max({data: [data]})

(static) mean(data) → {Number}

Calculates the mean of a 1d array.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Mean of the data.

Type
Number
Example
hydro.analyze.stats.mean({data: [data]})

(static) meanSquaredError(args) → {number}

Mean Squared Error (MSE) Estimation - Computes the Mean Squared Error (MSE) between two datasets

Parameters:
Name Type Description
args Object

Contains the two datasets as 'data1' and 'data2' (1D JavaScript arrays)

Author:
  • riya-patil
Source:
Returns:

The Mean Squared Error (MSE) between the two datasets

Type
number
Example
const dataset1 = [1, 2, 3, 4, 5];
const dataset2 = [1.5, 2.8, 3.6, 4.2, 4.9];
hydro.analyze.stats.meanSquaredError({ data: { data1: dataset1, data2: dataset2 } });

(static) median(data) → {Number}

Calculates the median values for a 1d array.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Median of the data.

Type
Number
Example
hydro.analyze.stats.median({data: [data]})

(static) min(data) → {Number}

Minimum value of an array.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Minimum value of a dataset.

Type
Number
Example
hydro.analyze.stats.min({data: [data]})

(static) MK(data) → {Array.<Object>}

Mann-Kendall trend test Checks for mononicity of data throughout time. Reference: Kottegoda & Rosso, 2008.

Parameters:
Name Type Description
data Array.<Object>

Contains: 1d-JS array with timeseries

Author:
  • Alexander Michalek & Renato Amorim, IFC, University of Iowa.
Source:
Returns:

1d array with 3 values: p-value, value sum and z value

Type
Array.<Object>
Example
hydro.analyze.stats.MK({data: [someData]})

(static) multinomialDistribution(params) → {Object}

Multinomial Distribution - Generates random samples from a multinomial distribution.

Parameters:
Name Type Description
params Object

probabilities: 1D array of probabilities for each category; n: Number of samples to generate

Author:
  • riya-patil
Source:
Returns:

samples: 2D array of generated samples, where each row represents a sample and each column represents a category frequencies: 2D array of frequencies for each category in the generated samples

Type
Object
Example
const multinomialData = {
  probabilities: [0.2, 0.3, 0.5],
  n: 100
};
hydro.analyze.stats.multinomialDistribution({ params: multinomialData });

(static) multipleMatrix(matrix1, matrix2) → {Array}

Multiplies two matrices

Parameters:
Name Type Description
matrix1 Array

First matrix

matrix2 Array

Second matrix

Author:
  • riya-patil
Source:
Returns:

Result of matrix multiplication

Type
Array
Example
const matrix1 = [[1, 2], [3, 4]];
const matrix2 = [[5, 6], [7, 8]];
hydro.analyze.stats.multiplyMatrix(matrix1, matrix2)

(static) multiregression(data) → {Array}

Performs multivariate regression analysis

Parameters:
Name Type Description
data Object

Data for the multivariate regression

Author:
  • riya-patil
Source:
Returns:

Coefficients of the linear regression model.

Type
Array
Example
const X = [[1, 2], [3, 4], [5, 6]];
const y = [3, 5, 7];
hydro.analyze.stats.multiregression({ data: { X, y } });

(static) normalcdf(data, data) → {Array.<Object>|Number}

Normal distribution

Parameters:
Name Type Description
data Array.<Object>

Contains: 1d-JS array with timeseries

data Array.<Object>

1d-JS array

Author:
  • Alexander Michalek & Renato Amorim, IFC, University of Iowa.
Source:
Returns:
  • 1d array with 3 values: p-value, value sum and z value

    Type
    Array.<Object>
  • number value for the distribution

    Type
    Number
Example
hydro.analyze.stats.normalcdf({data: [someData]})

(static) normalDistribution(params) → {Number}

Computes the probability density function of a normal distribution.

Parameters:
Name Type Description
params Object

Contains: z-value.

Source:
Returns:

Probability density function of the normal distribution.

Type
Number
Example
hydro.analyze.stats.normalDistributio
({params: {z: 1.5}})

(static) normoutliers(paramsopt, argsopt, data, data[0]opt, data[1) → {Array}

Filters the outliers from the given data set based on its standard score (z-score).

Parameters:
Name Type Attributes Default Description
params Object <optional>
{}

An object containing optional parameters.

Properties
Name Type Attributes Default Description
low Number <optional>
-0.5

The lower threshold value for filtering data.

high Number <optional>
0.5

The higher threshold value for filtering data.

args Object <optional>

An object containing any additional arguments.

data Array

The data set to filter outliers from.

data[0] Array <optional>
[]

An optional array of timestamps corresponding to the data.

data[1 Array

The main data array containing values to filter outliers from.

Source:
Returns:

Returns the filtered data set. If timestamps are provided, it will return an array of timestamps and filtered data set as [t, out]. If no timestamps are provided, it will return the filtered data set.

Type
Array
Example
// Filter outliers from the data set between z-scores of -0.5 and 0.5
let data = [1, 2, 3, 4, 5, 10, 12, 15, 20];
let filteredData = hydro.analyze.stats.normoutliers({ params: { low: -0.5, high: 0.5 }, data: data });
// filteredData => [1, 2, 3, 4, 5, 15, 20]

// Filter outliers from the data set between z-scores of -1 and 1 with timestamps
let data = [[1, 2, 3, 4, 5, 10, 12, 15, 20], [1, 2, 3, 4, 5, 10, 12, 15, 200]];
let [timestamps, filteredData] = hydro.analyze.stats.normoutliers({ params: { low: -1, high: 1 }, data: data });
// timestamps => [1, 2, 3, 4, 5, 10, 12, 15]
// filteredData => [1, 2, 3, 4, 5, 10, 12, 15]

(static) numerise(data) → {Array.<Object>}

Turns data from numbers to strings. Usable when retrieving data or uploading data.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array with data composed of strings as [dataValues].

Source:
Returns:

Array as numbers.

Type
Array.<Object>
Example
hydro.analyze.stats.numerise({data: [someValues]})

(static) onearray(data) → {Array.<Object>}

Retrieves a 1D array with the data.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array as [data]

Source:
Returns:

Array object.

Type
Array.<Object>
Example
hydro.analyze.stats.onearray({data: [someData]})

(static) outremove(params, args, data) → {Array.<Object>}

Remove outliers from dataset. It uses p1 and p2 as outliers to remove.

Parameters:
Name Type Description
params Object

Contains: type ('normalized', 'interquartile')

args Object

Contains: p1 (low end value), p2 (high end value) both depending on outlier analysis type

data Object

Contains: 2d-JS array with time series data as [[time],[data]].

Source:
Returns:

Array with cleaned data.

Type
Array.<Object>
Example
hydro.analyze.stats.outremove({params: {type: 'someType'}, args: {p1: 'someNum', p2: 'someNum'},
data: [[time1, time2,...], [data1, data2,...]]})

(static) poissonProcess(params, args) → {Array}

Generates a sequence of events representing a Poisson Process

Parameters:
Name Type Description
params Object

Contains the type of Poisson process ('homogeneous' or 'nonhomogeneous') and the time period 'T'.

args Object

Additional arguments depending on the type of Poisson process.

Author:
  • riya-patil
Source:
Returns:

Array of event times.

Type
Array
Example
hydro.analyze.stats.poissonProcess({ params: { type: 'homogeneous', T: 10 }, args: { lambda: 2 } });
hydro.analyze.stats.poissonProcess({ params: { type: 'nonhomogeneous', T: 10 }, args: { rateFunction: (t) => Math.sin(t) } });

(static) push(data) → {Array.<Object>}

Pushes at the end of an array the data of another array.

Parameters:
Name Type Description
data Object

Contains: 2d-JS array with data arranged as [[willPush],[pushed]]

Source:
Returns:

Last dataset with pushed data.

Type
Array.<Object>
Example
hydro.analyze.stats.push({data: [[dataSet1], [dataSet2]]})

(static) quantile(params, data) → {Array.<Object>}

Quantile calculator for given data.

Parameters:
Name Type Description
params Object

Contains: q(quartile as 0.25, 0.75, or required)

data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Array with values fitting the quartile.

Type
Array.<Object>
Example
hydro.analyze.stats.quantile({params: {q: 'someNum'}, data: [data]})

(static) range(data) → {Array}

Gives the range of a dataset

Parameters:
Name Type Description
data Object

Contains: 1d-JS array with data as [data].

Source:
Returns:

Range of the data.

Type
Array
Example
hydro.analyze.stats.range({data: [someData]})

(static) regression(data) → {Array}

Computes the coefficients of a linear regression model.

Parameters:
Name Type Description
data Object

Object containing predictor variables (X) and target variable (y).

Author:
  • riya-patil
Source:
Returns:

Coefficients of the linear regression model.

Type
Array
Example
const X = [[1, 2], [3, 4], [5, 6]];
const y = [3, 5, 7];
hydro.analyze.stats.regression({ data: { X, y } });

(static) residualVariance(data) → {number|Error}

Computes the variance of residuals in a regression model to detect heteroskedasticity

Parameters:
Name Type Description
data Array

1D array of numerical values representing the residuals.

Author:
  • riya-patil
Source:
Returns:
  • Variance of residuals

    Type
    number
  • if not given valid array of residuals or not given correct number of arrays

    Type
    Error
Example
const residuals = [1.5, -2.1, 0.8, -1.2, 2.5];
const variance = stats.residualVariance({ data: residuals });

(static) returnPeriod(params) → {Number}

Return Period - Calculates the return period for a given probability of occurrence.

Parameters:
Name Type Description
params Object

probability: Probability of occurrence (between 0 and 1)

Author:
  • riya-patil
Source:
Returns:

Return period corresponding to the given probability

Type
Number
Example
const returnPeriodData = {
  probability: 0.1
};
hydro.analyze.stats.returnPeriod({ params: returnPeriodData });

(static) runMarkovChainMonteCarlo(data) → {Array.<number>}

Generates a random simulated number when run with a dataset

Parameters:
Name Type Description
data Array.<Object>

passes data from multiple objects

Author:
  • riya-patil
Source:
Returns:

returns an array of the simulated results

Type
Array.<number>
Example
const options = {
      params: {
      iterations: 100,
    },
    data: {
      initialState,
      transitionMatrix,
      },
    };
    hydro.analyze.stats.runMarkovChainMonteCarlo(options);

(static) runMonteCarlo(data) → {Array.<number>}

Generates a random simulated number when run with a dataset

Parameters:
Name Type Description
data Array.<Object>

passes data from multiple objects

Author:
  • riya-patil
Source:
Returns:

returns an array of the simulated results

Type
Array.<number>
Example
const testData = [
      [1, 2, 3, 4, 5],
      [6, 7, 8, 9, 10],
      [11, 12, 13, 14, 15],
    ];
    hydro.analyze.stats.runMonteCarlo({data: testData})

(static) runSimulation(data) → {Number}

Generates a random simulated number when run with a dataset

Parameters:
Name Type Description
data Object

passes data from an object

Author:
  • riya-patil
Source:
Returns:

Returns a simulated number

Type
Number
Example
const testData = [
      [1, 2, 3, 4, 5],
      [6, 7, 8, 9, 10],
      [11, 12, 13, 14, 15],
    ];
    hydro.analyze.stats.simulate({data: testData})

(static) runVegas(data) → {Array.<number>}

Generates a random simulated number when run with a dataset

Parameters:
Name Type Description
data Array.<Object>

passes data from multiple objects

Author:
  • riya-patil
Source:
Returns:

returns an array of the simulated results

Type
Array.<number>
Example
const testData = [
      [1, 2, 3, 4, 5],
      [6, 7, 8, 9, 10],
      [11, 12, 13, 14, 15],
    ];
    hydro.analyze.stats.runVegas({data: testData})

(static) simpleMovingAverage(params, data) → {Array}

Calculates the Simple Moving Average of a given data set

Parameters:
Name Type Description
params Object

Contains the parameter 'windowSize' which specifies the size of the moving average window.

data Object

Contains the array of data points.

Author:
  • riya-patil
Source:
Returns:

Array of moving average values.

Type
Array
Example
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const windowSize = 3;
hydro.analyze.stats.simpleMovingAverage({ params: { windowSize }, data });

(static) standardize(data) → {Array.<Object>}

Use mean and standard deviation to standardize the original dataset.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Array with standardized data.

Type
Array.<Object>
Example
hydro.analyze.stats.standardize({data: [data]})

(static) stddev(data) → {Number}

Calculates standard deviation of a 1d array.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Standard deviation.

Type
Number
Example
hydro.analyze.stats.stddev({data: [data]})

(static) sum(data) → {Number}

Sums all data in a 1-d array.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Sum of all data in an array.

Type
Number
Example
hydro.analyze.stats.sum({data: [data]})

(static) sumsqrd(data) → {Number}

Calculates sum of squares for a dataset.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Sum of squares for data.

Type
Number
Example
hydro.analyze.stats.sumsqrd({data: [data]})

(static) timegaps(params, data) → {Array.<Object>}

Identifies gaps in time. Used for filling gaps if required by the user. Time in minutes and timestep must be divisible by the total time of the event.

Parameters:
Name Type Description
params Object

Contains: timestep (in min)

data Object

Contains: 1d-JS array with timedata in minutes as [timeData].

Source:
Returns:

Array with gaps.

Type
Array.<Object>
Example
hydro.analyze.stats.timegaps({params: {timestep: 'someNum'} data: [timeData]})

(static) transposeMatrix(matrix) → {Array}

Transposes a matrix

Parameters:
Name Type Description
matrix Array

Matrix to transpose

Author:
  • riya-patil
Source:
Returns:

Transposed matrix

Type
Array
Example
const matrix = [[1, 2, 3], [4, 5, 6]];
hydro.analyze.stats.transposeMatrix(matrix)

(static) uniformDist(params, args) → {Number}

Calculates the probability density function (PDF) of the Uniform Distribution

Parameters:
Name Type Description
params Object

Contains the parameters 'a' (lower bound) and 'b' (upper bound).

args Object

Contains the argument 'x' at which to evaluate the PDF.

Author:
  • riya-patil
Source:
Returns:

Probability density at the given value 'x'.

Type
Number
Example
hydro.analyze.stats.uniformDist({ params: { a: 0, b: 1 }, args: { x: 0.5 } })

(static) unique(data) → {Array.<Object>}

Unique values in an array.

Parameters:
Name Type Description
data Object

Contains: 1d-JS array object with data as [data].

Source:
Returns:

Array with unique values.

Type
Array.<Object>
Example
hydro.analyze.stats.unique({data: [data]})

(static) variance(data) → {Number}

Calculate variance for an 1-d array of data.

Parameters:
Name Type Description
data Object

Contains 1d-JS array object with data as [data].

Source:
Returns:

Variance of the data.

Type
Number
Example
hydro.analyze.stats.variance({data: [data]})