kstest — Perform a one-sample Kolmogorov-Smirnov test.
kstest(x) tests whether the numeric vector x could come from a standard normal distribution. [h,p,ksstat,cv] = kstest(...) returns the logical decision, approximate p-value, KS statistic, and approximate critical value.
Syntax
h = kstest(x)
h = kstest(x, Name, Value)
[h, p] = kstest(___)
[h, p, ksstat] = kstest(___)
[h, p, ksstat, cv] = kstest(___)Inputs
x- Type
Any- Required
- Yes
- Description
- Sample data.
nameValuePairs- Type
Any- Required
- Variadic
- Description
- Alpha, CDF, and Tail options.
Returns
h- Type
LogicalArray- Description
- Hypothesis test decision.
p- Type
NumericArray- Description
- P-value.
ksstat- Type
NumericArray- Description
- Kolmogorov-Smirnov test statistic.
cv- Type
NumericArray- Description
- Approximate critical value.
Returned values from kstest depend on how many outputs the caller requests.
Errors
RunMat:kstest:InvalidArgument- When
- Inputs, CDF specification, tail, or significance level are malformed.
- Message
kstest: invalid argument
RunMat:kstest:Internal- When
- RunMat cannot construct kstest outputs.
- Message
kstest: internal error
Samples and controls
kstest(x) requires a numeric vector, omits NaN observations, and uses the standard normal CDF. At least one non-NaN observation is required.
Alpha must be a scalar in (0,1). Tail accepts "unequal"/"both", "larger"/"right", and "smaller"/"left".
Native integer samples are a RunMat-only extension, admitted only when every value is exactly representable as binary64. Integer Alpha cannot satisfy the required open interval and is rejected.
Reference CDF
CDF accepts a two-column numeric table of sample points and probabilities in [0,1]. Rows are sorted by sample point; duplicate points collapse to the largest probability. Probabilities must be nondecreasing after normalization, and all sample values must lie within the table's x range. Intermediate values use linear interpolation.
CDF also accepts "normcdf", "normal", "norm", "gaussian", or an @normcdf function handle for the standard normal CDF. Arbitrary function handles and continuous distribution objects are not yet supported.
Native integer CDF tables are a separately gated RunMat extension and reject values that would lose precision during binary64 statistical conversion.
Approximations and residency
P-values use large-sample approximations. The approximate critical value is returned for two-sided Alpha in [0.01,0.20] or one-sided Alpha in [0.005,0.10]; otherwise cv is NaN.
Automatic internal residency gathers transparently. Explicit gpuArray input is a mode-gated RunMat extension and follows the host reference path when enabled. No resident KS kernel or fusion path is claimed.
Examples
Test a centered sample
h = kstest([-1 -0.25 0 0.25 1]); disp(h);Request all outputs with a one-sided alternative
x = [2 2.5 3 3.5 4]; [h,p,ksstat,cv] = kstest(x, "Tail", "smaller"); disp(p); disp(ksstat);Use a tabulated CDF
x = [0.2 0.4 0.6 0.8]; cdf = [0 0; 0.5 0.5; 1 1]; [h,p,ksstat,cv] = kstest(x, "CDF", cdf); disp(h);Using kstest with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how kstest changes the result.
Run a small kstest example, explain the result, then change one input and compare the output.
FAQ
Does kstest accept arbitrary CDF function handles?⌄
Only @normcdf is recognized as a function handle. Use a two-column CDF table for a custom reference distribution.
Related Stats functions
Summary
anova1 · binocdf · binscatter · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · ksdensity · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pca · pdf · prctile · qqplot · quantile · refline · rmse · scatterhist · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest · ttest2 · wblinv
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · nlparci · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · gpurng · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Source you can read
Every RunMat function's source is public. Read exactly how kstest is executed, line by line, in Rust.
- View the source for kstest in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.