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 ¶m=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)). | |
Descriptive statistics, 20+ probability distributions, hypothesis testing (t-test, ANOVA), regression models, PCA, and clustering.
|
strong |
GLM family of error distributions.
Definition at line 218 of file regress.hpp.
|
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.
|
strong |
|
strong |
Multiple-comparison correction methods for multcompare.
|
strong |
Robust regression weight functions (MATLAB robustfit set).
Definition at line 158 of file regress.hpp.
|
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.
| 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.
| x | Sample data (length ≥ 8 for reliable p-values). |
| alpha | Significance level (default 0.05). |
| mr | Memory resource (nullptr → process default). |
| 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.
| y | Response vector. |
| group | Grouping labels (same length as y). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | First sample. |
| y | Second sample. |
| alpha | Significance level (default 0.05). |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |
Augment knot sequence (aug = augknt(knots, k)).
Pads knots so each endpoint has multiplicity k. Used to build B-spline open knot vectors.
| knots | Interior knot vector (non-decreasing). |
| k | Spline order. |
| mr | Memory resource (nullptr → process default). |
| 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.
| y | Real 1-D series. |
| numLags | Number of lags; < 0 → MATLAB default min(20, N-1). |
| numSTD | Bound width in standard errors (MATLAB default 2). |
| mr | Memory resource (nullptr → process default). |
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.
| t | Non-decreasing knot vector. |
| k | Spline order (k >= 1). |
| mr | Memory resource (nullptr → process default). |
| 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) \).
| x | Evaluation points (any shape). |
| a | First shape parameter (a > 0). |
| b | Second shape parameter (b > 0). |
| mr | Memory resource (nullptr → process default). |
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].
| x | Samples in [0, 1]. |
| mr | Memory resource. |
| 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).
| 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.
| p | Probability levels in [0, 1] (any shape). |
| a | First shape parameter. |
| b | Second shape parameter. |
| mr | Memory resource (nullptr → process default). |
| double nk::stats::betalike | ( | double | a, |
| double | b, | ||
| const Value & | x, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Beta nLogL (nLogL = betalike(a, b, x)).
| a | First shape parameter. |
| b | Second shape parameter. |
| x | Sample data in (0, 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| a | First shape parameter (a > 0). |
| b | Second shape parameter (b > 0). |
| mr | Memory resource (nullptr → process default). |
| 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).
| a | First shape parameter (a > 0). |
| b | Second shape parameter (b > 0). |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| a | First shape parameter. |
| b | Second shape parameter. |
| 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.
| k | Evaluation points (any shape). |
| n | Number of trials. |
| p | Success probability per trial. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Success counts (scalar or vector). |
| n | Trial counts (matching shape). |
| alpha | Significance level. |
| mr | Memory resource (nullptr → process default). |
| 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.
| p_in | Probability levels in [0, 1] (any shape). |
| n | Number of trials. |
| p | Success probability per trial. |
| mr | Memory resource (nullptr → process default). |
| 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.
| k | Random-variable values where the pmf is evaluated. Any shape; output matches k. Non-integer or out-of-range entries return 0. |
| n | Number of trials (positive integer-valued double). |
| p | Success probability per trial, 0 ≤ p ≤ 1. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| n | Number of trials. |
| p | Success probability per trial. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| n | Number of trials. |
| p | Success probability per trial. |
| 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)).
| x | Input array. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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.
| breaks | Distinct break values. |
| mults | Multiplicities (length(mults) == length(breaks)). |
| mr | Memory resource (nullptr → process default). |
| 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).
| X | n × p first set of variables. |
| Y | n × q second set of variables (rows(Y) == rows(X)). |
| mr | Memory resource (nullptr → process default). |
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) \).
| x | Evaluation points (any shape). |
| k | Degrees of freedom (k > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| observed | Observed count vector (length k). |
| expected | Expected count vector (length k). |
| nparams | Number of distribution parameters estimated from data (0 for fully specified null). |
| alpha | Significance level. |
| mr | Memory resource (nullptr → process default). |
Chi-squared inverse cdf (x = chi2inv(p, k)).
Computed via gammaincinv: x = 2 · P^{-1}(p; k/2).
| p | Probability levels in [0, 1] (any shape). |
| k | Degrees of freedom (k > 0). |
| mr | Memory resource (nullptr → process default). |
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.
| x | Evaluation points (any shape; broadcasts elementwise). |
| k | Degrees of freedom (k > 0). |
| mr | Memory resource (nullptr → process default). |
| 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).
| k | Degrees of freedom (k > 0). |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| std::tuple< double, double > nk::stats::chi2stat | ( | double | k | ) |
Chi-squared mean and variance ([m, v] = chi2stat(k)).
Closed form: m = k, v = 2k.
| k | Degrees of freedom. |
| 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:
| SIGMA | Symmetric covariance matrix. |
| mr | Memory resource (nullptr → process default). |
| 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:
| sample | N_samp × d points to classify. |
| training | N_trn × d training data. |
| group | N_trn × 1 numeric class labels. |
| type | Discriminant model — see list above. |
| mr | Memory resource (nullptr → process default). |
| 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.
| Z | Linkage table from linkage. |
| maxclust | See cluster_from_linkage. |
| cutoff | See cluster_from_linkage. |
| criterion | "inconsistent" or "distance". |
| depth | Inconsistency-coefficient depth (≥ 1). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| Z | Linkage table from linkage. |
| maxclust | Cap number of clusters (cuts at the lowest distance that yields ≤ maxclust clusters). Pass 0 to ignore. |
| cutoff | Cut at given inconsistency / distance threshold. |
| criterion | "inconsistent" (default) or "distance". |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | Raw data matrix (N×D). |
| maxclust | See cluster_from_linkage. |
| cutoff | See cluster_from_linkage. |
| linkage_method | Linkage rule. |
| criterion | Threshold criterion. |
| depth | Inconsistency-coefficient depth. |
| distance_metric | Distance metric for the internal pdist. |
| p | Metric parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | Raw data matrix (N×D). |
| maxclust | See cluster_from_linkage. |
| cutoff | See cluster_from_linkage. |
| linkage_method | Linkage rule. |
| criterion | Threshold criterion. |
| depth | Inconsistency-coefficient depth. |
| mr | Memory resource (nullptr → process default). |
| 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).
| X | Raw data matrix (N×D). |
| maxclust | See cluster_from_linkage. |
| cutoff | See cluster_from_linkage. |
| linkage_method | Linkage rule. |
| criterion | Threshold criterion. |
| mr | Memory resource (nullptr → process default). |
| Value nk::stats::combnk | ( | int | N, |
| int | K, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Enumerate K-combinations of 1..N (C = combnk(N, K)).
| N | Population size (combinations drawn from 1..N). |
| K | Combination size. |
| mr | Memory resource (nullptr → process default). |
| Error | K out of [0, N]. |
Enumerate K-combinations of an arbitrary vector (C = combnk(v, K)).
| v | Input vector (length n). |
| K | Combination size. |
| mr | Memory resource (nullptr → process default). |
| Error | K out of [0, v.size()]. |
| 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.
| Z | Linkage table from linkage. |
| Y | Original pdist row vector. |
| mr | Memory resource (nullptr → process default). |
| 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.
| 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).
| 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.
| 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+).
| 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.
Auto-correlation across columns of X (R = corr(X)).
Equivalent to corrcoef(X). Non-Pearson type options ("Spearman", "Kendall") deferred.
| X | Input matrix. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| X | First matrix. |
| Y | Second matrix (Y.rows == X.rows). |
| mr | Memory resource (nullptr → process default). |
| Value nk::stats::corrcoef | ( | const Value & | x, |
| const Value & | y, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Joint correlation matrix (R = corrcoef(X, Y)).
| x | First vector / matrix. |
| y | Second vector / matrix (compatible shape). |
| mr | Memory resource (nullptr → process default). |
| 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.
| C | Covariance matrix. |
| mr | Memory resource (nullptr → process default). |
| Error | Negative diagonal entry (m:corrcov:negDiag). |
| 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.
| x | First vector. |
| y | Second vector (same length as x). |
| normFlag | 0 (sample) or 1 (population). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| normFlag | 0 (default, sample, divide by n-1) or 1 (population, by n). |
| mr | Memory resource (nullptr → process default). |
| 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.
| y1 | First real 1-D series. |
| y2 | Second real 1-D series (same length as y1). |
| numLags | Number of lags each side; < 0 → default min(20, N-1). |
| numSTD | Bound width in standard errors (default 2). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input data column. |
| y_opt | Second column (Value::Empty for single-arg form). |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Sample sites (strictly increasing). |
| y | Sample values (matching shape with x). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| X | Source data (matrix or higher-D array). |
| K | Number of draws. |
| dim | 1-based dimension to sample along (1 = rows, 2 = columns). |
| with_replacement | When true, draw with replacement. |
| weights | Optional probability weights along dim (pass empty Value for uniform). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| mr | Memory resource (nullptr → process default). |
| 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::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.
| X | N×D data matrix or N×N precomputed distances. |
| eps | Neighbourhood radius. |
| minpts | Minimum neighbour count for a core point. |
| metric | pdist metric, or "precomputed". |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| order | Polynomial order (default 1 = linear). |
| mr | Memory resource (nullptr → process default). |
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.
| group | Categorical labels (N-element vector). |
| mr | Memory resource (nullptr → process default). |
| 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.
| r | OLS residuals (length n, column). |
| X | Design matrix (n × k) used to fit the residuals. |
| mr | Memory resource (nullptr → process default). |
| 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.
| y | Input samples. |
| mr | Memory resource (nullptr → process default). |
| 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.
| f | f column from ecdf. |
| x | x column from ecdf. |
| m | Number of bins (default 10). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Observations. |
| censoring | Length-n 0/1 indicator (1 = right-censored). Pass Value::Empty to disable. |
| freq | Length-n non-negative frequency weights. Pass Value::Empty to disable (uniform weight). |
| mr | Memory resource. |
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).
| x | Observations. |
| mr | Memory resource. |
| 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).
| 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)).
| p | Probability levels in [0, 1] (any shape). |
| mu | Location parameter. |
| sigma | Scale parameter. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| mu | Location parameter. |
| sigma | Scale parameter. |
| x | Sample data. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| mu | Location parameter. |
| sigma | Scale parameter (sigma > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| mu | Location parameter. |
| sigma | Scale parameter. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| mu | Location parameter. |
| sigma | Scale parameter. |
| 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.
| x | Sample data. |
| alpha | Significance level. |
| cens | Right-censoring mask (Value::Empty → no censoring). |
| freq | Per-sample weights (Value::Empty → ones). |
| mr | Memory resource (nullptr → process default). |
Exponential inverse cdf (x = expinv(p, mu)).
Closed form: x = -mu · log(1 - p).
| p | Probability levels in [0, 1] (any shape). |
| mu | Mean of the distribution. |
| mr | Memory resource (nullptr → process default). |
| double nk::stats::explike | ( | double | mu, |
| const Value & | x, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Exponential nLogL (nLogL = explike(mu, x)).
| mu | Mean parameter. |
| x | Sample data. |
| mr | Memory resource (nullptr → process default). |
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).
| x | Evaluation points (any shape). |
| mu | Mean of the distribution (mu > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| mu | Mean of the distribution. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| std::tuple< double, double > nk::stats::expstat | ( | double | mu | ) |
Exponential mean and variance ([m, v] = expstat(mu)).
Closed form: m = mu, v = mu².
| mu | Mean parameter. |
| 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) \).
| x | Evaluation points (any shape). |
| v1 | Numerator degrees of freedom (v1 > 0). |
| v2 | Denominator degrees of freedom (v2 > 0). |
| mr | Memory resource (nullptr → process default). |
| 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".
| x | Input array. |
| method | Fill method name. |
| constVal | Constant value for "constant" method (default 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| A | Input vector / matrix (column-wise). |
| fillMethod | Fill rule (numeric scalar or method string). |
| findMethod | "median" (default), "mean", or "quartiles". |
| thresholdFactor | Detection 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. |
| mr | Memory resource (nullptr → process default). |
| Error | if findMethod is unsupported by this C++ entry. |
| 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.
| p | Probability levels in [0, 1] (any shape). |
| v1 | Numerator degrees of freedom. |
| v2 | Denominator degrees of freedom. |
| mr | Memory resource (nullptr → process default). |
| 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.
| T | 2 × 2 contingency table. |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |
| 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.
| pp | pp-form spline. |
| part | Field name. |
| mr | Memory resource (nullptr → process default). |
| Error | Unknown field name (m:fnbrk:badPart). |
| 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)).
| pp1 | First pp-form spline. |
| c1 | Coefficient on pp1. |
| pp2 | Second spline. Pass Value::Empty for the scalar-multiply form. |
| c2 | Coefficient on pp2 (ignored when pp2.isEmpty()). |
| mr | Memory resource (nullptr → process default). |
| Error | Mismatched breaks / order / dim (m:fncmb:incompatible). |
Differentiate a pp-form spline (dpp = fnder(pp, order)).
Differentiates the spline order times (default 1). Result has reduced polynomial order K - order.
| pp | pp-form spline. |
| order | Differentiation order (>= 1, default 1). |
| mr | Memory resource (nullptr → process default). |
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.
| pp | pp-form spline. |
| mr | Memory resource (nullptr → process default). |
| 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.
| pp | pp-form spline produced by ppmak / csapi. |
| x | Evaluation points (any shape). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| v1 | Numerator degrees of freedom (v1 > 0). |
| v2 | Denominator degrees of freedom (v2 > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | n × k data matrix (blocks × treatments). |
| reps | Replicates per cell (only 1 is currently supported). |
| mr | Memory resource (nullptr → process default). |
| 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).
| v1 | Numerator degrees of freedom. |
| v2 | Denominator degrees of freedom. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| v1 | Numerator degrees of freedom. |
| v2 | Denominator degrees of freedom. |
| 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) \).
| x | Evaluation points (any shape). |
| a | Shape parameter (a > 0). |
| b | Scale parameter (b > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
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.
| x | Positive sample data (1-D vector or matrix; flattened). |
| mr | Memory resource (nullptr → process default). |
| 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).
| 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).
| p | Probability levels in [0, 1] (any shape). |
| a | Shape parameter (a > 0). |
| b | Scale parameter (b > 0). |
| mr | Memory resource (nullptr → process default). |
| double nk::stats::gamlike | ( | double | a, |
| double | b, | ||
| const Value & | x, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Gamma nLogL (nLogL = gamlike(a, b, x)).
| a | Shape parameter. |
| b | Scale parameter. |
| x | Sample data. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Evaluation points (any shape). |
| a | Shape parameter (a > 0). |
| b | Scale parameter (b > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| a | Shape parameter (a > 0). |
| b | Scale parameter (b > 0). |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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².
| a | Shape parameter. |
| b | Scale parameter. |
Geometric inverse cdf (k = geoinv(q, p)).
Smallest non-negative integer k such that geocdf(k, p) >= q.
| q | Probability levels in [0, 1] (any shape). |
| p | Success probability per trial. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array (positive values). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
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.
| k | Evaluation points (any shape). |
| p | Success probability per trial, 0 < p <= 1. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| p | Success probability per trial. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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².
| p | Success probability per trial. |
GEV MLE fit ([parmhat, parmci] = gevfit(x, alpha)).
Maximum likelihood estimation of the 3-parameter GEV (k, σ, μ):
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.
| x | Observations. |
| mr | Memory resource. |
| 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).
| 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)).
| p | Probability levels in [0, 1] (any shape). |
| k | Shape parameter. |
| sigma | Scale parameter. |
| mu | Location parameter. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| k | Shape parameter. |
| sigma | Scale parameter. |
| mu | Location parameter. |
| x | Sample data. |
| mr | Memory resource (nullptr → process default). |
| 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:
For k ≠ 0, the standardised t = 1 + k·(x-mu)/sigma must be > 0.
| x | Evaluation points (any shape). |
| k | Shape parameter (any real). |
| sigma | Scale parameter (sigma > 0). |
| mu | Location parameter. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| k | Shape parameter. |
| sigma | Scale parameter. |
| mu | Location parameter. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| k | Shape parameter. |
| sigma | Scale parameter. |
| mu | Location parameter. |
| 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:
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):
| X | Design matrix (n × p, no intercept column). |
| y | Response (n × 1). |
| distr | Distribution family. |
| link | Link function (default = canonical for distr). |
| mr | Memory resource (nullptr → process default). |
| 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).
| b | Coefficient vector from glmfit. |
| X | Query points (m × p, no intercept column). |
| link | Link function used in the fit. |
| mr | Memory resource. |
Generalised Pareto MLE fit ([khat, sigmahat] = gpfit(x)).
Maximum likelihood estimation in two stages:
Threshold θ is assumed 0 (MATLAB convention for gpfit).
| x | Observations (must be ≥ 0; threshold θ = 0). |
| mr | Memory resource. |
| 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).
| 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)).
| p | Probability levels in [0, 1] (any shape). |
| k | Shape parameter. |
| sigma | Scale parameter. |
| theta | Threshold parameter. |
| mr | Memory resource (nullptr → process default). |
| 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).
| k | Shape parameter. |
| sigma | Scale parameter. |
| x | Sample data. |
| mr | Memory resource (nullptr → process default). |
| 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:
| x | Evaluation points (any shape). |
| k | Shape parameter (any real). |
| sigma | Scale parameter (sigma > 0). |
| theta | Threshold / location parameter. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| k | Shape parameter. |
| sigma | Scale parameter. |
| theta | Threshold parameter. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| k | Shape parameter. |
| sigma | Scale parameter. |
| theta | Threshold parameter. |
| 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):
| s | Grouping variable (numeric, logical, char, string, or cellstr). |
| mr | Memory resource (nullptr → process default). |
| Error | if s is empty (no argument). |
| 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).
| X | N × C data matrix. |
| group | N × 1 group labels. |
| fn_names | Aggregator names; empty → defaults to { "mean" }. |
| mr | Memory resource (nullptr → process default). |
| 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.
| d | Dimensionality (d >= 1; primes 2, 3, 5, … used in order). |
| skip | Number of initial points to discard. |
| leap | Stride between successive points (0 → no leap). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | 1-D real input signal (vectors only; matrix form deferred). |
| k | Half-window length (full window is 2k+1). Default 3. |
| nsigmas | Outlier threshold in robust-σ units. Default 3.0. |
| mr | Memory resource (nullptr → process default). |
| Error | k < 0 (m:hampel:badK), nsigmas <= 0 (m:hampel:badSigmas), or non-vector input (m:hampel:notVector). |
| 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.
| x | Input array (positive values). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| q | Probability levels in [0, 1] (any shape). |
| M | Population size. |
| K | Number of successes in population. |
| N | Sample size. |
| mr | Memory resource (nullptr → process default). |
| 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} \).
| k | Evaluation points (any shape). |
| M | Population size. |
| K | Number of successes in population. |
| N | Sample size. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| M | Population size. |
| K | Number of successes in population. |
| N | Sample size. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| M | Population size. |
| K | Number of successes in population. |
| N | Sample size. |
| 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".
| Z | Linkage table from linkage. |
| depth | Number of levels below each link to include (≥ 1, default 2). |
| mr | Memory resource (nullptr → process default). |
Outlier mask (tf = isoutlier(x)).
Default method: median + 3·MAD test per dimension.
| x | Input array. |
| mr | Memory resource (nullptr → process default). |
| 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.
| Tau | p × p symmetric positive-definite scale matrix. |
| df | Degrees of freedom (> p - 1). |
| mr | Memory resource (nullptr → process default). |
| 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.)
| 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)).
| x | Sample data. |
| alpha | Significance level. |
| mctol | Target MC standard-error tolerance (default 1e-3 in the other overload). Pass NaN to force the asymptotic path even for small n. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Sample data. |
| alpha | Significance level. |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | N×D data matrix (one observation per row). |
| K | Number of clusters (≥ 1). |
| max_iter | Maximum Lloyd iterations (default 100). |
| replicates | Number of random restarts; the best (lowest sum of squared distances) is returned (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| X | N×D data matrix. |
| K | Number of clusters. |
| max_iter | Maximum PAM iterations. |
| replicates | Random restarts; best (lowest total distance) wins. |
| metric | Distance metric (see pdist). |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | Reference points (M_X × D). |
| Y | Query points (M_Y × D). |
| K | Neighbour count (≥ 1; default 1). |
| metric | pdist metric (default "euclidean"). |
| p | Minkowski exponent (default 2). |
| mr | Memory resource (nullptr → process default). |
| 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).
| knots | Non-decreasing knot vector. |
| mr | Memory resource (nullptr → process default). |
| 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.
| y | Response vector. |
| group | Grouping labels. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input samples. |
| pts | Evaluation grid (column vector) or Value::Empty for auto. |
| bw_user | User-specified bandwidth (≤ 0 → Silverman's rule). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Sample data. |
| cdf | Reference CDF as a 2-column [x_grid, F_grid] matrix. Empty → standard normal N(0, 1). |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | First sample. |
| y | Second sample. |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Input array. |
| normFlag | Bias correction switch (0 or 1). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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·β||²
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.
| X | Design matrix (n × p). |
| y | Response (n × 1). |
| lambdas | Length-nLambda vector of regularisation values. |
| alpha | Elastic-net mixing parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | Design matrix (n × p). |
| y | Response (n × 1). |
| distr | Error family. |
| lambdas | nLambda λ values. |
| alpha | Elastic-net mixing parameter. |
| mr | Memory resource. |
| 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:
Uses the shared MT19937 stream — rng(seed) makes designs reproducible. iterations default is 5 (MATLAB convention).
| n | Number of samples (rows). |
| p | Number of variables (columns). |
| smooth | true for (π[i] - U)/n, false for midpoints. |
| criterion | Optimization objective (see enum). |
| iterations | Maximum trials for the criterion search (≥ 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| mu | Length-d mean vector. |
| Sigma | d × d covariance matrix. |
| n | Number of samples. |
| mr | Memory resource (nullptr → process default). |
| 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]).
| x | Sample (numel >= 4). |
| alpha | Significance level in (0, 1) (default 0.05). |
| mr | Memory resource (nullptr → process default). |
| Error | if numel(x) < 4, alpha is not in (0, 1), or the sample has zero variance. |
| 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.
| Y | Raw N×D data matrix. |
| method | Linkage rule. |
| metric | Distance metric for the internal pdist. |
| p | Metric parameter (e.g. Minkowski exponent). |
| mr | Memory resource (nullptr → process default). |
| 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".
| Y | pdist-row vector (1 × N(N-1)/2). |
| method | Linkage rule (see list above). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| mu | Mean of the underlying normal. |
| sigma | Standard deviation of the underlying normal. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Sample data. |
| alpha | Significance level. |
| cens | Right-censoring mask (Value::Empty → no censoring). |
| freq | Per-sample weights (Value::Empty → ones). |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Sample data (positive). |
| alpha | Significance level. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| p | Probability levels in [0, 1] (any shape). |
| mu | Mean of the underlying normal. |
| sigma | Standard deviation of the underlying normal. |
| mr | Memory resource (nullptr → process default). |
| double nk::stats::lognlike | ( | double | mu, |
| double | sigma, | ||
| const Value & | x, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Lognormal nLogL (nLogL = lognlike(mu, sigma, x)).
| mu | Mean of log(x). |
| sigma | Std of log(x). |
| x | Sample data (positive). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| mu | Mean of the underlying normal. |
| sigma | Standard deviation of the underlying normal (sigma > 0). |
| mr | Memory resource (nullptr → process default). |
| 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()).
| mu | Mean of the underlying normal. |
| sigma | Standard deviation of the underlying normal. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| mu | Mean of the underlying normal. |
| sigma | Standard deviation of the underlying normal. |
| 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)².
| A | Design matrix. |
| b | Response vector. |
| w | Optional 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. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| flag | Method selector (0 = MAD from mean, 1 = MAD from median). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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.
| Y | N×D query rows. |
| X | M×D reference rows defining the covariance. |
| mr | Memory resource (nullptr → process default). |
| 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.
| f | Forecast values. |
| a | Actual values. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| k | Number of values to return. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
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).
| x | Input array. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| k | Number of values to return. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Value nk::stats::mnpdf | ( | const Value & | X, |
| const Value & | P, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Multinomial pmf (y = mnpdf(X, P)).
| X | 1 × k count vector, or N × k batch. |
| P | 1 × k probability vector (must sum to 1, entries non-negative). |
| mr | Memory resource (nullptr → process default). |
| 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.
| N | Trials per sample (positive integer). |
| P | Length-k probability vector. |
| m | Number of samples (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Input array. |
| order | Moment order (integer >= 1). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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)|).
| x | Input array. |
| k | Window descriptor — see moving.hpp file note. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movmad:badK). |
| 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)).
| x | Input array. |
| k | Window descriptor — see moving.hpp file note. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movmax:badK). |
| 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.
| x | Input array; any numeric type promoted to DOUBLE on read. |
| k | Window descriptor — see moving.hpp file note. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movmean:badK). |
| 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.
| x | Input array. |
| k | Window descriptor — see moving.hpp file note. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movmedian:badK). |
| 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)).
| x | Input array. |
| k | Window descriptor — see moving.hpp file note. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movmin:badK). |
| 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)).
| x | Input array. |
| k | Window descriptor — see moving.hpp file note. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movprod:badK). |
| 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)).
| x | Input array. |
| k | Window descriptor — see moving.hpp file note. |
| normFlag | Bias flag: 0 (default) divides by n-1 (unbiased), 1 divides by n (population). Must be 0 or 1. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movstd:badK) or invalid normFlag (m:movstd:badNormFlag). |
| 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)).
| x | Input array. |
| k | Window descriptor — see moving.hpp file note. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movsum:badK). |
| 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.
| x | Input array. |
| k | Window descriptor — see moving.hpp file note. |
| normFlag | Bias flag: 0 → divide by n-1, 1 → divide by n. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Invalid window length (m:movvar:badK) or invalid normFlag (m:movvar:badNormFlag). |
| 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:
KNOWN GAP: Tukey HSD (MATLAB default) requires the studentized range distribution — not in v1.
| stats | Struct from anova1. |
| alpha | Significance level (default 0.05). |
| ctype | Correction method. |
| mr | Memory resource. |
| 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:
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.
| X | n × d evaluation points (each row one query). |
| mu | 1 × d mean (may be empty → zero). |
| Sigma | d × d covariance (may be empty → identity). |
| mr | Memory resource (nullptr → process default). |
| 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)} \).
| X | N × d (one point per row) or 1 × d single point. |
| mu | 1 × d mean. Pass empty Value for zeros. |
| Sigma | d × d covariance (PSD). Pass empty Value for identity. |
| mr | Memory resource (nullptr → process default). |
| 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:
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.
| mu | Location parameter (1×d, d×1, or n×d). |
| Sigma | Covariance matrix (d×d, symmetric PD). |
| n | Sample count. 0 → infer from mu (1 if mu is a vector, rows(mu) if mu is a matrix). |
| mr | Memory resource (nullptr → process default). |
| Error | on shape mismatch or non-PD Sigma. |
| 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:
| X | Evaluation points (n × d or length-d row). |
| C | d × d correlation/scale matrix (symmetric PD). |
| df | Degrees of freedom (df > 0). |
| tol | Target MC absolute error (default 0.01). |
| mr | Memory resource (nullptr → process default). |
| 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.
| L | Lower bounds (n × d or length-d row); -Inf allowed. |
| U | Upper bounds (same shape as L); +Inf allowed. |
| C | Correlation/scale matrix. |
| df | Degrees of freedom. |
| tol | Target MC absolute error (default 0.01). |
| mr | Memory resource. |
| 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.
| X | N × d points. |
| C | d × d correlation (or covariance — auto-normalised). |
| df | Degrees of freedom (df > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| C | d × d correlation matrix. |
| df | Degrees of freedom (df > 0). |
| n | Sample count. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Evaluation points (any shape). |
| mu | Shape parameter (mu >= 0.5). |
| omega | Spread parameter (omega > 0). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| p | Probability levels in [0, 1] (any shape). |
| mu | Shape parameter. |
| omega | Spread parameter. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Evaluation points (any shape). |
| mu | Shape parameter (mu >= 0.5). |
| omega | Spread parameter (omega > 0). |
| mr | Memory resource (nullptr → process default). |
| 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).
| mu | Shape parameter. |
| omega | Spread parameter. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| mu | Shape parameter. |
| omega | Spread parameter. |
| 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.
| x | First vector. |
| y | Second vector (same length as x). |
| normFlag | 0 → unbiased (default), 1 → population. |
| mr | Memory resource. |
| 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.
| x | Input matrix or vector. |
| normFlag | 0 → divide by N - 1 (unbiased; default). 1 → divide by N. |
| mr | Memory resource (nullptr → process default). |
NaN-aware maximum along dim (y = nanmax(x, dim)).
| x | Input array. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| x | Input array. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
NaN-aware minimum along dim (y = nanmin(x, dim)).
| x | Input array. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| x | Input array. |
| normFlag | Bias flag. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
NaN-aware sum along dim (y = nansum(x, dim)).
All-NaN slices return 0.
| x | Input array. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| normFlag | Bias flag (0 = unbiased, 1 = population). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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) \).
| k | Evaluation points (any shape). |
| r | Number of successes. |
| p | Success probability per trial. |
| mr | Memory resource (nullptr → process default). |
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).
| x | Non-negative count observations. |
| mr | Memory resource. |
| 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).
| 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.
| q | Probability levels in [0, 1] (any shape). |
| r | Number of successes. |
| p | Success probability per trial. |
| mr | Memory resource (nullptr → process default). |
| 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.
| k | Evaluation points (any shape). |
| r | Number of successes (r > 0). |
| p | Success probability per trial. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| r | Number of successes (r > 0). |
| p | Success probability per trial. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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².
| r | Number of successes. |
| p | Success probability per trial. |
| 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.
| x | Evaluation points (any shape). |
| nu1 | Numerator degrees of freedom (> 0). |
| nu2 | Denominator degrees of freedom (> 0). |
| delta | Noncentrality parameter (>= 0). |
| upper | If true, return upper-tail 1 - F (default false). |
| mr | Memory resource (nullptr → process default). |
| 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, ν₁, ν₂).
| p | Probability levels in [0, 1] (any shape). |
| nu1 | Numerator degrees of freedom. |
| nu2 | Denominator degrees of freedom. |
| delta | Noncentrality parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| nu1 | Numerator degrees of freedom (> 0). |
| nu2 | Denominator degrees of freedom (> 0). |
| delta | Noncentrality parameter (>= 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| nu1 | Numerator degrees of freedom. |
| nu2 | Denominator degrees of freedom. |
| delta | Noncentrality parameter (>= 0). |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| nu1 | Numerator degrees of freedom. |
| nu2 | Denominator degrees of freedom. |
| delta | Noncentrality parameter. |
| 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)
The optional 'upper' flag returns 1 - F.
| x | Evaluation points (any shape). |
| nu | Degrees of freedom (nu > 0). |
| delta | Noncentrality parameter. |
| upper | If true, return upper-tail 1 - F (default false). |
| mr | Memory resource (nullptr → process default). |
| 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 δ.
| p | Probability levels in [0, 1] (any shape). |
| nu | Degrees of freedom (nu > 0). |
| delta | Noncentrality parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| nu | Degrees of freedom (nu > 0). |
| delta | Noncentrality parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| nu | Degrees of freedom (nu > 0). |
| delta | Noncentrality parameter. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| nu | Degrees of freedom. |
| delta | Noncentrality parameter. |
| 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.
| x | Evaluation points (any shape). |
| k | Degrees of freedom. |
| lambda | Noncentrality parameter. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| p | Probability levels in [0, 1] (any shape). |
| k | Degrees of freedom. |
| lambda | Noncentrality parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| k | Degrees of freedom (k > 0). |
| lambda | Noncentrality parameter (lambda >= 0). |
| mr | Memory resource (nullptr → process default). |
| 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).
| k | Degrees of freedom. |
| lambda | Noncentrality parameter. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| k | Degrees of freedom. |
| lambda | Noncentrality parameter. |
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.
| A | Input symmetric matrix. |
| mr | Memory resource (nullptr → process default). |
| 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.
| stream | Stream descriptor produced by haltonset. |
| n | Number of points to extract (n >= 0). |
| mr | Memory resource (nullptr → process default). |
| Error | Unknown stream kind (m:net:badStream). |
| 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).
| X | Predictor data (n × k). |
| y | Response vector (n × 1). |
| fun | Function handle fun(beta, X) returning predictions. |
| beta0 | Initial parameter estimate. |
| engine | Engine pointer for callFunctionHandle (required — adapters pass ctx.engine). |
| mr | Memory resource (nullptr → process default). |
| 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}).
| beta | Parameter vector from nlinfit (p × 1). |
| R | Residuals from nlinfit (n × 1). |
| J | Jacobian from nlinfit (n × p). |
| alpha | Significance level (default 0.05 → 95% CI). |
| mr | Memory resource. |
| 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,:).
| fun | Function handle. |
| X | Query points (m × k). |
| beta | Parameter vector. |
| R | Residuals from the fit. |
| J | Jacobian from the fit (n × p). |
| alpha | Significance level (default 0.05). |
| engine | Engine pointer (adapter passes ctx.engine). |
| mr | Memory resource. |
| 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(...)).
| A | Input array. |
| method | Normalization method ("zscore", "range", "scale", "center", "median"). |
| param | Optional method-specific parameter (e.g. range target [lo, hi]). |
| mr | Memory resource for output allocation. |
| 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] \).
| x | Evaluation points (any shape). |
| mu | Mean parameter (default 0). |
| sigma | Standard deviation (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Sample data. |
| alpha | Significance level. |
| cens | Right-censoring mask (cens[i] != 0 → censored). Pass Value::Empty for no censoring. |
| freq | Per-sample weights. Value::Empty → all ones. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Sample data. |
| alpha | Significance level (default 0.05 in *_reg). |
| mr | Memory resource (nullptr → process default). |
| 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.
| p | Probability levels in [0, 1] (any shape). |
| mu | Mean parameter (default 0). |
| sigma | Standard deviation (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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:
Boundary handling: sigma <= 0 → NaN; any NaN in x → NaN; empty x → 0.
| mu | Location parameter. |
| sigma | Scale parameter (sigma > 0). |
| x | Sample data. |
| cens | Right-censoring mask (empty Value for none). |
| freq | Per-sample weights (empty Value for ones). |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Evaluation points (any shape). |
| mu | Mean parameter (default 0). |
| sigma | Standard deviation (default 1, sigma > 0). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| mu | Mean parameter. |
| sigma | Standard deviation (sigma > 0). |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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².
| mu | Mean parameter. |
| sigma | Standard deviation. |
| 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.
| y | Real 1-D series. |
| numLags | Number of lags; < 0 → MATLAB default min(20, N-1). |
| numSTD | Bound width in standard errors (default 2). |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | n × p first set of variables. |
| Y | n × q second set of variables (Y.rows == X.rows). |
| Z | n × r controlling variables. |
| mr | Memory resource (nullptr → process default). |
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.
| X | n × p matrix; columns are the variables. |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | n × p matrix of variables of interest. |
| Z | n × r controlling variables. |
| mr | Memory resource (nullptr → process default). |
| 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.
| Y | n × p_Y outcome variables. |
| X | n × p_X predictor variables. |
| Z | Optional n × p_Z extra controls (may be an empty matrix to skip). |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | N × D data matrix (observations as rows). |
| mr | Memory resource (nullptr → process default). |
| 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.
| C | D × D symmetric covariance matrix. |
| mr | Memory resource (nullptr → process default). |
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)'.
| X | N × D data matrix. |
| ndim | Number of PCs to retain (1 <= ndim <= D). |
| mr | Memory resource (nullptr → process default). |
| 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) |
| X | M×D matrix (each row a point). |
| metric | Metric name (see table). |
| p | Minkowski exponent (only used for "minkowski"). |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | M×D matrix. |
| Y | N×D matrix. |
| metric | Metric name (see pdist). |
| p | Minkowski exponent. |
| mr | Memory resource (nullptr → process default). |
| 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.
| k | Evaluation points (any shape). |
| lambda | Rate parameter, lambda >= 0. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Sample counts. |
| alpha | Significance level. |
| mr | Memory resource (nullptr → process default). |
| 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.
| p | Probability levels in [0, 1] (any shape). |
| lambda | Rate parameter, lambda >= 0. |
| mr | Memory resource (nullptr → process default). |
| 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.
| k | Evaluation points (any shape). |
| lambda | Rate parameter, lambda >= 0. |
| mr | Memory resource (nullptr → process default). |
| 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.
| lambda | Rate parameter, lambda >= 0. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| std::tuple< double, double > nk::stats::poisstat | ( | double | lambda | ) |
Poisson mean and variance ([m, v] = poisstat(lambda)).
Closed form: m = lambda, v = lambda.
| lambda | Rate parameter. |
| 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.
| breaks | Knot break vector (length L + 1). |
| coefs | Coefficient matrix (L × K or d·L × K). |
| d | Output dimension (1 for univariate). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | x-coordinates. |
| y | y-coordinates. |
| w | Optional weights (pass Value::Empty to skip). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | x-coordinates. |
| y | y-coordinates. |
| z | z-coordinates. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Input array. |
| p | Probability level(s) in [0, 1]; scalar or vector. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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).
| shapeArray | Array-valued shape parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| shape | Shape parameter (shape > 0); array-valued shape is supported via the adapter-only entry — see randg_reg. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| N | Upper bound of the sampling range. |
| K | Number of draws. |
| with_replacement | When true, draw with replacement; false → permutation-style without replacement (requires K <= N). |
| weights | Optional probability weights of length N (pass empty Value for uniform). Need not sum to 1 — re-normalised internally. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| x | Input array. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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.
| X | Reference points. |
| Y | Query points. |
| r | Search radius. |
| metric | pdist metric (default "euclidean"). |
| p | Minkowski exponent (default 2). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | First sample. |
| y | Second sample. |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| method | "exact" or "approximate". |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Sample data (positive). |
| alpha | Significance level. |
| mr | Memory resource (nullptr → process default). |
Rayleigh inverse cdf (x = raylinv(p, b)).
Closed form: x = b · sqrt(-2 · log(1 - p)).
| p | Probability levels in [0, 1] (any shape). |
| b | Scale parameter. |
| mr | Memory resource (nullptr → process default). |
| 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).
| b | Scale parameter. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| b | Scale parameter. |
| 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.
| y | Response vector (N × 1). |
| X | Design matrix (N × p; include a column of ones for an intercept if desired). |
| alpha | Significance level for the CIs on b (e.g. 0.05). |
| mr | Memory resource (nullptr → process default). |
| 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.
| A | Input array. |
| lo | Target lower bound (default 0 via overload). |
| hi | Target upper bound (default 1 via overload). |
| mr | Memory resource (nullptr → process default). |
| inputMin | Input lower bound (NaN → per-column data min). When given, values are clamped to [inputMin, inputMax] before mapping (MATLAB 'InputMin'/'InputMax'). |
| inputMax | Input upper bound (NaN → per-column data max). |
| 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) \).
| x | Evaluation points (any shape). |
| s | Noncentrality parameter. |
| sigma | Scale parameter. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| p | Probability levels in [0, 1] (any shape). |
| s | Noncentrality parameter. |
| sigma | Scale parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| s | Noncentrality / offset (s >= 0). |
| sigma | Scale parameter (sigma > 0). |
| mr | Memory resource (nullptr → process default). |
| 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, σ²).
| s | Noncentrality parameter. |
| sigma | Scale parameter. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| s | Noncentrality parameter. |
| sigma | Scale parameter. |
| mr | Memory resource (nullptr → process default). |
| 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.
| y | Response vector. |
| X | Design matrix. |
| k | Scalar λ or vector of λ values; output has one column per entry of k. |
| scaled | When 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). |
| mr | Memory resource (nullptr → process default). |
Remove rows / cols containing missing values (y = rmmissing(x)).
| x | Input array. |
| mr | Memory resource (nullptr → process default). |
Remove outliers (y = rmoutliers(x)).
Drops entries flagged by isoutlier_of along the first non-singleton dim.
| x | Input array. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| f | Forecast / predicted values. |
| a | Actual / reference values (broadcast-compatible with f). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| RobustcovResult nk::stats::robustcov | ( | const Value & | X, |
| std::pmr::memory_resource * | mr = nullptr ) |
Robust multivariate covariance estimate via trimmed-MCD ([sigma, mu] = robustcov(X)).
| X | Data matrix (n × d, rows = observations). |
| mr | Memory resource for output allocation. |
| 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)).
| X | Design matrix (n × p). |
| y | Response vector (n × 1). |
| weight | Weight function (Bisquare, Huber, Cauchy, Fair, Logistic, Talwar, Welsch). |
| tune | Tuning constant (NaN to use weight-specific default). |
| mr | Memory resource for output allocation. |
| 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.
| x | Sample data. |
| v | Threshold for the binary split (NaN → use median(x)). |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| method | Computation method. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Sample data. |
| y_or_m | Paired sample or scalar hypothesised median. |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| method | "exact" or "approximate". |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Sample data. |
| y_or_m | Paired sample (same length as x) or scalar hypothesised median, depending on y_or_m.numel(). |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |
| 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:
Singleton clusters are assigned s(i) = 0.
| X | N × d data matrix (one observation per row). |
| clust | N × 1 integer cluster labels. |
| metric | Distance metric — see pdist (default "sqeuclidean"). |
| p | Minkowski exponent (used only for metric == "minkowski", default 2). |
| mr | Memory resource (nullptr → process default). |
| 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] \).
| x | Input array. |
| normFlag | Bias correction switch (0 or 1). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| method | One of: |
| k | Centred window length. Pass 0 for the default heuristic max(min(round(0.1·n), 10), 3). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | Unsupported method (m:smoothdata:unsupportedMethod). |
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.
| d | pdist row OR symmetric square matrix. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| sentinel | Value to treat as missing. |
| mr | Memory resource (nullptr → process default). |
| 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)).
| x | Input array. |
| normFlag | 0 (default, unbiased) or 1 (population). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
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.
| x | Input array. |
| mr | Memory resource (nullptr → process default). |
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, ½).
| x | Evaluation points (any shape). |
| nu | Degrees of freedom (nu > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| mr | Memory resource (nullptr → process default). |
Student's t inverse cdf (x = tinv(p, nu)).
Computed via betaincinv.
| p | Probability levels in [0, 1] (any shape). |
| nu | Degrees of freedom (nu > 0). |
| mr | Memory resource (nullptr → process default). |
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 → ∞.
| x | Evaluation points (any shape). |
| nu | Degrees of freedom (nu > 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input array. |
| pct | Total trim percentage in [0, 100). |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| useFloor | Rounding of the per-end trim count: false (default, MATLAB 'round') rounds n*pct/200 half-down; true (MATLAB 'floor') takes the floor. |
| mr | Memory resource (nullptr → process default). |
| 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).
| nu | Degrees of freedom (nu > 0). |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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).
| nu | Degrees of freedom. |
| 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.
| x | Sample data (1-D). |
| m | Hypothesised mean (default 0). |
| alpha | Significance level (default 0.05). |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | First sample. |
| y | Second sample. |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| vartype | "equal" (pooled variance) or "unequal" (Welch, default). |
| mr | Memory resource (nullptr → process default). |
Discrete-uniform inverse cdf (k = unidinv(p, N)).
Closed form: k = ceil(p · N).
| p | Probability levels in [0, 1] (any shape). |
| N | Upper bound of support. |
| mr | Memory resource (nullptr → process default). |
Discrete-uniform pmf (y = unidpdf(k, N)).
f = 1/N for k ∈ {1, 2, …, N}, 0 elsewhere.
| k | Evaluation points (any shape). |
| N | Upper bound of support (positive integer-valued double). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| N | Upper bound of support. |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| N | Upper bound of support. |
| 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.
| x | Evaluation points (any shape). |
| a | Lower bound. |
| b | Upper bound (b > a). |
| mr | Memory resource (nullptr → process default). |
| 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).
| p | Probability levels in [0, 1] (any shape). |
| a | Lower bound. |
| b | Upper bound (b > a). |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Sample data. |
| alpha | Significance level. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Evaluation points (any shape). |
| a | Lower bound of the support. |
| b | Upper bound of the support (b > a). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| a | Lower bound. |
| b | Upper bound (b > a). |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| a | Lower bound. |
| b | Upper bound. |
| 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)).
| x | Input array. |
| normFlag | 0 → divide by N-1 (default, sample), 1 → divide by N. |
| dim | 1-based dimension; 0 → first non-singleton dim. |
| mr | Memory resource (nullptr → process default). |
| Error | normFlag not in {0, 1} (m:var:badNormFlag). |
| 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.
| x | Sample data. |
| v | Hypothesised variance. |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | First sample. |
| y | Second sample. |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Pooled sample column. |
| group | Group labels (same length as x). |
| alpha | Significance level. |
| mr | Memory resource (nullptr → process default). |
| 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:
For non-Bartlett tests df1 = k - 1, df2 = N - k.
| x | Pooled sample column. |
| group | Group labels. |
| test | Statistic selector (0..4). |
| mr | Memory resource (nullptr → process default). |
| 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.
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}.
| x | Positive sample data. |
| mr | Memory resource (nullptr → process default). |
| 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).
| 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).
| p | Probability levels in [0, 1] (any shape). |
| a | Scale parameter. |
| b | Shape parameter. |
| mr | Memory resource (nullptr → process default). |
| double nk::stats::wbllike | ( | double | a, |
| double | b, | ||
| const Value & | x, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Weibull nLogL (nLogL = wbllike(a, b, x)).
| a | Scale parameter. |
| b | Shape parameter. |
| x | Sample data. |
| mr | Memory resource (nullptr → process default). |
| 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).
| x | Evaluation points (any shape). |
| a | Scale parameter (a > 0). |
| b | Shape parameter (b > 0). |
| mr | Memory resource (nullptr → process default). |
| 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)).
| a | Scale parameter (a > 0). |
| b | Shape parameter (b > 0). |
| rows | Output rows (default 1). |
| cols | Output columns (default 1). |
| mr | Memory resource (nullptr → process default). |
| 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)²].
| a | Scale parameter. |
| b | Shape parameter. |
| 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:
df must satisfy df > p - 1.
KNOWN GAPs: third-argument D (pre-computed Cholesky) and the two-output [W, D] = wishrnd(...) form are deferred.
| Sigma | p × p symmetric positive-definite scale matrix. |
| df | Degrees of freedom (> p - 1). |
| mr | Memory resource (nullptr → process default). |
| 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.
| Sigma | p × p covariance / scale matrix. |
| df | Degrees of freedom (df > p - 1). |
| D | Pre-computed chol(Sigma, 'upper'), or Value::Empty. |
| mr | Memory resource. |
| 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.
| x | Sample data. |
| m | Hypothesised mean. |
| sigma | Known population standard deviation (sigma > 0). |
| alpha | Significance level. |
| tail | Direction of the alternative. |
| mr | Memory resource (nullptr → process default). |