bootstrp — Bootstrap samples and evaluate a statistic.
bootstrp(nboot,bootfun,d) draws nboot bootstrap samples with replacement from d and applies bootfun to each sample. bootstrp(nboot,bootfun,d1,...,dN) resamples rows jointly across nonscalar data arguments while scalar arguments are passed through unchanged. [bootstat,bootsam] = bootstrp(...) also returns one-based bootstrap sample indices.
Syntax
bootstat = bootstrp(nboot, bootfun, d)
bootstat = bootstrp(nboot, bootfun, d1, ..., dN)
[bootstat, bootsam] = bootstrp(___)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
nboot | IntegerScalar | Yes | — | Number of bootstrap samples. |
bootfun | Any | Yes | — | Function handle applied to each bootstrap sample. |
data | Any | Variadic | — | Data arrays and name-value options. |
Returns
| Name | Type | Description |
|---|---|---|
bootstat | NumericArray | Bootstrap statistics, one bootstrap replicate per row. |
bootsam | NumericArray | One-based bootstrap sample indices. |
Returned values from bootstrp depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:bootstrp:InvalidArgument | Inputs, dimensions, replacement flags, or weights are malformed. | sampling: invalid argument |
RunMat:bootstrp:Internal | Internal conversion or allocation fails. | sampling: internal error |
How bootstrp works
- Each row of
bootstatcontains one bootstrap replicate. Nonscalarbootfunoutputs are flattened into one row per replicate. - A single vector input is sampled along its first nonsingleton dimension; multiple nonscalar inputs are sampled by rows and must have matching row counts.
bootfuncan be a function handle, string function name, or empty array. Emptybootfunskips callback evaluation and returns an emptybootstatwithbootsamavailable as the second output."Weights",wsamples rows proportionally to nonnegative weights with at least one positive value."Options",optsaccepts a statset-style options struct for compatibility. Parallel execution options are accepted but currently evaluated serially.- Numeric, logical, string, char, and cell data arrays are supported for sampling;
bootfunmust return numeric or logical values.
Examples
Bootstrap a mean
b = bootstrp(1000, @mean, x)Return sample indices
[b,bootsam] = bootstrp(200, @median, x)Bootstrap a two-input statistic
b = bootstrp(500, @corr, x, y)Using bootstrp with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how bootstrp changes the result.
Run a small bootstrp example, explain the result, then change one input and compare the output.
FAQ
Does bootstrp use the global random stream?⌄
Yes. It uses RunMat's global random stream, like datasample and randsample.
Does bootstrp run callbacks in parallel?⌄
No. RunMat accepts the Options name-value for MATLAB compatibility, but callback evaluation is currently serial.
Related Stats functions
Random
binornd · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
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
Summary
binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · 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
Hist
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how bootstrp is executed, line by line, in Rust.
- View the source for bootstrp 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.