chi2pdf
Builtin index · Statistics & ML
result = chi2pdf(x, k)
Input: x, k · Output: result
What it is
Chi-square probability density at x (a number or vector, elementwise) with k degrees of freedom (a positive number), computed in log space so it survives modest k without overflowing.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = chi2pdf(x, k) | x number or vectornot documented yetk number or vectornot documented yet | result number or vector | Returns a number or vector the same shape as x. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
seed(42) # reseed the shared stream
u = rand(3, seed = 1) # an explicit seed still wins
print("rand draws: {round(u, 3)}")
print("chi2pdf(2, 3): {round(chi2pdf(2, 3), 4)}")
print("normpdf(0): {round(normpdf(0), 4)}")
walk = random_walk(20, drift = 0.1, volatility = 1.0, seed = 3)
print("random walk, last value: {round(walk[19], 3)}")
rand draws: [0.746, 0.971, 0.444] chi2pdf(2, 3): 0.2076 normpdf(0): 0.3989 random walk, last value: -3.552
from statistics-ml
How it works
chi2pdf(x, k) — the chi-square density with k degrees of freedom, computed in log-space via ln_gamma (the naive x^(k/2-1)*exp(-x/2)/(2^(k/2)*Gamma(k/2)) overflows/ underflows for even modest k) then exponentiated. Broadcasts over a vector x like any elemental-math builtin.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.