Mann-Whitney U rank test of whether two independent samples come from the same distribution, matching
scipy.stats.mannwhitneyu. greater tests that values of first tend to exceed values of second. The statistic
is the U of first.
auto uses the exact null distribution when there are no tied values and the smaller sample has at most 8 values,
which is SciPy's rule, provided the distribution costs at most 2e7 steps to build; otherwise it uses the normal
approximation with tie correction. exact with tied values truncates the statistic as SciPy does. Building the exact
distribution takes O(m² n) time and O(m n) space for sizes m <= n.
When every value is equal the variance is zero. SciPy returns NaN there; this function throws.
@throws ― {HypothesisTestInvalidInputError} With EMPTY_SAMPLE, NON_FINITE_SAMPLE, INVALID_OPTION (also for an
exact method beyond the work limit), or ZERO_VARIANCE.
mannWhitneyUTest } from'knotkit/hypothesis-test'
// Page load times in milliseconds, before and after a change.
Mann-Whitney U rank test of whether two independent samples come from the same distribution, matching
scipy.stats.mannwhitneyu. greater tests that values of first tend to exceed values of second. The statistic
is the U of first.
auto uses the exact null distribution when there are no tied values and the smaller sample has at most 8 values,
which is SciPy's rule, provided the distribution costs at most 2e7 steps to build; otherwise it uses the normal
approximation with tie correction. exact with tied values truncates the statistic as SciPy does. Building the exact
distribution takes O(m² n) time and O(m n) space for sizes m <= n.
When every value is equal the variance is zero. SciPy returns NaN there; this function throws.
@throws ― {HypothesisTestInvalidInputError} With EMPTY_SAMPLE, NON_FINITE_SAMPLE, INVALID_OPTION (also for an
exact method beyond the work limit), or ZERO_VARIANCE.
mannWhitneyUTest(
constbefore:number[]
before,
constafter:number[]
after)
constresult:MannWhitneyUTestResult
result.
HypothesisTestResult.pValue: Probability
Null probability of a result at least as extreme as the observed one.
pValue<0.05// true
constresult:MannWhitneyUTestResult
result.
HypothesisTestResult.pValue: Probability
Null probability of a result at least as extreme as the observed one.
pValue.
Number.toFixed(fractionDigits?: number): string
Returns a string representing a number in fixed-point notation.
@param ― fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
Mann-Whitney U rank test of whether two independent samples come from the same distribution, matching
scipy.stats.mannwhitneyu. greater tests that values of first tend to exceed values of second. The statistic
is the U of first.
auto uses the exact null distribution when there are no tied values and the smaller sample has at most 8 values,
which is SciPy's rule, provided the distribution costs at most 2e7 steps to build; otherwise it uses the normal
approximation with tie correction. exact with tied values truncates the statistic as SciPy does. Building the exact
distribution takes O(m² n) time and O(m n) space for sizes m <= n.
When every value is equal the variance is zero. SciPy returns NaN there; this function throws.
@throws ― {HypothesisTestInvalidInputError} With EMPTY_SAMPLE, NON_FINITE_SAMPLE, INVALID_OPTION (also for an
exact method beyond the work limit), or ZERO_VARIANCE.
mannWhitneyUTest } from'knotkit/hypothesis-test'
import {
functionsplitmix32(seed:number): () =>number
Creates a deterministic 32-bit pseudorandom number generator.
Each call advances a private state by 0x9e3779b9. This constant equals
floor(2^32 / phi), where phi is the golden ratio. Addition wraps modulo
2^32. Because the increment is odd, it is coprime to 2^32. The resulting
Weyl sequence visits every 32-bit state once before it repeats.
The mixing function uses the constants 0x21f0aaad and 0x735a2d97 from
the
search
for low avalanche bias. Its XOR-shifts and multiplications by odd integers
are invertible over 32-bit values. The mixer therefore preserves the full
period while diffusing nearby states across the output bits.
Math.imul and the bitwise operators keep the mixing steps in 32-bit
arithmetic. The final unsigned conversion produces an integer from 0 to
2^32 - 1. Dividing by 2^32 maps that integer to [0, 1).
The SplitMix family was introduced by Steele, Lea, and Flood in
Create a log-normal distribution from the parameters of its underlying normal distribution.
Each draw uses two 32-bit words.
@throws ― {DistributionInvalidInputError} With INVALID_PARAMETER for an unsupported log mean or log standard deviation.
logNormalDistribution({
LogNormalDistributionParameters.logMean: number
logMean:
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.log(x: number): number
Returns the natural logarithm (base e) of a number.
@param ― x A numeric expression.
log(380),
LogNormalDistributionParameters.logStandardDeviation: number
logStandardDeviation: 0.5 })
const
constbeforeRandom: () =>number
beforeRandom=
functionsplitmix32(seed:number): () =>number
Creates a deterministic 32-bit pseudorandom number generator.
Each call advances a private state by 0x9e3779b9. This constant equals
floor(2^32 / phi), where phi is the golden ratio. Addition wraps modulo
2^32. Because the increment is odd, it is coprime to 2^32. The resulting
Weyl sequence visits every 32-bit state once before it repeats.
The mixing function uses the constants 0x21f0aaad and 0x735a2d97 from
the
search
for low avalanche bias. Its XOR-shifts and multiplications by odd integers
are invertible over 32-bit values. The mixer therefore preserves the full
period while diffusing nearby states across the output bits.
Math.imul and the bitwise operators keep the mixing steps in 32-bit
arithmetic. The final unsigned conversion produces an integer from 0 to
2^32 - 1. Dividing by 2^32 maps that integer to [0, 1).
The SplitMix family was introduced by Steele, Lea, and Flood in
This generator is not cryptographically secure. Use crypto.getRandomValues()
when unpredictability matters.
@param ― seed - Initial seed, coerced to a signed 32-bit integer.
@returns ― A stateful function that returns the next value in the range [0, 1).
splitmix32(1)
const
constafterRandom: () =>number
afterRandom=
functionsplitmix32(seed:number): () =>number
Creates a deterministic 32-bit pseudorandom number generator.
Each call advances a private state by 0x9e3779b9. This constant equals
floor(2^32 / phi), where phi is the golden ratio. Addition wraps modulo
2^32. Because the increment is odd, it is coprime to 2^32. The resulting
Weyl sequence visits every 32-bit state once before it repeats.
The mixing function uses the constants 0x21f0aaad and 0x735a2d97 from
the
search
for low avalanche bias. Its XOR-shifts and multiplications by odd integers
are invertible over 32-bit values. The mixer therefore preserves the full
period while diffusing nearby states across the output bits.
Math.imul and the bitwise operators keep the mixing steps in 32-bit
arithmetic. The final unsigned conversion produces an integer from 0 to
2^32 - 1. Dividing by 2^32 maps that integer to [0, 1).
The SplitMix family was introduced by Steele, Lea, and Flood in
@param ― iterable An iterable object to convert to an array.
@param ― mapfn A mapping function to call on every element of the array.
@param ― thisArg Value of 'this' used to invoke the mapfn.
from({
ArrayLike<T>.length: number
length: 5_000 }, () =>
constbefore:LogNormalDistribution
before.
CumulativeDistribution<"log-normal", LogNormalDistributionParameters>.draw: (random:RandomSource) => number
Draw one value from the supplied source. There is no state between draws besides the caller's source.
The same seed replays on the same engine build and platform. One differing comparison or rounding on another
engine can change that draw and every later one, including how many words a rejection sampler consumes.
@throws ― {PrngInvalidInputError} With INVALID_SOURCE_VALUE for an invalid value from the source.
@param ― iterable An iterable object to convert to an array.
@param ― mapfn A mapping function to call on every element of the array.
@param ― thisArg Value of 'this' used to invoke the mapfn.
from({
ArrayLike<T>.length: number
length: 5_000 }, () =>
constafter:LogNormalDistribution
after.
CumulativeDistribution<"log-normal", LogNormalDistributionParameters>.draw: (random:RandomSource) => number
Draw one value from the supplied source. There is no state between draws besides the caller's source.
The same seed replays on the same engine build and platform. One differing comparison or rounding on another
engine can change that draw and every later one, including how many words a rejection sampler consumes.
@throws ― {PrngInvalidInputError} With INVALID_SOURCE_VALUE for an invalid value from the source.
Mann-Whitney U rank test of whether two independent samples come from the same distribution, matching
scipy.stats.mannwhitneyu. greater tests that values of first tend to exceed values of second. The statistic
is the U of first.
auto uses the exact null distribution when there are no tied values and the smaller sample has at most 8 values,
which is SciPy's rule, provided the distribution costs at most 2e7 steps to build; otherwise it uses the normal
approximation with tie correction. exact with tied values truncates the statistic as SciPy does. Building the exact
distribution takes O(m² n) time and O(m n) space for sizes m <= n.
When every value is equal the variance is zero. SciPy returns NaN there; this function throws.
@throws ― {HypothesisTestInvalidInputError} With EMPTY_SAMPLE, NON_FINITE_SAMPLE, INVALID_OPTION (also for an
exact method beyond the work limit), or ZERO_VARIANCE.
compareFn Function used to determine the order of the elements. It is expected to return
a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order.
[11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22]
toSorted((
left: number
left,
right: number
right) =>
left: number
left-
right: number
right)
return (
constsorted:number[]
sorted[
constsorted:number[]
sorted.
Array<number>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length/2-1]!+
constsorted:number[]
sorted[
constsorted:number[]
sorted.
Array<number>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length/2]!) /2
}
constbeforeSamples:number[]
beforeSamples.
Array<number>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length// 5000
constresult:MannWhitneyUTestResult
result.
HypothesisTestResult.pValue: Probability
Null probability of a result at least as extreme as the observed one.
pValue<0.001// true, the samples differ
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.round(x: number): number
Returns a supplied numeric expression rounded to the nearest integer.
@param ― x The value to be rounded to the nearest integer.
round(
constmedian: (samples:readonlynumber[]) =>number
median(
constbeforeSamples:number[]
beforeSamples)) // 397
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.round(x: number): number
Returns a supplied numeric expression rounded to the nearest integer.
@param ― x The value to be rounded to the nearest integer.
round(
constmedian: (samples:readonlynumber[]) =>number
median(
constafterSamples:number[]
afterSamples)) // 379, the medians say by how much
A small p-value says the samples differ, not by how much, so report a difference such as the medians beside it. Its p-values agree with SciPy to 1e-9. For a difference in means with roughly normal data, use welchTTest. For paired measurements, use pairedTTest.