Namespace JXG.Math.Statistics
↳ JXG.Math.Statistics
Defined in: statistics.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Functions for mathematical statistics.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
JXG.Math.Statistics.abs(arr)
Determines the absolute value of every given value.
|
<static> |
JXG.Math.Statistics.add(arr1, arr2)
Adds up two (sequences of) values.
|
<static> |
JXG.Math.Statistics.div(arr1, arr2)
Divides two (sequences of) values.
|
<static> <deprecated> |
JXG.Math.Statistics.divide()
|
<static> |
JXG.Math.Statistics.generateGaussian(mean, stdDev)
Generate values of a standard normal random variable with the Marsaglia polar method, see
https://en.wikipedia.org/wiki/Marsaglia_polar_method.
|
<static> |
JXG.Math.Statistics.histogram(x, opt)
Compute the histogram of a dataset.
|
<static> |
JXG.Math.Statistics.max(arr)
Extracts the maximum value from the array.
|
<static> |
JXG.Math.Statistics.mean(arr)
Determines the mean value of the values given in an array.
|
<static> |
JXG.Math.Statistics.median(arr)
The median of a finite set of values is the value that divides the set
into two equal sized subsets.
|
<static> |
JXG.Math.Statistics.min(arr)
Extracts the minimum value from the array.
|
<static> |
JXG.Math.Statistics.mod(arr1, arr2, math)
Divides two (sequences of) values and returns the remainder.
|
<static> |
JXG.Math.Statistics.multiply(arr1, arr2)
Multiplies two (sequences of) values.
|
<static> |
JXG.Math.Statistics.percentile(arr, percentile)
The P-th percentile ( 0 < P ≤ 100 ) of a list of N ordered values (sorted from least to greatest)
is the smallest value in the list such that no more than P percent of the data is strictly less
than the value and at least P percent of the data is less than or equal to that value.
|
<static> |
JXG.Math.Statistics.prod(arr)
Multiplies all elements of the given array.
|
<static> |
JXG.Math.Statistics.randomBeta(alpha, beta)
Generate value of a random variable with beta distribution with shape parameters alpha and beta.
|
<static> |
JXG.Math.Statistics.randomBinomial(n, p)
Generate values for a random variable in binomial distribution with parameters n and p.
|
<static> |
JXG.Math.Statistics.randomChisquare(k)
Generate value of a random variable with chi-square distribution with k degrees of freedom.
|
<static> |
JXG.Math.Statistics.randomExponential(lambda)
Generate value of a random variable with exponential distribution, i.e.
|
<static> |
JXG.Math.Statistics.randomF(d1, d2)
Generate value of a random variable with F-distribution with d1 and d2 degrees of freedom.
|
<static> |
JXG.Math.Statistics.randomGamma(a, b, t)
Generate value of a random variable with gamma distribution of order alpha.
|
<static> |
JXG.Math.Statistics.randomGeometric(p)
Generate values for a random variable in geometric distribution with probability p.
|
<static> |
JXG.Math.Statistics.randomHypergeometric(good, bad, samples)
Generate values for a random variable in hypergeometric distribution.
|
<static> |
JXG.Math.Statistics.randomNormal(mean, stdDev)
Generate value of a standard normal random variable with given mean and standard deviation.
|
<static> |
JXG.Math.Statistics.randomPareto(gamma, k)
Generate values for a random variable in Pareto distribution with
shape gamma and scale k.
|
<static> |
JXG.Math.Statistics.randomPoisson(mu)
Generate values for a random variable in Poisson distribution with mean mu.
|
<static> |
JXG.Math.Statistics.randomT(nu)
Generate value of a random variable with Students-t-distribution with ν degrees of freedom.
|
<static> |
JXG.Math.Statistics.randomUniform(a, b)
Generate value of a uniform distributed random variable in the interval [a, b].
|
<static> |
JXG.Math.Statistics.range(arr)
Determines the lowest and the highest value from the given array.
|
<static> |
JXG.Math.Statistics.sd(arr)
Determines the standard deviation which shows how much
variation there is from the average value of a set of numbers.
|
<static> |
JXG.Math.Statistics.subtract(arr1, arr2)
Subtracts two (sequences of) values.
|
<static> |
JXG.Math.Statistics.sum(arr)
Sums up all elements of the given array.
|
<static> |
JXG.Math.Statistics.TheilSenRegression(coords)
The Theil-Sen estimator can be used to determine a more robust linear regression of a set of sample
points than least squares regression in JXG.Math.Numerics.regressionPolynomial.
|
<static> |
JXG.Math.Statistics.variance(arr)
Bias-corrected sample variance.
|
<static> |
JXG.Math.Statistics.weightedMean(arr, w)
Weighted mean value is basically the same as JXG.Math.Statistics.mean but here the values
are weighted, i.e.
|
Namespace Detail
JXG.Math.Statistics
Functions for mathematical statistics. Most functions are like in the statistics package R.
Method Detail
<static>
{Array|Number}
JXG.Math.Statistics.abs(arr)
Determines the absolute value of every given value.
- Parameters:
- {Array|Number} arr
- Returns:
- {Array|Number}
<static>
{Array|Number}
JXG.Math.Statistics.add(arr1, arr2)
Adds up two (sequences of) values. If one value is an array and the other one is a number the number
is added to every element of the array. If two arrays are given and the lengths don't match the shortest
length is taken.
- Parameters:
- {Array|Number} arr1
- {Array|Number} arr2
- Returns:
- {Array|Number}
<static>
{Array|Number}
JXG.Math.Statistics.div(arr1, arr2)
Divides two (sequences of) values. If two arrays are given and the lengths don't match the shortest length
is taken.
- Parameters:
- {Array|Number} arr1
- Dividend
- {Array|Number} arr2
- Divisor
- Returns:
- {Array|Number}
<static>
JXG.Math.Statistics.divide()
- Deprecated:
- Use JXG.Math.Statistics.div instead.
<static>
{Number}
JXG.Math.Statistics.generateGaussian(mean, stdDev)
Generate values of a standard normal random variable with the Marsaglia polar method, see
https://en.wikipedia.org/wiki/Marsaglia_polar_method.
See also D. E. Knuth, The art of computer programming, vol 2, p. 117.
- Parameters:
- {Number} mean
- mean value of the normal distribution
- {Number} stdDev
- standard deviation of the normal distribution
- Returns:
- {Number} value of a standard normal random variable
<static>
JXG.Math.Statistics.histogram(x, opt)
Compute the histogram of a dataset.
Optional parameters can be supplied through a JavaScript object
with the following default values:
{ bins: 10, // Number of bins range: false, // false or array. The lower and upper range of the bins. // If not provided, range is simply [min(x), max(x)]. // Values outside the range are ignored. density: false, // If true, normalize the counts by dividing by sum(counts) cumulative: false }The function returns an array containing two arrays. The first array is of length bins+1 containing the start values of the bins. The last entry contains the end values of the last bin.
The second array contains the counts of each bin.
- Parameters:
- {Array} x
- {Object} opt
- Optional parameters
- Returns:
- Array [bin, counts] Array bins contains start values of bins, array counts contains the number of entries of x which are contained in each bin.
- Examples:
let board = JXG.JSXGraph.initBoard('jxgbox', { boundingbox: [-1.7, .5, 20, -.03], axis: true}); let board2 = JXG.JSXGraph.initBoard('jxgbox2', { boundingbox: [-1.6, 1.1, 20, -.06], axis: true}); let runs = [ [0.5, 1.0, 'brown'], [1.0, 2.0, 'red'], [2.0, 2.0, 'orange'], [3.0, 2.0, 'yellow'], [5.0, 1.0, 'green'], [9.0, 0.5, 'black'], [7.5, 1.0, 'purple'], ] let labelY = .4 runs.forEach((run,i) => { board.create('segment',[[7,labelY-(i/50)],[9,labelY-(i/50)]],{strokeColor:run[2]}) board.create('text',[10,labelY-(i/50),`k=${run[0]}, θ=${run[1]}`]) // density let x = Array(50000).fill(0).map(() => JXG.Math.Statistics.randomGamma(run[0],run[1])) let res = JXG.Math.Statistics.histogram(x, { bins: 50, density: true, cumulative: false, range: [0, 20] }); board.create('curve', [res[1], res[0]], { strokeColor: run[2], strokeWidth:2}); // cumulative density res = JXG.Math.Statistics.histogram(x, { bins: 50, density: true, cumulative: true, range: [0, 20] }); res[0].unshift(0) // add zero to front so cumulative starts at zero res[1].unshift(0) board2.create('curve', [res[1], res[0]], { strokeColor: run[2], strokeWidth:2 }); })
<static>
{Number}
JXG.Math.Statistics.max(arr)
Extracts the maximum value from the array.
- Parameters:
- {Array} arr
- Returns:
- {Number} The highest number from the array. It returns NaN if not every element could be interpreted as a number and -Infinity if an empty array is given or no element could be interpreted as a number.
<static>
{Number}
JXG.Math.Statistics.mean(arr)
Determines the mean value of the values given in an array.
- Parameters:
- {Array} arr
- Returns:
- {Number}
<static>
{Number}
JXG.Math.Statistics.median(arr)
The median of a finite set of values is the value that divides the set
into two equal sized subsets.
- Parameters:
- {Array} arr
- The set of values.
- Returns:
- {Number}
<static>
{Number}
JXG.Math.Statistics.min(arr)
Extracts the minimum value from the array.
- Parameters:
- {Array} arr
- Returns:
- {Number} The lowest number from the array. It returns NaN if not every element could be interpreted as a number and Infinity if an empty array is given or no element could be interpreted as a number.
<static>
{Array|Number}
JXG.Math.Statistics.mod(arr1, arr2, math)
Divides two (sequences of) values and returns the remainder. If two arrays are given and the lengths don't
match the shortest length is taken.
- Parameters:
- {Array|Number} arr1
- Dividend
- {Array|Number} arr2
- Divisor
- {Boolean} math Optional, Default: false
- Mathematical mod or symmetric mod? Default is symmetric, the JavaScript % operator.
- Returns:
- {Array|Number}
<static>
{Array|Number}
JXG.Math.Statistics.multiply(arr1, arr2)
Multiplies two (sequences of) values. If one value is an array and the other one is a number the number
is multiplied to every element of the array. If two arrays are given and the lengths don't match the shortest
length is taken.
- Parameters:
- {Array|Number} arr1
- {Array|Number} arr2
- Returns:
- {Array|Number}
<static>
{Number|Array}
JXG.Math.Statistics.percentile(arr, percentile)
The P-th percentile ( 0 < P ≤ 100 ) of a list of N ordered values (sorted from least to greatest)
is the smallest value in the list such that no more than P percent of the data is strictly less
than the value and at least P percent of the data is less than or equal to that value.
See https://en.wikipedia.org/wiki/Percentile.
Here, the linear interpolation between closest ranks method is used.
- Parameters:
- {Array} arr
- The set of values, need not be ordered.
- {Number|Array} percentile
- One or several percentiles
- Returns:
- {Number|Array} Depending if a number or an array is the input for percentile, a number or an array containing the percentiles is returned.
<static>
{Number}
JXG.Math.Statistics.prod(arr)
Multiplies all elements of the given array.
- Parameters:
- {Array} arr
- An array of numbers.
- Returns:
- {Number}
<static>
JXG.Math.Statistics.randomBeta(alpha, beta)
Generate value of a random variable with beta distribution with shape parameters alpha and beta.
See https://en.wikipedia.org/wiki/Beta_distribution.
- Parameters:
- {Number} alpha
- > 0
- {Number} beta
- > 0
- Returns:
- Number
<static>
JXG.Math.Statistics.randomBinomial(n, p)
Generate values for a random variable in binomial distribution with parameters n and p.
See https://en.wikipedia.org/wiki/Binomial_distribution.
It uses algorithm BG from https://dl.acm.org/doi/pdf/10.1145/42372.42381.
- Parameters:
- {Number} n
- Number of trials (n >= 0)
- {Number} p
- Probability (0 <= p <= 1)
- Returns:
- Number Integer value of a random variable in binomial distribution
- Examples:
let board = JXG.JSXGraph.initBoard('jxgbox', { boundingbox: [-1.7, .5, 30, -.03], axis: true }); let runs = [ [0.5, 20, 'blue'], [0.7, 20, 'green'], [0.5, 40, 'red'], ]; let labelY = .4; runs.forEach((run, i) => { board.create('segment', [[7, labelY - (i / 50)], [9, labelY - (i / 50)]], { strokeColor: run[2] }); board.create('text', [10, labelY - (i / 50), `p=${run[0]}, n=${run[1]}`]); let x = Array(50000).fill(0).map(() => JXG.Math.Statistics.randomBinomial(run[1], run[0])); let res = JXG.Math.Statistics.histogram(x, { bins: 40, density: true, cumulative: false, range: [0, 40] }); board.create('curve', [res[1], res[0]], { strokeColor: run[2] }); });
<static>
JXG.Math.Statistics.randomChisquare(k)
Generate value of a random variable with chi-square distribution with k degrees of freedom.
See https://en.wikipedia.org/wiki/Chi-squared_distribution.
- Parameters:
- {Number} k
- > 0
- Returns:
- Number
<static>
JXG.Math.Statistics.randomExponential(lambda)
Generate value of a random variable with exponential distribution, i.e.
f(x; lambda) = lambda * e^(-lambda x) if x >= 0 and f(x; lambda) = 0 if x < 0.
See https://en.wikipedia.org/wiki/Exponential_distribution.
Algorithm: D.E. Knuth, TAOCP 2, p. 128.
- Parameters:
- {Number} lambda
- > 0
- Returns:
- Number
- Examples:
let board = JXG.JSXGraph.initBoard('JXGbox', { boundingbox: [-.5, 1.5, 5, -.1], axis: true}); let runs = [ [0.5, 'red'], [1.0, 'green'], [1.5, 'blue'], ] let labelY = 1 runs.forEach((run,i) => { board.create('segment',[[1.8,labelY-(i/20)],[2.3,labelY-(i/20)]],{strokeColor:run[1]}) board.create('text',[2.5,labelY-(i/20),`λ=${run[0]}`]) let x = Array(50000).fill(0).map(() => JXG.Math.Statistics.randomExponential(run[0])) let res = JXG.Math.Statistics.histogram(x, { bins: 40, density: true, cumulative: false, range: false }); board.create('curve', [res[1], res[0]], { strokeColor: run[1], strokeWidth:2}); })
<static>
JXG.Math.Statistics.randomF(d1, d2)
Generate value of a random variable with F-distribution with d1 and d2 degrees of freedom.
See https://en.wikipedia.org/wiki/F-distribution.
- Parameters:
- {Number} d1
- > 0
- {Number} d2
- > 0
- Returns:
- Number
<static>
JXG.Math.Statistics.randomGamma(a, b, t)
Generate value of a random variable with gamma distribution of order alpha.
See https://en.wikipedia.org/wiki/Gamma_distribution.
Algorithm: D.E. Knuth, TAOCP 2, p. 129.
- Parameters:
- {Number} a
- shape, > 0
- {Number} b Optional, Default: 1
- scale, > 0
- {Number} t Optional, Default: 0
- threshold
- Returns:
- Number
- Examples:
let board = JXG.JSXGraph.initBoard('jxgbox', { boundingbox: [-1.7, .5, 20, -.03], axis: true}); let runs = [ [0.5, 1.0, 'brown'], [1.0, 2.0, 'red'], [2.0, 2.0, 'orange'], [3.0, 2.0, 'yellow'], [5.0, 1.0, 'green'], [9.0, 0.5, 'black'], [7.5, 1.0, 'purple'], ] let labelY = .4 runs.forEach((run,i) => { board.create('segment',[[7,labelY-(i/50)],[9,labelY-(i/50)]],{strokeColor:run[2]}) board.create('text',[10,labelY-(i/50),`k=${run[0]}, θ=${run[1]}`]) // density let x = Array(50000).fill(0).map(() => JXG.Math.Statistics.randomGamma(run[0],run[1])) let res = JXG.Math.Statistics.histogram(x, { bins: 50, density: true, cumulative: false, range: [0, 20] }); board.create('curve', [res[1], res[0]], { strokeColor: run[2]}); })
<static>
JXG.Math.Statistics.randomGeometric(p)
Generate values for a random variable in geometric distribution with probability p.
See https://en.wikipedia.org/wiki/Geometric_distribution.
- Parameters:
- {Number} p
- (0 <= p <= 1)
- Returns:
- Number
<static>
JXG.Math.Statistics.randomHypergeometric(good, bad, samples)
Generate values for a random variable in hypergeometric distribution.
Samples are drawn from a hypergeometric distribution with specified parameters, good (ways to make a good selection),
bad (ways to make a bad selection), and samples (number of items sampled, which is less than or equal to good + bad).
Naive implementation with runtime O(samples).
- Parameters:
- {Number} good
- ways to make a good selection
- {Number} bad
- ways to make a bad selection
- {Number} samples
- number of items sampled
- Returns:
<static>
JXG.Math.Statistics.randomNormal(mean, stdDev)
Generate value of a standard normal random variable with given mean and standard deviation.
Alias for JXG.Math.Statistics#generateGaussian
- Parameters:
- {Number} mean
- {Number} stdDev
- Returns:
- Number
- See:
- JXG.Math.Statistics#generateGaussian
- Examples:
let board = JXG.JSXGraph.initBoard('JXGbox', { boundingbox: [-5, 1.5, 5, -.03], axis: true}); let runs = [ [0, 0.2, 'blue'], [0, 1.0, 'red'], [0, 5.0, 'orange'], [-2,0.5, 'green'], ] let labelY = 1.2 runs.forEach((run,i) => { board.create('segment',[[1.0,labelY-(i/20)],[2.0,labelY-(i/20)]],{strokeColor:run[2]}) board.create('text',[2.5,labelY-(i/20),`μ=${run[0]}, σ2=${run[1]}`]) let x = Array(50000).fill(0).map(() => JXG.Math.Statistics.randomNormal(run[0],Math.sqrt(run[1]))) // sqrt so Std Dev, not Variance let res = JXG.Math.Statistics.histogram(x, { bins: 40, density: true, cumulative: false, range: false }); board.create('curve', [res[1], res[0]], { strokeColor: run[2], strokeWidth:2}); })
<static>
JXG.Math.Statistics.randomPareto(gamma, k)
Generate values for a random variable in Pareto distribution with
shape gamma and scale k.
See https://en.wikipedia.org/wiki/Pareto_distribution.
Method: use inverse transformation sampling.
- Parameters:
- {Number} gamma
- shape (0 < gamma)
- {Number} k
- scale (0 < k < x)
- Returns:
- Number
<static>
JXG.Math.Statistics.randomPoisson(mu)
Generate values for a random variable in Poisson distribution with mean mu.
See https://en.wikipedia.org/wiki/Poisson_distribution.
- Parameters:
- {Number} mu
- (0 < mu)
- Returns:
- Number
<static>
JXG.Math.Statistics.randomT(nu)
Generate value of a random variable with Students-t-distribution with ν degrees of freedom.
See https://en.wikipedia.org/wiki/Student%27s_t-distribution.
- Parameters:
- {Number} nu
- > 0
- Returns:
- Number
<static>
JXG.Math.Statistics.randomUniform(a, b)
Generate value of a uniform distributed random variable in the interval [a, b].
- Parameters:
- {Number} a
- {Number} b
- Returns:
- Number
<static>
{Array}
JXG.Math.Statistics.range(arr)
Determines the lowest and the highest value from the given array.
- Parameters:
- {Array} arr
- Returns:
- {Array} The minimum value as the first and the maximum value as the second value.
<static>
{Number}
JXG.Math.Statistics.sd(arr)
Determines the standard deviation which shows how much
variation there is from the average value of a set of numbers.
- Parameters:
- {Array} arr
- Returns:
- {Number}
<static>
{Array|Number}
JXG.Math.Statistics.subtract(arr1, arr2)
Subtracts two (sequences of) values. If two arrays are given and the lengths don't match the shortest
length is taken.
- Parameters:
- {Array|Number} arr1
- Minuend
- {Array|Number} arr2
- Subtrahend
- Returns:
- {Array|Number}
<static>
{Number}
JXG.Math.Statistics.sum(arr)
Sums up all elements of the given array.
- Parameters:
- {Array} arr
- An array of numbers.
- Returns:
- {Number}
<static>
{Array}
JXG.Math.Statistics.TheilSenRegression(coords)
The Theil-Sen estimator can be used to determine a more robust linear regression of a set of sample
points than least squares regression in JXG.Math.Numerics.regressionPolynomial.
If the function should be applied to an array a of points, a the coords array can be generated with
JavaScript array.map:
JXG.Math.Statistics.TheilSenRegression(a.map(el => el.coords));
- Parameters:
- {Array} coords
- Array of JXG.Coords.
- Returns:
- {Array} A stdform array of the regression line.
- Examples:
var board = JXG.JSXGraph.initBoard('jxgbox', { boundingbox: [-6,6,6,-6], axis : true }); var a=[]; a[0]=board.create('point', [0,0]); a[1]=board.create('point', [3,0]); a[2]=board.create('point', [0,3]); board.create('line', [ () => JXG.Math.Statistics.TheilSenRegression(a.map(el => el.coords)) ], {strokeWidth:1, strokeColor:'black'});
<static>
{Number}
JXG.Math.Statistics.variance(arr)
Bias-corrected sample variance. A variance is a measure of how far a
set of numbers are spread out from each other.
- Parameters:
- {Array} arr
- Returns:
- {Number}
<static>
{Number}
JXG.Math.Statistics.weightedMean(arr, w)
Weighted mean value is basically the same as JXG.Math.Statistics.mean but here the values
are weighted, i.e. multiplied with another value called weight. The weight values are given
as a second array with the same length as the value array..
- Parameters:
- {Array} arr
- Set of alues.
- {Array} w
- Weight values.
- Throws:
- {Error}
- If the dimensions of the arrays don't match.
- Returns:
- {Number}