Bootstrapping a Single Statistic (k=1) The following example…

November 1, 2011

Bootstrapping a Single Statistic (k=1)

The following example generates the bootstrapped 95% confidence interval for R-squared in the linear regression of miles per gallon (mpg) on car weight (wt) and displacement (disp). The data source is mtcars. The bootstrapped confidence interval is based on 1000 replications.

# Bootstrap 95% CI for R-Squared
# function to obtain R-Squared from the data
rsq = function(formula, data, indices) {
  d = data[indices,] # allows boot to select sample
  fit = lm(formula, data=d)
# bootstrapping with 1000 replications
results = boot(data=mtcars, statistic=rsq,
   R=1000, formula=mpg~wt+disp)

# view results

# get 95% confidence interval, type="bca")

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , ,

Comments are closed.