| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
bootstat = bootstrp(nboot,bootfun,d1,...)
[bootstat,bootsam] = bootstrp(...)
bootstat = bootstrp(...,'Options',options)
bootstat = bootstrp(nboot,bootfun,d1,...) draws nboot bootstrap data samples, computes statistics on each sample using bootfun, and returns the results in the matrix bootstat. nboot must be a positive integer. bootfun is a function handle specified with @. Each row of bootstat contains the results of applying bootfun to one bootstrap sample. If bootfun returns a matrix or array, then this output is converted to a row vector for storage in bootstat.
The third and later input arguments (d1,...) are data (scalars, column vectors, or matrices) used to create inputs to bootfun. bootstrp creates each bootstrap sample by sampling with replacement from the rows of the non-scalar data arguments (these must have the same number of rows). bootfun accepts scalar data unchanged.
[bootstat,bootsam] = bootstrp(...) returns an n-by-nboot matrix of bootstrap indices, bootsam. Each column in bootsam contains indices of the values that were drawn from the original data sets to constitute the corresponding bootstrap sample. For example, if d1,... each contain 16 values, and nboot = 4, then bootsam is a 16-by-4 matrix. The first column contains the indices of the 16 values drawn from d1,..., for the first of the four bootstrap samples, the second column contains the indices for the second of the four bootstrap samples, and so on. (The bootstrap indices are the same for all input data sets.) To get the output samples bootsam without applying a function, set bootfun to empty ([]).
bootstat = bootstrp(...,'Options',options) specifies options that govern the computation of bootstrap iterations. One option requests that bootstrap iterations use multiple processors, if the Parallel Computing Toolbox is available. Two options specify the random number streams used in bootstrap resampling. This argument is a struct you can create with a call to statset. You can retrieve values of the individual fields with a call to statget. Applicable statset parameters are:
'UseParallel' — If 'always' and if a matlabpool of the Parallel Computing Toolbox is open, compute bootstrap iterations in parallel. If the Parallel Computing Toolbox is not installed, or a matlabpool is not open, computation occurs in serial mode. Default is 'never', or serial computation.
'UseSubstreams' — If 'always', perform each bootstrap iteration using a separate Substream of the random number generator (aka Stream). This option is available only with RandStream types that support Substreams. Default is 'never', or do not use a different Substream for each bootstrap iteration.
'Streams' — An object of the RandStream class,or a cell array of RandStream objects. Defaults is an empty cell array. If you do not supply a value for this parameter, bootci uses the default RandStream on each MATLAB executable to generate boostrap samples. Otherwise, bootci selects bootstrap samples using the supplied RandStream object(s).
If you select 'UseSubstreams', the Streams parameter, if present, must be a scalar RandStream object.
If you do not select 'UseSubstreams', then the Streams parameter, if present, must match the number of processors used for the computation. For serial computation, the Streams parameter must be a scalar.
If computation is distributed ('UseParallel' is 'always' and a matlabpool is open), then the Streams parameter must be a cell array of the same length as the matlabpool size. In this case, each element of the cell array supplies the random number generator for bootstrap sampling on one of the parallel workers.
Load a data set containing the LSAT scores and law-school GPA for 15 students. These 15 data points are resampled to create 1000 different data sets, and the correlation between the two variables is computed for each data set.
load lawdata [bootstat,bootsam] = bootstrp(1000,@corr,lsat,gpa);
Display the first 5 bootstrapped correlation coefficients.
bootstat(1:5,:)
ans =
0.6600
0.7969
0.5807
0.8766
0.9197Display the indices of the data selected for the first 5 bootstrap samples.
bootsam(:,1:5)
ans =
9 8 15 11 15
14 7 6 7 14
4 6 10 3 11
3 10 11 9 2
15 4 13 4 14
9 4 5 2 10
8 5 4 3 13
1 9 1 15 11
10 8 6 12 3
1 4 5 2 8
1 1 10 6 2
3 10 15 10 8
14 6 10 3 8
13 12 1 2 4
12 6 4 9 8
hist(bootstat)

The histogram shows the variation of the correlation coefficient across all the bootstrap samples. The sample minimum is positive, indicating that the relationship between LSAT score and GPA is not accidental.
Finally, compute a bootstrap standard of error for the estimated correlation coefficient.
se = std(bootstat)
se =
0.1327Compute a sample of 100 bootstrapped means of random samples taken from the vector Y, and plot an estimate of the density of these bootstrapped means:
y = exprnd(5,100,1); m = bootstrp(100,@mean,y); [fi,xi] = ksdensity(m); plot(xi,fi);

Compute a sample of 100 bootstrapped means and standard deviations of random samples taken from the vector Y, and plot the bootstrap estimate pairs:
y = exprnd(5,100,1); stats = bootstrp(100,@(x)[mean(x) std(x)],y); plot(stats(:,1),stats(:,2),'o')

Estimate the standard errors for a coefficient vector in a linear regression by bootstrapping residuals:
load hald
x = [ones(size(heat)),ingredients];
y = heat;
b = regress(y,x);
yfit = x*b;
resid = y - yfit;
se = std(bootstrp(...
1000,@(bootr)regress(yfit+bootr,x),resid));hist, ksdensity,parfor,random, randsample, RandStream, statget, statset
![]() | bootci | boxplot | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |