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

November 1, 2011
By

(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
library(boot)
# 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)
return(summary(fit)\$r.square)
}
# bootstrapping with 1000 replications
results = boot(data=mtcars, statistic=rsq,
R=1000, formula=mpg~wt+disp)

# view results
results
plot(results)

# get 95% confidence interval
boot.ci(results, type="bca")
```

To leave a comment for the author, please follow the link and comment on their blog: CloudStat.

R-bloggers.com 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.

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