nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Statistics and Machine Learning Toolbox (stats)

Descriptive statistics, 20+ probability distributions, hypothesis testing (t-test, ANOVA), regression models, PCA, and clustering. More...

Files

file  anova.hpp
file  distance.hpp
file  kmeans.hpp
file  kmedoids.hpp
file  knnsearch.hpp
file  linkage.hpp
file  silhouette.hpp
file  copulas.hpp
file  descriptive.hpp
 Descriptive statistics.
file  pca.hpp
file  beta.hpp
file  binomial.hpp
file  chi2.hpp
file  exponential.hpp
file  extreme_value.hpp
file  fisher_f.hpp
file  gamma_dist.hpp
file  geometric.hpp
file  gev.hpp
file  gp.hpp
file  hypergeom.hpp
file  lognormal.hpp
file  multivariate.hpp
file  nakagami.hpp
file  ncx2.hpp
file  negbin.hpp
file  normal.hpp
file  poisson.hpp
file  rayleigh.hpp
file  rician.hpp
file  students_t.hpp
file  unid.hpp
file  uniform.hpp
file  weibull.hpp
file  fit.hpp
 Distribution fitters (*fit) and negative-log-likelihood scoring (*like).
file  lda.hpp
file  moments.hpp
file  moving.hpp
 Moving / sliding-window statistics over a 1-D / N-D array.
file  mvdist.hpp
file  nan_aware.hpp
 NaN-aware reductions.
file  qmc.hpp
file  regress.hpp
file  resample.hpp
file  lhs.hpp
file  spline.hpp
file  hypothesis.hpp
 Hypothesis tests.

Classes

struct  nk::stats::CanoncorrResult
 Canonical correlation analysis ([A, B, r] = canoncorr(X, Y)). More...
struct  nk::stats::NormalizeResult
 Column-wise normalisation (Y = normalize(A, method)). More...
struct  nk::stats::Grp2idxResult
 Result of grp2idx — [G, GN, GL]. More...
struct  nk::stats::NlinfitResult
 Nonlinear least-squares fit result ([beta, R, J, CovB, MSE] = nlinfit(X, y, fun, beta0)). More...
struct  nk::stats::RobustfitResult
 Robust linear regression via iteratively-reweighted least squares ([b, stats] = robustfit(X, y)). More...
struct  nk::stats::RobustcovResult
 Result of robust covariance estimation ([sigma, mu] = robustcov(X)). More...
struct  nk::stats::GlmfitResult
 GLM fit result. More...
struct  nk::stats::LassoResult
 Lasso result. More...

Enumerations

enum class  nk::stats::McCorrection { Bonferroni , LSD }
 Multiple-comparison correction methods for multcompare. More...
enum class  nk::stats::RobustWeight {
  Andrews , Bisquare , Cauchy , Fair ,
  Huber , Logistic , Ols , Talwar ,
  Welsch
}
 Robust regression weight functions (MATLAB robustfit set). More...
enum class  nk::stats::GlmDistribution {
  Normal , Binomial , Poisson , Gamma ,
  InverseGaussian
}
 GLM family of error distributions. More...
enum class  nk::stats::GlmLink {
  GlmLink::Identity , GlmLink::Logit , GlmLink::Log , GlmLink::Reciprocal ,
  GlmLink::Probit
}
 GLM link function. More...
enum class  nk::stats::LhsCriterion { LhsCriterion::None , LhsCriterion::Maximin , LhsCriterion::Correlation }
 Criterion for lhsdesign optimization. More...
enum class  nk::stats::TestTail { TestTail::Both , TestTail::Right , TestTail::Left }
 Direction of the alternative hypothesis. More...

Functions

std::tuple< double, double, double, double, double, double > nk::stats::anova1 (const Value &y, const Value &group, std::pmr::memory_resource *mr=nullptr)
 One-way ANOVA ([p, F, df_b, df_w, ss_b, ss_w] = anova1(y, group)).
std::tuple< Value, Value, Value, Value > nk::stats::kruskalwallis (const Value &y, const Value &group, std::pmr::memory_resource *mr=nullptr)
 Kruskal–Wallis non-parametric one-way ANOVA ([p, H, df, ssRanks] = kruskalwallis(y, group)).
std::tuple< Value, Value, Value > nk::stats::friedman (const Value &x, int reps=1, std::pmr::memory_resource *mr=nullptr)
 Friedman non-parametric two-way ANOVA by ranks ([p, Q, df] = friedman(x, reps)).
Value nk::stats::dummyvar (const Value &group, std::pmr::memory_resource *mr=nullptr)
 Convert categorical labels to indicator columns (X = dummyvar(group)).
Value nk::stats::multcompare (const Value &stats, double alpha=0.05, McCorrection ctype=McCorrection::Bonferroni, std::pmr::memory_resource *mr=nullptr)
 Pairwise post-hoc comparisons after one-way ANOVA (c = multcompare(stats [, alpha [, ctype]])).
Value nk::stats::pdist (const Value &X, const std::string &metric, double p, std::pmr::memory_resource *mr=nullptr)
 Pairwise distances between rows of X (d = pdist(X, metric, p)).
Value nk::stats::pdist2 (const Value &X, const Value &Y, const std::string &metric, double p, std::pmr::memory_resource *mr=nullptr)
 Cross-set pairwise distances (D = pdist2(X, Y, metric, p)).
Value nk::stats::squareform (const Value &d, std::pmr::memory_resource *mr=nullptr)
 Pack / unpack the pdist row form (Y = squareform(d)).
Value nk::stats::mahal (const Value &Y, const Value &X, std::pmr::memory_resource *mr=nullptr)
 Mahalanobis distance squared (d² = mahal(Y, X)).
std::tuple< Value, Value, Value > nk::stats::kmeans (::nk::ops::RngContext &rng, const Value &X, int K, int max_iter, int replicates, std::pmr::memory_resource *mr=nullptr)
 Lloyd's k-means clustering ([idx, C, sumd] = kmeans(X, K, …)).
std::tuple< Value, Value, Value > nk::stats::kmedoids (::nk::ops::RngContext &rng, const Value &X, int K, int max_iter, int replicates, const std::string &metric, std::pmr::memory_resource *mr=nullptr)
 PAM-style k-medoids clustering ([idx, medoids, sumd] = kmedoids(...)).
std::tuple< Value, Value > nk::stats::dbscan (const Value &X, double eps, int minpts, const std::string &metric, std::pmr::memory_resource *mr=nullptr)
 DBSCAN density-based clustering ([idx, corepts] = dbscan(X, eps, minpts, metric)).
std::tuple< Value, Value > nk::stats::dbscan (const Value &X, double eps, int minpts, const std::string &metric, double p, std::pmr::memory_resource *mr=nullptr)
 DBSCAN with explicit Minkowski exponent p (for metric = "minkowski").
std::tuple< Value, Value > nk::stats::knnsearch (const Value &X, const Value &Y, int K=1, const std::string &metric="euclidean", double p=2.0, std::pmr::memory_resource *mr=nullptr)
 k-nearest-neighbour search ([Idx, D] = knnsearch(X, Y, K, metric, p)).
std::tuple< Value, Value > nk::stats::rangesearch (const Value &X, const Value &Y, double r, const std::string &metric="euclidean", double p=2.0, std::pmr::memory_resource *mr=nullptr)
 Radius search ([Idx, D] = rangesearch(X, Y, r, metric, p)).
Value nk::stats::linkage (const Value &Y, const std::string &method, std::pmr::memory_resource *mr=nullptr)
 Agglomerative hierarchical clustering tree (Z = linkage(Y, method)).
Value nk::stats::linkage (const Value &Y, const std::string &method, const std::string &metric, double p, std::pmr::memory_resource *mr=nullptr)
 4-arg overload: when Y is a raw N×D data matrix, computes pdist(Y, metric, p) internally before linkage.
Value nk::stats::cluster_from_linkage (const Value &Z, int maxclust, double cutoff, const std::string &criterion, std::pmr::memory_resource *mr=nullptr)
 Flatten a linkage tree into cluster labels (T = cluster(Z, opts)).
Value nk::stats::cluster_from_linkage (const Value &Z, int maxclust, double cutoff, const std::string &criterion, int depth, std::pmr::memory_resource *mr=nullptr)
 5-arg overload of cluster_from_linkage with explicit inconsistency depth.
Value nk::stats::clusterdata (const Value &X, int maxclust, double cutoff, const std::string &linkage_method, const std::string &criterion, std::pmr::memory_resource *mr=nullptr)
 Convenience: pdist + linkage + cluster in one call (clusterdata).
Value nk::stats::clusterdata (const Value &X, int maxclust, double cutoff, const std::string &linkage_method, const std::string &criterion, int depth, std::pmr::memory_resource *mr=nullptr)
 6-arg clusterdata overload: explicit inconsistency depth.
Value nk::stats::clusterdata (const Value &X, int maxclust, double cutoff, const std::string &linkage_method, const std::string &criterion, int depth, const std::string &distance_metric, double p, std::pmr::memory_resource *mr=nullptr)
 8-arg clusterdata overload: explicit depth + custom distance metric.
Value nk::stats::cophenet (const Value &Z, const Value &Y, std::pmr::memory_resource *mr=nullptr)
 Cophenetic correlation (c = cophenet(Z, Y)).
Value nk::stats::inconsistent (const Value &Z, int depth, std::pmr::memory_resource *mr=nullptr)
 Inconsistency coefficient table (R = inconsistent(Z, depth)).
Value nk::stats::silhouette (const Value &X, const Value &clust, const std::string &metric="sqeuclidean", double p=2.0, std::pmr::memory_resource *mr=nullptr)
 Per-point silhouette coefficient (s = silhouette(X, clust, metric, p)).
Value nk::stats::copulapdf_gaussian (const Value &U, const Value &R, std::pmr::memory_resource *mr=nullptr)
 Gaussian copula density (y = copulapdf('Gaussian', U, R)).
Value nk::stats::copulacdf_gaussian (const Value &U, const Value &R, std::pmr::memory_resource *mr=nullptr)
 Gaussian copula CDF (p = copulacdf('Gaussian', U, R)).
Value nk::stats::copulapdf_t (const Value &U, const Value &R, double nu, std::pmr::memory_resource *mr=nullptr)
 Student-t copula density (y = copulapdf('t', U, R, nu)).
Value nk::stats::copulacdf_t (const Value &U, const Value &R, double nu, std::pmr::memory_resource *mr=nullptr)
 Student-t copula CDF (p = copulacdf('t', U, R, nu)).
Value nk::stats::copulapdf_clayton (const Value &U, double alpha, std::pmr::memory_resource *mr=nullptr)
 Clayton copula density (y = copulapdf('Clayton', U, alpha)).
Value nk::stats::copulacdf_clayton (const Value &U, double alpha, std::pmr::memory_resource *mr=nullptr)
 Clayton copula CDF (C(u, v; α) = (u^{−α} + v^{−α} − 1)^{−1/α}).
Value nk::stats::copulapdf_frank (const Value &U, double alpha, std::pmr::memory_resource *mr=nullptr)
 Frank copula density (y = copulapdf('Frank', U, alpha)).
Value nk::stats::copulacdf_frank (const Value &U, double alpha, std::pmr::memory_resource *mr=nullptr)
 Frank copula CDF.
Value nk::stats::copulapdf_gumbel (const Value &U, double alpha, std::pmr::memory_resource *mr=nullptr)
 Gumbel copula density (y = copulapdf('Gumbel', U, alpha)).
Value nk::stats::copulacdf_gumbel (const Value &U, double alpha, std::pmr::memory_resource *mr=nullptr)
 Gumbel copula CDF.
