Quantcast
Channel: r software hub
Viewing all articles
Browse latest Browse all 1015

bayesboot: An R package for doing the Bayesian bootstrap

$
0
0

By Rasmus Bååth

I recently wrapped up a version of my R function for easy Bayesian bootstrappin’ into the package bayesboot. This package implements a function, also named bayesboot, which performs the Bayesian bootstrap introduced by Rubin in 1981. The Bayesian bootstrap can be seen as a smoother version of the classical non-parametric bootstrap, but I prefer seeing the classical bootstrap as an approximation to the Bayesian bootstrap

The implementation in bayesboot can handle both summary statistics that works on a weighted version of the data (such as weighted.mean) and that works on a resampled data set (like median). As bayesboot just got accepted on CRAN you can install it in the usual way:

install.packages("bayesboot")

You'll find the source code for bayesboot on GitHub.
If you want to know more about the model behind the Bayesian bootstrap you can check out my previous blog post on the subject and, of course, the original paper by Rubin (1981).

A simple example of bayesboot in action

As in a previous post on the Bayesian bootstrap, here is again a Bayesian bootstrap analysis of the mean height of American presidents using the heights of the last ten presidents:

# Heights of the last ten American presidents in cm (Kennedy to Obama).
heights  c(183, 192, 182, 183, 177, 185, 188, 188, 182, 185)

The bayesboot function needs, at least, a vector of data and a function implementing a summary statistic. Here we have the data height and we're going with the sample mean as our summary statistic:

library(bayesboot)
b1  bayesboot(heights, mean)

The resulting posterior distribution over probable mean heights can now be plotted and summaryized:

summary(b1)


## Bayesian bootstrap
##
## Number of posterior draws: 4000
##
## Summary of the posterior (with 95% Highest Density Intervals):
## statistic mean ...read more

Source:: r-bloggers.com


Viewing all articles
Browse latest Browse all 1015

Trending Articles