Statistics Functions (38)

Statistical analysis, distributions, hypothesis testing, regression

anova
Perform a one-way ANOVA (Analysis of Variance) F-test comparing means across multiple groups.
Syntax
anova(groups)
Parameters
NameTypeDescription
groupsArrayArray of arrays, each inner array is one group
Returns
Object — Object with F, pValue, dfBetween, dfWithin
Examples
anova([[1
2
3
betaDist
Create a Beta distribution with shape parameters alpha and beta. Returns an object with pdf(x), cdf(x), mean, and variance.
Syntax
betaDist(alpha | beta)
Type Signatures
number, number
Parameters
NameTypeDescription
alphanumberFirst shape parameter (must be positive)
betanumberSecond shape parameter (must be positive)
Returns
Object — Distribution object with pdf, cdf, mean, variance
Examples
d = betaDist(2
5)
d.pdf(0.3)
d.cdf(0.3)
d.mean
binomialDist
Create a binomial distribution with n trials and success probability p. The binomial distribution models the number of successes in n independent trials. Returns an object with pmf(k), cdf(k), mean, and variance.
Syntax
binomialDist(n | p)
Type Signatures
number, number
Parameters
NameTypeDescription
nnumberNumber of trials (positive integer)
pnumberProbability of success (in [0, 1])
Returns
Object — Distribution object with pmf, cdf, mean, variance
Examples
d = binomialDist(10
0.5)
d.pmf(5)
d.cdf(5)
d.mean
chiSquareTest
Perform a chi-squared test. For 1D arrays (observed, expected), performs a goodness-of-fit test.
Syntax
chiSquareTest(observed | expected) | chiSquareTest(observed)
Type Signatures
Array, Array
Parameters
NameTypeDescription
observedArray1D or 2D array of observed counts
expectedArray1D array of expected counts (only for 1D case)
Returns
Object — Object with chiSquared, pValue, df
Examples
chiSquareTest([10
20
30
See Also
anova studentTTest
chiSquaredDist
Create a chi-squared distribution with k degrees of freedom. Commonly used in hypothesis testing and confidence interval estimation for variance. Returns an object with pdf(x), cdf(x), mean, and variance.
Syntax
chiSquaredDist(k)
Parameters
NameTypeDescription
knumberDegrees of freedom (must be a positive integer)
Returns
Object — Distribution object with pdf, cdf, mean, variance
Examples
d = chiSquaredDist(3)
d.pdf(1)
d.cdf(7.815)
d.mean
d.variance
See Also
tDist normalDist
corr
Compute the correlation coefficient of a two list with values, For matrices, the matrix correlation coefficient is calculated.
Syntax
corr(A | B)
Type Signatures
Array, Array, Matrix, Matrix
Parameters
NameTypeDescription
AArray | MatrixThe first array or matrix to compute correlation coefficient
BArray | MatrixThe second array or matrix to compute correlation coefficient
Returns
* — The correlation coefficient
Examples
corr([2
4
6
8
covariance
Compute the sample covariance of two datasets. cov(x, y) = sum((x_i - mean_x) * (y_i - mean_y)) / (n - 1)
Syntax
covariance(x | y)
Type Signatures
Array | Matrix, Array | Matrix
Parameters
NameTypeDescription
xArray | MatrixFirst dataset
yArray | MatrixSecond dataset (must be same length as x)
Returns
number — The sample covariance
Examples
covariance([1
2
3
4
5
See Also
mean std variance linreg
cumsum
Compute the cumulative sum of all values.
Syntax
cumsum(a | b | c
Type Signatures
Matrix, number | BigNumber, ...
Parameters
NameTypeDescription
args... *A single matrix or or multiple scalar values
Returns
* — The cumulative sum of all values
Examples
cumsum(2
3
4
1)
cumsum([2
exponentialDist
Create an exponential distribution with rate parameter lambda. Models the time between events in a Poisson process. Returns an object with pdf(x), cdf(x), icdf(p), mean, and variance.
Syntax
exponentialDist(lambda)
Parameters
NameTypeDescription
lambdanumberRate parameter (must be positive)
Returns
Object — Distribution object with pdf, cdf, icdf, mean, variance
Examples
d = exponentialDist(2)
d.pdf(1)
d.cdf(1)
d.icdf(0.5)
d.mean
fDist
Create an F-distribution with numerator df1 and denominator df2 degrees of freedom. Returns an object with pdf(x), cdf(x), mean, and variance.
Syntax
fDist(df1 | df2)
Type Signatures
number, number
Parameters
NameTypeDescription
df1numberNumerator degrees of freedom (must be positive)
df2numberDenominator degrees of freedom (must be positive)
Returns
Object — Distribution object with pdf, cdf, mean, variance
Examples
d = fDist(5
10)
d.pdf(1)
d.cdf(1)
d.mean
gammaDist
Create a Gamma distribution with shape k and rate beta. Returns an object with pdf(x), cdf(x), mean, and variance.
Syntax
gammaDist(k | beta)
Type Signatures
number, number
Parameters
NameTypeDescription
knumberShape parameter (must be positive)
betanumberRate parameter (must be positive)
Returns
Object — Distribution object with pdf, cdf, mean, variance
Examples
d = gammaDist(2
1)
d.pdf(1)
d.cdf(1)
d.mean
histogram
Compute a frequency histogram. If bins is a number, creates that many equal-width bins from min to max. If bins is an array, uses those values as bin edges. Returns an object with counts, binEdges, and binCenters.
Syntax
histogram(data | bins) | histogram(data
Type Signatures
Array, number, Array, Array
Parameters
NameTypeDescription
dataArrayArray of numeric values
binsnumber|ArrayNumber of equal-width bins, or array of bin edges
Returns
Object — Object with counts, binEdges, binCenters
Examples
histogram([1
2
2
3
3
See Also
mean std variance
kolmogorovSmirnovTest
Perform a Kolmogorov-Smirnov test. One-sample: compare a sample ECDF to a theoretical CDF function.
Syntax
kolmogorovSmirnovTest(sample | cdfFn) | kolmogorovSmirnovTest(sample1
Type Signatures
Array, Array, Array, function
Parameters
NameTypeDescription
sampleArrayFirst sample (or only sample for one-sample test)
distOrSampleArray|FunctionCDF function or second sample array
Returns
Object — Object with D (KS statistic) and pValue
Examples
kolmogorovSmirnovTest([1
2
3
kurtosis
Compute the sample excess kurtosis of a dataset. Kurtosis measures the "tailedness" of the probability distribution. A normal distribution has excess kurtosis of 0.
Syntax
kurtosis(array)
Type Signatures
Array | Matrix
Parameters
NameTypeDescription
arrayArray | MatrixA single matrix or array with values
Returns
number — The sample excess kurtosis
Examples
kurtosis([2
4
4
4
5
linreg
Perform simple linear regression (ordinary least squares) on two datasets. Returns an object with slope, intercept, r (correlation coefficient), r2 (R-squared), and predict(x) function.
Syntax
linreg(x | y)
Type Signatures
Array | Matrix, Array | Matrix
Parameters
NameTypeDescription
xArray | MatrixIndependent variable (predictor)
yArray | MatrixDependent variable (response)
Returns
Object — Object with slope, intercept, r, r2, predict
Examples
r = linreg([1
2
3
4
5
See Also
covariance mean std
logNormalDist
Create a log-normal distribution with log-scale parameters mu and sigma. Returns an object with pdf(x), cdf(x), icdf(p), mean, and variance.
Syntax
logNormalDist(mu | sigma)
Type Signatures
number, number
Parameters
NameTypeDescription
munumberMean of the underlying normal distribution (log-scale)
sigmanumberStandard deviation of the underlying normal distribution (must be positive)
Returns
Object — Distribution object with pdf, cdf, icdf, mean, variance
Examples
d = logNormalDist(0
1)
d.pdf(1)
d.cdf(1)
d.icdf(0.5)
mad
Compute the median absolute deviation of a matrix or a list with values. The median absolute deviation is defined as the median of the absolute deviations from the median.
Syntax
mad(a | b | c
Type Signatures
...
Parameters
NameTypeDescription
arrayArray | Matrix
Returns
* — The median absolute deviation.
Examples
mad(10
20
30)
mad([1
2
See Also
mean median std abs
mannWhitneyTest
Perform a Mann-Whitney U test (Wilcoxon rank-sum test), a non-parametric test for whether
Syntax
mannWhitneyTest(sample1 | sample2)
Type Signatures
Array, Array
Parameters
NameTypeDescription
sample1ArrayFirst sample (array of numbers)
sample2ArraySecond sample (array of numbers)
Returns
Object — Object with U and pValue
Examples
mannWhitneyTest([1
2
3
4
max
Compute the maximum value of a list of values. If any NaN values are found, the function yields the last NaN in the input.
Syntax
max(a | b | c
Type Signatures
Array | Matrix, number | BigNumber, ...
Parameters
NameTypeDescription
args... *A single matrix or or multiple scalar values
Returns
* — The maximum value
Examples
max(2
3
4
1)
max([2
mean
Compute the arithmetic mean of a list of values.
Syntax
mean(a | b | c
Type Signatures
...
Parameters
NameTypeDescription
args... *A single matrix or or multiple scalar values
Returns
* — The mean of all values
Examples
mean(2
3
4
1)
mean([2
median
Compute the median of all values. The values are sorted and the middle value is returned. In case of an even number of values, the average of the two middle values is returned.
Syntax
median(a | b | c
Type Signatures
number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit, Array | Matrix, number | BigNumber, ...
Parameters
NameTypeDescription
arrayArray
Returns
Number — median
Examples
median(5
2
7)
median([3
-1
min
Compute the minimum value of a list of values. If any NaN values are found, the function yields the last NaN in the input.
Syntax
min(a | b | c
Type Signatures
Array | Matrix, number | BigNumber, ...
Parameters
NameTypeDescription
args... *A single matrix or or multiple scalar values
Returns
* — The minimum value
Examples
min(2
3
4
1)
min([2
mode
Computes the mode of all values as an array. In case mode being more than one, multiple values are returned in an array.
Syntax
mode(a | b | c
Type Signatures
...
Parameters
NameTypeDescription
args... *A single matrix
Returns
* — The mode of all values
Examples
mode(2
1
4
3
1)
movingAverage
Compute the simple moving average of a dataset with a given window size. Returns an array of length (n - window + 1).
Syntax
movingAverage(array | window)
Type Signatures
Array | Matrix, number
Parameters
NameTypeDescription
arrayArray | MatrixInput data array
windownumberWindow size (must be a positive integer)
Returns
Array — Array of moving averages
Examples
movingAverage([1
2
3
4
5
See Also
mean sum
normalDist
Create a normal (Gaussian) distribution with mean mu and standard deviation sigma. Returns an object with pdf(x), cdf(x), icdf(p), mean, and variance.
Syntax
normalDist(mu | sigma)
Type Signatures
number, number
Parameters
NameTypeDescription
munumberMean of the distribution
sigmanumberStandard deviation (must be positive)
Returns
Object — Distribution object with pdf, cdf, icdf, mean, variance
Examples
d = normalDist(0
1)
d.pdf(0)
d.cdf(1.96)
d.icdf(0.975)
poissonDist
Create a Poisson distribution with rate parameter lambda. The Poisson distribution models the number of events in a fixed interval. Returns an object with pmf(k), cdf(k), mean, and variance.
Syntax
poissonDist(lambda)
Parameters
NameTypeDescription
lambdanumberRate parameter (must be positive)
Returns
Object — Distribution object with pmf, cdf, mean, variance
Examples
d = poissonDist(3)
d.pmf(3)
d.cdf(4)
d.mean
d.variance
principalComponentAnalysis
Perform Principal Component Analysis (PCA). Centers the data, computes the covariance matrix,
Syntax
principalComponentAnalysis(data)
Parameters
NameTypeDescription
dataArray2D array: rows = observations, columns = variables
Returns
Object — Object with components, eigenvalues, scores, explainedVariance
Examples
principalComponentAnalysis([[1
2
See Also
variance corr
prod
Compute the product of all values.
Syntax
prod(a | b | c
Type Signatures
Array | Matrix, number | BigNumber, ...
Parameters
NameTypeDescription
args... *A single matrix or or multiple scalar values
Returns
* — The product of all values
Examples
prod(2
3
4)
prod([2
3
quantileSeq
Compute the prob order quantile of a matrix or a list with values. The sequence is sorted and the middle value is returned. Supported types of sequence values are: Number, BigNumber, Unit Supported types of probability are: Number, BigNumber. \n\nIn case of a (multi dimensional) array or matrix, the
Syntax
quantileSeq(A | prob[ | sorted
Parameters
NameTypeDescription
dataArray, MatrixA single matrix or Array
probOrNNumber, BigNumber, Arrayprob is the order of the quantile, while N is
sortedBoolean=false is data sorted in ascending order
Returns
Number, BigNumber, Unit, Array — Quantile(s)
Examples
quantileSeq([3
-1
5
7
shapiroWilkTest
Perform the Shapiro-Wilk test for normality. Sorts the sample and computes W using
Syntax
shapiroWilkTest(sample)
Parameters
NameTypeDescription
sampleArrayArray of numeric values (3 <= n <= 5000)
Returns
Object — Object with W (statistic) and pValue
Examples
shapiroWilkTest([2.1
2.3
1.9
2.0
2.2
skewness
Compute the sample skewness of a dataset. Skewness measures the asymmetry of the probability distribution. Uses the adjusted Fisher-Pearson standardized moment coefficient.
Syntax
skewness(array)
Type Signatures
Array | Matrix
Parameters
NameTypeDescription
arrayArray | MatrixA single matrix or array with values
Returns
number — The sample skewness
Examples
skewness([2
4
6
8
10
std
Compute the standard deviation of all values, defined as std(A) = sqrt(variance(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".
Syntax
std(a | b | c
Type Signatures
...
Parameters
NameTypeDescription
arrayArray | Matrix
Returns
* — The standard deviation
Examples
std(2
4
6)
std([2
4
studentTTest
Perform a two-sample Welch t-test (unequal variances). Tests whether the means of two independent samples differ significantly. Uses the Welch-Satterthwaite approximation for degrees of freedom. Returns an object with t (statistic), df (degrees of freedom), and pValue (two-tailed).
Syntax
studentTTest(sample1 | sample2)
Type Signatures
Array, Array
Parameters
NameTypeDescription
sample1ArrayFirst sample (array of numbers)
sample2ArraySecond sample (array of numbers)
Returns
Object — Object with t, df, pValue
Examples
studentTTest([1
2
3
4
5
See Also
mean variance std
sum
Compute the sum of all values.
Syntax
sum(a | b | c
Type Signatures
...
Parameters
NameTypeDescription
args... *A single matrix or multiple scalar values
Returns
* — The sum of all values
Examples
sum(2
3
4
1)
sum([2
tDist
Syntax
tDist(df)
Parameters
NameTypeDescription
dfnumberDegrees of freedom (must be positive)
Returns
Object — Distribution object with pdf, cdf, mean, variance
Examples
d = tDist(10)
d.pdf(0)
d.cdf(2.228)
d.mean
d.variance
uniformDist
Create a continuous uniform distribution on [a, b]. Returns an object with pdf(x), cdf(x), icdf(p), mean, and variance.
Syntax
uniformDist(a | b)
Type Signatures
number, number
Parameters
NameTypeDescription
anumberLower bound of the distribution
bnumberUpper bound of the distribution (must be > a)
Returns
Object — Distribution object with pdf, cdf, icdf, mean, variance
Examples
d = uniformDist(0
1)
d.pdf(0.5)
d.cdf(0.5)
d.icdf(0.5)
variance
Compute the variance of all values. Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".
Syntax
variance(a | b | c
Type Signatures
Array | Matrix, Array | Matrix, number | BigNumber, ...
Parameters
NameTypeDescription
arrayArray | Matrix
Returns
* — The variance
Examples
variance(2
4
6)
variance([2
4
weibullDist
Create a Weibull distribution with shape parameter k and scale parameter lambda. Generalizes the exponential distribution (k=1 reduces to exponential with rate 1/lambda). Returns an object with pdf(x), cdf(x), mean, and variance.
Syntax
weibullDist(k | lambda)
Type Signatures
number, number
Parameters
NameTypeDescription
knumberShape parameter (must be positive)
lambdanumberScale parameter (must be positive)
Returns
Object — Distribution object with pdf, cdf, mean, variance
Examples
d = weibullDist(2
1)
d.pdf(1)
d.cdf(1)
d.mean