| Statistics Toolbox™ | ![]() |
bootstat = bootstrp(nboot,bootfun,d1,...)
[bootstat,bootsam] = bootstrp(...)
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 ([]).
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);

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.1327Display 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)Compute 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));
![]() | bootci | boundary | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |