μ
statistics library
Statistics library
Statistical functions auto-loaded from stdlib/stats.mu.
| name | definition | description |
|---|---|---|
| mean | {(+/x)%(#x)} | Arithmetic mean — sum divided by count. Returns a float. |
| avg | mean | Average — alias for mean. |
| variance | {(+/(x-mean x)*(x-mean x))%(#x)} | Population variance — mean of squared deviations from the mean. Automatically rewritten to a single-pass accumulator loop by the opt pass (~40x faster on large lists). |
| stddev | {sqrt(variance x)} | Population standard deviation — square root of variance. Automatically fused to a single-pass computation via the opt pass; equivalent definitions using avg also fuse. |
| median | {(<x)@_(#x)%2} | Median — middle value of a sorted list (lower-middle for even-length lists). |
| rng | {(max x)-(min x)} | Range — maximum minus minimum. |
| sumsq | {+/x*x} | Sum of squares — +/ applied to x*x element-wise. |
| demean | {x-mean x} | Demean — subtract the mean from each element; returns a list of deviations. |
| dot | {[x;y]+/x*y} | Dot product — inner product of two equal-length numeric lists. |
| cov | {[x;y](+/(x-mean x)*(y-mean y))%(#x)} | Population covariance — mean of the product of deviations of x and y from their means. |
| cor | {[x;y]((+/(x-mean x)*(y-mean y))%(#x))%((sqrt(variance x))*(sqrt(variance y)))} | Pearson correlation — covariance divided by the product of standard deviations; always in [-1,1]. |
| skew | {(+/(demean x)*((demean x)*(demean x)))%((#x)*(variance x)*stddev x)} | Population skewness — third standardised central moment; 0 for a symmetric distribution. |
| kurt | {((+/(demean x)*(((demean x)*(demean x))*(demean x)))%((#x)*(variance x)*(variance x)))-3} | Excess kurtosis — fourth standardised central moment minus 3; 0 for a normal distribution. |
| zscore | {(demean x)%stddev x} | Z-score — standardise x to zero mean and unit variance element-wise. |
| pctile | {(<x)@_ (y*(((#x)-1)%100))} | Percentile — p-th percentile (p in 0..100) of list x; uses floor index on sorted values (implicit x=list, y=p). |
| slope | {[x;y]((+/(x-mean x)*(y-mean y))%(#x))%variance x} | OLS slope — least-squares slope of y on x: covariance(x,y) / variance(x). |
| intercept | {[x;y](mean y)-(((+/(x-mean x)*(y-mean y))%(#x))%variance x)*mean x} | OLS intercept — least-squares intercept: mean(y) - slope(x,y) * mean(x). |
| rsq | {[x;y] (((+/(x-mean x)*(y-mean y))%(#x))%((sqrt(variance x))*(sqrt(variance y))))*(((+/(x-mean x)*(y-mean y))%(#x))%((sqrt(variance x))*(sqrt(variance y))))} | R-squared — coefficient of determination; square of the Pearson correlation. |
| predict | {[xs;ys;new_xs] (intercept[xs;ys]) + (slope[xs;ys]) * new_xs} | Predict — OLS prediction for new x values: ŷ = α + β·x predict[xs; ys; new_xs] → predicted y values |
| residuals | {[xs;ys] ys - predict[xs;ys;xs]} | Residuals — OLS residuals: y - ŷ residuals[xs; ys] → residual vector |