kstest — Perform a one-sample Kolmogorov-Smirnov test.
kstest(x) performs a one-sample Kolmogorov-Smirnov test of whether the sample in x could come from a standard normal distribution. [h,p,ksstat,cv] = kstest(...) also returns an approximate p-value, the KS statistic, and an approximate critical value.
Syntax
h = kstest(x)
h = kstest(x, Name, Value)
[h, p] = kstest(___)
[h, p, ksstat, cv] = kstest(___)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x | Any | Yes | — | Sample data. |
nameValuePairs | Any | Variadic | — | Alpha, CDF, and Tail options. |
Returns
| Name | Type | Description |
|---|---|---|
h | LogicalArray | Hypothesis test decision. |
p | NumericArray | P-value. |
ksstat | NumericArray | Kolmogorov-Smirnov test statistic. |
cv | NumericArray | Approximate critical value. |
Returned values from kstest depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:kstest:InvalidArgument | Inputs, CDF specification, tail, or significance level are malformed. | kstest: invalid argument |
RunMat:kstest:Internal | RunMat cannot construct kstest outputs. | kstest: internal error |
How kstest works
kstest(x)requires numeric vector input, omitsNaNsample values, and tests against the standard normal CDF.kstest(x,"Alpha",alpha)changes the significance level.alphamust be a scalar in(0,1).kstest(x,"Tail",tail)accepts"unequal"/"both","larger", and"smaller".kstest(x,"CDF",cdf)accepts a two-column numeric matrix whose first column contains sample points and whose second column contains CDF probabilities in[0,1]. Rows are sorted by sample point, duplicate sample points are collapsed to the largest probability at that point, and probabilities must be nondecreasing after normalization. Sample values must lie inside the table's x range. Values are linearly interpolated between table rows."CDF"also accepts"normcdf","normal","norm", or a@normcdffunction handle for the standard normal CDF.- The p-values use standard large-sample approximations. For two-sided tests,
cvis returned forAlphain[0.01,0.20]; for one-sided tests,cvis returned forAlphain[0.005,0.10]. Outside those ranges,cvisNaN, matching MATLAB's documented critical-value limitations. - Continuous probability distribution objects for
"CDF"are not supported until RunMat'smakedist/fitdistdistribution object surface exists.
Examples
Test a centered sample against the standard normal CDF
h = kstest([-1 -0.25 0 0.25 1])Request all outputs with a one-sided alternative
[h,p,ksstat,cv] = kstest(x, "Tail", "smaller")Use an explicit CDF table
cdf = [0 0; 0.5 0.5; 1 1];
h = kstest(x, "CDF", cdf)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 custom reference distributions.
Related Stats functions
Summary
binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. 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 an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.