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

November 1, 2011

(This article was first published on CloudStat, and kindly contributed to R-bloggers)

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")

To leave a comment for the author, please follow the link and comment on their blog: CloudStat. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

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.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)