fitdist — Fit a probability distribution object to sample data.
fitdist(x,distname) estimates distribution parameters from vector data and returns a ProbabilityDistribution object accepted by pdf, cdf, icdf, and random.
Syntax
pd = fitdist(x, distname)
pd = fitdist(x, distname, Name, Value)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x | NumericArray | Yes | — | Sample data or evaluation points. |
distname | StringScalar | Yes | — | Distribution name. |
NameValue | Any | Variadic | — | Name-value options. |
Returns
| Name | Type | Description |
|---|---|---|
pd | Any | Fitted probability distribution object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:fitdist:InvalidArgument | Sample data, distribution name, options, or evaluation inputs are malformed. | fitdist: invalid argument |
RunMat:fitdist:Numerical | Distribution parameter estimation fails to converge or is ill-conditioned. | fitdist: numerical failure |
RunMat:fitdist:Internal | RunMat cannot construct distribution outputs. | fitdist: internal error |
How fitdist works
- Supported fitted distributions are
"Normal","Exponential","Lognormal","Gamma","Weibull", and"Poisson"; common short aliases such as"norm","exp","logn","gam","wbl", and"poiss"are accepted. - Input data must be a numeric vector.
NaNobservations are ignored andInfobservations are rejected. fitdist(x,distname,"Frequency",w)accepts nonnegative finite observation weights with one weight per observation. Zero-weight observations are ignored.- Range constraints follow the selected distribution: exponential data must be nonnegative, lognormal/gamma/weibull data must be positive, and Poisson data must be nonnegative integers.
- The returned object exposes
DistributionName,DistName,ParameterNames,ParameterValues,NumParameters,NumObservations,NLogL,IsTruncated, and scalar parameter properties such asmu,sigma,lambda,a, orb.
Examples
Fit a normal distribution and evaluate it
pd = fitdist([1;2;3], "Normal"); y = pdf(pd, 2); p = cdf(pd, 2); x = icdf(pd, 0.5)Fit with observation frequencies
pd = fitdist([1;2], "Exponential", "Frequency", [1;3])Using fitdist with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how fitdist changes the result.
Run a small fitdist example, explain the result, then change one input and compare the output.
FAQ
Does fitdist support censoring or custom optimization options?⌄
Not yet. Censoring, Options, and grouped By fits are rejected explicitly rather than ignored.
Related Stats functions
Summary
binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · geomean · grpstats · harmmean · icdf · isoutlier · kstest · 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 fitdist is executed, line by line, in Rust.
- View the source for fitdist 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.