This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
How to | Perform a Bootstrap Analysis
Suppose that you have a limited amount of data from which to obtain estimates of statistics for a population. The sampling distribution for those estimates can be approximated by drawing new samples from the original data and then computing statistics from each sample. This process is called bootstrapping and can be performed in Mathematica with RandomChoice.
Begin with a dataset:
Click for copyable input
You can sample with replacement by using RandomChoice. By including Length as the second argument in RandomChoice, a new sample of the same size as the original is generated:
Click for copyable input
Assuming the original dataset is representative of the larger population it came from, then the resampled values should behave like a sample from the original population. Statistics of a sample from the original dataset should thus simulate sample statistics for the population.
Use Skewness to compute the skewness of the original data:
Click for copyable input
Compute the skewness of the resampled data:
Click for copyable input
By resampling from the original dataset several times and computing the skewness for each of these samples, you can approximate the sampling distribution for the skewness.
Here, Table is used to iteratively compute the skewness values for 1000 resampled datasets:
Click for copyable input
You can use Histogram to visualize the sampling distribution for the skewness values of the 1000 resampled datasets:
Click for copyable input
The list of resampled values provides a sample space for the estimate, which is skewness in this case, so you can also compute additional statistics.
Estimate the standard error in the skewness estimate. The standard deviation of the estimates is the standard error:
Click for copyable input
Use Quantile to obtain a 95% confidence interval for the sample skewness:
Click for copyable input
More complicated results can also be bootstrapped, such as parameter estimates in a maximum likelihood fitting.
Generate some points from a gamma distribution and display a histogram of the data:
Click for copyable input
Click for copyable input
It is often useful to obtain parameter estimates from a dataset, under the assumption that it follows a given distribution. For example, you may wish to use maximum likelihood to estimate the and parameters for the data generated from the gamma distribution.
You can obtain the log-likelihood function for the entire dataset by using FindDistributionParameters:
Click for copyable input
You can now bootstrap the statistics for the parameter estimates by replacing the data with a resampling of values from the original dataset. This can be done using RandomChoice to get the resampled dataset:
Click for copyable input
Define this computation as the function :
Click for copyable input
You can evaluate many times to generate numerous estimates for and , thus giving a sample space for the parameters.
Use Table with to generate 100 estimates for and :
Click for copyable input
To get a bootstrapped estimate of the parameter values, take the mean of the estimates:
Click for copyable input
The correlation matrix can be computed for the parameter estimates to assess the relationship between the and estimates:
Click for copyable input