Value nk::stats::var (const Value &x, int normFlag=0, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Sample / population variance along dim (y = var(X, normFlag, dim)).
Value nk::stats::stdev (const Value &x, int normFlag=0, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Sample / population standard deviation (y = std(X, normFlag, dim)).
Value nk::stats::median (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Median along dim (y = median(X, dim)).
Value nk::stats::quantile (const Value &x, const Value &p, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Empirical quantile (q = quantile(X, p, dim)).
Value nk::stats::prctile (const Value &x, const Value &p, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Empirical percentile (q = prctile(X, p, dim)).
std::tuple< Value, Value > nk::stats::mode (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Mode and frequency ([m, f] = mode(X, dim)).
Value nk::stats::cov (const Value &x, int normFlag=0, std::pmr::memory_resource *mr=nullptr)
 Sample / population covariance (C = cov(X, normFlag)).
Value nk::stats::cov (const Value &x, const Value &y, int normFlag=0, std::pmr::memory_resource *mr=nullptr)
 Joint covariance of two vectors (C = cov(X, Y, normFlag)).
Value nk::stats::corrcoef (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Pearson correlation matrix (R = corrcoef(X)).
Value nk::stats::corrcoef (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
 Joint correlation matrix (R = corrcoef(X, Y)).
std::tuple< Value, Value > nk::stats::bounds (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Min and max along dim ([lo, hi] = bounds(X, dim)).
Value nk::stats::iqr (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Interquartile range (r = iqr(X, dim)).
Value nk::stats::maxk (const Value &x, int k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 k largest values along dim (y = maxk(X, k, dim)).
Value nk::stats::mink (const Value &x, int k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 k smallest values along dim (y = mink(X, k, dim)).
Value nk::stats::rmse (const Value &f, const Value &a, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Root-mean-square error (e = rmse(F, A, dim)).
Value nk::stats::mape (const Value &f, const Value &a, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Mean absolute percentage error (e = mape(F, A, dim)).
Value nk::stats::partialcorr_of (const Value &X, const Value &Y, const Value &Z, std::pmr::memory_resource *mr=nullptr)
 Partial correlation controlling for Z (R = partialcorr(X, Y, Z)).
Value nk::stats::partialcorr_xx (const Value &X, std::pmr::memory_resource *mr=nullptr)
 One-argument partial correlation: pairwise partial correlation between columns of X, controlling for the remaining columns of X (R = partialcorr(X)).
Value nk::stats::partialcorr_xz (const Value &X, const Value &Z, std::pmr::memory_resource *mr=nullptr)
 Two-argument partial correlation (R = partialcorr(X, Z)).
Value nk::stats::partialcorri (const Value &Y, const Value &X, const Value &Z={}, std::pmr::memory_resource *mr=nullptr)
 Partial correlation between each column of Y and each column of X, controlling for the remaining columns of X (and optionally Z).
CanoncorrResult nk::stats::canoncorr (const Value &X, const Value &Y, std::pmr::memory_resource *mr=nullptr)
 Canonical correlation analysis ([A, B, r] = canoncorr(X, Y)).
Value nk::stats::corr_xx (const Value &X, std::pmr::memory_resource *mr=nullptr)
 Auto-correlation across columns of X (R = corr(X)).
Value nk::stats::corr_xy (const Value &X, const Value &Y, std::pmr::memory_resource *mr=nullptr)
 Cross-correlation between columns of X and Y (R = corr(X, Y)).
Value nk::stats::detrend_of (const Value &x, int order=1, std::pmr::memory_resource *mr=nullptr)
 Remove polynomial trend (y = detrend(x, order)).
Value nk::stats::isoutlier_of (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Outlier mask (tf = isoutlier(x)).
Value nk::stats::rmoutliers_of (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Remove outliers (y = rmoutliers(x)).
Value nk::stats::fillmissing_of (const Value &x, const std::string &method, double constVal=0.0, std::pmr::memory_resource *mr=nullptr)
 Fill missing values (y = fillmissing(x, method, constVal)).
Value nk::stats::rmmissing_of (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Remove rows / cols containing missing values (y = rmmissing(x)).
Value nk::stats::standardizeMissing_of (const Value &x, double sentinel, std::pmr::memory_resource *mr=nullptr)
 Convert sentinel value to missing (y = standardizeMissing(x, sentinel)).
Value nk::stats::range_of (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Range = max - min along dim (r = range(x, dim)).
Value nk::stats::mad_of (const Value &x, int flag=0, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Mean absolute deviation (y = mad(x, flag, dim)).
Value nk::stats::geomean_of (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Geometric mean (g = geomean(x, dim)).
Value nk::stats::harmmean_of (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Harmonic mean (h = harmmean(x, dim)).
Value nk::stats::moment_of (const Value &x, int order, int dim=0, std::pmr::memory_resource *mr=nullptr)
 k-th central moment (m = moment(x, k, dim)).
Value nk::stats::trimmean_of (const Value &x, double pct, int dim=0, bool useFloor=false, std::pmr::memory_resource *mr=nullptr)
 Trimmed mean (m = trimmean(x, pct, dim)).
std::tuple< Value, Value, Value > nk::stats::prepareCurveData (const Value &x, const Value &y, const Value &w, std::pmr::memory_resource *mr=nullptr)
 Curve-data cleanup ([xo, yo, wo] = prepareCurveData(x, y, w)).
std::tuple< Value, Value, Value > nk::stats::prepareSurfaceData (const Value &x, const Value &y, const Value &z, std::pmr::memory_resource *mr=nullptr)
 Surface-data cleanup ([xo, yo, zo] = prepareSurfaceData(x, y, z)).
std::tuple< Value, Value, Value, Value, Value, Value, Value > nk::stats::datastats (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Dataset descriptive summary (datastats(x)).
std::tuple< Value, Value > nk::stats::ecdf (const Value &y, std::pmr::memory_resource *mr=nullptr)
 Empirical cumulative distribution function ([f, x] = ecdf(y)).
std::tuple< Value, Value, Value > nk::stats::ksdensity (const Value &x, const Value &pts, double bw_user, std::pmr::memory_resource *mr=nullptr)
 Kernel density estimate ([f, xi, bw] = ksdensity(x, pts, bw_user)).
std::tuple< Value, Value > nk::stats::ecdfhist (const Value &f, const Value &x, int m=10, std::pmr::memory_resource *mr=nullptr)
 Histogram from empirical CDF ([n, c] = ecdfhist(f, x, m)).
NormalizeResult nk::stats::normalize (const Value &A, const std::string &method, const Value &param=Value::Empty, std::pmr::memory_resource *mr=nullptr)
 Normalizes data using z-score, min-max, scale, or center methods ([N, C, S] = normalize(...)).
Value nk::stats::rescale (const Value &A, double lo, double hi, std::pmr::memory_resource *mr=nullptr, double inputMin=std::numeric_limits< double >::quiet_NaN(), double inputMax=std::numeric_limits< double >::quiet_NaN())
 Linear range remap (Y = rescale(A, lo, hi)).
Value nk::stats::zscore (const Value &A, std::pmr::memory_resource *mr=nullptr)
 Z-score normalisation (Y = zscore(A)).
std::pair< Value, Value > nk::stats::tiedrank (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Tie-corrected ranks ([r, tieadj] = tiedrank(x)).
std::tuple< Value, Value, Value > nk::stats::autocorr (const Value &y, int numLags=-1, double numSTD=2.0, std::pmr::memory_resource *mr=nullptr)
 Sample autocorrelation function ([acf, lags, bounds] = autocorr(y)).
std::tuple< Value, Value, Value > nk::stats::crosscorr (const Value &y1, const Value &y2, int numLags=-1, double numSTD=2.0, std::pmr::memory_resource *mr=nullptr)
 Sample cross-correlation function ([xcf, lags, bounds] = crosscorr(y1, y2)).
std::tuple< Value, Value, Value > nk::stats::parcorr (const Value &y, int numLags=-1, double numSTD=2.0, std::pmr::memory_resource *mr=nullptr)
 Sample partial autocorrelation function ([pacf, lags, bounds] = parcorr(y)).
std::pair< Value, Value > nk::stats::corrcov (const Value &C, std::pmr::memory_resource *mr=nullptr)
 Correlation matrix from covariance ([R, sigma] = corrcov(C)).
Value nk::stats::tabulate (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Frequency table (T = tabulate(x)).
std::pair< Value, Value > nk::stats::cholcov (const Value &SIGMA, std::pmr::memory_resource *mr=nullptr)
 Cholesky-like factor of a covariance matrix ([T, p] = cholcov(SIGMA)).
std::tuple< Value, double, double > nk::stats::crosstab (const Value &x, const Value &y_opt=Value::Empty, std::pmr::memory_resource *mr=nullptr)
 Contingency table ([T, chi2, p] = crosstab(x, y_opt)).
std::vector< Value > nk::stats::grpstats (const Value &X, const Value &group, const std::vector< std::string > &fn_names, std::pmr::memory_resource *mr=nullptr)
 Per-group statistics (grpstats(X, group, fn_names)).
Value nk::stats::nearcorr (const Value &A, std::pmr::memory_resource *mr=nullptr)
 Nearest correlation matrix (Y = nearcorr(A)).
Grp2idxResult nk::stats::grp2idx (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Grouping variable → index vector ([G, GN, GL] = grp2idx(s)).
Value nk::stats::filloutliers (const Value &A, const Value &fillMethod, const std::string &findMethod="median", double thresholdFactor=std::numeric_limits< double >::quiet_NaN(), std::pmr::memory_resource *mr=nullptr)
 Replace outliers (B = filloutliers(A, fillMethod, findMethod, tf)).
std::tuple< Value, Value, Value, Value, Value, Value > nk::stats::pca (const Value &X, std::pmr::memory_resource *mr=nullptr)
 Principal Component Analysis ([coeff, score, latent, tsquared, explained, mu] = pca(X)).
std::tuple< Value, Value, Value > nk::stats::pcacov (const Value &C, std::pmr::memory_resource *mr=nullptr)
 PCA from a precomputed covariance matrix ([coeff, latent, explained] = pcacov(C)).
Value nk::stats::pcares (const Value &X, int ndim, std::pmr::memory_resource *mr=nullptr)
 PCA residuals (res = pcares(X, ndim)).
Value nk::stats::betapdf (const Value &x, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Beta pdf (y = betapdf(x, a, b)).
Value nk::stats::betacdf (const Value &x, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Beta cdf (p = betacdf(x, a, b)).
Value nk::stats::betainv (const Value &p, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Beta inverse cdf (x = betainv(p, a, b)).
Value nk::stats::betarnd (::nk::ops::RngContext &rng, double a, double b, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Beta random samples (r = betarnd(a, b, rows, cols)).
std::tuple< double, double > nk::stats::betastat (double a, double b)
 Beta mean and variance ([m, v] = betastat(a, b)).
Value nk::stats::betafit (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Beta(a, b) MLE fit ([ahat, bhat] = betafit(x)).
Value nk::stats::betafit_ci (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 95% Wald CI for betafit (pci = betafit_ci(x, alpha)).
Value nk::stats::binopdf (const Value &k, double n, double p, std::pmr::memory_resource *mr=nullptr)
 Binomial pmf (y = binopdf(k, n, p)).
Value nk::stats::binocdf (const Value &k, double n, double p, std::pmr::memory_resource *mr=nullptr)
 Binomial cumulative distribution (F = binocdf(k, n, p)).
Value nk::stats::binoinv (const Value &p_in, double n, double p, std::pmr::memory_resource *mr=nullptr)
 Binomial inverse cdf (k = binoinv(p_in, n, p)).
Value nk::stats::binornd (::nk::ops::RngContext &rng, double n, double p, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Binomial random samples (r = binornd(n, p, rows, cols)).
std::tuple< double, double > nk::stats::binostat (double n, double p)
 Binomial mean and variance ([m, v] = binostat(n, p)).
Value nk::stats::chi2pdf (const Value &x, double k, std::pmr::memory_resource *mr=nullptr)
 Chi-squared pdf (y = chi2pdf(x, k)).
Value nk::stats::chi2cdf (const Value &x, double k, std::pmr::memory_resource *mr=nullptr)
 Chi-squared cdf (F = chi2cdf(x, k)).
Value nk::stats::chi2inv (const Value &p, double k, std::pmr::memory_resource *mr=nullptr)
 Chi-squared inverse cdf (x = chi2inv(p, k)).
Value nk::stats::chi2rnd (::nk::ops::RngContext &rng, double k, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Chi-squared random samples (r = chi2rnd(k, rows, cols)).
std::tuple< double, double > nk::stats::chi2stat (double k)
 Chi-squared mean and variance ([m, v] = chi2stat(k)).
Value nk::stats::exppdf (const Value &x, double mu, std::pmr::memory_resource *mr=nullptr)
 Exponential pdf (y = exppdf(x, mu)).
Value nk::stats::expcdf (const Value &x, double mu, std::pmr::memory_resource *mr=nullptr)
 Exponential cdf (F = expcdf(x, mu)).
Value nk::stats::expinv (const Value &p, double mu, std::pmr::memory_resource *mr=nullptr)
 Exponential inverse cdf (x = expinv(p, mu)).
Value nk::stats::exprnd (::nk::ops::RngContext &rng, double mu, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Exponential random samples (r = exprnd(mu, rows, cols)).
std::tuple< double, double > nk::stats::expstat (double mu)
 Exponential mean and variance ([m, v] = expstat(mu)).
Value nk::stats::evpdf (const Value &x, double mu, double sigma, std::pmr::memory_resource *mr=nullptr)
 Type-I EV (Gumbel-for-minima) pdf (y = evpdf(x, mu, sigma)).
Value nk::stats::evcdf (const Value &x, double mu, double sigma, std::pmr::memory_resource *mr=nullptr)
 Type-I EV cdf (p = evcdf(x, mu, sigma)).
Value nk::stats::evinv (const Value &p, double mu, double sigma, std::pmr::memory_resource *mr=nullptr)
 Type-I EV inverse cdf (x = evinv(p, mu, sigma)).
Value nk::stats::evrnd (::nk::ops::RngContext &rng, double mu, double sigma, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Type-I EV random samples (r = evrnd(mu, sigma, rows, cols)).
std::tuple< double, double > nk::stats::evstat (double mu, double sigma)
 Type-I EV mean and variance ([m, v] = evstat(mu, sigma)).
Value nk::stats::evfit (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Type-I EV (Gumbel-min) MLE fit ([muhat, sigmahat] = evfit(x)).
Value nk::stats::evfit (const Value &x, const Value &censoring, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Type-I EV (Gumbel-min) MLE fit with right-censoring and frequency weights ([parmhat, parmci] = evfit(x, alpha, cens, freq)).
Value nk::stats::evfit_ci (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 Wald CI for evfit (pci = evfit_ci(x, alpha)).
Value nk::stats::evfit_ci (const Value &x, double alpha, const Value &censoring, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Wald CI for censored/weighted evfit (pci = evfit_ci(x, alpha, cens, freq)).
Value nk::stats::fpdf (const Value &x, double v1, double v2, std::pmr::memory_resource *mr=nullptr)
 F pdf (y = fpdf(x, v1, v2)).
Value nk::stats::fcdf (const Value &x, double v1, double v2, std::pmr::memory_resource *mr=nullptr)
 F cdf (F = fcdf(x, v1, v2)).
Value nk::stats::finv (const Value &p, double v1, double v2, std::pmr::memory_resource *mr=nullptr)
 F inverse cdf (x = finv(p, v1, v2)).
Value nk::stats::frnd (::nk::ops::RngContext &rng, double v1, double v2, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 F random samples (r = frnd(v1, v2, rows, cols)).
std::tuple< double, double > nk::stats::fstat (double v1, double v2)
 F mean and variance ([m, v] = fstat(v1, v2)).
Value nk::stats::ncfpdf (const Value &x, double nu1, double nu2, double delta, std::pmr::memory_resource *mr=nullptr)
 Noncentral F pdf (y = ncfpdf(x, nu1, nu2, delta)).
Value nk::stats::ncfcdf (const Value &x, double nu1, double nu2, double delta, bool upper=false, std::pmr::memory_resource *mr=nullptr)
 Noncentral F cdf (p = ncfcdf(x, nu1, nu2, delta)).
Value nk::stats::ncfinv (const Value &p, double nu1, double nu2, double delta, std::pmr::memory_resource *mr=nullptr)
 Noncentral F inverse cdf (x = ncfinv(p, nu1, nu2, delta)).
std::tuple< double, double > nk::stats::ncfstat (double nu1, double nu2, double delta)
 Noncentral F mean and variance ([m, v] = ncfstat(nu1, nu2, delta)).
Value nk::stats::ncfrnd (::nk::ops::RngContext &rng, double nu1, double nu2, double delta, std::size_t rows=1, std::size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Noncentral F random samples (R = ncfrnd(nu1, nu2, delta, rows, cols)).
Value nk::stats::gampdf (const Value &x, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Gamma pdf (y = gampdf(x, a, b)).
Value nk::stats::gamcdf (const Value &x, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Gamma cdf (F = gamcdf(x, a, b)).
Value nk::stats::gaminv (const Value &p, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Gamma inverse cdf (x = gaminv(p, a, b)).
Value nk::stats::gamrnd (::nk::ops::RngContext &rng, double a, double b, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Gamma random samples (r = gamrnd(a, b, rows, cols)).
std::tuple< double, double > nk::stats::gamstat (double a, double b)
 Gamma mean and variance ([m, v] = gamstat(a, b)).
Value nk::stats::randg (::nk::ops::RngContext &rng, double shape, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Raw gamma(shape, 1) RNG (r = randg(shape [, rows, cols])).
Value nk::stats::randg (::nk::ops::RngContext &rng, const Value &shapeArray, std::pmr::memory_resource *mr=nullptr)
 Per-element gamma RNG (r = randg(shapeArray)).
Value nk::stats::gamfit (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Gamma distribution MLE fit ([ahat, bhat] = gamfit(x)).
Value nk::stats::gamfit (const Value &x, const Value &censoring, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Gamma MLE fit with right-censoring and frequency weights ([parmhat, parmci] = gamfit(x, alpha, cens, freq)).
Value nk::stats::gamfit_ci (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 95% Wald CI for gamfit (pci = gamfit_ci(x, alpha)).
Value nk::stats::gamfit_ci (const Value &x, double alpha, const Value &censoring, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Wald CI for censored/weighted gamfit (pci = gamfit_ci(x, alpha, cens, freq)).
Value nk::stats::geopdf (const Value &k, double p, std::pmr::memory_resource *mr=nullptr)
 Geometric pmf (y = geopdf(k, p)).
Value nk::stats::geocdf (const Value &k, double p, std::pmr::memory_resource *mr=nullptr)
 Geometric cdf (F = geocdf(k, p)).
Value nk::stats::geoinv (const Value &q, double p, std::pmr::memory_resource *mr=nullptr)
 Geometric inverse cdf (k = geoinv(q, p)).
Value nk::stats::geornd (::nk::ops::RngContext &rng, double p, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Geometric random samples (r = geornd(p, rows, cols)).
std::tuple< double, double > nk::stats::geostat (double p)
 Geometric mean and variance ([m, v] = geostat(p)).
Value nk::stats::gevpdf (const Value &x, double k, double sigma, double mu, std::pmr::memory_resource *mr=nullptr)
 GEV pdf (y = gevpdf(x, k, sigma, mu)).
Value nk::stats::gevcdf (const Value &x, double k, double sigma, double mu, std::pmr::memory_resource *mr=nullptr)
 GEV cdf (p = gevcdf(x, k, sigma, mu)).
Value nk::stats::gevinv (const Value &p, double k, double sigma, double mu, std::pmr::memory_resource *mr=nullptr)
 GEV inverse cdf (x = gevinv(p, k, sigma, mu)).
Value nk::stats::gevrnd (::nk::ops::RngContext &rng, double k, double sigma, double mu, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 GEV random samples (r = gevrnd(k, sigma, mu, rows, cols)).
std::tuple< double, double > nk::stats::gevstat (double k, double sigma, double mu)
 GEV mean and variance ([m, v] = gevstat(k, sigma, mu)).
Value nk::stats::gevfit (const Value &x, std::pmr::memory_resource *mr=nullptr)
 GEV MLE fit ([parmhat, parmci] = gevfit(x, alpha)).
Value nk::stats::gevfit_ci (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 95% Wald CI for gevfit (pci = gevfit_ci(x, alpha)).
Value nk::stats::gppdf (const Value &x, double k, double sigma, double theta, std::pmr::memory_resource *mr=nullptr)
 Generalised Pareto pdf (y = gppdf(x, k, sigma, theta)).
Value nk::stats::gpcdf (const Value &x, double k, double sigma, double theta, std::pmr::memory_resource *mr=nullptr)
 Generalised Pareto cdf (p = gpcdf(x, k, sigma, theta)).
Value nk::stats::gpinv (const Value &p, double k, double sigma, double theta, std::pmr::memory_resource *mr=nullptr)
 Generalised Pareto inverse cdf (x = gpinv(p, k, sigma, theta)).
Value nk::stats::gprnd (::nk::ops::RngContext &rng, double k, double sigma, double theta, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Generalised Pareto random samples (r = gprnd(k, sigma, theta, rows, cols)).
std::tuple< double, double > nk::stats::gpstat (double k, double sigma, double theta)
 Generalised Pareto mean and variance ([m, v] = gpstat(k, sigma, theta)).
Value nk::stats::gpfit (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Generalised Pareto MLE fit ([khat, sigmahat] = gpfit(x)).
Value nk::stats::gpfit_ci (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 95% Wald CI for gpfit (pci = gpfit_ci(x, alpha)).
Value nk::stats::hygepdf (const Value &k, double M, double K, double N, std::pmr::memory_resource *mr=nullptr)
 Hypergeometric pmf (y = hygepdf(k, M, K, N)).
Value nk::stats::hygecdf (const Value &k, double M, double K, double N, std::pmr::memory_resource *mr=nullptr)
 Hypergeometric cdf (F = hygecdf(k, M, K, N)).
Value nk::stats::hygeinv (const Value &q, double M, double K, double N, std::pmr::memory_resource *mr=nullptr)
 Hypergeometric inverse cdf (k = hygeinv(q, M, K, N)).
Value nk::stats::hygernd (::nk::ops::RngContext &rng, double M, double K, double N, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Hypergeometric random samples (r = hygernd(M, K, N, rows, cols)).
std::tuple< double, double > nk::stats::hygestat (double M, double K, double N)
 Hypergeometric mean and variance ([m, v] = hygestat(M, K, N)).
Value nk::stats::lognpdf (const Value &x, double mu, double sigma, std::pmr::memory_resource *mr=nullptr)
 Lognormal pdf (y = lognpdf(x, mu, sigma)).
Value nk::stats::logncdf (const Value &x, double mu, double sigma, std::pmr::memory_resource *mr=nullptr)
 Lognormal cdf (p = logncdf(x, mu, sigma)).
Value nk::stats::logninv (const Value &p, double mu, double sigma, std::pmr::memory_resource *mr=nullptr)
 Lognormal inverse cdf (x = logninv(p, mu, sigma)).
Value nk::stats::lognrnd (::nk::ops::RngContext &rng, double mu, double sigma, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Lognormal random samples (r = lognrnd(mu, sigma, rows, cols)).
std::tuple< double, double > nk::stats::lognstat (double mu, double sigma)
 Lognormal mean and variance ([m, v] = lognstat(mu, sigma)).
Value nk::stats::mvnrnd (::nk::ops::RngContext &rng, const Value &mu, const Value &Sigma, std::size_t n=0, std::pmr::memory_resource *mr=nullptr)
 Multivariate normal random samples (R = mvnrnd(mu, Sigma [, n])).
Value nk::stats::mvncdf (const Value &X, const Value &mu, const Value &Sigma, std::pmr::memory_resource *mr=nullptr)
 Multivariate normal CDF (p = mvncdf(X, mu, Sigma)).
Value nk::stats::mvtrnd (::nk::ops::RngContext &rng, const Value &C, double df, std::size_t n, std::pmr::memory_resource *mr=nullptr)
 Multivariate Student's-t random samples (R = mvtrnd(C, df, n)).
Value nk::stats::mnrnd (::nk::ops::RngContext &rng, std::size_t N, const Value &P, std::size_t m=1, std::pmr::memory_resource *mr=nullptr)
 Multinomial random samples (R = mnrnd(N, P, m)).
Value nk::stats::wishrnd (::nk::ops::RngContext &rng, const Value &Sigma, double df, std::pmr::memory_resource *mr=nullptr)
 Wishart random matrix (W = wishrnd(Sigma, df)).
Value nk::stats::iwishrnd (::nk::ops::RngContext &rng, const Value &Tau, double df, std::pmr::memory_resource *mr=nullptr)
 Inverse-Wishart random matrix (W = iwishrnd(Tau, df)).
std::tuple< Value, Value > nk::stats::wishrnd_factor (::nk::ops::RngContext &rng, const Value &Sigma, double df, const Value &D, std::pmr::memory_resource *mr=nullptr)
 Wishart sample with pre-computed Cholesky factor (W = wishrnd(Sigma, df, D)).
std::tuple< Value, Value > nk::stats::iwishrnd_factor (::nk::ops::RngContext &rng, const Value &Tau, double df, const Value &DI, std::pmr::memory_resource *mr=nullptr)
 Inverse-Wishart sample with pre-computed Cholesky factor (W = iwishrnd(Tau, df, DI)).
Value nk::stats::mvtcdf (const Value &X, const Value &C, double df, double tol=0.01, std::pmr::memory_resource *mr=nullptr)
 Multivariate t cdf upper-tail (p = mvtcdf(X, C, df)).
Value nk::stats::mvtcdf_box (const Value &L, const Value &U, const Value &C, double df, double tol=0.01, std::pmr::memory_resource *mr=nullptr)
 Multivariate t box cdf (p = mvtcdf(L, U, C, df)).
Value nk::stats::nakapdf (const Value &x, double mu, double omega, std::pmr::memory_resource *mr=nullptr)
 Nakagami pdf (y = nakapdf(x, mu, omega)).
Value nk::stats::nakacdf (const Value &x, double mu, double omega, std::pmr::memory_resource *mr=nullptr)
 Nakagami cdf (p = nakacdf(x, mu, omega)).
Value nk::stats::nakainv (const Value &p, double mu, double omega, std::pmr::memory_resource *mr=nullptr)
 Nakagami inverse cdf (x = nakainv(p, mu, omega)).
Value nk::stats::nakarnd (::nk::ops::RngContext &rng, double mu, double omega, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Nakagami random samples (r = nakarnd(mu, omega, rows, cols)).
std::tuple< double, double > nk::stats::nakastat (double mu, double omega)
 Nakagami mean and variance ([m, v] = nakastat(mu, omega)).
Value nk::stats::ncx2pdf (const Value &x, double k, double lambda, std::pmr::memory_resource *mr=nullptr)
 Noncentral χ² pdf (y = ncx2pdf(x, k, lambda)).
Value nk::stats::ncx2cdf (const Value &x, double k, double lambda, std::pmr::memory_resource *mr=nullptr)
 Noncentral χ² cdf (p = ncx2cdf(x, k, lambda)).
Value nk::stats::ncx2inv (const Value &p, double k, double lambda, std::pmr::memory_resource *mr=nullptr)
 Noncentral χ² inverse cdf (x = ncx2inv(p, k, lambda)).
Value nk::stats::ncx2rnd (::nk::ops::RngContext &rng, double k, double lambda, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Noncentral χ² random samples (r = ncx2rnd(k, lambda, rows, cols)).
std::tuple< double, double > nk::stats::ncx2stat (double k, double lambda)
 Noncentral χ² mean and variance ([m, v] = ncx2stat(k, lambda)).
Value nk::stats::nbinpdf (const Value &k, double r, double p, std::pmr::memory_resource *mr=nullptr)
 Negative binomial pmf (y = nbinpdf(k, r, p)).
Value nk::stats::nbincdf (const Value &k, double r, double p, std::pmr::memory_resource *mr=nullptr)
 Negative binomial cdf (F = nbincdf(k, r, p)).
Value nk::stats::nbininv (const Value &q, double r, double p, std::pmr::memory_resource *mr=nullptr)
 Negative binomial inverse cdf (k = nbininv(q, r, p)).
Value nk::stats::nbinrnd (::nk::ops::RngContext &rng, double r, double p, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Negative binomial random samples (r_out = nbinrnd(r, p, rows, cols)).
std::tuple< double, double > nk::stats::nbinstat (double r, double p)
 Negative binomial mean and variance ([m, v] = nbinstat(r, p)).
Value nk::stats::nbinfit (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Negative-binomial MLE fit ([rhat, phat] = nbinfit(x)).
Value nk::stats::nbinfit_ci (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 95% Wald CI for nbinfit (pci = nbinfit_ci(x, alpha)).
Value nk::stats::normpdf (const Value &x, double mu=0.0, double sigma=1.0, std::pmr::memory_resource *mr=nullptr)
 Normal pdf (y = normpdf(x, mu, sigma)).
Value nk::stats::normcdf (const Value &x, double mu=0.0, double sigma=1.0, std::pmr::memory_resource *mr=nullptr)
 Normal cdf (p = normcdf(x, mu, sigma)).
Value nk::stats::norminv (const Value &p, double mu=0.0, double sigma=1.0, std::pmr::memory_resource *mr=nullptr)
 Normal inverse cdf / quantile (x = norminv(p, mu, sigma)).
Value nk::stats::normrnd (::nk::ops::RngContext &rng, double mu, double sigma, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Normal random samples (r = normrnd(mu, sigma, rows, cols)).
std::tuple< double, double > nk::stats::normstat (double mu, double sigma)
 Normal mean and variance ([m, v] = normstat(mu, sigma)).
Value nk::stats::poisspdf (const Value &k, double lambda, std::pmr::memory_resource *mr=nullptr)
 Poisson pmf (y = poisspdf(k, lambda)).
Value nk::stats::poisscdf (const Value &k, double lambda, std::pmr::memory_resource *mr=nullptr)
 Poisson cumulative distribution (F = poisscdf(k, lambda)).
Value nk::stats::poissinv (const Value &p, double lambda, std::pmr::memory_resource *mr=nullptr)
 Poisson inverse cdf (k = poissinv(p, lambda)).
Value nk::stats::poissrnd (::nk::ops::RngContext &rng, double lambda, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Poisson random samples (r = poissrnd(lambda, rows, cols)).
std::tuple< double, double > nk::stats::poisstat (double lambda)
 Poisson mean and variance ([m, v] = poisstat(lambda)).
Value nk::stats::raylpdf (const Value &x, double b, std::pmr::memory_resource *mr=nullptr)
 Rayleigh pdf (y = raylpdf(x, b)).
Value nk::stats::raylcdf (const Value &x, double b, std::pmr::memory_resource *mr=nullptr)
 Rayleigh cdf (p = raylcdf(x, b)).
Value nk::stats::raylinv (const Value &p, double b, std::pmr::memory_resource *mr=nullptr)
 Rayleigh inverse cdf (x = raylinv(p, b)).
Value nk::stats::raylrnd (::nk::ops::RngContext &rng, double b, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Rayleigh random samples (r = raylrnd(b, rows, cols)).
std::tuple< double, double > nk::stats::raylstat (double b)
 Rayleigh mean and variance ([m, v] = raylstat(b)).
Value nk::stats::ricepdf (const Value &x, double s, double sigma, std::pmr::memory_resource *mr=nullptr)
 Rician (Rice) pdf (y = ricepdf(x, s, sigma)).
Value nk::stats::ricecdf (const Value &x, double s, double sigma, std::pmr::memory_resource *mr=nullptr)
 Rician cdf (p = ricecdf(x, s, sigma)).
Value nk::stats::riceinv (const Value &p, double s, double sigma, std::pmr::memory_resource *mr=nullptr)
 Rician inverse cdf (x = riceinv(p, s, sigma)).
Value nk::stats::ricernd (::nk::ops::RngContext &rng, double s, double sigma, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Rician random samples (r = ricernd(s, sigma, rows, cols)).
std::tuple< double, double > nk::stats::ricestat (double s, double sigma, std::pmr::memory_resource *mr=nullptr)
 Rician mean and variance ([m, v] = ricestat(s, sigma)).
Value nk::stats::tpdf (const Value &x, double nu, std::pmr::memory_resource *mr=nullptr)
 Student's t pdf (y = tpdf(x, nu)).
Value nk::stats::tcdf (const Value &x, double nu, std::pmr::memory_resource *mr=nullptr)
 Student's t cdf (F = tcdf(x, nu)).
Value nk::stats::tinv (const Value &p, double nu, std::pmr::memory_resource *mr=nullptr)
 Student's t inverse cdf (x = tinv(p, nu)).
Value nk::stats::trnd (::nk::ops::RngContext &rng, double nu, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Student's t random samples (r = trnd(nu, rows, cols)).
std::tuple< double, double > nk::stats::tstat (double nu)
 Student's t mean and variance ([m, v] = tstat(nu)).
Value nk::stats::nctpdf (const Value &x, double nu, double delta, std::pmr::memory_resource *mr=nullptr)
 Noncentral Student's t pdf (y = nctpdf(x, nu, delta)).
Value nk::stats::nctcdf (const Value &x, double nu, double delta, bool upper=false, std::pmr::memory_resource *mr=nullptr)
 Noncentral Student's t cdf (p = nctcdf(x, nu, delta)).
Value nk::stats::nctinv (const Value &p, double nu, double delta, std::pmr::memory_resource *mr=nullptr)
 Noncentral t inverse cdf (x = nctinv(p, nu, delta)).
std::tuple< double, double > nk::stats::nctstat (double nu, double delta)
 Noncentral t mean and variance ([m, v] = nctstat(nu, delta)).
Value nk::stats::nctrnd (::nk::ops::RngContext &rng, double nu, double delta, std::size_t rows=1, std::size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Noncentral Student's t random samples (r = nctrnd(nu, delta, rows, cols)).
Value nk::stats::unidpdf (const Value &k, double N, std::pmr::memory_resource *mr=nullptr)
 Discrete-uniform pmf (y = unidpdf(k, N)).
Value nk::stats::unidcdf (const Value &k, double N, std::pmr::memory_resource *mr=nullptr)
 Discrete-uniform cdf (F = unidcdf(k, N)).
Value nk::stats::unidinv (const Value &p, double N, std::pmr::memory_resource *mr=nullptr)
 Discrete-uniform inverse cdf (k = unidinv(p, N)).
Value nk::stats::unidrnd (::nk::ops::RngContext &rng, double N, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Discrete-uniform random samples (r = unidrnd(N, rows, cols)).
std::tuple< double, double > nk::stats::unidstat (double N)
 Discrete-uniform mean and variance ([m, v] = unidstat(N)).
Value nk::stats::unifpdf (const Value &x, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Continuous-uniform pdf (y = unifpdf(x, a, b)).
Value nk::stats::unifcdf (const Value &x, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Continuous-uniform cdf (p = unifcdf(x, a, b)).
Value nk::stats::unifinv (const Value &p, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Continuous-uniform inverse cdf (x = unifinv(p, a, b)).
Value nk::stats::unifrnd (::nk::ops::RngContext &rng, double a, double b, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Continuous-uniform random samples (r = unifrnd(a, b, rows, cols)).
std::tuple< double, double > nk::stats::unifstat (double a, double b)
 Continuous-uniform mean and variance ([m, v] = unifstat(a, b)).
Value nk::stats::wblpdf (const Value &x, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Weibull pdf (y = wblpdf(x, a, b)).
Value nk::stats::wblcdf (const Value &x, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Weibull cdf (p = wblcdf(x, a, b)).
Value nk::stats::wblinv (const Value &p, double a, double b, std::pmr::memory_resource *mr=nullptr)
 Weibull inverse cdf (x = wblinv(p, a, b)).
Value nk::stats::wblrnd (::nk::ops::RngContext &rng, double a, double b, size_t rows=1, size_t cols=1, std::pmr::memory_resource *mr=nullptr)
 Weibull random samples (r = wblrnd(a, b, rows, cols)).
std::tuple< double, double > nk::stats::wblstat (double a, double b)
 Weibull mean and variance ([m, v] = wblstat(a, b)).
Value nk::stats::wblfit (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Weibull MLE fit ([ahat, bhat] = wblfit(x)).
Value nk::stats::wblfit (const Value &x, const Value &censoring, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Weibull MLE fit with right-censoring and frequency weights ([parmhat, parmci] = wblfit(x, alpha, cens, freq)).
Value nk::stats::wblfit_ci (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 95% Wald CI for wblfit (pci = wblfit_ci(x, alpha)).
Value nk::stats::wblfit_ci (const Value &x, double alpha, const Value &censoring, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Wald CI for censored/weighted wblfit (pci = wblfit_ci(x, alpha, cens, freq)).
std::tuple< Value, Value, Value, Value > nk::stats::normfit (const Value &x, double alpha, std::pmr::memory_resource *mr=nullptr)
 Normal MLE without censoring ([muhat, sigmahat, muci, sigmaci] = normfit(x, alpha)).
std::tuple< Value, Value, Value, Value > nk::stats::normfit (const Value &x, double alpha, const Value &cens, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Normal MLE with optional censoring and frequencies.
std::tuple< Value, Value > nk::stats::poissfit (const Value &x, double alpha, std::pmr::memory_resource *mr=nullptr)
 Poisson MLE ([lhat, lci] = poissfit(x, alpha)).
std::tuple< Value, Value > nk::stats::expfit (const Value &x, double alpha, const Value &cens=Value::Empty, const Value &freq=Value::Empty, std::pmr::memory_resource *mr=nullptr)
 Exponential MLE ([muhat, muci] = expfit(x, alpha, cens, freq)).
std::tuple< Value, Value, Value, Value > nk::stats::unifit (const Value &x, double alpha, std::pmr::memory_resource *mr=nullptr)
 Continuous-uniform MLE ([ahat, bhat, aci, bci] = unifit(x, alpha)).
std::tuple< Value, Value > nk::stats::lognfit (const Value &x, double alpha, std::pmr::memory_resource *mr=nullptr)
 Lognormal MLE without censoring ([parm, pci] = lognfit(x, alpha)).
std::tuple< Value, Value > nk::stats::lognfit (const Value &x, double alpha, const Value &cens, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Lognormal MLE with censoring and frequencies.
std::tuple< Value, Value > nk::stats::binofit (const Value &x, const Value &n, double alpha, std::pmr::memory_resource *mr=nullptr)
 Binomial parameter CI ([phat, pci] = binofit(x, n, alpha)).
std::tuple< Value, Value > nk::stats::raylfit (const Value &x, double alpha, std::pmr::memory_resource *mr=nullptr)
 Rayleigh MLE ([shat, sci] = raylfit(x, alpha)).
double nk::stats::normlike (double mu, double sigma, const Value &x, const Value &cens, const Value &freq, std::pmr::memory_resource *mr=nullptr)
 Normal negative-log-likelihood (nLogL = normlike(mu, sigma, x, cens, freq)).
double nk::stats::explike (double mu, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Exponential nLogL (nLogL = explike(mu, x)).
double nk::stats::lognlike (double mu, double sigma, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Lognormal nLogL (nLogL = lognlike(mu, sigma, x)).
double nk::stats::gamlike (double a, double b, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Gamma nLogL (nLogL = gamlike(a, b, x)).
double nk::stats::betalike (double a, double b, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Beta nLogL (nLogL = betalike(a, b, x)).
double nk::stats::wbllike (double a, double b, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Weibull nLogL (nLogL = wbllike(a, b, x)).
double nk::stats::evlike (double mu, double sigma, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Type-I EV nLogL (nLogL = evlike(mu, sigma, x)).
double nk::stats::gevlike (double k, double sigma, double mu, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Generalised Extreme Value nLogL (nLogL = gevlike(k, sigma, mu, x)).
double nk::stats::gplike (double k, double sigma, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Generalised Pareto nLogL (nLogL = gplike(k, sigma, x), theta = 0).
std::tuple< Value, Value, Value, Value > nk::stats::classify (const Value &sample, const Value &training, const Value &group, const std::string &type, std::pmr::memory_resource *mr=nullptr)
 Classify samples via LDA / QDA ([c, err, posterior, logp] = classify(sample, training, group, type)).
Value nk::stats::skewness (const Value &x, int normFlag=1, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Sample skewness along dim (y = skewness(X, normFlag, dim)).
Value nk::stats::kurtosis (const Value &x, int normFlag=1, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Sample kurtosis along dim (y = kurtosis(X, normFlag, dim)).
Value nk::stats::movmean (const Value &x, Span< const size_t > k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving mean along dim (y = movmean(x, k)).
Value nk::stats::movmedian (const Value &x, Span< const size_t > k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving median along dim (y = movmedian(x, k)).
Value nk::stats::movsum (const Value &x, Span< const size_t > k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving sum along dim (y = movsum(x, k)).
Value nk::stats::movmin (const Value &x, Span< const size_t > k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving minimum along dim (y = movmin(x, k)).
Value nk::stats::movmax (const Value &x, Span< const size_t > k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving maximum along dim (y = movmax(x, k)).
Value nk::stats::movstd (const Value &x, Span< const size_t > k, int normFlag=0, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving standard deviation along dim (y = movstd(x, k, normFlag)).
Value nk::stats::movvar (const Value &x, Span< const size_t > k, int normFlag=0, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving variance along dim (y = movvar(x, k, normFlag)).
Value nk::stats::movmad (const Value &x, Span< const size_t > k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving mean absolute deviation (y = movmad(x, k)).
Value nk::stats::movprod (const Value &x, Span< const size_t > k, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Moving product along dim (y = movprod(x, k)).
Value nk::stats::smoothdata (const Value &x, const std::string &method="movmean", int k=0, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Method-dispatching data smoother (y = smoothdata(x, method, k)).
Value nk::stats::hampel (const Value &x, int k=3, double nsigmas=3.0, std::pmr::memory_resource *mr=nullptr)
 Hampel outlier-resilient median filter (y = hampel(x, k, nsigmas)).
Value nk::stats::mvnpdf (const Value &X, const Value &mu, const Value &Sigma, std::pmr::memory_resource *mr=nullptr)
 Multivariate normal pdf (y = mvnpdf(X, mu, Sigma)).
Value nk::stats::mvtpdf (const Value &X, const Value &C, double df, std::pmr::memory_resource *mr=nullptr)
 Multivariate Student-t pdf (y = mvtpdf(X, C, df)).
Value nk::stats::mnpdf (const Value &X, const Value &P, std::pmr::memory_resource *mr=nullptr)
 Multinomial pmf (y = mnpdf(X, P)).
Value nk::stats::nansum (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware sum along dim (y = nansum(x, dim)).
Value nk::stats::nanmean (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware mean along dim (y = nanmean(x, dim)).
Value nk::stats::nanmax (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware maximum along dim (y = nanmax(x, dim)).
Value nk::stats::nanmin (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware minimum along dim (y = nanmin(x, dim)).
Value nk::stats::nanvar (const Value &x, int normFlag=0, int dim=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware variance (y = nanvar(x, normFlag, dim)).
Value nk::stats::nanstdev (const Value &x, int normFlag=0, int dim=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware standard deviation (y = nanstdev(x, normFlag, dim)).
Value nk::stats::nanmedian (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware median along dim (y = nanmedian(x, dim)).
Value nk::stats::nancov (const Value &x, int normFlag=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware covariance matrix (C = nancov(X [, normFlag])).
Value nk::stats::nancov (const Value &x, const Value &y, int normFlag=0, std::pmr::memory_resource *mr=nullptr)
 NaN-aware covariance from two vectors (C = nancov(x, y)).
Value nk::stats::haltonset (int d, long long skip, long long leap, std::pmr::memory_resource *mr=nullptr)
 Build a Halton stream descriptor (p = haltonset(d, 'Skip', s, 'Leap', l)).
Value nk::stats::net (const Value &stream, long long n, std::pmr::memory_resource *mr=nullptr)
 Extract points from a quasi-random stream (X = net(p, n)).
std::tuple< Value, Value, Value, Value > nk::stats::regress (const Value &y, const Value &X, double alpha, std::pmr::memory_resource *mr=nullptr)
 Ordinary least-squares regression ([b, bint, r, stats] = regress(y, X, alpha)).
Value nk::stats::ridge (const Value &y, const Value &X, const Value &k, bool scaled, std::pmr::memory_resource *mr=nullptr)
 Ridge regression (B = ridge(y, X, k, scaled)).
std::tuple< Value, Value, Value, Value > nk::stats::lscov (const Value &A, const Value &b, const Value &w, std::pmr::memory_resource *mr=nullptr)
 Weighted least squares ([x, stdx, mse, S] = lscov(A, b, w)).
NlinfitResult nk::stats::nlinfit (const Value &X, const Value &y, FnHandle model, const Value &beta0, std::pmr::memory_resource *mr=nullptr)
 Nonlinear least-squares fit via Levenberg-Marquardt.
Value nk::stats::nlparci (const Value &beta, const Value &R, const Value &J, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 Parameter confidence intervals from an nlinfit fit (ci = nlparci(beta, R, J [, alpha])).
std::tuple< Value, Value > nk::stats::nlpredci (FnHandle model, const Value &X, const Value &beta, const Value &R, const Value &J, double alpha, std::pmr::memory_resource *mr=nullptr)
 Prediction confidence intervals from an nlinfit fit ([ypred, delta] = nlpredci(fun, X, beta, R, J [, alpha])).
RobustfitResult nk::stats::robustfit (const Value &X, const Value &y, RobustWeight weight=RobustWeight::Bisquare, double tune=std::numeric_limits< double >::quiet_NaN(), std::pmr::memory_resource *mr=nullptr)
 Robust linear regression via Iteratively Reweighted Least Squares (IRLS) (robustfit(X, y)).
RobustcovResult nk::stats::robustcov (const Value &X, std::pmr::memory_resource *mr=nullptr)
 Robust multivariate covariance estimate via trimmed-MCD ([sigma, mu] = robustcov(X)).
GlmfitResult nk::stats::glmfit (const Value &X, const Value &y, GlmDistribution distr, GlmLink link=GlmLink::Identity, std::pmr::memory_resource *mr=nullptr)
 Fit a generalised linear model ([b, dev] = glmfit(X, y, distr [, link])).
Value nk::stats::glmval (const Value &b, const Value &X, GlmLink link, std::pmr::memory_resource *mr=nullptr)
 Evaluate a fitted GLM (yhat = glmval(b, X, link)).
LassoResult nk::stats::lasso (const Value &X, const Value &y, const Value &lambdas, double alpha=1.0, std::pmr::memory_resource *mr=nullptr)
 LASSO / elastic-net linear regression ([B, FitInfo] = lasso(X, y, lambdas, alpha)).
LassoResult nk::stats::lassoglm (const Value &X, const Value &y, GlmDistribution distr, const Value &lambdas, double alpha=1.0, std::pmr::memory_resource *mr=nullptr)
 Lasso-regularised GLM ([B, FitInfo] = lassoglm(X, y, distr, lambdas, alpha)).
Value nk::stats::randsample (::nk::ops::RngContext &rng, int N, int K, bool with_replacement, const Value &weights, std::pmr::memory_resource *mr=nullptr)
 Sample integers from 1..N (r = randsample(N, K, replacement, weights)).
Value nk::stats::datasample (::nk::ops::RngContext &rng, const Value &X, int K, int dim, bool with_replacement, const Value &weights, std::pmr::memory_resource *mr=nullptr)
 Sample rows / columns of an array (Y = datasample(X, K, dim, replacement, weights)).
Value nk::stats::combnk (int N, int K, std::pmr::memory_resource *mr=nullptr)
 Enumerate K-combinations of 1..N (C = combnk(N, K)).
Value nk::stats::combnk (Span< const double > v, int K, std::pmr::memory_resource *mr=nullptr)
 Enumerate K-combinations of an arbitrary vector (C = combnk(v, K)).
Value nk::stats::lhsdesign (::nk::ops::RngContext &rng, std::size_t n, std::size_t p, bool smooth, LhsCriterion criterion, std::size_t iterations, std::pmr::memory_resource *mr=nullptr)
 Latin Hypercube design (X = lhsdesign(n, p[, options])).
Value nk::stats::lhsdesign (::nk::ops::RngContext &rng, std::size_t n, std::size_t p, std::pmr::memory_resource *mr=nullptr)
 Latin Hypercube design with MATLAB defaults (smooth = on, criterion = maximin, iterations = 5).
Value nk::stats::lhsnorm (::nk::ops::RngContext &rng, const Value &mu, const Value &Sigma, std::size_t n, std::pmr::memory_resource *mr=nullptr)
 Latin Hypercube sample mapped to a Gaussian (Y = lhsnorm(mu, Sigma, n)).
Value nk::stats::aveknt (const Value &t, int k, std::pmr::memory_resource *mr=nullptr)
 Greville knot averages (a = aveknt(t, k)).
Value nk::stats::augknt (const Value &knots, int k, std::pmr::memory_resource *mr=nullptr)
 Augment knot sequence (aug = augknt(knots, k)).
Value nk::stats::brk2knt (const Value &breaks, const Value &mults, std::pmr::memory_resource *mr=nullptr)
 Replicate breaks by multiplicities (t = brk2knt(breaks, mults)).
std::tuple< Value, Value > nk::stats::knt2brk (const Value &knots, std::pmr::memory_resource *mr=nullptr)
 Decompose knot vector ([breaks, mults] = knt2brk(knots)).
Value nk::stats::ppmak (const Value &breaks, const Value &coefs, int d, std::pmr::memory_resource *mr=nullptr)
 Piecewise-polynomial constructor (pp = ppmak(breaks, coefs, d)).
Value nk::stats::fnval (const Value &pp, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Evaluate a pp-form spline (y = fnval(pp, x)).
Value nk::stats::fnder (const Value &pp, int order, std::pmr::memory_resource *mr=nullptr)
 Differentiate a pp-form spline (dpp = fnder(pp, order)).
Value nk::stats::fnint (const Value &pp, std::pmr::memory_resource *mr=nullptr)
 Antiderivative of a pp-form spline (ipp = fnint(pp)).
Value nk::stats::csapi (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
 Not-a-knot cubic spline interpolation (pp = csapi(x, y)).
Value nk::stats::fnbrk (const Value &pp, const std::string &part, std::pmr::memory_resource *mr=nullptr)
 Extract a named field from a pp-form spline (v = fnbrk(pp, part)).
Value nk::stats::fncmb (const Value &pp1, double c1, const Value &pp2=Value::Empty, double c2=0.0, std::pmr::memory_resource *mr=nullptr)
 Combine pp-form splines linearly (pp = fncmb(pp1, c1, pp2, c2)).
std::tuple< Value, Value, Value, Value > nk::stats::ttest (const Value &x, double m, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 One-sample Student's t-test ([h, p, ci, t] = ttest(x, m, alpha, tail)).
std::tuple< Value, Value, Value, Value > nk::stats::ttest2 (const Value &x, const Value &y, double alpha, TestTail tail, const std::string &vartype, std::pmr::memory_resource *mr=nullptr)
 Two-sample t-test ([h, p, ci, t] = ttest2(x, y, alpha, tail, vartype)).
std::tuple< Value, Value, Value, Value > nk::stats::ztest (const Value &x, double m, double sigma, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 Z-test with known σ ([h, p, ci, z] = ztest(x, m, sigma, alpha, tail)).
std::tuple< Value, Value, Value, Value > nk::stats::vartest (const Value &x, double v, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 Chi-squared one-sample variance test ([h, p, ci, chi2] = vartest(x, v, alpha, tail)).
std::tuple< Value, Value, Value, Value > nk::stats::vartest2 (const Value &x, const Value &y, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 F-test for equality of two variances ([h, p, ci, F] = vartest2(x, y, alpha, tail)).
std::tuple< Value, Value, Value, Value > nk::stats::kstest (const Value &x, const Value &cdf, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 One-sample Kolmogorov-Smirnov test ([h, p, ksstat, cv] = kstest(x, cdf, alpha, tail)).
std::tuple< Value, Value, Value, Value > nk::stats::kstest2 (const Value &x, const Value &y, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 Two-sample Kolmogorov-Smirnov test ([h, p, ksstat, cv] = kstest2(x, y, alpha, tail)).
std::tuple< Value, Value, Value, Value > nk::stats::jbtest (const Value &x, double alpha, std::pmr::memory_resource *mr=nullptr)
 Jarque-Bera normality test ([h, p, jbstat, cv] = jbtest(x, alpha)).
std::tuple< Value, Value, Value, Value > nk::stats::adtest (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 Anderson-Darling test for normality ([h, p, adstat, cv] = adtest(x, alpha)).
std::tuple< Value, Value > nk::stats::dwtest (const Value &r, const Value &X, std::pmr::memory_resource *mr=nullptr)
 Durbin-Watson test for first-order autocorrelation in regression residuals ([p, dw] = dwtest(r, X)).
std::tuple< Value, Value, Value, Value > nk::stats::jbtest (const Value &x, double alpha, double mctol, std::pmr::memory_resource *mr=nullptr)
 Jarque-Bera with explicit Monte-Carlo tolerance ([h, p, jbstat, cv] = jbtest(x, alpha, mctol)).
std::tuple< Value, Value, Value > nk::stats::signtest (const Value &x, const Value &y_or_m, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 Non-parametric sign test ([p, h, sign] = signtest(x, y_or_m, alpha, tail)).
std::tuple< Value, Value, Value > nk::stats::vartestn (const Value &x, const Value &group, double alpha, std::pmr::memory_resource *mr=nullptr)
 Bartlett's k-sample variance test ([p, chi2, df] = vartestn(x, group, alpha)).
std::tuple< Value, Value, Value, Value > nk::stats::vartestn_full (const Value &x, const Value &group, int test, std::pmr::memory_resource *mr=nullptr)
 Full k-sample variance test with method selection (vartestn_full(x, group, test)).
std::tuple< Value, Value, Value, Value, Value > nk::stats::fishertest (const Value &T, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 Fisher's exact test for a 2×2 table ([h, p, OR, ci_lo, ci_hi] = fishertest(T, alpha, tail)).
std::tuple< Value, Value, Value, Value > nk::stats::chi2gof (const Value &observed, const Value &expected, int nparams, double alpha, std::pmr::memory_resource *mr=nullptr)
 Chi-squared goodness-of-fit (frequency form) ([h, p, chi2, df] = chi2gof(observed, expected, nparams, alpha)).
std::tuple< Value, Value, Value, Value, Value, Value > nk::stats::runstest (const Value &x, double v, double alpha, TestTail tail, const std::string &method, std::pmr::memory_resource *mr=nullptr)
 Wald-Wolfowitz runs test for randomness ([p, h, nruns, n1, n0, zval] = runstest(x, v, alpha, tail, method)).
std::tuple< Value, Value, Value, Value > nk::stats::ranksum (const Value &x, const Value &y, double alpha, TestTail tail, const std::string &method, std::pmr::memory_resource *mr=nullptr)
 Wilcoxon rank-sum (Mann-Whitney U) test ([p, h, ranksum_x, zval] = ranksum(x, y, alpha, tail, method)).
std::tuple< Value, Value, Value, Value > nk::stats::signrank (const Value &x, const Value &y_or_m, double alpha, TestTail tail, const std::string &method, std::pmr::memory_resource *mr=nullptr)
 Wilcoxon signed-rank test ([p, h, signedrank, zval] = signrank(x, y_or_m, alpha, tail, method)).
std::tuple< Value, Value, Value, Value > nk::stats::ansaribradley (const Value &x, const Value &y, double alpha, TestTail tail, std::pmr::memory_resource *mr=nullptr)
 Ansari-Bradley two-sample scale (dispersion) test ([h, p, W, Wstar] = ansaribradley(x, y, alpha, tail)).
std::tuple< Value, Value, Value, Value > nk::stats::lillietest (const Value &x, double alpha=0.05, std::pmr::memory_resource *mr=nullptr)
 Lilliefors normality test ([h, p, kstat, critval] = lillietest(x, alpha)).

Detailed Description

Descriptive statistics, 20+ probability distributions, hypothesis testing (t-test, ANOVA), regression models, PCA, and clustering.

Enumeration Type Documentation

◆ GlmDistribution

enum class nk::stats::GlmDistribution
strong

GLM family of error distributions.

Definition at line 218 of file regress.hpp.

◆ GlmLink

enum class nk::stats::GlmLink
strong

GLM link function.

Enumerator
Identity 

g(μ) = μ

Logit 

g(μ) = log(μ / (1 - μ))

Log 

g(μ) = log(μ)

Reciprocal 

g(μ) = 1 / μ

Probit 

g(μ) = Φ^-1(μ)

Definition at line 227 of file regress.hpp.

◆ LhsCriterion

enum class nk::stats::LhsCriterion
strong

Criterion for lhsdesign optimization.

Enumerator
None 

Single random LHS.

Maximin 

Maximize the minimum pairwise Euclidean distance.

Correlation 

Minimize the maximum off-diagonal column correlation.

Definition at line 22 of file lhs.hpp.

◆ McCorrection

enum class nk::stats::McCorrection
strong

Multiple-comparison correction methods for multcompare.

Definition at line 91 of file anova.hpp.

◆ RobustWeight

enum class nk::stats::RobustWeight
strong

Robust regression weight functions (MATLAB robustfit set).

Definition at line 158 of file regress.hpp.

◆ TestTail

enum class nk::stats::TestTail
strong

Direction of the alternative hypothesis.

Enumerator
Both 

Two-sided alternative (default).

Right 

Upper-tailed (statistic > null).

Left 

Lower-tailed (statistic < null).

Definition at line 28 of file hypothesis.hpp.

Function Documentation

◆ adtest()

std::tuple< Value, Value, Value, Value > nk::stats::adtest ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

Anderson-Darling test for normality ([h, p, adstat, cv] = adtest(x, alpha)).

H0: x is drawn from a normal distribution with parameters estimated from the sample (mu = mean(x), sigma = std(x)).

Algorithm: sort and z-standardise, compute A² = -n - (1/n) · Σ (2i-1) · [ln Φ(z_i) + ln(1 - Φ(z_{n+1-i}))], then the Stephens-1986 small-sample adjustment A²* = A² · (1 + 0.75/n + 2.25/n²). p-value from D'Agostino-Stephens (1986) piecewise rational fit for the parameters-estimated case.

Parameters
xSample data (length ≥ 8 for reliable p-values).
alphaSignificance level (default 0.05).
mrMemory resource (nullptr → process default).
Returns
(h, p, adstat, cv) — decision, p-value, A²*, 5% critical value (0.752 for estimated parameters).

◆ anova1()

std::tuple< double, double, double, double, double, double > nk::stats::anova1 ( const Value & y,
const Value & group,
std::pmr::memory_resource * mr = nullptr )

One-way ANOVA ([p, F, df_b, df_w, ss_b, ss_w] = anova1(y, group)).

Returns the standard test statistics: between-group p-value p, F-statistic, between/within degrees of freedom, and between/within sums-of-squares. The engine wrapper packs the auxiliary outputs into a 4×6 cell-array summary table.

Parameters
yResponse vector.
groupGrouping labels (same length as y).
mrMemory resource (nullptr → process default).
Returns
(p, F, df_between, df_within, ss_between, ss_within).
See also
kruskalwallis

◆ ansaribradley()

std::tuple< Value, Value, Value, Value > nk::stats::ansaribradley ( const Value & x,
const Value & y,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

Ansari-Bradley two-sample scale (dispersion) test ([h, p, W, Wstar] = ansaribradley(x, y, alpha, tail)).

Non-parametric H0: x and y have the same dispersion (variances are equal). The Ansari-Bradley statistic W is the sum, in the pooled sorted sample, of the V-shaped ranks 1, 2, …, ⌈N/2⌉, …, 2, 1 over positions occupied by x.

Under H0, W is asymptotically normal with closed-form mean and variance (Hollander & Wolfe). The standardised statistic is Wstar = (W − E[W]) / sqrt(V[W]); the p-value follows from Φ(Wstar).

KNOWN GAPs: tied-rank correction (MATLAB applies a small tie-correction to V[W] when ties are present) and exact permutation distribution for small samples are deferred — asymptotic only.

Parameters
xFirst sample.
ySecond sample.
alphaSignificance level (default 0.05).
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(h, p, W, Wstar).
See also
vartest2, ranksum

◆ augknt()

Value nk::stats::augknt ( const Value & knots,
int k,
std::pmr::memory_resource * mr = nullptr )

Augment knot sequence (aug = augknt(knots, k)).

Pads knots so each endpoint has multiplicity k. Used to build B-spline open knot vectors.

Parameters
knotsInterior knot vector (non-decreasing).
kSpline order.
mrMemory resource (nullptr → process default).
Returns
Augmented knot vector.
See also
aveknt, brk2knt

◆ autocorr()

std::tuple< Value, Value, Value > nk::stats::autocorr ( const Value & y,
int numLags = -1,
double numSTD = 2.0,
std::pmr::memory_resource * mr = nullptr )

Sample autocorrelation function ([acf, lags, bounds] = autocorr(y)).

acf(k) = c(k)/c(0) with the BIASED autocovariance c(k) = (1/N) Σ_t (y_t-ȳ)(y_{t+k}-ȳ) — matches MATLAB's Econometrics autocorr (lag-0 == 1). Confidence bounds are ±numSTD/√N.

Parameters
yReal 1-D series.
numLagsNumber of lags; < 0 → MATLAB default min(20, N-1).
numSTDBound width in standard errors (MATLAB default 2).
mrMemory resource (nullptr → process default).
Returns
(acf, lags, bounds) column vectors; acf/lags have numLags+1 entries (lags 0..numLags), bounds is [+b; -b].
See also
crosscorr, xcorr

◆ aveknt()

Value nk::stats::aveknt ( const Value & t,
int k,
std::pmr::memory_resource * mr = nullptr )

Greville knot averages (a = aveknt(t, k)).

a_i = mean(t_{i+1}, …, t_{i+k-1}) for i = 1..length(t) - k. Useful for placing B-spline control sites along a knot vector.

Parameters
tNon-decreasing knot vector.
kSpline order (k >= 1).
mrMemory resource (nullptr → process default).
Returns
Row vector of length length(t) - k.
See also
augknt

◆ betacdf()

Value nk::stats::betacdf ( const Value & x,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Beta cdf (p = betacdf(x, a, b)).

Direct expression of the regularised incomplete beta: \( F(x; a, b) = I_x(a, b) \).

Parameters
xEvaluation points (any shape).
aFirst shape parameter (a > 0).
bSecond shape parameter (b > 0).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
betapdf, betainv

◆ betafit()

Value nk::stats::betafit ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Beta(a, b) MLE fit ([ahat, bhat] = betafit(x)).

Newton iteration on the digamma system ψ(a) - ψ(a+b) = mean log(x) ψ(b) - ψ(a+b) = mean log(1-x) Initial guess from method of moments. Throws on x outside [0, 1].

Parameters
xSamples in [0, 1].
mrMemory resource.
Returns
[ahat, bhat] as a 1 × 2 row.

◆ betafit_ci()

Value nk::stats::betafit_ci ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

95% Wald CI for betafit (pci = betafit_ci(x, alpha)).

Returns the 2 × 2 confidence matrix [lo; hi] for [a, b] from the observed Fisher information (central-FD Hessian of NLL). Both parameters use a log-scale Wald CI (MATLAB convention).

◆ betainv()

Value nk::stats::betainv ( const Value & p,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Beta inverse cdf (x = betainv(p, a, b)).

Computed via betaincinv.

Parameters
pProbability levels in [0, 1] (any shape).
aFirst shape parameter.
bSecond shape parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
betacdf

◆ betalike()

double nk::stats::betalike ( double a,
double b,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Beta nLogL (nLogL = betalike(a, b, x)).

Parameters
aFirst shape parameter.
bSecond shape parameter.
xSample data in (0, 1).
mrMemory resource (nullptr → process default).
Returns
Scalar negative log-likelihood.

◆ betapdf()

Value nk::stats::betapdf ( const Value & x,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Beta pdf (y = betapdf(x, a, b)).

\( f(x; a, b) = \dfrac{x^{a-1}(1-x)^{b-1}}{B(a, b)} \) for x ∈ [0, 1], 0 elsewhere.

Parameters
xEvaluation points (any shape).
aFirst shape parameter (a > 0).
bSecond shape parameter (b > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
betacdf, betainv, betarnd, betastat

◆ betarnd()

Value nk::stats::betarnd ( ::nk::ops::RngContext & rng,
double a,
double b,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Beta random samples (r = betarnd(a, b, rows, cols)).

Generated as X = U / (U + V) with U ~ Gamma(a, 1), V ~ Gamma(b, 1).

Parameters
aFirst shape parameter (a > 0).
bSecond shape parameter (b > 0).
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of Beta samples.
See also
betapdf

◆ betastat()

std::tuple< double, double > nk::stats::betastat ( double a,
double b )

Beta mean and variance ([m, v] = betastat(a, b)).

Closed form: m = a / (a + b), v = a·b / ((a + b)² · (a + b + 1)).

Parameters
aFirst shape parameter.
bSecond shape parameter.
Returns
{mean, variance} pair.
See also
betapdf

◆ binocdf()

Value nk::stats::binocdf ( const Value & k,
double n,
double p,
std::pmr::memory_resource * mr = nullptr )

Binomial cumulative distribution (F = binocdf(k, n, p)).

Computed via the regularised incomplete-beta identity \( F(k) = I_{1-p}(n - \lfloor k\rfloor,\ \lfloor k\rfloor + 1) \), which is accurate for the full k-range without summing the pmf tail.

Parameters
kEvaluation points (any shape).
nNumber of trials.
pSuccess probability per trial.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1], same shape as k.
See also
binopdf, binoinv

◆ binofit()

std::tuple< Value, Value > nk::stats::binofit ( const Value & x,
const Value & n,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Binomial parameter CI ([phat, pci] = binofit(x, n, alpha)).

Clopper–Pearson exact binomial CI for x successes out of n trials. Vector inputs produce a column vector phat and N × 2 pci.

Parameters
xSuccess counts (scalar or vector).
nTrial counts (matching shape).
alphaSignificance level.
mrMemory resource (nullptr → process default).
Returns
(phat, pci).

◆ binoinv()

Value nk::stats::binoinv ( const Value & p_in,
double n,
double p,
std::pmr::memory_resource * mr = nullptr )

Binomial inverse cdf (k = binoinv(p_in, n, p)).

Smallest integer k such that binocdf(k, n, p) >= p_in.

Parameters
p_inProbability levels in [0, 1] (any shape).
nNumber of trials.
pSuccess probability per trial.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p_in.
See also
binocdf, binopdf

◆ binopdf()

Value nk::stats::binopdf ( const Value & k,
double n,
double p,
std::pmr::memory_resource * mr = nullptr )

Binomial pmf (y = binopdf(k, n, p)).

\( f(k; n, p) = \binom{n}{k}\,p^{k}(1-p)^{n-k} \) for k ∈ {0, …, n}. Returns 0 outside the support; broadcasts elementwise over k.

Parameters
kRandom-variable values where the pmf is evaluated. Any shape; output matches k. Non-integer or out-of-range entries return 0.
nNumber of trials (positive integer-valued double).
pSuccess probability per trial, 0 ≤ p ≤ 1.
mrMemory resource (nullptr → process default).
Returns
Array of pmf values, same shape as k.
See also
binocdf, binoinv, binornd, binostat

◆ binornd()

Value nk::stats::binornd ( ::nk::ops::RngContext & rng,
double n,
double p,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Binomial random samples (r = binornd(n, p, rows, cols)).

Parameters
nNumber of trials.
pSuccess probability per trial.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of binomial samples.
See also
binopdf

◆ binostat()

std::tuple< double, double > nk::stats::binostat ( double n,
double p )

Binomial mean and variance ([m, v] = binostat(n, p)).

Closed form: m = n·p, v = n·p·(1-p).

Parameters
nNumber of trials.
pSuccess probability per trial.
Returns
{mean, variance} pair.
See also
binopdf

◆ bounds()

std::tuple< Value, Value > nk::stats::bounds ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Min and max along dim ([lo, hi] = bounds(X, dim)).

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
(min, max) reduced along dim.

◆ brk2knt()

Value nk::stats::brk2knt ( const Value & breaks,
const Value & mults,
std::pmr::memory_resource * mr = nullptr )

Replicate breaks by multiplicities (t = brk2knt(breaks, mults)).

Returns the concatenation where each breaks(i) appears mults(i) times. Inverse of knt2brk.

Parameters
breaksDistinct break values.
multsMultiplicities (length(mults) == length(breaks)).
mrMemory resource (nullptr → process default).
Returns
Expanded knot vector.
See also
knt2brk

◆ canoncorr()

CanoncorrResult nk::stats::canoncorr ( const Value & X,
const Value & Y,
std::pmr::memory_resource * mr = nullptr )

Canonical correlation analysis ([A, B, r] = canoncorr(X, Y)).

Finds linear combinations U = X·A and V = Y·B such that corr(U(:, i), V(:, i)) = r(i) is maximised, with the standard orthogonality / unit-variance constraints on U and V.

Algorithm: centre X and Y; compute QX, QY from thin QR; SVD QX' · QY for the canonical directions; back-substitute through R_X, R_Y to recover A, B. r is the singular-value vector (clamped to [0, 1] to absorb FP drift).

Parameters
Xn × p first set of variables.
Yn × q second set of variables (rows(Y) == rows(X)).
mrMemory resource (nullptr → process default).
Returns
{A, B, r} struct.

◆ chi2cdf()

Value nk::stats::chi2cdf ( const Value & x,
double k,
std::pmr::memory_resource * mr = nullptr )

Chi-squared cdf (F = chi2cdf(x, k)).

Computed via the regularised lower-incomplete gamma: \( F(x; k) = P(k/2,\ x/2) = \text{gammainc}(x/2,\ k/2) \).

Parameters
xEvaluation points (any shape).
kDegrees of freedom (k > 0).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
chi2pdf, chi2inv

◆ chi2gof()

std::tuple< Value, Value, Value, Value > nk::stats::chi2gof ( const Value & observed,
const Value & expected,
int nparams,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Chi-squared goodness-of-fit (frequency form) ([h, p, chi2, df] = chi2gof(observed, expected, nparams, alpha)).

df = k - 1 - nparams. The auto-binned distribution-fit form (without Frequency) is not supported in this release.

Parameters
observedObserved count vector (length k).
expectedExpected count vector (length k).
nparamsNumber of distribution parameters estimated from data (0 for fully specified null).
alphaSignificance level.
mrMemory resource (nullptr → process default).
Returns
(h, p, chi2stat, df).

◆ chi2inv()

Value nk::stats::chi2inv ( const Value & p,
double k,
std::pmr::memory_resource * mr = nullptr )

Chi-squared inverse cdf (x = chi2inv(p, k)).

Computed via gammaincinv: x = 2 · P^{-1}(p; k/2).

Parameters
pProbability levels in [0, 1] (any shape).
kDegrees of freedom (k > 0).
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
chi2cdf

◆ chi2pdf()

Value nk::stats::chi2pdf ( const Value & x,
double k,
std::pmr::memory_resource * mr = nullptr )

Chi-squared pdf (y = chi2pdf(x, k)).

\( f(x; k) = \dfrac{x^{k/2-1}\,e^{-x/2}}{2^{k/2}\,\Gamma(k/2)} \) for x > 0 (0 elsewhere). Special case of gampdf with shape k/2, scale 2.

Parameters
xEvaluation points (any shape; broadcasts elementwise).
kDegrees of freedom (k > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
chi2cdf, chi2inv, chi2rnd, chi2stat

◆ chi2rnd()

Value nk::stats::chi2rnd ( ::nk::ops::RngContext & rng,
double k,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Chi-squared random samples (r = chi2rnd(k, rows, cols)).

Sampled as Gamma(k/2, 2).

Parameters
kDegrees of freedom (k > 0).
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of χ² samples.
See also
chi2pdf

◆ chi2stat()

std::tuple< double, double > nk::stats::chi2stat ( double k)

Chi-squared mean and variance ([m, v] = chi2stat(k)).

Closed form: m = k, v = 2k.

Parameters
kDegrees of freedom.
Returns
{mean, variance} pair.
See also
chi2pdf

◆ cholcov()

std::pair< Value, Value > nk::stats::cholcov ( const Value & SIGMA,
std::pmr::memory_resource * mr = nullptr )

Cholesky-like factor of a covariance matrix ([T, p] = cholcov(SIGMA)).

Returns T with T'·T == SIGMA and a non-PD count p:

  • PD (n×n): T upper-triangular n × n, p = 0
  • PSD (rank r < n): T is r × n, p = 0
  • indefinite: T empty 0 × 0, p = #(eig <= -tol)
Parameters
SIGMASymmetric covariance matrix.
mrMemory resource (nullptr → process default).
Returns
(T, p) pair.

◆ classify()

std::tuple< Value, Value, Value, Value > nk::stats::classify ( const Value & sample,
const Value & training,
const Value & group,
const std::string & type,
std::pmr::memory_resource * mr = nullptr )

Classify samples via LDA / QDA ([c, err, posterior, logp] = classify(sample, training, group, type)).

Fits a discriminant model on (training, group) and assigns labels to each row of sample. Empirical priors (n_k / N).

Supported type:

  • "linear" — LDA with pooled covariance (default)
  • "diaglinear" — LDA with diagonal pooled covariance (naive Bayes)
  • "quadratic" — QDA with per-class covariance
  • "diagquadratic" — QDA with per-class diagonal covariance
  • "mahalanobis" — class-pooled Mahalanobis distance
Parameters
sampleN_samp × d points to classify.
trainingN_trn × d training data.
groupN_trn × 1 numeric class labels.
typeDiscriminant model — see list above.
mrMemory resource (nullptr → process default).
Returns
Tuple (c, err, posterior, logp):
  • c : N_samp × 1 predicted labels.
  • err : apparent training error rate.
  • posterior : N_samp × K posterior probabilities.
  • logp : N_samp × 1 log unconditional density.
See also
pca

◆ cluster_from_linkage() [1/2]

Value nk::stats::cluster_from_linkage ( const Value & Z,
int maxclust,
double cutoff,
const std::string & criterion,
int depth,
std::pmr::memory_resource * mr = nullptr )

5-arg overload of cluster_from_linkage with explicit inconsistency depth.

Parameters
ZLinkage table from linkage.
maxclustSee cluster_from_linkage.
cutoffSee cluster_from_linkage.
criterion"inconsistent" or "distance".
depthInconsistency-coefficient depth (≥ 1).
mrMemory resource (nullptr → process default).
Returns
N×1 column of 1-based cluster labels.
See also
cluster_from_linkage, inconsistent

◆ cluster_from_linkage() [2/2]

Value nk::stats::cluster_from_linkage ( const Value & Z,
int maxclust,
double cutoff,
const std::string & criterion,
std::pmr::memory_resource * mr = nullptr )

Flatten a linkage tree into cluster labels (T = cluster(Z, opts)).

Parameters
ZLinkage table from linkage.
maxclustCap number of clusters (cuts at the lowest distance that yields ≤ maxclust clusters). Pass 0 to ignore.
cutoffCut at given inconsistency / distance threshold.
criterion"inconsistent" (default) or "distance".
mrMemory resource (nullptr → process default).
Returns
N×1 column of 1-based cluster labels.

◆ clusterdata() [1/3]

Value nk::stats::clusterdata ( const Value & X,
int maxclust,
double cutoff,
const std::string & linkage_method,
const std::string & criterion,
int depth,
const std::string & distance_metric,
double p,
std::pmr::memory_resource * mr = nullptr )

8-arg clusterdata overload: explicit depth + custom distance metric.

Parameters
XRaw data matrix (N×D).
maxclustSee cluster_from_linkage.
cutoffSee cluster_from_linkage.
linkage_methodLinkage rule.
criterionThreshold criterion.
depthInconsistency-coefficient depth.
distance_metricDistance metric for the internal pdist.
pMetric parameter.
mrMemory resource (nullptr → process default).
Returns
N×1 cluster labels.
See also
clusterdata

◆ clusterdata() [2/3]

Value nk::stats::clusterdata ( const Value & X,
int maxclust,
double cutoff,
const std::string & linkage_method,
const std::string & criterion,
int depth,
std::pmr::memory_resource * mr = nullptr )

6-arg clusterdata overload: explicit inconsistency depth.

Parameters
XRaw data matrix (N×D).
maxclustSee cluster_from_linkage.
cutoffSee cluster_from_linkage.
linkage_methodLinkage rule.
criterionThreshold criterion.
depthInconsistency-coefficient depth.
mrMemory resource (nullptr → process default).
Returns
N×1 cluster labels.
See also
clusterdata

◆ clusterdata() [3/3]

Value nk::stats::clusterdata ( const Value & X,
int maxclust,
double cutoff,
const std::string & linkage_method,
const std::string & criterion,
std::pmr::memory_resource * mr = nullptr )

Convenience: pdist + linkage + cluster in one call (clusterdata).

Parameters
XRaw data matrix (N×D).
maxclustSee cluster_from_linkage.
cutoffSee cluster_from_linkage.
linkage_methodLinkage rule.
criterionThreshold criterion.
mrMemory resource (nullptr → process default).
Returns
N×1 cluster labels.

◆ combnk() [1/2]

Value nk::stats::combnk ( int N,
int K,
std::pmr::memory_resource * mr = nullptr )

Enumerate K-combinations of 1..N (C = combnk(N, K)).

Parameters
NPopulation size (combinations drawn from 1..N).
KCombination size.
mrMemory resource (nullptr → process default).
Returns
C(N, K) × K DOUBLE matrix of combinations.
Exceptions
ErrorK out of [0, N].

◆ combnk() [2/2]

Value nk::stats::combnk ( Span< const double > v,
int K,
std::pmr::memory_resource * mr = nullptr )

Enumerate K-combinations of an arbitrary vector (C = combnk(v, K)).

Parameters
vInput vector (length n).
KCombination size.
mrMemory resource (nullptr → process default).
Returns
C(n, K) × K DOUBLE matrix of combinations of v's elements.
Exceptions
ErrorK out of [0, v.size()].

◆ cophenet()

Value nk::stats::cophenet ( const Value & Z,
const Value & Y,
std::pmr::memory_resource * mr = nullptr )

Cophenetic correlation (c = cophenet(Z, Y)).

Correlation between linkage distances (in Z) and the original pdist distances Y. A measure of how faithfully the tree represents the input dissimilarities; higher = better.

Parameters
ZLinkage table from linkage.
YOriginal pdist row vector.
mrMemory resource (nullptr → process default).
Returns
Scalar correlation in [-1, 1].
See also
linkage

◆ copulacdf_frank()

Value nk::stats::copulacdf_frank ( const Value & U,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Frank copula CDF.

C(u, v; α) = −(1/α) log[1 + (e^{−αu} − 1)(e^{−αv} − 1)/(e^{−α} − 1)] for α ≠ 0.

◆ copulacdf_gaussian()

Value nk::stats::copulacdf_gaussian ( const Value & U,
const Value & R,
std::pmr::memory_resource * mr = nullptr )

Gaussian copula CDF (p = copulacdf('Gaussian', U, R)).

C(u; R) = Φ_d(Φ^{-1}(u_1), …, Φ^{-1}(u_d); 0, R).

◆ copulacdf_gumbel()

Value nk::stats::copulacdf_gumbel ( const Value & U,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Gumbel copula CDF.

C(u, v; α) = exp[−{(−log u)^α + (−log v)^α}^{1/α}] for α ≥ 1.

◆ copulapdf_clayton()

Value nk::stats::copulapdf_clayton ( const Value & U,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Clayton copula density (y = copulapdf('Clayton', U, alpha)).

c(u, v; α) = (1 + α) (uv)^{−(1+α)} (u^{−α} + v^{−α} − 1)^{−2 − 1/α} for α > 0 (independence at α → 0+).

◆ copulapdf_gaussian()

Value nk::stats::copulapdf_gaussian ( const Value & U,
const Value & R,
std::pmr::memory_resource * mr = nullptr )

Gaussian copula density (y = copulapdf('Gaussian', U, R)).

c(u; R) = (det R)^{-1/2} · exp(−½·z'·(R^{-1} − I)·z) where z_i = Φ^{-1}(u_i). Currently implemented for d = 2.

◆ corr_xx()

Value nk::stats::corr_xx ( const Value & X,
std::pmr::memory_resource * mr = nullptr )

Auto-correlation across columns of X (R = corr(X)).

Equivalent to corrcoef(X). Non-Pearson type options ("Spearman", "Kendall") deferred.

Parameters
XInput matrix.
mrMemory resource (nullptr → process default).
Returns
Correlation matrix across columns.
See also
corrcoef

◆ corr_xy()

Value nk::stats::corr_xy ( const Value & X,
const Value & Y,
std::pmr::memory_resource * mr = nullptr )

Cross-correlation between columns of X and Y (R = corr(X, Y)).

Parameters
XFirst matrix.
YSecond matrix (Y.rows == X.rows).
mrMemory resource (nullptr → process default).
Returns
Correlation matrix between columns of X and Y.
See also
corrcoef

◆ corrcoef() [1/2]

Value nk::stats::corrcoef ( const Value & x,
const Value & y,
std::pmr::memory_resource * mr = nullptr )

Joint correlation matrix (R = corrcoef(X, Y)).

Parameters
xFirst vector / matrix.
ySecond vector / matrix (compatible shape).
mrMemory resource (nullptr → process default).
Returns
Joint correlation matrix.
See also
corrcoef

◆ corrcoef() [2/2]

Value nk::stats::corrcoef ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Pearson correlation matrix (R = corrcoef(X)).

R(i, j) = C(i, j) / sqrt(C(i, i) · C(j, j)) where C = cov(X).

Parameters
xInput matrix.
mrMemory resource (nullptr → process default).
Returns
Correlation matrix.
See also
cov, corr_xx

◆ corrcov()

std::pair< Value, Value > nk::stats::corrcov ( const Value & C,
std::pmr::memory_resource * mr = nullptr )

Correlation matrix from covariance ([R, sigma] = corrcov(C)).

R(i, j) = C(i, j) / sqrt(C(i, i) · C(j, j)); sigma(i) = sqrt(C(i, i)) returned as a row vector. Throws on negative diagonal; zero diagonal yields NaN off-diagonal.

Parameters
CCovariance matrix.
mrMemory resource (nullptr → process default).
Returns
(R, sigma) pair.
Exceptions
ErrorNegative diagonal entry (m:corrcov:negDiag).

◆ cov() [1/2]

Value nk::stats::cov ( const Value & x,
const Value & y,
int normFlag = 0,
std::pmr::memory_resource * mr = nullptr )

Joint covariance of two vectors (C = cov(X, Y, normFlag)).

Returns a 2 × 2 covariance matrix of two equal-length vectors.

Parameters
xFirst vector.
ySecond vector (same length as x).
normFlag0 (sample) or 1 (population).
mrMemory resource (nullptr → process default).
Returns
2 × 2 joint covariance matrix.
See also
corrcoef

◆ cov() [2/2]

Value nk::stats::cov ( const Value & x,
int normFlag = 0,
std::pmr::memory_resource * mr = nullptr )

Sample / population covariance (C = cov(X, normFlag)).

For vector X returns var(X); for n × p matrix returns the p × p sample covariance C = (X - mean(X))' · (X - mean(X)) / (n - 1). 2-D path only — 3-D / N-D inputs throw.

Parameters
xInput array.
normFlag0 (default, sample, divide by n-1) or 1 (population, by n).
mrMemory resource (nullptr → process default).
Returns
Covariance matrix.
See also
corrcoef

◆ crosscorr()

std::tuple< Value, Value, Value > nk::stats::crosscorr ( const Value & y1,
const Value & y2,
int numLags = -1,
double numSTD = 2.0,
std::pmr::memory_resource * mr = nullptr )

Sample cross-correlation function ([xcf, lags, bounds] = crosscorr(y1, y2)).

xcf(k) = [(1/N) Σ_t (y1_t-ȳ1)(y2_{t+k}-ȳ2)] / √(c1(0)·c2(0)) for k = -numLags..numLags — matches MATLAB's Econometrics crosscorr (zero-lag = sample correlation). Confidence bounds are ±numSTD/√N.

Parameters
y1First real 1-D series.
y2Second real 1-D series (same length as y1).
numLagsNumber of lags each side; < 0 → default min(20, N-1).
numSTDBound width in standard errors (default 2).
mrMemory resource (nullptr → process default).
Returns
(xcf, lags, bounds) column vectors; xcf/lags have 2·numLags+1 entries (lags -numLags..numLags).
See also
autocorr, xcorr

◆ crosstab()

std::tuple< Value, double, double > nk::stats::crosstab ( const Value & x,
const Value & y_opt = Value::Empty,
std::pmr::memory_resource * mr = nullptr )

Contingency table ([T, chi2, p] = crosstab(x, y_opt)).

Single-arg form (pass Value::Empty for y_opt): T is a column vector of frequency counts of unique x. Two-arg: T(i, j) counts pairs (x_k, y_k) where x_k = unique_x(i) and y_k = unique_y(j); chi2 and p give a χ² test of independence. Numeric input only in v1; cell / string deferred.

Parameters
xInput data column.
y_optSecond column (Value::Empty for single-arg form).
mrMemory resource (nullptr → process default).
Returns
(T, chi2, p) — table, χ² statistic, p-value.

◆ csapi()

Value nk::stats::csapi ( const Value & x,
const Value & y,
std::pmr::memory_resource * mr = nullptr )

Not-a-knot cubic spline interpolation (pp = csapi(x, y)).

Returns a pp-form spline of order 4 that interpolates (x, y) and is C² with continuous third derivatives at x(2) and x(end-1).

Parameters
xSample sites (strictly increasing).
ySample values (matching shape with x).
mrMemory resource (nullptr → process default).
Returns
pp-form spline.
See also
ppmak, fnval

◆ datasample()

Value nk::stats::datasample ( ::nk::ops::RngContext & rng,
const Value & X,
int K,
int dim,
bool with_replacement,
const Value & weights,
std::pmr::memory_resource * mr = nullptr )

Sample rows / columns of an array (Y = datasample(X, K, dim, replacement, weights)).

Parameters
XSource data (matrix or higher-D array).
KNumber of draws.
dim1-based dimension to sample along (1 = rows, 2 = columns).
with_replacementWhen true, draw with replacement.
weightsOptional probability weights along dim (pass empty Value for uniform).
mrMemory resource (nullptr → process default).
Returns
Subsample of X.
See also
randsample

◆ datastats()

std::tuple< Value, Value, Value, Value, Value, Value, Value > nk::stats::datastats ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Dataset descriptive summary (datastats(x)).

Returns the seven curve-fitting descriptors. NaN values propagate via the underlying reductions.

Parameters
xInput array.
mrMemory resource (nullptr → process default).
Returns
(num, max, min, mean, median, range, std) tuple of scalars.

◆ dbscan() [1/2]

std::tuple< Value, Value > nk::stats::dbscan ( const Value & X,
double eps,
int minpts,
const std::string & metric,
double p,
std::pmr::memory_resource * mr = nullptr )

DBSCAN with explicit Minkowski exponent p (for metric = "minkowski").

See also
dbscan(X, eps, minpts, metric, mr)

◆ dbscan() [2/2]

std::tuple< Value, Value > nk::stats::dbscan ( const Value & X,
double eps,
int minpts,
const std::string & metric,
std::pmr::memory_resource * mr = nullptr )

DBSCAN density-based clustering ([idx, corepts] = dbscan(X, eps, minpts, metric)).

Builds clusters from corepts — points with at least minpts neighbours within distance eps. Output labels: cluster index ≥ 1, or -1 for noise.

Pass metric = "precomputed" to use X as a pre-built N×N pairwise distance matrix directly.

Parameters
XN×D data matrix or N×N precomputed distances.
epsNeighbourhood radius.
minptsMinimum neighbour count for a core point.
metricpdist metric, or "precomputed".
mrMemory resource (nullptr → process default).
Returns
(idx, corepts):
  • idx : N×1 cluster labels (≥1 or -1 for noise).
  • corepts : N×1 LOGICAL marking core points.
See also
kmedoids, kmeans

◆ detrend_of()

Value nk::stats::detrend_of ( const Value & x,
int order = 1,
std::pmr::memory_resource * mr = nullptr )

Remove polynomial trend (y = detrend(x, order)).

Returns x minus its best-fit polynomial of the given order. Vectors detrend whole; matrices detrend per column.

Parameters
xInput array.
orderPolynomial order (default 1 = linear).
mrMemory resource (nullptr → process default).
Returns
Detrended array, same shape as x.

◆ dummyvar()

Value nk::stats::dummyvar ( const Value & group,
std::pmr::memory_resource * mr = nullptr )

Convert categorical labels to indicator columns (X = dummyvar(group)).

Result is N×K where K is the number of distinct labels (sorted ascending for numeric labels; string labels are normalised via toString conversion first). Useful as the design matrix for regression with categorical predictors.

Parameters
groupCategorical labels (N-element vector).
mrMemory resource (nullptr → process default).
Returns
N×K indicator matrix.
See also
anova1

◆ dwtest()

std::tuple< Value, Value > nk::stats::dwtest ( const Value & r,
const Value & X,
std::pmr::memory_resource * mr = nullptr )

Durbin-Watson test for first-order autocorrelation in regression residuals ([p, dw] = dwtest(r, X)).

H0: residuals are uncorrelated (DW = 2). Alternative: positive or negative first-order autocorrelation.

DW = Σ_{i=2..n}(r_i - r_{i-1})² / Σ_{i=1..n} r_i².

p-value uses the beta-approximation (Durbin & Watson 1971): the second-moment matches of DW under H0 are computed from the design matrix X and fit to a Beta(a, b) on [0, 4]. This is MATLAB's 'approximate' method. The exact Pan-1965 algorithm is a v1 KNOWN GAP — method = 'exact' is not supported and throws.

Parameters
rOLS residuals (length n, column).
XDesign matrix (n × k) used to fit the residuals.
mrMemory resource (nullptr → process default).
Returns
(p, dw) — two-sided p-value, DW statistic.

◆ ecdf()

std::tuple< Value, Value > nk::stats::ecdf ( const Value & y,
std::pmr::memory_resource * mr = nullptr )

Empirical cumulative distribution function ([f, x] = ecdf(y)).

Returns column vectors of length K + 1, where K is the number of unique values in y. f starts at 0 and steps up to 1 at x = max(y). Each jump has height count / N. NaN excluded silently.

Parameters
yInput samples.
mrMemory resource (nullptr → process default).
Returns
(f, x) columns describing the step function.
See also
ecdfhist, ksdensity

◆ ecdfhist()

std::tuple< Value, Value > nk::stats::ecdfhist ( const Value & f,
const Value & x,
int m = 10,
std::pmr::memory_resource * mr = nullptr )

Histogram from empirical CDF ([n, c] = ecdfhist(f, x, m)).

Converts the output of ecdf into a probability-density histogram. Each bin spans equal width range/m; last bin includes its right edge.

Parameters
ff column from ecdf.
xx column from ecdf.
mNumber of bins (default 10).
mrMemory resource (nullptr → process default).
Returns
(n, c) — bin heights, bin centres.
See also
ecdf

◆ evcdf()

Value nk::stats::evcdf ( const Value & x,
double mu,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Type-I EV cdf (p = evcdf(x, mu, sigma)).

Closed form: \( F(x) = 1 - e^{-e^{t}},\ t = (x - \mu)/\sigma \).

Parameters
xEvaluation points (any shape).
muLocation parameter.
sigmaScale parameter.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
evpdf, evinv

◆ evfit() [1/2]

Value nk::stats::evfit ( const Value & x,
const Value & censoring,
const Value & freq,
std::pmr::memory_resource * mr = nullptr )

Type-I EV (Gumbel-min) MLE fit with right-censoring and frequency weights ([parmhat, parmci] = evfit(x, alpha, cens, freq)).

Likelihood is the product of f(x_i) over uncensored observations and S(x_i) (survival) over right-censored observations, each raised to the frequency-weight freq_i. When both censoring and freq are empty or trivial, dispatches to the fast closed-form path; otherwise refines via 2-D Newton on (μ, σ) with FD gradient and Hessian and a backtracking line search.

Parameters
xObservations.
censoringLength-n 0/1 indicator (1 = right-censored). Pass Value::Empty to disable.
freqLength-n non-negative frequency weights. Pass Value::Empty to disable (uniform weight).
mrMemory resource.
Returns
[muhat, sigmahat] as a 1 × 2 row.

◆ evfit() [2/2]

Value nk::stats::evfit ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Type-I EV (Gumbel-min) MLE fit ([muhat, sigmahat] = evfit(x)).

Concentrates the location out via μ = σ · log(Σ exp(x_i/σ) / n) and runs Newton iteration on the resulting 1-D equation Σ x_i e^{x_i/σ} / Σ e^{x_i/σ} - mean(x) - σ = 0. Initial guess from the moment relation var(x) = σ² · π²/6.

Numerical stability: exponentials shifted by max(x)/σ (the ratio U/T is invariant under that shift).

Parameters
xObservations.
mrMemory resource.
Returns
[muhat, sigmahat] as a 1 × 2 row.
See also
evpdf, evcdf

◆ evfit_ci()

Value nk::stats::evfit_ci ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

Wald CI for evfit (pci = evfit_ci(x, alpha)).

Returns the 2 × 2 confidence matrix [lo; hi] for [mu, sigma] from the observed Fisher information (central-FD Hessian of NLL). mu uses a linear Wald CI; sigma uses a log-scale CI (MATLAB convention).

◆ evinv()

Value nk::stats::evinv ( const Value & p,
double mu,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Type-I EV inverse cdf (x = evinv(p, mu, sigma)).

Closed form: x = mu + sigma · log(-log(1 - p)).

Parameters
pProbability levels in [0, 1] (any shape).
muLocation parameter.
sigmaScale parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
evcdf

◆ evlike()

double nk::stats::evlike ( double mu,
double sigma,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Type-I EV nLogL (nLogL = evlike(mu, sigma, x)).

Parameters
muLocation parameter.
sigmaScale parameter.
xSample data.
mrMemory resource (nullptr → process default).
Returns
Scalar negative log-likelihood.

◆ evpdf()

Value nk::stats::evpdf ( const Value & x,
double mu,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Type-I EV (Gumbel-for-minima) pdf (y = evpdf(x, mu, sigma)).

\( f(x; \mu, \sigma) = \dfrac{1}{\sigma}\,e^{t}\,e^{-e^{t}}, \ t = (x - \mu)/\sigma \). Gumbel parameterisation for minima, NOT for maxima.

Parameters
xEvaluation points (any shape).
muLocation parameter.
sigmaScale parameter (sigma > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
evcdf, evinv, evrnd, evstat

◆ evrnd()

Value nk::stats::evrnd ( ::nk::ops::RngContext & rng,
double mu,
double sigma,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Type-I EV random samples (r = evrnd(mu, sigma, rows, cols)).

Generated via inverse-CDF sampling.

Parameters
muLocation parameter.
sigmaScale parameter.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of EV samples.
See also
evpdf

◆ evstat()

std::tuple< double, double > nk::stats::evstat ( double mu,
double sigma )

Type-I EV mean and variance ([m, v] = evstat(mu, sigma)).

Closed form: m = mu - sigma · γ_E, v = sigma² · π²/6 (γ_E ≈ 0.57721566490153286 is the Euler-Mascheroni constant).

Parameters
muLocation parameter.
sigmaScale parameter.
Returns
{mean, variance} pair.
See also
evpdf

◆ expcdf()

Value nk::stats::expcdf ( const Value & x,
double mu,
std::pmr::memory_resource * mr = nullptr )

Exponential cdf (F = expcdf(x, mu)).

Closed form: F(x) = 1 - exp(-x/mu) for x >= 0.

Parameters
xEvaluation points (any shape).
muMean of the distribution.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
exppdf, expinv

◆ expfit()

std::tuple< Value, Value > nk::stats::expfit ( const Value & x,
double alpha,
const Value & cens = Value::Empty,
const Value & freq = Value::Empty,
std::pmr::memory_resource * mr = nullptr )

Exponential MLE ([muhat, muci] = expfit(x, alpha, cens, freq)).

mu = Σ(freq·x) / Σ(freq·(1 - cens)). Exact CI via χ²(2D) where D = Σ(freq·(1 - cens)) is the event count.

Parameters
xSample data.
alphaSignificance level.
censRight-censoring mask (Value::Empty → no censoring).
freqPer-sample weights (Value::Empty → ones).
mrMemory resource (nullptr → process default).
Returns
(muhat, muci).
See also
explike

◆ expinv()

Value nk::stats::expinv ( const Value & p,
double mu,
std::pmr::memory_resource * mr = nullptr )

Exponential inverse cdf (x = expinv(p, mu)).

Closed form: x = -mu · log(1 - p).

Parameters
pProbability levels in [0, 1] (any shape).
muMean of the distribution.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
expcdf

◆ explike()

double nk::stats::explike ( double mu,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Exponential nLogL (nLogL = explike(mu, x)).

Parameters
muMean parameter.
xSample data.
mrMemory resource (nullptr → process default).
Returns
Scalar negative log-likelihood.
See also
expfit

◆ exppdf()

Value nk::stats::exppdf ( const Value & x,
double mu,
std::pmr::memory_resource * mr = nullptr )

Exponential pdf (y = exppdf(x, mu)).

\( f(x; \mu) = e^{-x/\mu} / \mu \) for x >= 0, 0 elsewhere. Parameterised by the mean mu, NOT the rate (use lambda = 1/mu).

Parameters
xEvaluation points (any shape).
muMean of the distribution (mu > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
expcdf, expinv, exprnd, expstat

◆ exprnd()

Value nk::stats::exprnd ( ::nk::ops::RngContext & rng,
double mu,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Exponential random samples (r = exprnd(mu, rows, cols)).

Uses std::exponential_distribution with rate 1/mu.

Parameters
muMean of the distribution.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of exponential samples.
See also
exppdf

◆ expstat()

std::tuple< double, double > nk::stats::expstat ( double mu)

Exponential mean and variance ([m, v] = expstat(mu)).

Closed form: m = mu, v = mu².

Parameters
muMean parameter.
Returns
{mean, variance} pair.
See also
exppdf

◆ fcdf()

Value nk::stats::fcdf ( const Value & x,
double v1,
double v2,
std::pmr::memory_resource * mr = nullptr )

F cdf (F = fcdf(x, v1, v2)).

Computed via the regularised incomplete beta: \( F(x) = I_{v_1 x / (v_1 x + v_2)}(v_1/2,\ v_2/2) \).

Parameters
xEvaluation points (any shape).
v1Numerator degrees of freedom (v1 > 0).
v2Denominator degrees of freedom (v2 > 0).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
fpdf, finv

◆ fillmissing_of()

Value nk::stats::fillmissing_of ( const Value & x,
const std::string & method,
double constVal = 0.0,
std::pmr::memory_resource * mr = nullptr )

Fill missing values (y = fillmissing(x, method, constVal)).

Replaces NaN / missing entries using the named method. Supported methods: "constant", "previous", "next", "nearest", "linear", "spline", "pchip", "makima", "movmean", "movmedian".

Parameters
xInput array.
methodFill method name.
constValConstant value for "constant" method (default 0).
mrMemory resource (nullptr → process default).
Returns
Array with missing values filled.
See also
rmmissing_of, standardizeMissing_of

◆ filloutliers()

Value nk::stats::filloutliers ( const Value & A,
const Value & fillMethod,
const std::string & findMethod = "median",
double thresholdFactor = std::numeric_limits< double >::quiet_NaN(),
std::pmr::memory_resource * mr = nullptr )

Replace outliers (B = filloutliers(A, fillMethod, findMethod, tf)).

Detects outliers in A by findMethod and replaces them per fillMethod, returning the filled array. fillMethod is a numeric scalar (constant fill) or a string ("center", "clip", "previous", "next", "nearest", "linear", …, per the underlying engine). This C++ entry covers the "median" (default), "mean", and "quartiles" find-methods; "percentiles" (needs a [lo hi] pair) and the grubbs/gesd/movmedian/movmean methods remain script-only.

Parameters
AInput vector / matrix (column-wise).
fillMethodFill rule (numeric scalar or method string).
findMethod"median" (default), "mean", or "quartiles".
thresholdFactorDetection threshold; NaN (default) → the per-method default (3 for median/mean; the MATLAB 1.5·IQR for quartiles). For quartiles a finite value is the IQR multiplier k.
mrMemory resource (nullptr → process default).
Returns
Array with outliers filled.
Exceptions
Errorif findMethod is unsupported by this C++ entry.
See also
isoutlier

◆ finv()

Value nk::stats::finv ( const Value & p,
double v1,
double v2,
std::pmr::memory_resource * mr = nullptr )

F inverse cdf (x = finv(p, v1, v2)).

Computed via betaincinv.

Parameters
pProbability levels in [0, 1] (any shape).
v1Numerator degrees of freedom.
v2Denominator degrees of freedom.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
fcdf

◆ fishertest()

std::tuple< Value, Value, Value, Value, Value > nk::stats::fishertest ( const Value & T,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

Fisher's exact test for a 2×2 table ([h, p, OR, ci_lo, ci_hi] = fishertest(T, alpha, tail)).

T = [a b; c d]. Returns the odds ratio OR = a·d / (b·c) and a 1 - α Woolf log-OR confidence interval.

Parameters
T2 × 2 contingency table.
alphaSignificance level.
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(h, p, OR, ci_lo, ci_hi).

◆ fnbrk()

Value nk::stats::fnbrk ( const Value & pp,
const std::string & part,
std::pmr::memory_resource * mr = nullptr )

Extract a named field from a pp-form spline (v = fnbrk(pp, part)).

part ∈ {"breaks", "coefs", "pieces"|"l", "order"|"k", "dim", "form"}. Interval-restriction form is not yet supported.

Parameters
pppp-form spline.
partField name.
mrMemory resource (nullptr → process default).
Returns
Requested field as a Value.
Exceptions
ErrorUnknown field name (m:fnbrk:badPart).

◆ fncmb()

Value nk::stats::fncmb ( const Value & pp1,
double c1,
const Value & pp2 = Value::Empty,
double c2 = 0.0,
std::pmr::memory_resource * mr = nullptr )

Combine pp-form splines linearly (pp = fncmb(pp1, c1, pp2, c2)).

  • Two-arg form (pp2.isEmpty()): c1 · pp1 (scalar multiply).
  • Four-arg form: c1 · pp1 + c2 · pp2 — requires pp1 and pp2 to share breaks, order and dim.
Parameters
pp1First pp-form spline.
c1Coefficient on pp1.
pp2Second spline. Pass Value::Empty for the scalar-multiply form.
c2Coefficient on pp2 (ignored when pp2.isEmpty()).
mrMemory resource (nullptr → process default).
Returns
Combined pp-form spline.
Exceptions
ErrorMismatched breaks / order / dim (m:fncmb:incompatible).

◆ fnder()

Value nk::stats::fnder ( const Value & pp,
int order,
std::pmr::memory_resource * mr = nullptr )

Differentiate a pp-form spline (dpp = fnder(pp, order)).

Differentiates the spline order times (default 1). Result has reduced polynomial order K - order.

Parameters
pppp-form spline.
orderDifferentiation order (>= 1, default 1).
mrMemory resource (nullptr → process default).
Returns
Derivative spline (pp form).
See also
fnval, fnint

◆ fnint()

Value nk::stats::fnint ( const Value & pp,
std::pmr::memory_resource * mr = nullptr )

Antiderivative of a pp-form spline (ipp = fnint(pp)).

Integration constant chosen so the integral evaluates to 0 at the first break and is continuous at piece boundaries.

Parameters
pppp-form spline.
mrMemory resource (nullptr → process default).
Returns
Antiderivative spline (pp form).
See also
fnder, fnval

◆ fnval()

Value nk::stats::fnval ( const Value & pp,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Evaluate a pp-form spline (y = fnval(pp, x)).

Horner-form evaluation. Only form == "pp" is supported here; B-spline form is deferred to future work.

Parameters
pppp-form spline produced by ppmak / csapi.
xEvaluation points (any shape).
mrMemory resource (nullptr → process default).
Returns
Spline values, same shape as x.
See also
ppmak, fnder, fnint

◆ fpdf()

Value nk::stats::fpdf ( const Value & x,
double v1,
double v2,
std::pmr::memory_resource * mr = nullptr )

F pdf (y = fpdf(x, v1, v2)).

\( f(x; v_1, v_2) = \dfrac{\Gamma((v_1+v_2)/2)}{\Gamma(v_1/2)\Gamma(v_2/2)} \left(\dfrac{v_1}{v_2}\right)^{v_1/2} x^{v_1/2 - 1}\left(1 + \dfrac{v_1 x}{v_2}\right)^{-(v_1+v_2)/2} \) for x > 0.

Parameters
xEvaluation points (any shape).
v1Numerator degrees of freedom (v1 > 0).
v2Denominator degrees of freedom (v2 > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
fcdf, finv, frnd, fstat

◆ friedman()

std::tuple< Value, Value, Value > nk::stats::friedman ( const Value & x,
int reps = 1,
std::pmr::memory_resource * mr = nullptr )

Friedman non-parametric two-way ANOVA by ranks ([p, Q, df] = friedman(x, reps)).

Ranks the k treatments (columns) within each of the n blocks (rows), then forms the tie-corrected chi-square statistic Q = [12/(n·k·(k+1)) · Σ Rⱼ² − 3·n·(k+1)] / C, C = 1 − Σ(t³−t)/(n·(k³−k)), with p = 1 − chi2cdf(Q, k−1).

NB: like kruskalwallis, this returns the statistic + df rather than MATLAB's display (tbl, stats); the primary p matches MATLAB exactly. Only reps == 1 is supported — reps > 1 (a replicated two-way layout) is rejected at the register, since its ranking does not match MATLAB here yet.

Parameters
xn × k data matrix (blocks × treatments).
repsReplicates per cell (only 1 is currently supported).
mrMemory resource (nullptr → process default).
Returns
(p, Q, df).
See also
kruskalwallis, anova1

◆ frnd()

Value nk::stats::frnd ( ::nk::ops::RngContext & rng,
double v1,
double v2,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

F random samples (r = frnd(v1, v2, rows, cols)).

Sampled as (X1/v1) / (X2/v2) where Xi ~ χ²(vi).

Parameters
v1Numerator degrees of freedom.
v2Denominator degrees of freedom.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of F-samples.
See also
fpdf

◆ fstat()

std::tuple< double, double > nk::stats::fstat ( double v1,
double v2 )

F mean and variance ([m, v] = fstat(v1, v2)).

Closed form: m = v2/(v2 - 2) for v2 > 2; variance well-defined only for v2 > 4 (NaN otherwise).

Parameters
v1Numerator degrees of freedom.
v2Denominator degrees of freedom.
Returns
{mean, variance} pair.
See also
fpdf

◆ gamcdf()

Value nk::stats::gamcdf ( const Value & x,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Gamma cdf (F = gamcdf(x, a, b)).

Computed via the regularised lower-incomplete gamma: \( F(x) = P(a,\ x/b) = \text{gammainc}(x/b,\ a) \).

Parameters
xEvaluation points (any shape).
aShape parameter (a > 0).
bScale parameter (b > 0).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
gampdf, gaminv

◆ gamfit() [1/2]

Value nk::stats::gamfit ( const Value & x,
const Value & censoring,
const Value & freq,
std::pmr::memory_resource * mr = nullptr )

Gamma MLE fit with right-censoring and frequency weights ([parmhat, parmci] = gamfit(x, alpha, cens, freq)).

Likelihood is ∏ f(x_i)^(u_i · f_i) · S(x_i)^(c_i · f_i) where the survival is S(x; a, b) = 1 − gammainc(x/b, a) (upper-tail regularised incomplete gamma). When censoring and freq are both empty/trivial, falls through to the fast Newton path. Otherwise runs 2-D Newton on (a, b) with FD gradient/Hessian on the censored-weighted NLL, with backtracking line search.

◆ gamfit() [2/2]

Value nk::stats::gamfit ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Gamma distribution MLE fit ([ahat, bhat] = gamfit(x)).

Solves the MLE system for Gamma(a, b) on positive data. The shape a is found by Newton iteration on log a - ψ(a) = s where s = log(mean(x)) - mean(log(x)) (Minka 2002 initial guess + digamma/trigamma Newton); the scale b = mean(x) / a.

Returns a 2-element vector [ahat, bhat]. KNOWN GAP: confidence intervals (bci second output) deferred — MATLAB ships them but the v1 nk form is single-output.

Parameters
xPositive sample data (1-D vector or matrix; flattened).
mrMemory resource (nullptr → process default).
Returns
[ahat, bhat] as a 1 × 2 row.

◆ gamfit_ci()

Value nk::stats::gamfit_ci ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

95% Wald CI for gamfit (pci = gamfit_ci(x, alpha)).

Returns the 2 × 2 confidence matrix [lo; hi] for [a, b] from the observed Fisher information at the MLE (central-FD Hessian). Both parameters use a log-scale Wald CI (MATLAB convention).

◆ gaminv()

Value nk::stats::gaminv ( const Value & p,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Gamma inverse cdf (x = gaminv(p, a, b)).

Computed via gammaincinv: x = b · P^{-1}(p; a).

Parameters
pProbability levels in [0, 1] (any shape).
aShape parameter (a > 0).
bScale parameter (b > 0).
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
gamcdf

◆ gamlike()

double nk::stats::gamlike ( double a,
double b,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Gamma nLogL (nLogL = gamlike(a, b, x)).

Parameters
aShape parameter.
bScale parameter.
xSample data.
mrMemory resource (nullptr → process default).
Returns
Scalar negative log-likelihood.

◆ gampdf()

Value nk::stats::gampdf ( const Value & x,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Gamma pdf (y = gampdf(x, a, b)).

\( f(x; a, b) = \dfrac{x^{a-1}\,e^{-x/b}}{b^{a}\,\Gamma(a)} \) for x > 0. Convention: a is the shape, b is the scale (NOT rate).

Parameters
xEvaluation points (any shape).
aShape parameter (a > 0).
bScale parameter (b > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
gamcdf, gaminv, gamrnd, gamstat

◆ gamrnd()

Value nk::stats::gamrnd ( ::nk::ops::RngContext & rng,
double a,
double b,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Gamma random samples (r = gamrnd(a, b, rows, cols)).

Uses std::gamma_distribution with shape a, scale b.

Parameters
aShape parameter (a > 0).
bScale parameter (b > 0).
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of Gamma samples.
See also
gampdf

◆ gamstat()

std::tuple< double, double > nk::stats::gamstat ( double a,
double b )

Gamma mean and variance ([m, v] = gamstat(a, b)).

Closed form: m = a·b, v = a·b².

Parameters
aShape parameter.
bScale parameter.
Returns
{mean, variance} pair.
See also
gampdf

◆ geocdf()

Value nk::stats::geocdf ( const Value & k,
double p,
std::pmr::memory_resource * mr = nullptr )

Geometric cdf (F = geocdf(k, p)).

Closed form: \( F(k) = 1 - (1-p)^{\lfloor k\rfloor + 1} \) for k >= 0.

Parameters
kEvaluation points (any shape).
pSuccess probability per trial.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
geopdf, geoinv

◆ geoinv()

Value nk::stats::geoinv ( const Value & q,
double p,
std::pmr::memory_resource * mr = nullptr )

Geometric inverse cdf (k = geoinv(q, p)).

Smallest non-negative integer k such that geocdf(k, p) >= q.

Parameters
qProbability levels in [0, 1] (any shape).
pSuccess probability per trial.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as q.
See also
geocdf

◆ geomean_of()

Value nk::stats::geomean_of ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Geometric mean (g = geomean(x, dim)).

g = (prod(x))^(1/n) = exp(mean(log(x))). Requires all entries > 0.

Parameters
xInput array (positive values).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Geometric mean reduced along dim.
See also
harmmean_of

◆ geopdf()

Value nk::stats::geopdf ( const Value & k,
double p,
std::pmr::memory_resource * mr = nullptr )

Geometric pmf (y = geopdf(k, p)).

\( f(k; p) = (1-p)^{k}\,p \) for k = 0, 1, 2, …. Convention: k counts failures BEFORE the first success (Pascal's). Returns 0 outside support.

Parameters
kEvaluation points (any shape).
pSuccess probability per trial, 0 < p <= 1.
mrMemory resource (nullptr → process default).
Returns
Array of pmf values, same shape as k.
See also
geocdf, geoinv, geornd, geostat

◆ geornd()

Value nk::stats::geornd ( ::nk::ops::RngContext & rng,
double p,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Geometric random samples (r = geornd(p, rows, cols)).

Parameters
pSuccess probability per trial.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of geometric samples (failure counts).
See also
geopdf

◆ geostat()

std::tuple< double, double > nk::stats::geostat ( double p)

Geometric mean and variance ([m, v] = geostat(p)).

Closed form: m = (1-p)/p, v = (1-p)/p².

Parameters
pSuccess probability per trial.
Returns
{mean, variance} pair.
See also
geopdf

◆ gevcdf()

Value nk::stats::gevcdf ( const Value & x,
double k,
double sigma,
double mu,
std::pmr::memory_resource * mr = nullptr )

GEV cdf (p = gevcdf(x, k, sigma, mu)).

Parameters
xEvaluation points (any shape).
kShape parameter.
sigmaScale parameter.
muLocation parameter.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
gevpdf, gevinv

◆ gevfit()

Value nk::stats::gevfit ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

GEV MLE fit ([parmhat, parmci] = gevfit(x, alpha)).

Maximum likelihood estimation of the 3-parameter GEV (k, σ, μ):

  • Initial guess from probability-weighted moments (Hosking, Wallis & Wood 1985): k_pwm = 7.8590·c + 2.9554·c² where c = 2β_1/(β_2 - β_0) − ln 2 / ln 3, σ_pwm = k·(β_0 − 2β_1) / (Γ(1+k)·(1 − 2^{-k})), μ_pwm = β_0 + σ_pwm·(1 − Γ(1+k))/k.
  • 3-D Newton refinement on (k, σ, μ) with FD gradient/Hessian on the log-likelihood, backtracking line search with support-constraint guard (1 + k(x−μ)/σ > 0 for all x).

At k = 0 the support constraint collapses to the Gumbel-max limit; the iteration handles it by treating |k| < 1e−10 via the small-k Taylor expansion of log(1+kz)/k ≈ z − k z²/2.

Parameters
xObservations.
mrMemory resource.
Returns
[khat, sigmahat, muhat] as a 1 × 3 row.
See also
gevpdf, gevlike

◆ gevfit_ci()

Value nk::stats::gevfit_ci ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

95% Wald CI for gevfit (pci = gevfit_ci(x, alpha)).

Returns the 2 × 3 confidence matrix [lo; hi] for [k, σ, μ] from the observed Fisher information (central-FD Hessian of NLL). k and μ use linear Wald CI; σ uses log-scale (MATLAB convention).

◆ gevinv()

Value nk::stats::gevinv ( const Value & p,
double k,
double sigma,
double mu,
std::pmr::memory_resource * mr = nullptr )

GEV inverse cdf (x = gevinv(p, k, sigma, mu)).

Parameters
pProbability levels in [0, 1] (any shape).
kShape parameter.
sigmaScale parameter.
muLocation parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
gevcdf

◆ gevlike()

double nk::stats::gevlike ( double k,
double sigma,
double mu,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Generalised Extreme Value nLogL (nLogL = gevlike(k, sigma, mu, x)).

Parameters
kShape parameter.
sigmaScale parameter.
muLocation parameter.
xSample data.
mrMemory resource (nullptr → process default).
Returns
Scalar negative log-likelihood.

◆ gevpdf()

Value nk::stats::gevpdf ( const Value & x,
double k,
double sigma,
double mu,
std::pmr::memory_resource * mr = nullptr )

GEV pdf (y = gevpdf(x, k, sigma, mu)).

Three sub-families depending on the shape k:

  • k > 0 → Fréchet (heavy-tailed, lower bound mu - sigma/k)
  • k = 0 → Gumbel-for-maxima limit: f = (1/σ) e^{-z} e^{-e^{-z}}, z = (x-mu)/sigma
  • k < 0 → Reverse Weibull (bounded above at mu - sigma/k)

For k ≠ 0, the standardised t = 1 + k·(x-mu)/sigma must be > 0.

Parameters
xEvaluation points (any shape).
kShape parameter (any real).
sigmaScale parameter (sigma > 0).
muLocation parameter.
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
gevcdf, gevinv, gevrnd, gevstat

◆ gevrnd()

Value nk::stats::gevrnd ( ::nk::ops::RngContext & rng,
double k,
double sigma,
double mu,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

GEV random samples (r = gevrnd(k, sigma, mu, rows, cols)).

Parameters
kShape parameter.
sigmaScale parameter.
muLocation parameter.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of GEV samples.
See also
gevpdf

◆ gevstat()

std::tuple< double, double > nk::stats::gevstat ( double k,
double sigma,
double mu )

GEV mean and variance ([m, v] = gevstat(k, sigma, mu)).

Mean is defined only for k < 1; variance only for k < 1/2. Returns NaN outside those ranges.

Parameters
kShape parameter.
sigmaScale parameter.
muLocation parameter.
Returns
{mean, variance} pair.
See also
gevpdf

◆ glmfit()

GlmfitResult nk::stats::glmfit ( const Value & X,
const Value & y,
GlmDistribution distr,
GlmLink link = GlmLink::Identity,
std::pmr::memory_resource * mr = nullptr )

Fit a generalised linear model ([b, dev] = glmfit(X, y, distr [, link])).

Solves μ = g^{-1}(X · β) via iteratively-reweighted least squares (IRLS) with the natural / canonical link by default.

Supported distributions and canonical links:

  • 'normal' → identity
  • 'binomial' → logit
  • 'poisson' → log
  • 'gamma' → reciprocal

A column of ones is prepended automatically to X for the intercept term (MATLAB convention). Pass [] for link to use the canonical link.

KNOWN GAPs (v1):

  • y for 'binomial' must be a proportion (y ∈ [0, 1]); the [successes, trials] two-column form is not yet supported.
  • Returned stats reduced to dev (deviance) only — no standard errors, t-statistics, p-values, residuals struct.
  • 'constant' name-value pair (off/on) not supported — intercept is always added.
Parameters
XDesign matrix (n × p, no intercept column).
yResponse (n × 1).
distrDistribution family.
linkLink function (default = canonical for distr).
mrMemory resource (nullptr → process default).
Returns
{b, dev} — coefficients with intercept first, and total deviance.

◆ glmval()

Value nk::stats::glmval ( const Value & b,
const Value & X,
GlmLink link,
std::pmr::memory_resource * mr = nullptr )

Evaluate a fitted GLM (yhat = glmval(b, X, link)).

Computes yhat = g^{-1}([1, X] · b) where g^{-1} is the inverse of the link used in the fit. b is (p + 1) × 1 (intercept first, as returned by glmfit).

Parameters
bCoefficient vector from glmfit.
XQuery points (m × p, no intercept column).
linkLink function used in the fit.
mrMemory resource.
Returns
m × 1 vector of predicted means.

◆ gpcdf()

Value nk::stats::gpcdf ( const Value & x,
double k,
double sigma,
double theta,
std::pmr::memory_resource * mr = nullptr )

Generalised Pareto cdf (p = gpcdf(x, k, sigma, theta)).

Parameters
xEvaluation points (any shape).
kShape parameter.
sigmaScale parameter.
thetaThreshold parameter.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
gppdf, gpinv

◆ gpfit()

Value nk::stats::gpfit ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Generalised Pareto MLE fit ([khat, sigmahat] = gpfit(x)).

Maximum likelihood estimation in two stages:

  1. Initial guess via the probability-weighted-moments estimator (Hosking & Wallis 1987, α-form): α_0 = mean(x), α_1 = mean((1 − F̂_i) · x_(i)), F̂_i = (i − 0.35)/n, k̂_0 = 2 − α_0/(α_0 − 2α_1), σ̂_0 = 2·α_0·α_1/(α_0 − 2α_1).
  2. Newton-Raphson refinement on the 2-D log-likelihood with analytical gradient and central-FD Hessian on the gradient. Backtracking line search rejects infeasible (support-violating or NLL-worsening) steps. Converges to MATLAB's Grimshaw MLE (1993) to ~1e-9 in typical samples.

Threshold θ is assumed 0 (MATLAB convention for gpfit).

Parameters
xObservations (must be ≥ 0; threshold θ = 0).
mrMemory resource.
Returns
[khat, sigmahat] as a 1 × 2 row.
See also
gppdf, gplike

◆ gpfit_ci()

Value nk::stats::gpfit_ci ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

95% Wald CI for gpfit (pci = gpfit_ci(x, alpha)).

Returns the 2 × 2 confidence matrix [lo; hi] for [k, sigma] from the observed Fisher information (central-FD Hessian of NLL). k uses a linear Wald CI; sigma uses a log-scale CI (MATLAB convention).

◆ gpinv()

Value nk::stats::gpinv ( const Value & p,
double k,
double sigma,
double theta,
std::pmr::memory_resource * mr = nullptr )

Generalised Pareto inverse cdf (x = gpinv(p, k, sigma, theta)).

Parameters
pProbability levels in [0, 1] (any shape).
kShape parameter.
sigmaScale parameter.
thetaThreshold parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
gpcdf

◆ gplike()

double nk::stats::gplike ( double k,
double sigma,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Generalised Pareto nLogL (nLogL = gplike(k, sigma, x), theta = 0).

Parameters
kShape parameter.
sigmaScale parameter.
xSample data.
mrMemory resource (nullptr → process default).
Returns
Scalar negative log-likelihood.

◆ gppdf()

Value nk::stats::gppdf ( const Value & x,
double k,
double sigma,
double theta,
std::pmr::memory_resource * mr = nullptr )

Generalised Pareto pdf (y = gppdf(x, k, sigma, theta)).

Three sub-families depending on the shape k:

  • k = 0 → exponential with mean sigma, threshold theta
  • k > 0 → heavy-tailed, support x >= theta
  • k < 0 → bounded support x ∈ [theta, theta - sigma/k]
Parameters
xEvaluation points (any shape).
kShape parameter (any real).
sigmaScale parameter (sigma > 0).
thetaThreshold / location parameter.
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
gpcdf, gpinv, gprnd, gpstat

◆ gprnd()

Value nk::stats::gprnd ( ::nk::ops::RngContext & rng,
double k,
double sigma,
double theta,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Generalised Pareto random samples (r = gprnd(k, sigma, theta, rows, cols)).

Parameters
kShape parameter.
sigmaScale parameter.
thetaThreshold parameter.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of GP samples.
See also
gppdf

◆ gpstat()

std::tuple< double, double > nk::stats::gpstat ( double k,
double sigma,
double theta )

Generalised Pareto mean and variance ([m, v] = gpstat(k, sigma, theta)).

Mean defined only for k < 1; variance defined only for k < 1/2. Returns NaN outside those ranges.

Parameters
kShape parameter.
sigmaScale parameter.
thetaThreshold parameter.
Returns
{mean, variance} pair.
See also
gppdf

◆ grp2idx()

Grp2idxResult nk::stats::grp2idx ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Grouping variable → index vector ([G, GN, GL] = grp2idx(s)).

Converts a grouping variable s into a 1-based group-index column plus the group names. Ordering rules (MATLAB R2025b):

  • Numeric/logical s: groups are the sorted-ascending unique values; each name is the value formatted like MATLAB (num2str-ish). NaN maps to a NaN index and is excluded from the group set.
  • cellstr / multi-element string s: unique strings in first-appearance order; the name is the string itself.
  • A single char row / string scalar is one group label. (Categorical input and column-aligned char matrices are not yet handled.)
Parameters
sGrouping variable (numeric, logical, char, string, or cellstr).
mrMemory resource (nullptr → process default).
Returns
Grp2idxResult { G, GN, GL } (GL == GN here).
Exceptions
Errorif s is empty (no argument).

◆ grpstats()

std::vector< Value > nk::stats::grpstats ( const Value & X,
const Value & group,
const std::vector< std::string > & fn_names,
std::pmr::memory_resource * mr = nullptr )

Per-group statistics (grpstats(X, group, fn_names)).

Returns one Value per requested aggregator. Default (fn_names empty) is { "mean" }. Supported: mean, std, sum, numel, min, max, var, sem. Each output is Ng × C where Ng is the number of unique non-NaN groups and C = size(X, 2).

Parameters
XN × C data matrix.
groupN × 1 group labels.
fn_namesAggregator names; empty → defaults to { "mean" }.
mrMemory resource (nullptr → process default).
Returns
Vector of result Values, one per aggregator.

◆ haltonset()

Value nk::stats::haltonset ( int d,
long long skip,
long long leap,
std::pmr::memory_resource * mr = nullptr )

Build a Halton stream descriptor (p = haltonset(d, 'Skip', s, 'Leap', l)).

Returns an opaque stream value (struct {kind='halton', dim, skip, leap}) suitable for use with net. Halton uses prime-base radical-inverse per dimension.

Parameters
dDimensionality (d >= 1; primes 2, 3, 5, … used in order).
skipNumber of initial points to discard.
leapStride between successive points (0 → no leap).
mrMemory resource (nullptr → process default).
Returns
Stream descriptor.
See also
net

◆ hampel()

Value nk::stats::hampel ( const Value & x,
int k = 3,
double nsigmas = 3.0,
std::pmr::memory_resource * mr = nullptr )

Hampel outlier-resilient median filter (y = hampel(x, k, nsigmas)).

Replaces each sample that deviates by more than nsigmas · MAD from the local median (window of 2k+1 samples) with the local median itself. The MAD→std conversion uses the standard 1.4826 constant.

Parameters
x1-D real input signal (vectors only; matrix form deferred).
kHalf-window length (full window is 2k+1). Default 3.
nsigmasOutlier threshold in robust-σ units. Default 3.0.
mrMemory resource (nullptr → process default).
Returns
Cleaned signal of the same length as x.
Exceptions
Errork < 0 (m:hampel:badK), nsigmas <= 0 (m:hampel:badSigmas), or non-vector input (m:hampel:notVector).

◆ harmmean_of()

Value nk::stats::harmmean_of ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Harmonic mean (h = harmmean(x, dim)).

h = n / sum(1/x). Requires all entries > 0.

Parameters
xInput array (positive values).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Harmonic mean reduced along dim.
See also
geomean_of

◆ hygecdf()

Value nk::stats::hygecdf ( const Value & k,
double M,
double K,
double N,
std::pmr::memory_resource * mr = nullptr )

Hypergeometric cdf (F = hygecdf(k, M, K, N)).

Parameters
kEvaluation points (any shape).
MPopulation size.
KNumber of successes in population.
NSample size.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
hygepdf, hygeinv

◆ hygeinv()

Value nk::stats::hygeinv ( const Value & q,
double M,
double K,
double N,
std::pmr::memory_resource * mr = nullptr )

Hypergeometric inverse cdf (k = hygeinv(q, M, K, N)).

Parameters
qProbability levels in [0, 1] (any shape).
MPopulation size.
KNumber of successes in population.
NSample size.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as q.
See also
hygecdf

◆ hygepdf()

Value nk::stats::hygepdf ( const Value & k,
double M,
double K,
double N,
std::pmr::memory_resource * mr = nullptr )

Hypergeometric pmf (y = hygepdf(k, M, K, N)).

\( f(k; M, K, N) = \binom{K}{k}\,\binom{M-K}{N-k} \big/ \binom{M}{N} \).

Parameters
kEvaluation points (any shape).
MPopulation size.
KNumber of successes in population.
NSample size.
mrMemory resource (nullptr → process default).
Returns
Array of pmf values, same shape as k.
See also
hygecdf, hygeinv, hygernd, hygestat

◆ hygernd()

Value nk::stats::hygernd ( ::nk::ops::RngContext & rng,
double M,
double K,
double N,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Hypergeometric random samples (r = hygernd(M, K, N, rows, cols)).

Parameters
MPopulation size.
KNumber of successes in population.
NSample size.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of hypergeometric samples.
See also
hygepdf

◆ hygestat()

std::tuple< double, double > nk::stats::hygestat ( double M,
double K,
double N )

Hypergeometric mean and variance ([m, v] = hygestat(M, K, N)).

Closed form: m = N·K/M, v = N·K·(M-K)·(M-N) / (M² · (M-1)).

Parameters
MPopulation size.
KNumber of successes in population.
NSample size.
Returns
{mean, variance} pair.
See also
hygepdf

◆ inconsistent()

Value nk::stats::inconsistent ( const Value & Z,
int depth,
std::pmr::memory_resource * mr = nullptr )

Inconsistency coefficient table (R = inconsistent(Z, depth)).

Returns an (N−1)×4 array [mean, std, count, inconsistency]. Use with cluster_from_linkage and criterion = "inconsistent".

Parameters
ZLinkage table from linkage.
depthNumber of levels below each link to include (≥ 1, default 2).
mrMemory resource (nullptr → process default).
Returns
(N−1)×4 inconsistency table.
See also
cluster_from_linkage

◆ iqr()

Value nk::stats::iqr ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Interquartile range (r = iqr(X, dim)).

Computed as quantile(X, 0.75) - quantile(X, 0.25) along dim.

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
IQR reduced along dim.
See also
quantile

◆ isoutlier_of()

Value nk::stats::isoutlier_of ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Outlier mask (tf = isoutlier(x)).

Default method: median + 3·MAD test per dimension.

Parameters
xInput array.
mrMemory resource (nullptr → process default).
Returns
LOGICAL mask, same shape as x.
See also
rmoutliers

◆ iwishrnd()

Value nk::stats::iwishrnd ( ::nk::ops::RngContext & rng,
const Value & Tau,
double df,
std::pmr::memory_resource * mr = nullptr )

Inverse-Wishart random matrix (W = iwishrnd(Tau, df)).

Draws one p × p positive-definite matrix from the inverse Wishart W ~ IW_p(Tau, df). Implementation: sample Y ~ W_p(inv(Tau), df) via Bartlett, then return inv(Y).

df must satisfy df > p - 1.

KNOWN GAPs: third-argument DI (pre-computed Cholesky of inv(Tau)) and the two-output [W, DI] = iwishrnd(...) form are deferred.

Parameters
Taup × p symmetric positive-definite scale matrix.
dfDegrees of freedom (> p - 1).
mrMemory resource (nullptr → process default).
Returns
Single p × p inverse Wishart draw.
See also
wishrnd

◆ iwishrnd_factor()

std::tuple< Value, Value > nk::stats::iwishrnd_factor ( ::nk::ops::RngContext & rng,
const Value & Tau,
double df,
const Value & DI,
std::pmr::memory_resource * mr = nullptr )

Inverse-Wishart sample with pre-computed Cholesky factor (W = iwishrnd(Tau, df, DI)).

DI = chol(inv(Tau), 'lower'): a lower-triangular factor with DI · DI' = inv(Tau). When provided, skips the inverse-Cholesky computation. (Note: MATLAB's iwishrnd returns a different but numerically equivalent factor inv(chol(Tau, 'upper'))', which satisfies DI' · DI = inv(Tau) instead. Both produce statistically identical Inv-Wishart draws; the numerical orientation differs.)

Returns
{W, DI} — Inv-Wishart draw and the lower-Cholesky of inv(Tau).

◆ jbtest() [1/2]

std::tuple< Value, Value, Value, Value > nk::stats::jbtest ( const Value & x,
double alpha,
double mctol,
std::pmr::memory_resource * mr = nullptr )

Jarque-Bera with explicit Monte-Carlo tolerance ([h, p, jbstat, cv] = jbtest(x, alpha, mctol)).

Parameters
xSample data.
alphaSignificance level.
mctolTarget MC standard-error tolerance (default 1e-3 in the other overload). Pass NaN to force the asymptotic path even for small n.
mrMemory resource (nullptr → process default).
Returns
(h, p, jbstat, cv).

◆ jbtest() [2/2]

std::tuple< Value, Value, Value, Value > nk::stats::jbtest ( const Value & x,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Jarque-Bera normality test ([h, p, jbstat, cv] = jbtest(x, alpha)).

Small samples (n < 2000) use Monte-Carlo simulation under H0 for the p-value; large n uses the asymptotic χ²(2). The p-value is capped at 0.5.

Parameters
xSample data.
alphaSignificance level.
mrMemory resource (nullptr → process default).
Returns
(h, p, jbstat, cv).
See also
jbtest(x, alpha, mctol, mr)

◆ kmeans()

std::tuple< Value, Value, Value > nk::stats::kmeans ( ::nk::ops::RngContext & rng,
const Value & X,
int K,
int max_iter,
int replicates,
std::pmr::memory_resource * mr = nullptr )

Lloyd's k-means clustering ([idx, C, sumd] = kmeans(X, K, …)).

Standard Euclidean k-means with random initial seeding. Multiple restarts are run and the lowest-distortion solution is returned.

Parameters
XN×D data matrix (one observation per row).
KNumber of clusters (≥ 1).
max_iterMaximum Lloyd iterations (default 100).
replicatesNumber of random restarts; the best (lowest sum of squared distances) is returned (default 1).
mrMemory resource (nullptr → process default).
Returns
(idx, C, sumd):
  • idx : N×1 cluster assignments in {1, …, K}.
  • C : K×D cluster centroids.
  • sumd : K×1 within-cluster sum of squared distances.
See also
kmedoids, linkage

◆ kmedoids()

std::tuple< Value, Value, Value > nk::stats::kmedoids ( ::nk::ops::RngContext & rng,
const Value & X,
int K,
int max_iter,
int replicates,
const std::string & metric,
std::pmr::memory_resource * mr = nullptr )

PAM-style k-medoids clustering ([idx, medoids, sumd] = kmedoids(...)).

Like kmeans but cluster centres are required to be data points (medoids), so the algorithm works with any distance metric (metric argument follows pdist).

Parameters
XN×D data matrix.
KNumber of clusters.
max_iterMaximum PAM iterations.
replicatesRandom restarts; best (lowest total distance) wins.
metricDistance metric (see pdist).
mrMemory resource (nullptr → process default).
Returns
(idx, medoids, sumd) — analogous to kmeans.
See also
kmeans, dbscan

◆ knnsearch()

std::tuple< Value, Value > nk::stats::knnsearch ( const Value & X,
const Value & Y,
int K = 1,
const std::string & metric = "euclidean",
double p = 2.0,
std::pmr::memory_resource * mr = nullptr )

k-nearest-neighbour search ([Idx, D] = knnsearch(X, Y, K, metric, p)).

For each row of Y find the K nearest rows of X under the given metric. Brute-force scan (no kd-tree). Ties are broken by ascending row index.

Parameters
XReference points (M_X × D).
YQuery points (M_Y × D).
KNeighbour count (≥ 1; default 1).
metricpdist metric (default "euclidean").
pMinkowski exponent (default 2).
mrMemory resource (nullptr → process default).
Returns
(Idx, D):
  • Idx : M_Y × K row indices into X (1-based).
  • D : M_Y × K matching distances.
See also
rangesearch, pdist

◆ knt2brk()

std::tuple< Value, Value > nk::stats::knt2brk ( const Value & knots,
std::pmr::memory_resource * mr = nullptr )

Decompose knot vector ([breaks, mults] = knt2brk(knots)).

Extracts distinct values and their multiplicities, preserving order (input must be non-decreasing).

Parameters
knotsNon-decreasing knot vector.
mrMemory resource (nullptr → process default).
Returns
(breaks, mults) pair.
See also
brk2knt

◆ kruskalwallis()

std::tuple< Value, Value, Value, Value > nk::stats::kruskalwallis ( const Value & y,
const Value & group,
std::pmr::memory_resource * mr = nullptr )

Kruskal–Wallis non-parametric one-way ANOVA ([p, H, df, ssRanks] = kruskalwallis(y, group)).

Tie-corrected H statistic. Use as the non-parametric alternative to anova1 when normality is suspect.

Parameters
yResponse vector.
groupGrouping labels.
mrMemory resource (nullptr → process default).
Returns
(p, H, df, ssRanks).
See also
anova1

◆ ksdensity()

std::tuple< Value, Value, Value > nk::stats::ksdensity ( const Value & x,
const Value & pts,
double bw_user,
std::pmr::memory_resource * mr = nullptr )

Kernel density estimate ([f, xi, bw] = ksdensity(x, pts, bw_user)).

Gaussian kernel; auto bandwidth via Silverman's rule when bw_user <= 0. Empty pts requests the default 100-point grid centred on the data range.

Parameters
xInput samples.
ptsEvaluation grid (column vector) or Value::Empty for auto.
bw_userUser-specified bandwidth (≤ 0 → Silverman's rule).
mrMemory resource (nullptr → process default).
Returns
(f, xi, bw) — densities, grid, chosen bandwidth.
See also
ecdf

◆ kstest()

std::tuple< Value, Value, Value, Value > nk::stats::kstest ( const Value & x,
const Value & cdf,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

One-sample Kolmogorov-Smirnov test ([h, p, ksstat, cv] = kstest(x, cdf, alpha, tail)).

H0: x is drawn from the reference CDF.

Parameters
xSample data.
cdfReference CDF as a 2-column [x_grid, F_grid] matrix. Empty → standard normal N(0, 1).
alphaSignificance level.
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(h, p, ksstat, cv) — h, p-value, KS statistic, critical value.
See also
kstest2

◆ kstest2()

std::tuple< Value, Value, Value, Value > nk::stats::kstest2 ( const Value & x,
const Value & y,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

Two-sample Kolmogorov-Smirnov test ([h, p, ksstat, cv] = kstest2(x, y, alpha, tail)).

H0: x and y come from the same continuous distribution.

Parameters
xFirst sample.
ySecond sample.
alphaSignificance level.
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(h, p, ksstat, cv).
See also
kstest

◆ kurtosis()

Value nk::stats::kurtosis ( const Value & x,
int normFlag = 1,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Sample kurtosis along dim (y = kurtosis(X, normFlag, dim)).

Non-excess kurtosis (= 3 for a standard normal).

  • normFlag = 1 (default): uncorrected y = m4 / m2^2
  • normFlag = 0: bias-corrected y = ((n-1)/((n-2)(n-3))) · ((n+1)·g2 - 3·(n-1)) + 3 where g2 = m4/m2^2. Requires n >= 4.
Parameters
xInput array.
normFlagBias correction switch (0 or 1).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Kurtosis reduced along dim.
See also
skewness

◆ lasso()

LassoResult nk::stats::lasso ( const Value & X,
const Value & y,
const Value & lambdas,
double alpha = 1.0,
std::pmr::memory_resource * mr = nullptr )

LASSO / elastic-net linear regression ([B, FitInfo] = lasso(X, y, lambdas, alpha)).

Solves min_β,β0 (1/2n) · ||y - β0 - X·β||²

  • λ · [ α · ||β||₁ + (1 - α)/2 · ||β||₂² ] via cyclic coordinate descent with soft-thresholding. The predictors are standardised internally; coefficients are returned in the original units. The intercept β0 is the response mean minus the standardised-coefficient projection (auto-fit, MATLAB convention).

lambdas must be a vector of λ values (each ≥ 0). For an auto λ-path use linspace(0, lambda_max(X, y), 100) at the call site.

alpha ∈ [0, 1] mixes L1 (α = 1, pure lasso, default) and L2 (α = 0, ridge) penalties.

KNOWN GAPs (v1): no auto λ-path, no cross-validation, no 'CV'/'NumLambda'/'LambdaRatio' name-value pairs, no observation weights. Intercept is always included.

Parameters
XDesign matrix (n × p).
yResponse (n × 1).
lambdasLength-nLambda vector of regularisation values.
alphaElastic-net mixing parameter.
mrMemory resource (nullptr → process default).
Returns
{B, Intercept, Lambda}.

◆ lassoglm()

LassoResult nk::stats::lassoglm ( const Value & X,
const Value & y,
GlmDistribution distr,
const Value & lambdas,
double alpha = 1.0,
std::pmr::memory_resource * mr = nullptr )

Lasso-regularised GLM ([B, FitInfo] = lassoglm(X, y, distr, lambdas, alpha)).

L1-regularised GLM via the IRLS+coord-descent inner loop: at each IRLS step, solve a weighted lasso on the current working response.

Supports the same distributions as glmfit. v1 KNOWN GAPs: same as lasso (no auto λ-path, no CV), plus lassoglm reduces the inner IRLS to at most 25 iterations to keep the joint optimisation tractable.

Parameters
XDesign matrix (n × p).
yResponse (n × 1).
distrError family.
lambdasnLambda λ values.
alphaElastic-net mixing parameter.
mrMemory resource.
Returns
{B, Intercept, Lambda} (same layout as lasso).

◆ lhsdesign()

Value nk::stats::lhsdesign ( ::nk::ops::RngContext & rng,
std::size_t n,
std::size_t p,
bool smooth,
LhsCriterion criterion,
std::size_t iterations,
std::pmr::memory_resource * mr = nullptr )

Latin Hypercube design (X = lhsdesign(n, p[, options])).

Generates an n × p matrix where each column is a Latin hypercube sample: the unit interval (0, 1) is partitioned into n equal bins and exactly one sample lands in each bin.

With smooth = true (default) the value within each bin is (π[i] − U)/n with U ~ Uniform(0, 1); with smooth = false midpoints (π[i] − 0.5)/n are used.

criterion controls optimization over iterations trials:

  • None – single random design (fastest).
  • Maximin – pick the trial maximising min pairwise Euclidean distance between rows (DEFAULT, matches MATLAB).
  • Correlation – pick the trial minimising max absolute off-diagonal Pearson correlation between columns.

Uses the shared MT19937 stream — rng(seed) makes designs reproducible. iterations default is 5 (MATLAB convention).

Parameters
nNumber of samples (rows).
pNumber of variables (columns).
smoothtrue for (π[i] - U)/n, false for midpoints.
criterionOptimization objective (see enum).
iterationsMaximum trials for the criterion search (≥ 1).
mrMemory resource (nullptr → process default).
Returns
n × p design matrix with entries in (0, 1).
See also
lhsnorm

◆ lhsnorm()

Value nk::stats::lhsnorm ( ::nk::ops::RngContext & rng,
const Value & mu,
const Value & Sigma,
std::size_t n,
std::pmr::memory_resource * mr = nullptr )

Latin Hypercube sample mapped to a Gaussian (Y = lhsnorm(mu, Sigma, n)).

Apply norminv to a lhsdesign(n, length(mu)) uniform design, then transform via the Cholesky factor of Sigma: Y = Z · chol(Sigma) + mu, where Z is the matrix of standard normal LHS draws.

mu must be a length-d row or column vector; Sigma must be d × d symmetric positive-definite.

Parameters
muLength-d mean vector.
Sigmad × d covariance matrix.
nNumber of samples.
mrMemory resource (nullptr → process default).
Returns
n × d matrix of Gaussian-mapped LHS samples.
See also
lhsdesign, mvnrnd

◆ lillietest()

std::tuple< Value, Value, Value, Value > nk::stats::lillietest ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

Lilliefors normality test ([h, p, kstat, critval] = lillietest(x, alpha)).

Tests the composite hypothesis that x comes from a normal distribution with unknown mean and variance. Computes the Kolmogorov-Smirnov statistic against the fitted normal, applies the Stephens (1974) modified statistic D* = D·(sqrt(n) - 0.01 + 0.85/sqrt(n)), and reads p / the critical value from the Lilliefors table (interpolated; p clamped to [1e-10, 0.5]).

Parameters
xSample (numel >= 4).
alphaSignificance level in (0, 1) (default 0.05).
mrMemory resource (nullptr → process default).
Returns
(h, p, kstat, critval) — reject flag, approximate p-value, KS statistic D, and critical D at alpha.
Exceptions
Errorif numel(x) < 4, alpha is not in (0, 1), or the sample has zero variance.

◆ linkage() [1/2]

Value nk::stats::linkage ( const Value & Y,
const std::string & method,
const std::string & metric,
double p,
std::pmr::memory_resource * mr = nullptr )

4-arg overload: when Y is a raw N×D data matrix, computes pdist(Y, metric, p) internally before linkage.

Parameters
YRaw N×D data matrix.
methodLinkage rule.
metricDistance metric for the internal pdist.
pMetric parameter (e.g. Minkowski exponent).
mrMemory resource (nullptr → process default).
Returns
(N−1)×3 linkage table.
See also
linkage

◆ linkage() [2/2]

Value nk::stats::linkage ( const Value & Y,
const std::string & method,
std::pmr::memory_resource * mr = nullptr )

Agglomerative hierarchical clustering tree (Z = linkage(Y, method)).

Builds an N−1 × 3 linkage table from a pdist row Y. Row i is [a, b, d]: ids a, b of the two clusters merged at step i, and the distance d at the merge. Cluster ids: 1..N for original points, N+1, N+2, … for new clusters formed by each merge.

Supported method: "single" (default), "complete", "average", "weighted", "centroid", "median", "ward".

Parameters
Ypdist-row vector (1 × N(N-1)/2).
methodLinkage rule (see list above).
mrMemory resource (nullptr → process default).
Returns
(N−1)×3 linkage table.
See also
cluster_from_linkage, cophenet, inconsistent

◆ logncdf()

Value nk::stats::logncdf ( const Value & x,
double mu,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Lognormal cdf (p = logncdf(x, mu, sigma)).

Closed form: F(x) = Φ((log(x) - mu) / sigma) for x > 0.

Parameters
xEvaluation points (any shape).
muMean of the underlying normal.
sigmaStandard deviation of the underlying normal.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
lognpdf, logninv

◆ lognfit() [1/2]

std::tuple< Value, Value > nk::stats::lognfit ( const Value & x,
double alpha,
const Value & cens,
const Value & freq,
std::pmr::memory_resource * mr = nullptr )

Lognormal MLE with censoring and frequencies.

Closed-form weighted moments when freq is supplied without censoring; EM-iterated MLE on log(x) with numeric Hessian for CIs when right-censored.

Parameters
xSample data.
alphaSignificance level.
censRight-censoring mask (Value::Empty → no censoring).
freqPer-sample weights (Value::Empty → ones).
mrMemory resource (nullptr → process default).
Returns
(parm, pci).
See also
lognfit(x, alpha, mr)

◆ lognfit() [2/2]

std::tuple< Value, Value > nk::stats::lognfit ( const Value & x,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Lognormal MLE without censoring ([parm, pci] = lognfit(x, alpha)).

MLE of mu, sigma on log(x). parm is a 1 × 2 row; pci is 2 × 2 (col 1 = mu CI, col 2 = sigma CI; row 1 = lower, row 2 = upper).

Parameters
xSample data (positive).
alphaSignificance level.
mrMemory resource (nullptr → process default).
Returns
(parm, pci).
See also
lognlike

◆ logninv()

Value nk::stats::logninv ( const Value & p,
double mu,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Lognormal inverse cdf (x = logninv(p, mu, sigma)).

Closed form: x = exp(mu + sigma · Φ^{-1}(p)).

Parameters
pProbability levels in [0, 1] (any shape).
muMean of the underlying normal.
sigmaStandard deviation of the underlying normal.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
logncdf

◆ lognlike()

double nk::stats::lognlike ( double mu,
double sigma,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Lognormal nLogL (nLogL = lognlike(mu, sigma, x)).

Parameters
muMean of log(x).
sigmaStd of log(x).
xSample data (positive).
mrMemory resource (nullptr → process default).
Returns
Scalar negative log-likelihood.
See also
lognfit

◆ lognpdf()

Value nk::stats::lognpdf ( const Value & x,
double mu,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Lognormal pdf (y = lognpdf(x, mu, sigma)).

\( f(x; \mu, \sigma) = \dfrac{1}{x\,\sigma\sqrt{2\pi}}\, e^{-(\ln x - \mu)^2 / (2\sigma^2)} \) for x > 0. Convention: mu / sigma describe the underlying normal distribution log(X) ~ N(mu, sigma²), NOT the mean/std of X itself.

Parameters
xEvaluation points (any shape).
muMean of the underlying normal.
sigmaStandard deviation of the underlying normal (sigma > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
logncdf, logninv, lognrnd, lognstat

◆ lognrnd()

Value nk::stats::lognrnd ( ::nk::ops::RngContext & rng,
double mu,
double sigma,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Lognormal random samples (r = lognrnd(mu, sigma, rows, cols)).

Sampled as exp(mu + sigma · randn()).

Parameters
muMean of the underlying normal.
sigmaStandard deviation of the underlying normal.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of lognormal samples.
See also
lognpdf

◆ lognstat()

std::tuple< double, double > nk::stats::lognstat ( double mu,
double sigma )

Lognormal mean and variance ([m, v] = lognstat(mu, sigma)).

Closed form: m = exp(mu + sigma²/2), v = exp(2·mu + sigma²) · (exp(sigma²) - 1).

Parameters
muMean of the underlying normal.
sigmaStandard deviation of the underlying normal.
Returns
{mean, variance} pair (of the lognormal RV X, not the log).
See also
lognpdf

◆ lscov()

std::tuple< Value, Value, Value, Value > nk::stats::lscov ( const Value & A,
const Value & b,
const Value & w,
std::pmr::memory_resource * mr = nullptr )

Weighted least squares ([x, stdx, mse, S] = lscov(A, b, w)).

Solves min Σ w_i · (A_i · x - b_i)².

Parameters
ADesign matrix.
bResponse vector.
wOptional length-N vector of positive row weights (pass empty Value for uniform weights, i.e. plain OLS). Full N × N covariance form V is not yet supported.
mrMemory resource (nullptr → process default).
Returns
Tuple (x, stdx, mse, S):
  • x : coefficient estimates
  • stdx : standard errors of x
  • mse : mean squared error
  • S : coefficient covariance matrix.
See also
regress

◆ mad_of()

Value nk::stats::mad_of ( const Value & x,
int flag = 0,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Mean absolute deviation (y = mad(x, flag, dim)).

flag = 0 (default): mean absolute deviation from mean (mean(|x - mean(x)|)). flag = 1: median absolute deviation from median.

Parameters
xInput array.
flagMethod selector (0 = MAD from mean, 1 = MAD from median).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
MAD reduced along dim.

◆ mahal()

Value nk::stats::mahal ( const Value & Y,
const Value & X,
std::pmr::memory_resource * mr = nullptr )

Mahalanobis distance squared (d² = mahal(Y, X)).

For each row of Y, computes d² = (y − x̄) · S⁻¹ · (y − x̄)ᵀ where S is the sample covariance of X and x̄ its mean.

Parameters
YN×D query rows.
XM×D reference rows defining the covariance.
mrMemory resource (nullptr → process default).
Returns
N×1 column of squared Mahalanobis distances.

◆ mape()

Value nk::stats::mape ( const Value & f,
const Value & a,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Mean absolute percentage error (e = mape(F, A, dim)).

e = 100 · mean(|(A - F) / A|, dim). Zero entries in A produce Inf in the ratio.

Parameters
fForecast values.
aActual values.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
MAPE reduced along dim.
See also
rmse

◆ maxk()

Value nk::stats::maxk ( const Value & x,
int k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

k largest values along dim (y = maxk(X, k, dim)).

Output is sorted descending. NaN sorts last.

Parameters
xInput array.
kNumber of values to return.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
k largest values along dim.
See also
mink

◆ median()

Value nk::stats::median ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Median along dim (y = median(X, dim)).

For an even-length slice, returns the average of the two middle elements. NaN currently propagates (use nanmedian to skip them).

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Median reduced along dim.
See also
quantile, prctile

◆ mink()

Value nk::stats::mink ( const Value & x,
int k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

k smallest values along dim (y = mink(X, k, dim)).

Output is sorted ascending. NaN sorts last.

Parameters
xInput array.
kNumber of values to return.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
k smallest values along dim.
See also
maxk

◆ mnpdf()

Value nk::stats::mnpdf ( const Value & X,
const Value & P,
std::pmr::memory_resource * mr = nullptr )

Multinomial pmf (y = mnpdf(X, P)).

Parameters
X1 × k count vector, or N × k batch.
P1 × k probability vector (must sum to 1, entries non-negative).
mrMemory resource (nullptr → process default).
Returns
N × 1 column of probabilities.
See also
mvnpdf

◆ mnrnd()

Value nk::stats::mnrnd ( ::nk::ops::RngContext & rng,
std::size_t N,
const Value & P,
std::size_t m = 1,
std::pmr::memory_resource * mr = nullptr )

Multinomial random samples (R = mnrnd(N, P, m)).

Draws m samples from Multinomial(N, P) (k categories with probabilities P, total trials N per sample). Returns an m × k matrix where each row sums to N.

P must be a length-k probability vector (non-negative, sums to 1; renormalised if not). Implementation: per-trial categorical sampling via CDF lookup — O(m · N · k).

KNOWN GAP: P matrix form (per-sample probability rows) not yet supported in v1.

Parameters
NTrials per sample (positive integer).
PLength-k probability vector.
mNumber of samples (default 1).
mrMemory resource (nullptr → process default).
Returns
m × k count matrix.

◆ mode()

std::tuple< Value, Value > nk::stats::mode ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Mode and frequency ([m, f] = mode(X, dim)).

Returns the most-frequent value (m) and its count (f). Ties are broken by returning the smallest value.

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
(mode_value, frequency) along dim.

◆ moment_of()

Value nk::stats::moment_of ( const Value & x,
int order,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

k-th central moment (m = moment(x, k, dim)).

m = mean((x - mean(x))^k, dim). order = 2 reproduces population variance (i.e. var with normFlag = 1).

Parameters
xInput array.
orderMoment order (integer >= 1).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
order-th central moment reduced along dim.

◆ movmad()

Value nk::stats::movmad ( const Value & x,
Span< const size_t > k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving mean absolute deviation (y = movmad(x, k)).

Per window, computes mean(|x[i] - median(window)|).

Parameters
xInput array.
kWindow descriptor — see moving.hpp file note.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Per-element moving MAD.
Exceptions
ErrorInvalid window length (m:movmad:badK).
See also
movmedian, movstd

◆ movmax()

Value nk::stats::movmax ( const Value & x,
Span< const size_t > k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving maximum along dim (y = movmax(x, k)).

Parameters
xInput array.
kWindow descriptor — see moving.hpp file note.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Per-element moving maximum.
Exceptions
ErrorInvalid window length (m:movmax:badK).
See also
movmin

◆ movmean()

Value nk::stats::movmean ( const Value & x,
Span< const size_t > k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving mean along dim (y = movmean(x, k)).

For each output element y[i], computes mean(x[i-kb .. i+kf]) where the window is determined by k. This is the movmean(x, k, dim) operation.

Parameters
xInput array; any numeric type promoted to DOUBLE on read.
kWindow descriptor — see moving.hpp file note.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Array of the same shape as x with the per-element mean.
Exceptions
ErrorInvalid window length (m:movmean:badK).
See also
movsum, movmedian

◆ movmedian()

Value nk::stats::movmedian ( const Value & x,
Span< const size_t > k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving median along dim (y = movmedian(x, k)).

Per-window quickselect median. Window semantics as in movmean.

Parameters
xInput array.
kWindow descriptor — see moving.hpp file note.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Per-element moving median.
Exceptions
ErrorInvalid window length (m:movmedian:badK).
See also
movmean, movmad

◆ movmin()

Value nk::stats::movmin ( const Value & x,
Span< const size_t > k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving minimum along dim (y = movmin(x, k)).

Parameters
xInput array.
kWindow descriptor — see moving.hpp file note.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Per-element moving minimum.
Exceptions
ErrorInvalid window length (m:movmin:badK).
See also
movmax

◆ movprod()

Value nk::stats::movprod ( const Value & x,
Span< const size_t > k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving product along dim (y = movprod(x, k)).

Parameters
xInput array.
kWindow descriptor — see moving.hpp file note.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Per-element moving product.
Exceptions
ErrorInvalid window length (m:movprod:badK).
See also
movsum

◆ movstd()

Value nk::stats::movstd ( const Value & x,
Span< const size_t > k,
int normFlag = 0,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving standard deviation along dim (y = movstd(x, k, normFlag)).

Computed as sqrt(movvar(x, k, normFlag)).

Parameters
xInput array.
kWindow descriptor — see moving.hpp file note.
normFlagBias flag: 0 (default) divides by n-1 (unbiased), 1 divides by n (population). Must be 0 or 1.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Per-element moving standard deviation.
Exceptions
ErrorInvalid window length (m:movstd:badK) or invalid normFlag (m:movstd:badNormFlag).
See also
movvar, movmean

◆ movsum()

Value nk::stats::movsum ( const Value & x,
Span< const size_t > k,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving sum along dim (y = movsum(x, k)).

Parameters
xInput array.
kWindow descriptor — see moving.hpp file note.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Per-element moving sum.
Exceptions
ErrorInvalid window length (m:movsum:badK).
See also
movmean, movprod

◆ movvar()

Value nk::stats::movvar ( const Value & x,
Span< const size_t > k,
int normFlag = 0,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Moving variance along dim (y = movvar(x, k, normFlag)).

Same normFlag semantics as movstd.

Parameters
xInput array.
kWindow descriptor — see moving.hpp file note.
normFlagBias flag: 0 → divide by n-1, 1 → divide by n.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Per-element moving variance.
Exceptions
ErrorInvalid window length (m:movvar:badK) or invalid normFlag (m:movvar:badNormFlag).
See also
movstd, movmean

◆ multcompare()

Value nk::stats::multcompare ( const Value & stats,
double alpha = 0.05,
McCorrection ctype = McCorrection::Bonferroni,
std::pmr::memory_resource * mr = nullptr )

Pairwise post-hoc comparisons after one-way ANOVA (c = multcompare(stats [, alpha [, ctype]])).

stats is the 3rd output of anova1 (a struct with fields gnames, means, n, s, df). For each pair (i, j) of groups, returns a row

[ i, j, lower_CI, mean_diff, upper_CI, p_value ]

where mean_diff = means(i) - means(j), p_value is the two-sided t-test p adjusted for multiplicity, and CI half-width is t_crit · s · sqrt(1/n_i + 1/n_j).

Supported ctype:

  • McCorrection::Bonferroni (default in v1) — multiply each unadjusted p by the number of pairs K = k(k-1)/2, clip to 1.
  • McCorrection::LSD — Fisher's least-significant-difference; no multiplicity correction (raw t-test).

KNOWN GAP: Tukey HSD (MATLAB default) requires the studentized range distribution — not in v1.

Parameters
statsStruct from anova1.
alphaSignificance level (default 0.05).
ctypeCorrection method.
mrMemory resource.
Returns
K × 6 matrix of pairwise comparisons.

◆ mvncdf()

Value nk::stats::mvncdf ( const Value & X,
const Value & mu,
const Value & Sigma,
std::pmr::memory_resource * mr = nullptr )

Multivariate normal CDF (p = mvncdf(X, mu, Sigma)).

Returns the probability P(Y ≤ X) for Y ~ N(mu, Sigma), row-wise (each row of X is one evaluation point).

Algorithm by dimension:

  • d = 1 → direct normcdf.
  • d = 2 → Owen's tetrachoric / Drezner-Wesolowsky numerical integration (16-point Gauss-Legendre).
  • d ≥ 3 → Monte Carlo with antithetic sampling (10000 draws by default). KNOWN GAP: Genz separation-of-variables quasi-MC is more accurate but not yet in v1.

Mu may be omitted (defaults to zero vector). Sigma defaults to identity. The standard-normal one-arg form mvncdf(X) is the most common usage in practice.

Parameters
Xn × d evaluation points (each row one query).
mu1 × d mean (may be empty → zero).
Sigmad × d covariance (may be empty → identity).
mrMemory resource (nullptr → process default).
Returns
n × 1 column of cumulative probabilities.

◆ mvnpdf()

Value nk::stats::mvnpdf ( const Value & X,
const Value & mu,
const Value & Sigma,
std::pmr::memory_resource * mr = nullptr )

Multivariate normal pdf (y = mvnpdf(X, mu, Sigma)).

\( f(x; \mu, \Sigma) = \dfrac{1}{(2\pi)^{d/2}\,|\Sigma|^{1/2}}\, e^{-\tfrac{1}{2}(x-\mu)^\top \Sigma^{-1} (x-\mu)} \).

Parameters
XN × d (one point per row) or 1 × d single point.
mu1 × d mean. Pass empty Value for zeros.
Sigmad × d covariance (PSD). Pass empty Value for identity.
mrMemory resource (nullptr → process default).
Returns
N × 1 column of densities.
See also
mvtpdf, mnpdf

◆ mvnrnd()

Value nk::stats::mvnrnd ( ::nk::ops::RngContext & rng,
const Value & mu,
const Value & Sigma,
std::size_t n = 0,
std::pmr::memory_resource * mr = nullptr )

Multivariate normal random samples (R = mvnrnd(mu, Sigma [, n])).

Draws n independent samples from N(mu, Sigma) via Cholesky: R = mu + Z · L' where L = chol(Sigma, 'lower') and Z is a standard-normal n × d matrix.

Supports three calling conventions for mu:

  • 1 × d row vector — same mu for every sample
  • d × 1 column vector — same mu for every sample
  • n × d matrix — per-sample location (n must match)

Sigma must be d × d, symmetric positive-definite. Non-PD inputs throw m:mvnrnd:notPD at the Cholesky step. Sigma-as-diagonal-vector shorthand (mvnrnd(mu, sigmaVec, n)) is a v1 KNOWN GAP.

Uses the shared MT19937 stream so rng(seed) makes draws reproducible.

Parameters
muLocation parameter (1×d, d×1, or n×d).
SigmaCovariance matrix (d×d, symmetric PD).
nSample count. 0 → infer from mu (1 if mu is a vector, rows(mu) if mu is a matrix).
mrMemory resource (nullptr → process default).
Returns
n × d matrix of samples.
Exceptions
Erroron shape mismatch or non-PD Sigma.

◆ mvtcdf()

Value nk::stats::mvtcdf ( const Value & X,
const Value & C,
double df,
double tol = 0.01,
std::pmr::memory_resource * mr = nullptr )

Multivariate t cdf upper-tail (p = mvtcdf(X, C, df)).

Returns the probability P(Y ≤ X) for Y ~ MVT(0, C, df), row-wise (each row of X is one evaluation point).

Algorithm by dimension:

  • d = 1 → direct tcdf (bit-exact).
  • d ≥ 2 → deterministic Monte Carlo on the Y = Z / sqrt(W/df) representation with a fixed seed (12345), N = ceil(1/tol²) ≥ 10000 draws, antithetic.
Parameters
XEvaluation points (n × d or length-d row).
Cd × d correlation/scale matrix (symmetric PD).
dfDegrees of freedom (df > 0).
tolTarget MC absolute error (default 0.01).
mrMemory resource (nullptr → process default).
Returns
n × 1 column of cdf values.
See also
mvtpdf, mvtrnd

◆ mvtcdf_box()

Value nk::stats::mvtcdf_box ( const Value & L,
const Value & U,
const Value & C,
double df,
double tol = 0.01,
std::pmr::memory_resource * mr = nullptr )

Multivariate t box cdf (p = mvtcdf(L, U, C, df)).

Returns P(L ≤ Y ≤ U) for Y ~ MVT(0, C, df), row-wise. Each row of L (and U) is a length-d lower (upper) bound; entries may be -Inf / +Inf. Implemented via the same deterministic Monte Carlo path as the upper-tail form.

Parameters
LLower bounds (n × d or length-d row); -Inf allowed.
UUpper bounds (same shape as L); +Inf allowed.
CCorrelation/scale matrix.
dfDegrees of freedom.
tolTarget MC absolute error (default 0.01).
mrMemory resource.
Returns
n × 1 column of box probabilities.

◆ mvtpdf()

Value nk::stats::mvtpdf ( const Value & X,
const Value & C,
double df,
std::pmr::memory_resource * mr = nullptr )

Multivariate Student-t pdf (y = mvtpdf(X, C, df)).

C is treated as a correlation matrix; if its diagonal is not all 1, the input is normalised to a correlation matrix.

Parameters
XN × d points.
Cd × d correlation (or covariance — auto-normalised).
dfDegrees of freedom (df > 0).
mrMemory resource (nullptr → process default).
Returns
N × 1 column of densities.
See also
mvnpdf

◆ mvtrnd()

Value nk::stats::mvtrnd ( ::nk::ops::RngContext & rng,
const Value & C,
double df,
std::size_t n,
std::pmr::memory_resource * mr = nullptr )

Multivariate Student's-t random samples (R = mvtrnd(C, df, n)).

Draws n samples from t_df(0, C) via the canonical algorithm: T = X / sqrt(χ² / df) where X ~ N(0, C) and χ² ~ χ²(df).

C is a d × d correlation matrix (diagonal = 1). df is the degrees of freedom (positive scalar).

KNOWN GAP: location parameter not supported (MATLAB also defaults to zero); pass mu + mvtrnd(...) at the call site if needed.

Parameters
Cd × d correlation matrix.
dfDegrees of freedom (df > 0).
nSample count.
mrMemory resource (nullptr → process default).
Returns
n × d matrix of samples.

◆ nakacdf()

Value nk::stats::nakacdf ( const Value & x,
double mu,
double omega,
std::pmr::memory_resource * mr = nullptr )

Nakagami cdf (p = nakacdf(x, mu, omega)).

Computed via the regularised lower-incomplete gamma: F(x) = P(mu, mu·x²/omega).

Parameters
xEvaluation points (any shape).
muShape parameter (mu >= 0.5).
omegaSpread parameter (omega > 0).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
nakapdf, nakainv

◆ nakainv()

Value nk::stats::nakainv ( const Value & p,
double mu,
double omega,
std::pmr::memory_resource * mr = nullptr )

Nakagami inverse cdf (x = nakainv(p, mu, omega)).

Parameters
pProbability levels in [0, 1] (any shape).
muShape parameter.
omegaSpread parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
nakacdf

◆ nakapdf()

Value nk::stats::nakapdf ( const Value & x,
double mu,
double omega,
std::pmr::memory_resource * mr = nullptr )

Nakagami pdf (y = nakapdf(x, mu, omega)).

\( f(x; \mu, \Omega) = \dfrac{2\mu^{\mu}}{\Gamma(\mu)\,\Omega^{\mu}}\, x^{2\mu - 1}\,e^{-\mu x^2 / \Omega} \) for x >= 0. X² ~ Gamma(shape = mu, scale = omega/mu).

Parameters
xEvaluation points (any shape).
muShape parameter (mu >= 0.5).
omegaSpread parameter (omega > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
nakacdf, nakainv, nakarnd, nakastat

◆ nakarnd()

Value nk::stats::nakarnd ( ::nk::ops::RngContext & rng,
double mu,
double omega,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Nakagami random samples (r = nakarnd(mu, omega, rows, cols)).

Sampled as sqrt(G) with G ~ Gamma(mu, omega/mu).

Parameters
muShape parameter.
omegaSpread parameter.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of Nakagami samples.
See also
nakapdf

◆ nakastat()

std::tuple< double, double > nk::stats::nakastat ( double mu,
double omega )

Nakagami mean and variance ([m, v] = nakastat(mu, omega)).

Closed form (using c_mu = Γ(mu + 1/2) / Γ(mu)): m = sqrt(omega/mu) · c_mu, v = omega · (1 - c_mu² / mu).

Parameters
muShape parameter.
omegaSpread parameter.
Returns
{mean, variance} pair.
See also
nakapdf

◆ nancov() [1/2]

Value nk::stats::nancov ( const Value & x,
const Value & y,
int normFlag = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware covariance from two vectors (C = nancov(x, y)).

Treats [x y] as a 2-column matrix and applies the row-omit rule. Returns the 2 × 2 covariance matrix.

Parameters
xFirst vector.
ySecond vector (same length as x).
normFlag0 → unbiased (default), 1 → population.
mrMemory resource.
See also
nancov

◆ nancov() [2/2]

Value nk::stats::nancov ( const Value & x,
int normFlag = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware covariance matrix (C = nancov(X [, normFlag])).

Each row of X is one observation, each column one variable. Rows where any column is NaN are dropped before computing the standard covariance — i.e. equivalent to cov(X, 'omitrows'). This is MATLAB's 'complete' mode and the documented default for nancov.

The 'pairwise' mode (each (i,j) entry uses rows where both columns are non-NaN) is not supported in v1 — KNOWN GAP.

Parameters
xInput matrix or vector.
normFlag0 → divide by N - 1 (unbiased; default). 1 → divide by N.
mrMemory resource (nullptr → process default).
Returns
p × p covariance matrix where p = size(X, 2). Vector input → scalar variance.
See also
nanvar, cov

◆ nanmax()

Value nk::stats::nanmax ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware maximum along dim (y = nanmax(x, dim)).

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Maximum along dim, NaN entries skipped.
See also
nanmin

◆ nanmean()

Value nk::stats::nanmean ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware mean along dim (y = nanmean(x, dim)).

All-NaN slices return NaN.

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Mean along dim, NaN entries skipped.
See also
nansum, nanvar

◆ nanmedian()

Value nk::stats::nanmedian ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware median along dim (y = nanmedian(x, dim)).

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Median along dim, NaN entries skipped.
See also
nanmean

◆ nanmin()

Value nk::stats::nanmin ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware minimum along dim (y = nanmin(x, dim)).

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Minimum along dim, NaN entries skipped.
See also
nanmax

◆ nanstdev()

Value nk::stats::nanstdev ( const Value & x,
int normFlag = 0,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware standard deviation (y = nanstdev(x, normFlag, dim)).

Computed as sqrt(nanvar(x, normFlag, dim)).

Parameters
xInput array.
normFlagBias flag.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Standard deviation along dim, NaN entries skipped.
See also
nanvar

◆ nansum()

Value nk::stats::nansum ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware sum along dim (y = nansum(x, dim)).

All-NaN slices return 0.

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Sum along dim, NaN entries skipped.
See also
nanmean

◆ nanvar()

Value nk::stats::nanvar ( const Value & x,
int normFlag = 0,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

NaN-aware variance (y = nanvar(x, normFlag, dim)).

normFlag matches var's semantics: 0 → divide by N - 1 (where N is the count of non-NaN observations in the slice), 1 → divide by N.

Parameters
xInput array.
normFlagBias flag (0 = unbiased, 1 = population).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Variance along dim, NaN entries skipped.
See also
nanstdev, nanmean

◆ nbincdf()

Value nk::stats::nbincdf ( const Value & k,
double r,
double p,
std::pmr::memory_resource * mr = nullptr )

Negative binomial cdf (F = nbincdf(k, r, p)).

Computed via the regularised incomplete beta: \( F(k) = I_{p}(r,\ \lfloor k\rfloor + 1) \).

Parameters
kEvaluation points (any shape).
rNumber of successes.
pSuccess probability per trial.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
nbinpdf, nbininv

◆ nbinfit()

Value nk::stats::nbinfit ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Negative-binomial MLE fit ([rhat, phat] = nbinfit(x)).

Newton iteration on the profile log-likelihood for the count parameter r, with closed-form update for p = r/(r + mean(x)) at each step. Initial guess from moment matching.

x must be non-negative integers (treated as counts).

Parameters
xNon-negative count observations.
mrMemory resource.
Returns
[rhat, phat] as a 1 × 2 row.

◆ nbinfit_ci()

Value nk::stats::nbinfit_ci ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

95% Wald CI for nbinfit (pci = nbinfit_ci(x, alpha)).

Returns the 2 × 2 confidence matrix [lo; hi] for [r, p] from the observed Fisher information at the MLE. r uses a log-scale Wald CI; p uses a logit-scale Wald CI (MATLAB convention).

◆ nbininv()

Value nk::stats::nbininv ( const Value & q,
double r,
double p,
std::pmr::memory_resource * mr = nullptr )

Negative binomial inverse cdf (k = nbininv(q, r, p)).

Smallest non-negative integer k such that nbincdf(k, r, p) >= q.

Parameters
qProbability levels in [0, 1] (any shape).
rNumber of successes.
pSuccess probability per trial.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as q.
See also
nbincdf

◆ nbinpdf()

Value nk::stats::nbinpdf ( const Value & k,
double r,
double p,
std::pmr::memory_resource * mr = nullptr )

Negative binomial pmf (y = nbinpdf(k, r, p)).

\( f(k; r, p) = \binom{k + r - 1}{k}\,p^{r}(1-p)^{k} \) for k = 0, 1, 2, …. Convention: k counts failures before the r-th success; r > 0 real-valued allowed; 0 < p ≤ 1.

Parameters
kEvaluation points (any shape).
rNumber of successes (r > 0).
pSuccess probability per trial.
mrMemory resource (nullptr → process default).
Returns
Array of pmf values, same shape as k.
See also
nbincdf, nbininv, nbinrnd, nbinstat

◆ nbinrnd()

Value nk::stats::nbinrnd ( ::nk::ops::RngContext & rng,
double r,
double p,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Negative binomial random samples (r_out = nbinrnd(r, p, rows, cols)).

Parameters
rNumber of successes (r > 0).
pSuccess probability per trial.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of negative-binomial samples.
See also
nbinpdf

◆ nbinstat()

std::tuple< double, double > nk::stats::nbinstat ( double r,
double p )

Negative binomial mean and variance ([m, v] = nbinstat(r, p)).

Closed form: m = r·(1-p)/p, v = r·(1-p)/p².

Parameters
rNumber of successes.
pSuccess probability per trial.
Returns
{mean, variance} pair.
See also
nbinpdf

◆ ncfcdf()

Value nk::stats::ncfcdf ( const Value & x,
double nu1,
double nu2,
double delta,
bool upper = false,
std::pmr::memory_resource * mr = nullptr )

Noncentral F cdf (p = ncfcdf(x, nu1, nu2, delta)).

Poisson-mixture in the regularised incomplete beta: F(x; ν₁, ν₂, δ) = Σ_k Poisson(k; δ/2) · I_y(ν₁/2 + k, ν₂/2) with y = ν₁ x / (ν₁ x + ν₂). Series truncated at 1e-16 relative contribution. Reduces to fcdf(x, ν₁, ν₂) at δ = 0. The 'upper' flag returns 1 - F.

Parameters
xEvaluation points (any shape).
nu1Numerator degrees of freedom (> 0).
nu2Denominator degrees of freedom (> 0).
deltaNoncentrality parameter (>= 0).
upperIf true, return upper-tail 1 - F (default false).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
ncfpdf, ncfinv

◆ ncfinv()

Value nk::stats::ncfinv ( const Value & p,
double nu1,
double nu2,
double delta,
std::pmr::memory_resource * mr = nullptr )

Noncentral F inverse cdf (x = ncfinv(p, nu1, nu2, delta)).

Returns x such that ncfcdf(x, ν₁, ν₂, δ) = p. Newton iteration on ncfcdf using ncfpdf as derivative; safeguarded by bracketing bisection if Newton steps oscillate. Initial guess from finv(p, ν₁, ν₂).

Parameters
pProbability levels in [0, 1] (any shape).
nu1Numerator degrees of freedom.
nu2Denominator degrees of freedom.
deltaNoncentrality parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
ncfcdf

◆ ncfpdf()

Value nk::stats::ncfpdf ( const Value & x,
double nu1,
double nu2,
double delta,
std::pmr::memory_resource * mr = nullptr )

Noncentral F pdf (y = ncfpdf(x, nu1, nu2, delta)).

Poisson-mixture representation: f(x; ν₁, ν₂, δ) = e^{-δ/2} Σ_{k=0}^∞ (1/k!) (δ/2)^k · (ν₁/ν₂)^{ν₁/2 + k} · x^{ν₁/2 + k − 1} · (1 + ν₁ x / ν₂)^{−(ν₁+ν₂)/2 − k} / B(ν₁/2 + k, ν₂/2) for x > 0; series truncated at 1e-16 relative contribution. Reduces to fpdf(x, ν₁, ν₂) at δ = 0.

Parameters
xEvaluation points (any shape).
nu1Numerator degrees of freedom (> 0).
nu2Denominator degrees of freedom (> 0).
deltaNoncentrality parameter (>= 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
ncfcdf, ncfinv, ncfrnd, ncfstat

◆ ncfrnd()

Value nk::stats::ncfrnd ( ::nk::ops::RngContext & rng,
double nu1,
double nu2,
double delta,
std::size_t rows = 1,
std::size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Noncentral F random samples (R = ncfrnd(nu1, nu2, delta, rows, cols)).

Sampled as F = (X₁/ν₁) / (X₂/ν₂) where X₁ ~ χ²(ν₁, δ) (noncentral chi-square via Poisson-mixture representation, J ~ Poisson(δ/2) then χ²(ν₁ + 2J)) and X₂ ~ χ²(ν₂). Uses the shared MT19937 stream.

Parameters
nu1Numerator degrees of freedom.
nu2Denominator degrees of freedom.
deltaNoncentrality parameter (>= 0).
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of noncentral F samples.
See also
ncfpdf

◆ ncfstat()

std::tuple< double, double > nk::stats::ncfstat ( double nu1,
double nu2,
double delta )

Noncentral F mean and variance ([m, v] = ncfstat(nu1, nu2, delta)).

Closed-form moments: m = ν₂(ν₁ + δ) / (ν₁(ν₂ - 2)) for ν₂ > 2, v = 2(ν₂/ν₁)² ((ν₁+δ)² + (ν₁+2δ)(ν₂-2)) / ((ν₂-2)²(ν₂-4)) for ν₂ > 4.

Parameters
nu1Numerator degrees of freedom.
nu2Denominator degrees of freedom.
deltaNoncentrality parameter.
Returns
{mean, variance} (NaN where undefined).
See also
ncfpdf

◆ nctcdf()

Value nk::stats::nctcdf ( const Value & x,
double nu,
double delta,
bool upper = false,
std::pmr::memory_resource * mr = nullptr )

Noncentral Student's t cdf (p = nctcdf(x, nu, delta)).

Owen series (1965, Lenth 1989): F(x; ν, δ) = Φ(-δ) + ½·Σ_k P_k · I_y(k+½, ν/2)

  • (δ/(2√(2π)))·Σ_k Q_k · I_y(k+1, ν/2) where y = x²/(x²+ν), P_k = e^{-δ²/2}(δ²/2)^k/k!, Q_k = e^{-δ²/2}(δ²/2)^k / Γ(k+3/2), and the symmetry F(x; ν, δ) = 1 - F(-x; ν, -δ) handles negative x.

The optional 'upper' flag returns 1 - F.

Parameters
xEvaluation points (any shape).
nuDegrees of freedom (nu > 0).
deltaNoncentrality parameter.
upperIf true, return upper-tail 1 - F (default false).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
nctpdf, nctinv

◆ nctinv()

Value nk::stats::nctinv ( const Value & p,
double nu,
double delta,
std::pmr::memory_resource * mr = nullptr )

Noncentral t inverse cdf (x = nctinv(p, nu, delta)).

Returns x such that nctcdf(x, ν, δ) = p. Newton iteration on nctcdf using nctpdf as derivative; safeguarded by bisection if Newton steps oscillate. Initial guess from the central tinv(p, ν) shifted by δ.

Parameters
pProbability levels in [0, 1] (any shape).
nuDegrees of freedom (nu > 0).
deltaNoncentrality parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
nctcdf

◆ nctpdf()

Value nk::stats::nctpdf ( const Value & x,
double nu,
double delta,
std::pmr::memory_resource * mr = nullptr )

Noncentral Student's t pdf (y = nctpdf(x, nu, delta)).

Distribution of T = (Z + δ)/sqrt(V/ν) where Z ~ N(0,1), V ~ χ²(ν), Z ⊥ V. Reduces to tpdf(x, ν) when δ = 0.

Implementation: Owen-Lenth series in terms of the regularised incomplete beta: f(x; ν, δ) = e^{-δ²/2} Σ_k a_k(δ) · g_k(x; ν) where the sum is truncated when contributions fall below 1e-16 · running_sum.

Parameters
xEvaluation points (any shape).
nuDegrees of freedom (nu > 0).
deltaNoncentrality parameter.
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
nctcdf, nctinv, nctrnd, nctstat

◆ nctrnd()

Value nk::stats::nctrnd ( ::nk::ops::RngContext & rng,
double nu,
double delta,
std::size_t rows = 1,
std::size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Noncentral Student's t random samples (r = nctrnd(nu, delta, rows, cols)).

Sampled as T = (Z + δ) / sqrt(V / ν) where Z ~ N(0, 1), V ~ χ²(ν). Uses the shared MT19937 stream so rng(seed) makes draws reproducible.

Parameters
nuDegrees of freedom (nu > 0).
deltaNoncentrality parameter.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of nct-samples.
See also
nctpdf

◆ nctstat()

std::tuple< double, double > nk::stats::nctstat ( double nu,
double delta )

Noncentral t mean and variance ([m, v] = nctstat(nu, delta)).

Closed-form moments: m = δ · sqrt(ν/2) · Γ((ν-1)/2) / Γ(ν/2) for ν > 1 (else NaN), v = ν(1 + δ²)/(ν - 2) − m² for ν > 2 (else NaN).

Parameters
nuDegrees of freedom.
deltaNoncentrality parameter.
Returns
{mean, variance} (NaN where undefined).
See also
nctpdf

◆ ncx2cdf()

Value nk::stats::ncx2cdf ( const Value & x,
double k,
double lambda,
std::pmr::memory_resource * mr = nullptr )

Noncentral χ² cdf (p = ncx2cdf(x, k, lambda)).

Computed via the Poisson mixture representation: \( F(x) = \sum_{j \ge 0} \text{Poisson}(j;\,\lambda/2)\cdot \chi^{2}_{\text{cdf}}(x;\,k + 2j) \). Series truncated when the Poisson tail probability falls below tolerance.

Parameters
xEvaluation points (any shape).
kDegrees of freedom.
lambdaNoncentrality parameter.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
ncx2pdf, ncx2inv

◆ ncx2inv()

Value nk::stats::ncx2inv ( const Value & p,
double k,
double lambda,
std::pmr::memory_resource * mr = nullptr )

Noncentral χ² inverse cdf (x = ncx2inv(p, k, lambda)).

Parameters
pProbability levels in [0, 1] (any shape).
kDegrees of freedom.
lambdaNoncentrality parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
ncx2cdf

◆ ncx2pdf()

Value nk::stats::ncx2pdf ( const Value & x,
double k,
double lambda,
std::pmr::memory_resource * mr = nullptr )

Noncentral χ² pdf (y = ncx2pdf(x, k, lambda)).

\( f(x; k, \lambda) = \tfrac{1}{2}\,e^{-(x + \lambda)/2} \left(\dfrac{x}{\lambda}\right)^{(k-2)/4} I_{(k-2)/2}(\sqrt{\lambda x}) \) for x > 0 when lambda > 0. For lambda == 0 reduces to chi2pdf.

Parameters
xEvaluation points (any shape).
kDegrees of freedom (k > 0).
lambdaNoncentrality parameter (lambda >= 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
ncx2cdf, ncx2inv, ncx2rnd, ncx2stat, chi2pdf

◆ ncx2rnd()

Value nk::stats::ncx2rnd ( ::nk::ops::RngContext & rng,
double k,
double lambda,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Noncentral χ² random samples (r = ncx2rnd(k, lambda, rows, cols)).

Sampled via the mixture representation X = Σ_{j ~ Poisson(λ/2)} χ²(k + 2j).

Parameters
kDegrees of freedom.
lambdaNoncentrality parameter.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of noncentral χ² samples.
See also
ncx2pdf

◆ ncx2stat()

std::tuple< double, double > nk::stats::ncx2stat ( double k,
double lambda )

Noncentral χ² mean and variance ([m, v] = ncx2stat(k, lambda)).

Closed form: m = k + lambda, v = 2·k + 4·lambda.

Parameters
kDegrees of freedom.
lambdaNoncentrality parameter.
Returns
{mean, variance} pair.
See also
ncx2pdf

◆ nearcorr()

Value nk::stats::nearcorr ( const Value & A,
std::pmr::memory_resource * mr = nullptr )

Nearest correlation matrix (Y = nearcorr(A)).

Higham's (2002) alternating-projections algorithm with Dykstra's correction. Returns a symmetric, PSD, unit-diagonal matrix closest (in Frobenius norm) to A. Defaults: tol = 1e-10, maxits = 100. tolconv / maxits name-value parameters deferred.

Parameters
AInput symmetric matrix.
mrMemory resource (nullptr → process default).
Returns
Nearest valid correlation matrix.

◆ net()

Value nk::stats::net ( const Value & stream,
long long n,
std::pmr::memory_resource * mr = nullptr )

Extract points from a quasi-random stream (X = net(p, n)).

Returns the next n points of the stream p. Indices walked: skip+1, skip+1+(leap+1), …. Output is n × dim. Only Halton streams supported in this revision.

Parameters
streamStream descriptor produced by haltonset.
nNumber of points to extract (n >= 0).
mrMemory resource (nullptr → process default).
Returns
n × dim matrix of quasi-random points in [0, 1)^d.
Exceptions
ErrorUnknown stream kind (m:net:badStream).
See also
haltonset

◆ nlinfit()

NlinfitResult nk::stats::nlinfit ( const Value & X,
const Value & y,
FnHandle model,
const Value & beta0,
std::pmr::memory_resource * mr = nullptr )

Nonlinear least-squares fit via Levenberg-Marquardt.

Fits y ≈ fun(beta, X) by minimising ||y - fun(beta, X)||². fun is a function handle taking (beta, X) and returning a length-n predicted vector.

Algorithm: classical LM with adaptive damping (λ scaled by 10× on rejected steps, by 0.1× on accepted steps), numerical Jacobian via central differences with relative step 1e-7 · max(|β|, 1).

KNOWN GAPs: name-value 'Weights', 'ErrorModel', 'Options' not supported. Returns MSE = SSE / (n - p).

Parameters
XPredictor data (n × k).
yResponse vector (n × 1).
funFunction handle fun(beta, X) returning predictions.
beta0Initial parameter estimate.
engineEngine pointer for callFunctionHandle (required — adapters pass ctx.engine).
mrMemory resource (nullptr → process default).
Returns
{beta, R, J, CovB, MSE}.

◆ nlparci()

Value nk::stats::nlparci ( const Value & beta,
const Value & R,
const Value & J,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

Parameter confidence intervals from an nlinfit fit (ci = nlparci(beta, R, J [, alpha])).

ci(i, :) = beta(i) ± t_{α/2, n-p} · se(i) where se(i) = sqrt(MSE · ((J'·J)^{-1})_{ii}).

Parameters
betaParameter vector from nlinfit (p × 1).
RResiduals from nlinfit (n × 1).
JJacobian from nlinfit (n × p).
alphaSignificance level (default 0.05 → 95% CI).
mrMemory resource.
Returns
p × 2 CI matrix; [lower, upper] per row.

◆ nlpredci()

std::tuple< Value, Value > nk::stats::nlpredci ( FnHandle model,
const Value & X,
const Value & beta,
const Value & R,
const Value & J,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Prediction confidence intervals from an nlinfit fit ([ypred, delta] = nlpredci(fun, X, beta, R, J [, alpha])).

For each row of X, returns ypred(i) = fun(beta, X(i,:)) and delta(i) = t_{α/2, n-p} · sqrt(MSE · g_i' · (J'·J)^{-1} · g_i) where g_i = ∂fun/∂beta at X(i,:).

Parameters
funFunction handle.
XQuery points (m × k).
betaParameter vector.
RResiduals from the fit.
JJacobian from the fit (n × p).
alphaSignificance level (default 0.05).
engineEngine pointer (adapter passes ctx.engine).
mrMemory resource.
Returns
Tuple (ypred, delta) — predictions and CI half-widths.

◆ normalize()

NormalizeResult nk::stats::normalize ( const Value & A,
const std::string & method,
const Value & param = Value::Empty,
std::pmr::memory_resource * mr = nullptr )

Normalizes data using z-score, min-max, scale, or center methods ([N, C, S] = normalize(...)).

Parameters
AInput array.
methodNormalization method ("zscore", "range", "scale", "center", "median").
paramOptional method-specific parameter (e.g. range target [lo, hi]).
mrMemory resource for output allocation.
Returns
NormalizeResult containing {n, c, s}.
See also
rescale, zscore

◆ normcdf()

Value nk::stats::normcdf ( const Value & x,
double mu = 0.0,
double sigma = 1.0,
std::pmr::memory_resource * mr = nullptr )

Normal cdf (p = normcdf(x, mu, sigma)).

Closed form: \( F(x; \mu, \sigma) = \tfrac{1}{2}\bigl[1 + \text{erf}\bigl((x-\mu)/(\sigma\sqrt{2})\bigr)\bigr] \).

Parameters
xEvaluation points (any shape).
muMean parameter (default 0).
sigmaStandard deviation (default 1).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
normpdf, norminv

◆ normfit() [1/2]

std::tuple< Value, Value, Value, Value > nk::stats::normfit ( const Value & x,
double alpha,
const Value & cens,
const Value & freq,
std::pmr::memory_resource * mr = nullptr )

Normal MLE with optional censoring and frequencies.

Wald CIs (analytic Fisher information) + log-σ transform for the censored case.

Parameters
xSample data.
alphaSignificance level.
censRight-censoring mask (cens[i] != 0 → censored). Pass Value::Empty for no censoring.
freqPer-sample weights. Value::Empty → all ones.
mrMemory resource (nullptr → process default).
Returns
(muhat, sigmahat, muci, sigmaci).
See also
normfit(x, alpha, mr)

◆ normfit() [2/2]

std::tuple< Value, Value, Value, Value > nk::stats::normfit ( const Value & x,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Normal MLE without censoring ([muhat, sigmahat, muci, sigmaci] = normfit(x, alpha)).

muhat = mean(x), sigmahat = std(x, normFlag=0) (sample, N-1). CIs: t-based for mu, χ² for sigma.

Parameters
xSample data.
alphaSignificance level (default 0.05 in *_reg).
mrMemory resource (nullptr → process default).
Returns
(muhat, sigmahat, muci, sigmaci).
See also
normlike

◆ norminv()

Value nk::stats::norminv ( const Value & p,
double mu = 0.0,
double sigma = 1.0,
std::pmr::memory_resource * mr = nullptr )

Normal inverse cdf / quantile (x = norminv(p, mu, sigma)).

p must be in [0, 1]; values outside the closed interval return NaN.

Parameters
pProbability levels in [0, 1] (any shape).
muMean parameter (default 0).
sigmaStandard deviation (default 1).
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
normcdf

◆ normlike()

double nk::stats::normlike ( double mu,
double sigma,
const Value & x,
const Value & cens,
const Value & freq,
std::pmr::memory_resource * mr = nullptr )

Normal negative-log-likelihood (nLogL = normlike(mu, sigma, x, cens, freq)).

Handles the (censoring, freq) optional args:

  • censoring[i] != 0 → element i is right-censored; contribute -log(1 - F(z_i)) = -log(0.5·erfc(z_i/√2)) instead of -log(f).
  • freq[i] (default 1) → multiplies the element's contribution. freq[i] == 0 removes the element from the sum.

Boundary handling: sigma <= 0 → NaN; any NaN in x → NaN; empty x → 0.

Parameters
muLocation parameter.
sigmaScale parameter (sigma > 0).
xSample data.
censRight-censoring mask (empty Value for none).
freqPer-sample weights (empty Value for ones).
mrMemory resource (nullptr → process default).
Returns
Scalar -Σ log f(x_i; θ).
See also
normfit

◆ normpdf()

Value nk::stats::normpdf ( const Value & x,
double mu = 0.0,
double sigma = 1.0,
std::pmr::memory_resource * mr = nullptr )

Normal pdf (y = normpdf(x, mu, sigma)).

\( f(x; \mu, \sigma) = \dfrac{1}{\sigma\sqrt{2\pi}}\, e^{-(x-\mu)^2 / (2\sigma^2)} \). Defaults give the standard normal N(0, 1).

Parameters
xEvaluation points (any shape).
muMean parameter (default 0).
sigmaStandard deviation (default 1, sigma > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
normcdf, norminv, normrnd, normstat

◆ normrnd()

Value nk::stats::normrnd ( ::nk::ops::RngContext & rng,
double mu,
double sigma,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Normal random samples (r = normrnd(mu, sigma, rows, cols)).

Parameters
muMean parameter.
sigmaStandard deviation (sigma > 0).
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of normal samples.
See also
normpdf

◆ normstat()

std::tuple< double, double > nk::stats::normstat ( double mu,
double sigma )

Normal mean and variance ([m, v] = normstat(mu, sigma)).

Trivially: m = mu, v = sigma².

Parameters
muMean parameter.
sigmaStandard deviation.
Returns
{mean, variance} pair.
See also
normpdf

◆ parcorr()

std::tuple< Value, Value, Value > nk::stats::parcorr ( const Value & y,
int numLags = -1,
double numSTD = 2.0,
std::pmr::memory_resource * mr = nullptr )

Sample partial autocorrelation function ([pacf, lags, bounds] = parcorr(y)).

Matches MATLAB's default parcorr Method (OLS): for each lag k, fits the AR(k) model y_t = c + Σ_{j=1..k} φ_j·y_{t-j} by least squares on observations t = k+1..N and returns PACF(k) = φ_k (lag-0 = 1). Confidence bounds are ±numSTD/√N. Solved via the normal equations — reproduces MATLAB's QR to full precision on well-conditioned lags (N-k ≥ k+1); deeper rank-deficient lags are numerically unstable in both engines.

Parameters
yReal 1-D series.
numLagsNumber of lags; < 0 → MATLAB default min(20, N-1).
numSTDBound width in standard errors (default 2).
mrMemory resource (nullptr → process default).
Returns
(pacf, lags, bounds) column vectors (numLags+1 entries).
See also
autocorr, crosscorr

◆ partialcorr_of()

Value nk::stats::partialcorr_of ( const Value & X,
const Value & Y,
const Value & Z,
std::pmr::memory_resource * mr = nullptr )

Partial correlation controlling for Z (R = partialcorr(X, Y, Z)).

Returns the partial correlation matrix between columns of X and columns of Y after removing the linear contribution of Z.

Parameters
Xn × p first set of variables.
Yn × q second set of variables (Y.rows == X.rows).
Zn × r controlling variables.
mrMemory resource (nullptr → process default).
Returns
p × q partial-correlation matrix.
See also
corrcoef

◆ partialcorr_xx()

Value nk::stats::partialcorr_xx ( const Value & X,
std::pmr::memory_resource * mr = nullptr )

One-argument partial correlation: pairwise partial correlation between columns of X, controlling for the remaining columns of X (R = partialcorr(X)).

For each pair (i, j) with i ≠ j the control set is the columns of X excluding both i and j (augmented with an intercept column). The diagonal is forced to 1.

Parameters
Xn × p matrix; columns are the variables.
mrMemory resource (nullptr → process default).
Returns
p × p symmetric partial-correlation matrix.
See also
partialcorr_xz, partialcorr_of

◆ partialcorr_xz()

Value nk::stats::partialcorr_xz ( const Value & X,
const Value & Z,
std::pmr::memory_resource * mr = nullptr )

Two-argument partial correlation (R = partialcorr(X, Z)).

Pairwise partial correlation between columns of X controlling for the columns of Z. Output is p × p symmetric with diagonal 1.

Parameters
Xn × p matrix of variables of interest.
Zn × r controlling variables.
mrMemory resource (nullptr → process default).
Returns
p × p symmetric partial-correlation matrix.
See also
partialcorr_xx, partialcorr_of

◆ partialcorri()

Value nk::stats::partialcorri ( const Value & Y,
const Value & X,
const Value & Z = {},
std::pmr::memory_resource * mr = nullptr )

Partial correlation between each column of Y and each column of X, controlling for the remaining columns of X (and optionally Z).

(R = partialcorri(Y, X) / R = partialcorri(Y, X, Z))

Unlike partialcorr_of(X, Y, Z), the control set varies per X column: for column j, the controls are X(:, ~j) (all other X columns), unioned with Z if supplied. Both the y and x_j columns are residualised on the control set, then the residuals are Pearson-correlated.

Parameters
Yn × p_Y outcome variables.
Xn × p_X predictor variables.
ZOptional n × p_Z extra controls (may be an empty matrix to skip).
mrMemory resource (nullptr → process default).
Returns
p_Y × p_X matrix of partial correlations.
See also
partialcorr_of, corrcoef

◆ pca()

std::tuple< Value, Value, Value, Value, Value, Value > nk::stats::pca ( const Value & X,
std::pmr::memory_resource * mr = nullptr )

Principal Component Analysis ([coeff, score, latent, tsquared, explained, mu] = pca(X)).

Standard PCA via eigendecomposition of the sample covariance.

Parameters
XN × D data matrix (observations as rows).
mrMemory resource (nullptr → process default).
Returns
Tuple:
  • coeff : D × D matrix; columns are PC directions (eigenvectors of cov(X)).
  • score : N × D projections ((X - mu) · coeff).
  • latent : D × 1 eigenvalues (descending).
  • tsquared : N × 1 Hotelling's T² statistic.
  • explained : D × 1 percent variance per component.
  • mu : 1 × D column means that were subtracted.
See also
pcacov, pcares

◆ pcacov()

std::tuple< Value, Value, Value > nk::stats::pcacov ( const Value & C,
std::pmr::memory_resource * mr = nullptr )

PCA from a precomputed covariance matrix ([coeff, latent, explained] = pcacov(C)).

Eigendecomposes a D × D covariance matrix.

Parameters
CD × D symmetric covariance matrix.
mrMemory resource (nullptr → process default).
Returns
Tuple (coeff, latent, explained).
See also
pca

◆ pcares()

Value nk::stats::pcares ( const Value & X,
int ndim,
std::pmr::memory_resource * mr = nullptr )

PCA residuals (res = pcares(X, ndim)).

Returns the residual of X after projecting onto the first ndim principal components: res = X - (X - mu) · coeff(:, 1:ndim) · coeff(:, 1:ndim)'.

Parameters
XN × D data matrix.
ndimNumber of PCs to retain (1 <= ndim <= D).
mrMemory resource (nullptr → process default).
Returns
N × D residual matrix.
See also
pca

◆ pdist()

Value nk::stats::pdist ( const Value & X,
const std::string & metric,
double p,
std::pmr::memory_resource * mr = nullptr )

Pairwise distances between rows of X (d = pdist(X, metric, p)).

Returns a 1 × M(M-1)/2 row (upper-triangular packed). Supported metrics:

metric formula
"euclidean" (def) √Σ(xᵢ − yᵢ)²
"squaredeuclidean" Σ(xᵢ − yᵢ)²

| "cityblock" | Σ|xᵢ − yᵢ| | | "chebychev" | max|xᵢ − yᵢ| | | "minkowski" | (Σ|xᵢ − yᵢ|^p)^(1/p) — uses p | | "cosine" | 1 − x·y / (‖x‖‖y‖) (NaN if a norm is 0) | | "correlation" | 1 − corr(x, y) (NaN if a row is const) | | "seuclidean" | √Σ((xᵢ−yᵢ)/Sᵢ)², Sᵢ=std(col) by default | | "spearman" | 1 − corr of tied ranks of each row | | "hamming" | mean(x ≠ y) | | "jaccard" | mean(x ≠ y given at least one nonzero) |

Parameters
XM×D matrix (each row a point).
metricMetric name (see table).
pMinkowski exponent (only used for "minkowski").
mrMemory resource (nullptr → process default).
Returns
Row of length M(M-1)/2.
See also
pdist2, squareform

◆ pdist2()

Value nk::stats::pdist2 ( const Value & X,
const Value & Y,
const std::string & metric,
double p,
std::pmr::memory_resource * mr = nullptr )

Cross-set pairwise distances (D = pdist2(X, Y, metric, p)).

Distances between rows of X (M×D) and rows of Y (N×D); output is M×N. Metric and p follow pdist.

Parameters
XM×D matrix.
YN×D matrix.
metricMetric name (see pdist).
pMinkowski exponent.
mrMemory resource (nullptr → process default).
Returns
M×N distance matrix.
See also
pdist

◆ poisscdf()

Value nk::stats::poisscdf ( const Value & k,
double lambda,
std::pmr::memory_resource * mr = nullptr )

Poisson cumulative distribution (F = poisscdf(k, lambda)).

Computed via the upper regularised gamma identity \( F(k) = Q(\lfloor k\rfloor + 1,\ \lambda) = 1 - \text{gammainc}(\lambda, \lfloor k\rfloor + 1) \). Numerically stable for the full k-range.

Parameters
kEvaluation points (any shape).
lambdaRate parameter, lambda >= 0.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1], same shape as k.
See also
poisspdf, poissinv

◆ poissfit()

std::tuple< Value, Value > nk::stats::poissfit ( const Value & x,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Poisson MLE ([lhat, lci] = poissfit(x, alpha)).

lambda = mean(x). Exact CI from χ² inversion of the cumulative Poisson tail.

Parameters
xSample counts.
alphaSignificance level.
mrMemory resource (nullptr → process default).
Returns
(lhat, lci).

◆ poissinv()

Value nk::stats::poissinv ( const Value & p,
double lambda,
std::pmr::memory_resource * mr = nullptr )

Poisson inverse cdf (k = poissinv(p, lambda)).

Smallest integer k such that poisscdf(k, lambda) >= p.

Parameters
pProbability levels in [0, 1] (any shape).
lambdaRate parameter, lambda >= 0.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
poisscdf

◆ poisspdf()

Value nk::stats::poisspdf ( const Value & k,
double lambda,
std::pmr::memory_resource * mr = nullptr )

Poisson pmf (y = poisspdf(k, lambda)).

\( f(k; \lambda) = \lambda^{k}\,e^{-\lambda} / k! \) for k = 0, 1, 2, …. Returns 0 for negative or non-integer k. Broadcasts elementwise over k.

Parameters
kEvaluation points (any shape).
lambdaRate parameter, lambda >= 0.
mrMemory resource (nullptr → process default).
Returns
Array of pmf values, same shape as k.
See also
poisscdf, poissinv, poissrnd, poisstat

◆ poissrnd()

Value nk::stats::poissrnd ( ::nk::ops::RngContext & rng,
double lambda,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Poisson random samples (r = poissrnd(lambda, rows, cols)).

Uses std::poisson_distribution on the shared RNG.

Parameters
lambdaRate parameter, lambda >= 0.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of Poisson samples.
See also
poisspdf

◆ poisstat()

std::tuple< double, double > nk::stats::poisstat ( double lambda)

Poisson mean and variance ([m, v] = poisstat(lambda)).

Closed form: m = lambda, v = lambda.

Parameters
lambdaRate parameter.
Returns
{mean, variance} pair.
See also
poisspdf

◆ ppmak()

Value nk::stats::ppmak ( const Value & breaks,
const Value & coefs,
int d,
std::pmr::memory_resource * mr = nullptr )

Piecewise-polynomial constructor (pp = ppmak(breaks, coefs, d)).

Builds a struct with fields {form='pp', breaks, coefs, pieces=L, order=K, dim=d}. breaks is length L+1; coefs is L × K for univariate (d = 1) or d·L × K for vector-valued.

Parameters
breaksKnot break vector (length L + 1).
coefsCoefficient matrix (L × K or d·L × K).
dOutput dimension (1 for univariate).
mrMemory resource (nullptr → process default).
Returns
pp-form spline struct.
See also
fnval, fnbrk

◆ prctile()

Value nk::stats::prctile ( const Value & x,
const Value & p,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Empirical percentile (q = prctile(X, p, dim)).

Equivalent to quantile(X, p/100, dim).

Parameters
xInput array.
pPercentile level(s) in [0, 100].
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Percentile(s) along dim.
See also
quantile

◆ prepareCurveData()

std::tuple< Value, Value, Value > nk::stats::prepareCurveData ( const Value & x,
const Value & y,
const Value & w,
std::pmr::memory_resource * mr = nullptr )

Curve-data cleanup ([xo, yo, wo] = prepareCurveData(x, y, w)).

Strips entries where any of x, y, w is NaN or Inf and returns column vectors. w == 0 entries are KEPT; only invalid floats drop a row. Empty input → 0 × 1 columns.

Parameters
xx-coordinates.
yy-coordinates.
wOptional weights (pass Value::Empty to skip).
mrMemory resource (nullptr → process default).
Returns
Cleaned (x, y, w) columns.

◆ prepareSurfaceData()

std::tuple< Value, Value, Value > nk::stats::prepareSurfaceData ( const Value & x,
const Value & y,
const Value & z,
std::pmr::memory_resource * mr = nullptr )

Surface-data cleanup ([xo, yo, zo] = prepareSurfaceData(x, y, z)).

Linearises (column-major) and strips NaN / Inf. Inputs may be equal-length vectors or shape-matched matrices.

Parameters
xx-coordinates.
yy-coordinates.
zz-coordinates.
mrMemory resource (nullptr → process default).
Returns
Cleaned (x, y, z) columns.

◆ quantile()

Value nk::stats::quantile ( const Value & x,
const Value & p,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Empirical quantile (q = quantile(X, p, dim)).

Linear interpolation between order statistics (the default). When p is a length-k vector, the reduced dim of the output has length k (one quantile per requested level).

Parameters
xInput array.
pProbability level(s) in [0, 1]; scalar or vector.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Quantile(s) along dim.
See also
prctile, median

◆ randg() [1/2]

Value nk::stats::randg ( ::nk::ops::RngContext & rng,
const Value & shapeArray,
std::pmr::memory_resource * mr = nullptr )

Per-element gamma RNG (r = randg(shapeArray)).

Draws one sample per entry of shapeArray, with shape = element value. Negative / zero shape entries produce NaN in the output (MATLAB convention).

Parameters
shapeArrayArray-valued shape parameter.
mrMemory resource (nullptr → process default).
Returns
Array same size as shapeArray, one Gamma(shape, 1) draw per entry.
See also
randg

◆ randg() [2/2]

Value nk::stats::randg ( ::nk::ops::RngContext & rng,
double shape,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Raw gamma(shape, 1) RNG (r = randg(shape [, rows, cols])).

MATLAB's undocumented-but-widely-used "raw" gamma sampler. Equivalent to gamrnd(shape, 1.0, rows, cols); uses the shared MT19937 stream so rng(seed) reproduces the draw sequence.

Parameters
shapeShape parameter (shape > 0); array-valued shape is supported via the adapter-only entry — see randg_reg.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of Gamma(shape, 1) samples.
See also
gamrnd

◆ randsample()

Value nk::stats::randsample ( ::nk::ops::RngContext & rng,
int N,
int K,
bool with_replacement,
const Value & weights,
std::pmr::memory_resource * mr = nullptr )

Sample integers from 1..N (r = randsample(N, K, replacement, weights)).

Draws K indices from {1, …, N} with optional weighting.

Parameters
NUpper bound of the sampling range.
KNumber of draws.
with_replacementWhen true, draw with replacement; false → permutation-style without replacement (requires K <= N).
weightsOptional probability weights of length N (pass empty Value for uniform). Need not sum to 1 — re-normalised internally.
mrMemory resource (nullptr → process default).
Returns
K × 1 column of 1-based indices.
See also
datasample

◆ range_of()

Value nk::stats::range_of ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Range = max - min along dim (r = range(x, dim)).

Parameters
xInput array.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Range reduced along dim.

◆ rangesearch()

std::tuple< Value, Value > nk::stats::rangesearch ( const Value & X,
const Value & Y,
double r,
const std::string & metric = "euclidean",
double p = 2.0,
std::pmr::memory_resource * mr = nullptr )

Radius search ([Idx, D] = rangesearch(X, Y, r, metric, p)).

For each row of Y list every row of X within distance r of it. Sorted by ascending distance.

Parameters
XReference points.
YQuery points.
rSearch radius.
metricpdist metric (default "euclidean").
pMinkowski exponent (default 2).
mrMemory resource (nullptr → process default).
Returns
(Idx, D):
  • Idx : M_Y × 1 cell array; each cell is a row of 1-based indices.
  • D : M_Y × 1 cell array of distances.
See also
knnsearch

◆ ranksum()

std::tuple< Value, Value, Value, Value > nk::stats::ranksum ( const Value & x,
const Value & y,
double alpha,
TestTail tail,
const std::string & method,
std::pmr::memory_resource * mr = nullptr )

Wilcoxon rank-sum (Mann-Whitney U) test ([p, h, ranksum_x, zval] = ranksum(x, y, alpha, tail, method)).

H0: median(x) = median(y). Default method is "exact" when both samples have < 10 observations, else "approximate" (normal with tie and continuity correction). zval is NaN in exact mode.

Parameters
xFirst sample.
ySecond sample.
alphaSignificance level.
tailDirection of the alternative.
method"exact" or "approximate".
mrMemory resource (nullptr → process default).
Returns
(p, h, ranksum_x, zval).
See also
signrank

◆ raylcdf()

Value nk::stats::raylcdf ( const Value & x,
double b,
std::pmr::memory_resource * mr = nullptr )

Rayleigh cdf (p = raylcdf(x, b)).

Closed form: \( F(x) = 1 - e^{-x^2/(2b^2)} \) for x >= 0.

Parameters
xEvaluation points (any shape).
bScale parameter.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
raylpdf, raylinv

◆ raylfit()

std::tuple< Value, Value > nk::stats::raylfit ( const Value & x,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Rayleigh MLE ([shat, sci] = raylfit(x, alpha)).

σ̂ = sqrt(Σx² / (2N)). CI from χ² inversion of 2N · σ̂² ~ σ² · χ²(2N).

Parameters
xSample data (positive).
alphaSignificance level.
mrMemory resource (nullptr → process default).
Returns
(shat, sci).

◆ raylinv()

Value nk::stats::raylinv ( const Value & p,
double b,
std::pmr::memory_resource * mr = nullptr )

Rayleigh inverse cdf (x = raylinv(p, b)).

Closed form: x = b · sqrt(-2 · log(1 - p)).

Parameters
pProbability levels in [0, 1] (any shape).
bScale parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
raylcdf

◆ raylpdf()

Value nk::stats::raylpdf ( const Value & x,
double b,
std::pmr::memory_resource * mr = nullptr )

Rayleigh pdf (y = raylpdf(x, b)).

\( f(x; b) = (x/b^2)\,e^{-x^2/(2b^2)} \) for x >= 0.

Parameters
xEvaluation points (any shape).
bScale parameter (b > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
raylcdf, raylinv, raylrnd, raylstat

◆ raylrnd()

Value nk::stats::raylrnd ( ::nk::ops::RngContext & rng,
double b,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Rayleigh random samples (r = raylrnd(b, rows, cols)).

Sampled as X = sqrt(-2·b²·log(U)) with U ~ Uniform(0, 1).

Parameters
bScale parameter.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of Rayleigh samples.
See also
raylpdf

◆ raylstat()

std::tuple< double, double > nk::stats::raylstat ( double b)

Rayleigh mean and variance ([m, v] = raylstat(b)).

Closed form: m = b · sqrt(π/2), v = b² · (2 - π/2).

Parameters
bScale parameter.
Returns
{mean, variance} pair.
See also
raylpdf

◆ regress()

std::tuple< Value, Value, Value, Value > nk::stats::regress ( const Value & y,
const Value & X,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Ordinary least-squares regression ([b, bint, r, stats] = regress(y, X, alpha)).

Fits the linear model y = X · b + ε by OLS.

Parameters
yResponse vector (N × 1).
XDesign matrix (N × p; include a column of ones for an intercept if desired).
alphaSignificance level for the CIs on b (e.g. 0.05).
mrMemory resource (nullptr → process default).
Returns
Tuple (b, bint, r, stats):
  • b : p × 1 coefficient estimates
  • bint : p × 2 confidence intervals at level 1 - α
  • r : N × 1 residuals
  • stats : 1 × 4 row [R², F, p_value, sigma²]. The rint output (outlier intervals on residuals) is not provided in this revision.
See also
ridge, lscov

◆ rescale()

Value nk::stats::rescale ( const Value & A,
double lo,
double hi,
std::pmr::memory_resource * mr = nullptr,
double inputMin = std::numeric_limits< double >::quiet_NaN(),
double inputMax = std::numeric_limits< double >::quiet_NaN() )

Linear range remap (Y = rescale(A, lo, hi)).

Linearly maps A onto [lo, hi]. Constant input collapses to lo.

Parameters
AInput array.
loTarget lower bound (default 0 via overload).
hiTarget upper bound (default 1 via overload).
mrMemory resource (nullptr → process default).
inputMinInput lower bound (NaN → per-column data min). When given, values are clamped to [inputMin, inputMax] before mapping (MATLAB 'InputMin'/'InputMax').
inputMaxInput upper bound (NaN → per-column data max).
Returns
Rescaled array, same shape as A.
See also
normalize

◆ ricecdf()

Value nk::stats::ricecdf ( const Value & x,
double s,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Rician cdf (p = ricecdf(x, s, sigma)).

Computed via the Marcum Q-function: \( F(x) = 1 - Q_1(s/\sigma,\ x/\sigma) \).

Parameters
xEvaluation points (any shape).
sNoncentrality parameter.
sigmaScale parameter.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
ricepdf, riceinv

◆ riceinv()

Value nk::stats::riceinv ( const Value & p,
double s,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Rician inverse cdf (x = riceinv(p, s, sigma)).

Parameters
pProbability levels in [0, 1] (any shape).
sNoncentrality parameter.
sigmaScale parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
ricecdf

◆ ricepdf()

Value nk::stats::ricepdf ( const Value & x,
double s,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Rician (Rice) pdf (y = ricepdf(x, s, sigma)).

\( f(x; s, \sigma) = (x/\sigma^2)\,e^{-(x^2 + s^2)/(2\sigma^2)}\, I_0(x s / \sigma^2) \) for x >= 0. Special case: s = 0 reduces to raylpdf.

Parameters
xEvaluation points (any shape).
sNoncentrality / offset (s >= 0).
sigmaScale parameter (sigma > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
ricecdf, riceinv, ricernd, ricestat, raylpdf

◆ ricernd()

Value nk::stats::ricernd ( ::nk::ops::RngContext & rng,
double s,
double sigma,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Rician random samples (r = ricernd(s, sigma, rows, cols)).

Generated as sqrt(N1² + N2²) with N1 ~ N(s, σ²), N2 ~ N(0, σ²).

Parameters
sNoncentrality parameter.
sigmaScale parameter.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of Rician samples.
See also
ricepdf

◆ ricestat()

std::tuple< double, double > nk::stats::ricestat ( double s,
double sigma,
std::pmr::memory_resource * mr = nullptr )

Rician mean and variance ([m, v] = ricestat(s, sigma)).

Expressed via the Laguerre polynomial L_{1/2} (or equivalently the confluent hypergeometric _1F_1). Returns {mean, variance} computed numerically.

Parameters
sNoncentrality parameter.
sigmaScale parameter.
mrMemory resource (nullptr → process default).
Returns
{mean, variance} pair.
See also
ricepdf

◆ ridge()

Value nk::stats::ridge ( const Value & y,
const Value & X,
const Value & k,
bool scaled,
std::pmr::memory_resource * mr = nullptr )

Ridge regression (B = ridge(y, X, k, scaled)).

Solves (X'X + λI) β = X'y for one or more regularisation values.

Parameters
yResponse vector.
XDesign matrix.
kScalar λ or vector of λ values; output has one column per entry of k.
scaledWhen true (default), returns coefficients in the standardised feature space (centred + unit-variance X). When false, returns coefficients in the original units with an intercept prepended: output is (p + 1) × length(k).
mrMemory resource (nullptr → process default).
Returns
Coefficient matrix.
See also
regress

◆ rmmissing_of()

Value nk::stats::rmmissing_of ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Remove rows / cols containing missing values (y = rmmissing(x)).

Parameters
xInput array.
mrMemory resource (nullptr → process default).
Returns
Compact array with missing entries dropped.
See also
fillmissing_of

◆ rmoutliers_of()

Value nk::stats::rmoutliers_of ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Remove outliers (y = rmoutliers(x)).

Drops entries flagged by isoutlier_of along the first non-singleton dim.

Parameters
xInput array.
mrMemory resource (nullptr → process default).
Returns
x with outlier entries dropped.
See also
isoutlier_of

◆ rmse()

Value nk::stats::rmse ( const Value & f,
const Value & a,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Root-mean-square error (e = rmse(F, A, dim)).

e = sqrt(mean((F - A)².data, dim)).

Parameters
fForecast / predicted values.
aActual / reference values (broadcast-compatible with f).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
RMSE reduced along dim.
See also
mape

◆ robustcov()

RobustcovResult nk::stats::robustcov ( const Value & X,
std::pmr::memory_resource * mr = nullptr )

Robust multivariate covariance estimate via trimmed-MCD ([sigma, mu] = robustcov(X)).

Parameters
XData matrix (n × d, rows = observations).
mrMemory resource for output allocation.
Returns
RobustcovResult containing robust covariance sigma and location mu.
See also
cov, corrcoef

◆ robustfit()

RobustfitResult nk::stats::robustfit ( const Value & X,
const Value & y,
RobustWeight weight = RobustWeight::Bisquare,
double tune = std::numeric_limits< double >::quiet_NaN(),
std::pmr::memory_resource * mr = nullptr )

Robust linear regression via Iteratively Reweighted Least Squares (IRLS) (robustfit(X, y)).

Parameters
XDesign matrix (n × p).
yResponse vector (n × 1).
weightWeight function (Bisquare, Huber, Cauchy, Fair, Logistic, Talwar, Welsch).
tuneTuning constant (NaN to use weight-specific default).
mrMemory resource for output allocation.
Returns
RobustfitResult containing coefficients b and robust scale s.
See also
regress, fitlm

◆ runstest()

std::tuple< Value, Value, Value, Value, Value, Value > nk::stats::runstest ( const Value & x,
double v,
double alpha,
TestTail tail,
const std::string & method,
std::pmr::memory_resource * mr = nullptr )

Wald-Wolfowitz runs test for randomness ([p, h, nruns, n1, n0, zval] = runstest(x, v, alpha, tail, method)).

Default v = median(x); values exactly equal to v are dropped. method ∈ {"exact", "approximate"}. zval is NaN in exact mode.

Parameters
xSample data.
vThreshold for the binary split (NaN → use median(x)).
alphaSignificance level.
tailDirection of the alternative.
methodComputation method.
mrMemory resource (nullptr → process default).
Returns
(p, h, nruns, n1, n0, zval).

◆ signrank()

std::tuple< Value, Value, Value, Value > nk::stats::signrank ( const Value & x,
const Value & y_or_m,
double alpha,
TestTail tail,
const std::string & method,
std::pmr::memory_resource * mr = nullptr )

Wilcoxon signed-rank test ([p, h, signedrank, zval] = signrank(x, y_or_m, alpha, tail, method)).

H0: median(x - m0) = 0 (one-sample) or median(x - y) = 0 (paired). Default method = "exact" if n_eff ≤ 15, else "approximate". zval is NaN in exact mode.

Parameters
xSample data.
y_or_mPaired sample or scalar hypothesised median.
alphaSignificance level.
tailDirection of the alternative.
method"exact" or "approximate".
mrMemory resource (nullptr → process default).
Returns
(p, h, signedrank, zval).
See also
ranksum, signtest

◆ signtest()

std::tuple< Value, Value, Value > nk::stats::signtest ( const Value & x,
const Value & y_or_m,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

Non-parametric sign test ([p, h, sign] = signtest(x, y_or_m, alpha, tail)).

H0: median(x - m0) = 0 (one-sample) or median(x - y) = 0 (paired).

Parameters
xSample data.
y_or_mPaired sample (same length as x) or scalar hypothesised median, depending on y_or_m.numel().
alphaSignificance level.
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(p, h, sign) — p-value, decision, # positive differences.
See also
signrank

◆ silhouette()

Value nk::stats::silhouette ( const Value & X,
const Value & clust,
const std::string & metric = "sqeuclidean",
double p = 2.0,
std::pmr::memory_resource * mr = nullptr )

Per-point silhouette coefficient (s = silhouette(X, clust, metric, p)).

For each point i with label k, computes:

  • a(i) = mean distance to other points with label k (0 if singleton)
  • b(i) = min over labels k' ≠ k of the mean distance from i to cluster k'
  • s(i) = (b(i) - a(i)) / max(a(i), b(i))

Singleton clusters are assigned s(i) = 0.

Parameters
XN × d data matrix (one observation per row).
clustN × 1 integer cluster labels.
metricDistance metric — see pdist (default "sqeuclidean").
pMinkowski exponent (used only for metric == "minkowski", default 2).
mrMemory resource (nullptr → process default).
Returns
Column vector of silhouette coefficients in [-1, 1].
See also
pdist, kmeans

◆ skewness()

Value nk::stats::skewness ( const Value & x,
int normFlag = 1,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Sample skewness along dim (y = skewness(X, normFlag, dim)).

Standardised third central moment: \( E[((X-\mu)/\sigma)^3] \).

  • normFlag = 1 (default): uncorrected y = m3 / m2^1.5
  • normFlag = 0: bias-corrected y *= sqrt(n·(n-1))/(n-2). Requires n >= 3.
Parameters
xInput array.
normFlagBias correction switch (0 or 1).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Skewness reduced along dim.
See also
kurtosis

◆ smoothdata()

Value nk::stats::smoothdata ( const Value & x,
const std::string & method = "movmean",
int k = 0,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Method-dispatching data smoother (y = smoothdata(x, method, k)).

Routes to the requested moving-window kernel.

Parameters
xInput array.
methodOne of:
  • "movmean" (default) → movmean
  • "movmedian" → movmedian
  • "gaussian" → Gaussian-weighted mean with sigma = (k-1)/4 The "lowess", "loess", "rlowess", "rloess", "sgolay" throw m:smoothdata:unsupportedMethod.
kCentred window length. Pass 0 for the default heuristic max(min(round(0.1·n), 10), 3).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Smoothed array, same shape as x.
Exceptions
ErrorUnsupported method (m:smoothdata:unsupportedMethod).
See also
movmean, movmedian

◆ squareform()

Value nk::stats::squareform ( const Value & d,
std::pmr::memory_resource * mr = nullptr )

Pack / unpack the pdist row form (Y = squareform(d)).

Converts a pdist row into a symmetric square matrix, or a square matrix back into a pdist row.

Parameters
dpdist row OR symmetric square matrix.
mrMemory resource (nullptr → process default).
Returns
Square matrix or pdist row, the other shape.
See also
pdist

◆ standardizeMissing_of()

Value nk::stats::standardizeMissing_of ( const Value & x,
double sentinel,
std::pmr::memory_resource * mr = nullptr )

Convert sentinel value to missing (y = standardizeMissing(x, sentinel)).

Replaces sentinel entries with NaN.

Parameters
xInput array.
sentinelValue to treat as missing.
mrMemory resource (nullptr → process default).
Returns
Array with sentinel → NaN.

◆ stdev()

Value nk::stats::stdev ( const Value & x,
int normFlag = 0,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Sample / population standard deviation (y = std(X, normFlag, dim)).

Computed as sqrt(var(X, normFlag, dim)).

Parameters
xInput array.
normFlag0 (default, unbiased) or 1 (population).
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Standard deviation reduced along dim.
See also
var

◆ tabulate()

Value nk::stats::tabulate ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Frequency table (T = tabulate(x)).

Returns a 3-column [value, count, percent] matrix. Dense layout for positive-integer inputs (rows for k = 1..max(x)); otherwise sparse (one row per unique value, sorted ascending). NaN entries excluded both from the row set and the percentage denominator.

Parameters
xInput array.
mrMemory resource (nullptr → process default).
Returns
[value, count, percent] matrix.

◆ tcdf()

Value nk::stats::tcdf ( const Value & x,
double nu,
std::pmr::memory_resource * mr = nullptr )

Student's t cdf (F = tcdf(x, nu)).

Computed via the regularised incomplete beta with the symmetry of the t: for x >= 0: F = 1 - ½·I_{ν/(ν+x²)}(ν/2, ½); for x < 0: F = ½·I_{ν/(ν+x²)}(ν/2, ½).

Parameters
xEvaluation points (any shape).
nuDegrees of freedom (nu > 0).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
tpdf, tinv

◆ tiedrank()

std::pair< Value, Value > nk::stats::tiedrank ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Tie-corrected ranks ([r, tieadj] = tiedrank(x)).

Equal values share the average of their would-be sequential ranks. Vector input → scalar tieadj; matrix input applies column-wise and tieadj is a 1 × cols row. NaN entries keep NaN rank.

Parameters
xInput array.
mrMemory resource (nullptr → process default).
Returns
(ranks, tie_adjustment) pair.

◆ tinv()

Value nk::stats::tinv ( const Value & p,
double nu,
std::pmr::memory_resource * mr = nullptr )

Student's t inverse cdf (x = tinv(p, nu)).

Computed via betaincinv.

Parameters
pProbability levels in [0, 1] (any shape).
nuDegrees of freedom (nu > 0).
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
tcdf

◆ tpdf()

Value nk::stats::tpdf ( const Value & x,
double nu,
std::pmr::memory_resource * mr = nullptr )

Student's t pdf (y = tpdf(x, nu)).

\( f(x; \nu) = \dfrac{\Gamma((\nu+1)/2)}{\sqrt{\nu\pi}\,\Gamma(\nu/2)} \left(1 + x^2/\nu\right)^{-(\nu+1)/2} \). Symmetric around 0; converges to standard normal as nu → ∞.

Parameters
xEvaluation points (any shape).
nuDegrees of freedom (nu > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
tcdf, tinv, trnd, tstat

◆ trimmean_of()

Value nk::stats::trimmean_of ( const Value & x,
double pct,
int dim = 0,
bool useFloor = false,
std::pmr::memory_resource * mr = nullptr )

Trimmed mean (m = trimmean(x, pct, dim)).

Mean after dropping the smallest and largest pct/2 percent of values.

Parameters
xInput array.
pctTotal trim percentage in [0, 100).
dim1-based dimension; 0 → first non-singleton dim.
useFloorRounding of the per-end trim count: false (default, MATLAB 'round') rounds n*pct/200 half-down; true (MATLAB 'floor') takes the floor.
mrMemory resource (nullptr → process default).
Returns
Trimmed mean reduced along dim.

◆ trnd()

Value nk::stats::trnd ( ::nk::ops::RngContext & rng,
double nu,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Student's t random samples (r = trnd(nu, rows, cols)).

Sampled as Z / sqrt(X / nu) where Z ~ N(0,1), X ~ χ²(nu).

Parameters
nuDegrees of freedom (nu > 0).
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of t-samples.
See also
tpdf

◆ tstat()

std::tuple< double, double > nk::stats::tstat ( double nu)

Student's t mean and variance ([m, v] = tstat(nu)).

Closed form: m = 0 for nu > 1 (else undefined), v = nu/(nu - 2) for nu > 2 (else NaN / Inf).

Parameters
nuDegrees of freedom.
Returns
{mean, variance} pair (returns NaN for variance when nu <= 2).
See also
tpdf

◆ ttest()

std::tuple< Value, Value, Value, Value > nk::stats::ttest ( const Value & x,
double m,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

One-sample Student's t-test ([h, p, ci, t] = ttest(x, m, alpha, tail)).

Tests H0: mean(x) = m versus the alternative selected by tail.

Parameters
xSample data (1-D).
mHypothesised mean (default 0).
alphaSignificance level (default 0.05).
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(h, p, ci, tstat).
See also
ttest2, ztest

◆ ttest2()

std::tuple< Value, Value, Value, Value > nk::stats::ttest2 ( const Value & x,
const Value & y,
double alpha,
TestTail tail,
const std::string & vartype,
std::pmr::memory_resource * mr = nullptr )

Two-sample t-test ([h, p, ci, t] = ttest2(x, y, alpha, tail, vartype)).

H0: mean(x) = mean(y).

Parameters
xFirst sample.
ySecond sample.
alphaSignificance level.
tailDirection of the alternative.
vartype"equal" (pooled variance) or "unequal" (Welch, default).
mrMemory resource (nullptr → process default).
Returns
(h, p, ci, tstat).
See also
ttest, vartest2

◆ unidcdf()

Value nk::stats::unidcdf ( const Value & k,
double N,
std::pmr::memory_resource * mr = nullptr )

Discrete-uniform cdf (F = unidcdf(k, N)).

Closed form: F(k) = floor(k) / N clipped to [0, 1].

Parameters
kEvaluation points (any shape).
NUpper bound of support.
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
unidpdf, unidinv

◆ unidinv()

Value nk::stats::unidinv ( const Value & p,
double N,
std::pmr::memory_resource * mr = nullptr )

Discrete-uniform inverse cdf (k = unidinv(p, N)).

Closed form: k = ceil(p · N).

Parameters
pProbability levels in [0, 1] (any shape).
NUpper bound of support.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
unidcdf

◆ unidpdf()

Value nk::stats::unidpdf ( const Value & k,
double N,
std::pmr::memory_resource * mr = nullptr )

Discrete-uniform pmf (y = unidpdf(k, N)).

f = 1/N for k ∈ {1, 2, …, N}, 0 elsewhere.

Parameters
kEvaluation points (any shape).
NUpper bound of support (positive integer-valued double).
mrMemory resource (nullptr → process default).
Returns
Array of pmf values, same shape as k.
See also
unidcdf, unidinv, unidrnd, unidstat

◆ unidrnd()

Value nk::stats::unidrnd ( ::nk::ops::RngContext & rng,
double N,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Discrete-uniform random samples (r = unidrnd(N, rows, cols)).

Parameters
NUpper bound of support.
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of discrete-uniform samples.
See also
unidpdf

◆ unidstat()

std::tuple< double, double > nk::stats::unidstat ( double N)

Discrete-uniform mean and variance ([m, v] = unidstat(N)).

Closed form: m = (N+1)/2, v = (N² - 1)/12.

Parameters
NUpper bound of support.
Returns
{mean, variance} pair.
See also
unidpdf

◆ unifcdf()

Value nk::stats::unifcdf ( const Value & x,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Continuous-uniform cdf (p = unifcdf(x, a, b)).

Closed form: 0 for x < a, (x-a)/(b-a) for x ∈ [a, b], 1 for x > b.

Parameters
xEvaluation points (any shape).
aLower bound.
bUpper bound (b > a).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1], same shape as x.
See also
unifpdf, unifinv

◆ unifinv()

Value nk::stats::unifinv ( const Value & p,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Continuous-uniform inverse cdf (x = unifinv(p, a, b)).

Closed form: a + p·(b-a).

Parameters
pProbability levels in [0, 1] (any shape).
aLower bound.
bUpper bound (b > a).
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
unifcdf

◆ unifit()

std::tuple< Value, Value, Value, Value > nk::stats::unifit ( const Value & x,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Continuous-uniform MLE ([ahat, bhat, aci, bci] = unifit(x, alpha)).

a = min(x), b = max(x). CI based on (b - a) · (alpha^{-1/n} - 1).

Parameters
xSample data.
alphaSignificance level.
mrMemory resource (nullptr → process default).
Returns
(ahat, bhat, aci, bci).

◆ unifpdf()

Value nk::stats::unifpdf ( const Value & x,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Continuous-uniform pdf (y = unifpdf(x, a, b)).

Constant 1/(b-a) inside [a, b], 0 outside. Broadcasts over x.

Parameters
xEvaluation points (any shape).
aLower bound of the support.
bUpper bound of the support (b > a).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
unifcdf, unifinv, unifrnd, unifstat

◆ unifrnd()

Value nk::stats::unifrnd ( ::nk::ops::RngContext & rng,
double a,
double b,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Continuous-uniform random samples (r = unifrnd(a, b, rows, cols)).

Parameters
aLower bound.
bUpper bound (b > a).
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of uniform samples.
See also
unifpdf

◆ unifstat()

std::tuple< double, double > nk::stats::unifstat ( double a,
double b )

Continuous-uniform mean and variance ([m, v] = unifstat(a, b)).

Closed form: m = (a+b)/2, v = (b-a)²/12.

Parameters
aLower bound.
bUpper bound.
Returns
{mean, variance} pair.
See also
unifpdf

◆ var()

Value nk::stats::var ( const Value & x,
int normFlag = 0,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Sample / population variance along dim (y = var(X, normFlag, dim)).

Parameters
xInput array.
normFlag0 → divide by N-1 (default, sample), 1 → divide by N.
dim1-based dimension; 0 → first non-singleton dim.
mrMemory resource (nullptr → process default).
Returns
Variance reduced along dim.
Exceptions
ErrornormFlag not in {0, 1} (m:var:badNormFlag).
See also
stdev

◆ vartest()

std::tuple< Value, Value, Value, Value > nk::stats::vartest ( const Value & x,
double v,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

Chi-squared one-sample variance test ([h, p, ci, chi2] = vartest(x, v, alpha, tail)).

H0: var(x) = v.

Parameters
xSample data.
vHypothesised variance.
alphaSignificance level.
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(h, p, ci, chisqstat).
See also
vartest2

◆ vartest2()

std::tuple< Value, Value, Value, Value > nk::stats::vartest2 ( const Value & x,
const Value & y,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

F-test for equality of two variances ([h, p, ci, F] = vartest2(x, y, alpha, tail)).

H0: var(x) = var(y).

Parameters
xFirst sample.
ySecond sample.
alphaSignificance level.
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(h, p, ci, Fstat).
See also
vartest

◆ vartestn()

std::tuple< Value, Value, Value > nk::stats::vartestn ( const Value & x,
const Value & group,
double alpha,
std::pmr::memory_resource * mr = nullptr )

Bartlett's k-sample variance test ([p, chi2, df] = vartestn(x, group, alpha)).

H0: all group variances are equal.

Parameters
xPooled sample column.
groupGroup labels (same length as x).
alphaSignificance level.
mrMemory resource (nullptr → process default).
Returns
(p, chisqstat, df).
See also
vartestn_full

◆ vartestn_full()

std::tuple< Value, Value, Value, Value > nk::stats::vartestn_full ( const Value & x,
const Value & group,
int test,
std::pmr::memory_resource * mr = nullptr )

Full k-sample variance test with method selection (vartestn_full(x, group, test)).

test selects the statistic:

  • 0 = Bartlett (χ², df2 = NaN)
  • 1 = Levene quadratic
  • 2 = Levene absolute
  • 3 = Brown-Forsythe
  • 4 = O'Brien

For non-Bartlett tests df1 = k - 1, df2 = N - k.

Parameters
xPooled sample column.
groupGroup labels.
testStatistic selector (0..4).
mrMemory resource (nullptr → process default).
Returns
(p, stat, df1, df2).

◆ wblcdf()

Value nk::stats::wblcdf ( const Value & x,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Weibull cdf (p = wblcdf(x, a, b)).

Closed form: \( F(x) = 1 - e^{-(x/a)^b} \) for x >= 0.

Parameters
xEvaluation points (any shape).
aScale parameter (a > 0).
bShape parameter (b > 0).
mrMemory resource (nullptr → process default).
Returns
Array of cdf values in [0, 1].
See also
wblpdf, wblinv

◆ wblfit() [1/2]

Value nk::stats::wblfit ( const Value & x,
const Value & censoring,
const Value & freq,
std::pmr::memory_resource * mr = nullptr )

Weibull MLE fit with right-censoring and frequency weights ([parmhat, parmci] = wblfit(x, alpha, cens, freq)).

Likelihood is ∏ f(x_i)^(u_i · f_i) · S(x_i)^(c_i · f_i) where S(x; a, b) = exp(-(x/a)^b) is the Weibull survival. Closed-form fast path used when both censoring and freq are empty/trivial; otherwise profiles a(b) = (Σ f_i x_i^b / Σ f_i u_i)^{1/b} and 1-D Newtons on b.

◆ wblfit() [2/2]

Value nk::stats::wblfit ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Weibull MLE fit ([ahat, bhat] = wblfit(x)).

Solves the MLE system for Weibull(a, b) (a = scale, b = shape). The shape b satisfies the implicit equation

1/b + mean(log x) - Σ x_i^b · log(x_i) / Σ x_i^b = 0

solved via Newton iteration on b starting from the moment-based initial guess. Scale follows as a = (Σ x_i^b / n)^{1/b}.

Parameters
xPositive sample data.
mrMemory resource (nullptr → process default).
Returns
[ahat, bhat] as a 1 × 2 row (scale, shape).

◆ wblfit_ci()

Value nk::stats::wblfit_ci ( const Value & x,
double alpha = 0.05,
std::pmr::memory_resource * mr = nullptr )

95% Wald CI for wblfit (pci = wblfit_ci(x, alpha)).

Returns the 2 × 2 confidence matrix [lo; hi] for [a, b] from the observed Fisher information (central-FD Hessian of NLL). Both parameters use a log-scale Wald CI (MATLAB convention).

◆ wblinv()

Value nk::stats::wblinv ( const Value & p,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Weibull inverse cdf (x = wblinv(p, a, b)).

Closed form: x = a · (-log(1 - p))^(1/b).

Parameters
pProbability levels in [0, 1] (any shape).
aScale parameter.
bShape parameter.
mrMemory resource (nullptr → process default).
Returns
Quantile array, same shape as p.
See also
wblcdf

◆ wbllike()

double nk::stats::wbllike ( double a,
double b,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Weibull nLogL (nLogL = wbllike(a, b, x)).

Parameters
aScale parameter.
bShape parameter.
xSample data.
mrMemory resource (nullptr → process default).
Returns
Scalar negative log-likelihood.

◆ wblpdf()

Value nk::stats::wblpdf ( const Value & x,
double a,
double b,
std::pmr::memory_resource * mr = nullptr )

Weibull pdf (y = wblpdf(x, a, b)).

\( f(x; a, b) = (b/a)\,(x/a)^{b-1}\,e^{-(x/a)^b} \) for x >= 0. Convention: a = scale, b = shape. Note: std::weibull_distribution uses the opposite order (shape, scale).

Parameters
xEvaluation points (any shape).
aScale parameter (a > 0).
bShape parameter (b > 0).
mrMemory resource (nullptr → process default).
Returns
Array of pdf values, same shape as x.
See also
wblcdf, wblinv, wblrnd, wblstat

◆ wblrnd()

Value nk::stats::wblrnd ( ::nk::ops::RngContext & rng,
double a,
double b,
size_t rows = 1,
size_t cols = 1,
std::pmr::memory_resource * mr = nullptr )

Weibull random samples (r = wblrnd(a, b, rows, cols)).

Parameters
aScale parameter (a > 0).
bShape parameter (b > 0).
rowsOutput rows (default 1).
colsOutput columns (default 1).
mrMemory resource (nullptr → process default).
Returns
rows × cols matrix of Weibull samples.
See also
wblpdf

◆ wblstat()

std::tuple< double, double > nk::stats::wblstat ( double a,
double b )

Weibull mean and variance ([m, v] = wblstat(a, b)).

Closed form: m = a · Γ(1 + 1/b), v = a² · [Γ(1 + 2/b) - Γ(1 + 1/b)²].

Parameters
aScale parameter.
bShape parameter.
Returns
{mean, variance} pair.
See also
wblpdf

◆ wishrnd()

Value nk::stats::wishrnd ( ::nk::ops::RngContext & rng,
const Value & Sigma,
double df,
std::pmr::memory_resource * mr = nullptr )

Wishart random matrix (W = wishrnd(Sigma, df)).

Draws one p × p positive-definite matrix from the Wishart distribution W_p(Sigma, df) via Bartlett decomposition:

  • Factor Sigma = L · L' (lower Cholesky).
  • Sample B lower triangular with B(i,i) = sqrt(χ²(df - i)) and B(i,j) ~ N(0,1) for i > j.
  • Then M = L · B and W = M · M'.

df must satisfy df > p - 1.

KNOWN GAPs: third-argument D (pre-computed Cholesky) and the two-output [W, D] = wishrnd(...) form are deferred.

Parameters
Sigmap × p symmetric positive-definite scale matrix.
dfDegrees of freedom (> p - 1).
mrMemory resource (nullptr → process default).
Returns
Single p × p Wishart draw.
See also
iwishrnd, mvnrnd

◆ wishrnd_factor()

std::tuple< Value, Value > nk::stats::wishrnd_factor ( ::nk::ops::RngContext & rng,
const Value & Sigma,
double df,
const Value & D,
std::pmr::memory_resource * mr = nullptr )

Wishart sample with pre-computed Cholesky factor (W = wishrnd(Sigma, df, D)).

If D is empty, internally compute D = chol(Sigma, 'upper'); otherwise reuse the supplied factor (which must satisfy D' * D == Sigma). The 2-output form returns the Cholesky factor.

Parameters
Sigmap × p covariance / scale matrix.
dfDegrees of freedom (df > p - 1).
DPre-computed chol(Sigma, 'upper'), or Value::Empty.
mrMemory resource.
Returns
{W, D} — Wishart draw and the upper-Cholesky factor.

◆ zscore()

Value nk::stats::zscore ( const Value & A,
std::pmr::memory_resource * mr = nullptr )

Z-score normalisation (Y = zscore(A)).

Convenience alias for normalize(A, "zscore").

Parameters
AInput matrix.
mrMemory resource (nullptr → process default).
Returns
Z-score-normalised matrix.
See also
normalize

◆ ztest()

std::tuple< Value, Value, Value, Value > nk::stats::ztest ( const Value & x,
double m,
double sigma,
double alpha,
TestTail tail,
std::pmr::memory_resource * mr = nullptr )

Z-test with known σ ([h, p, ci, z] = ztest(x, m, sigma, alpha, tail)).

H0: mean(x) = m assuming the population standard deviation sigma is known.

Parameters
xSample data.
mHypothesised mean.
sigmaKnown population standard deviation (sigma > 0).
alphaSignificance level.
tailDirection of the alternative.
mrMemory resource (nullptr → process default).
Returns
(h, p, ci, zstat).
See also
ttest