# An Implementation of Rubin's (1981) Bayesian Bootstrap

Functions for performing the Bayesian bootstrap as introduced by Rubin (1981) and for summarizing the result. The implementation can handle both summary statistics that works on a weighted version of the data and summary statistics that works on a resampled data set.

The `bayesboot` package implements a function `bayesboot` that performs the Bayesian bootstrap introduced by Rubin (1981). The implementation can both handle summary statistics that works on a weighted version of the data or that works on a resampled data set.

`bayesboot` is available on CRAN and can be installed in the usual way:

## A simple example

Here is a Bayesian bootstrap analysis of the mean height of the last ten American presidents:

The resulting posterior distribution in `b1` can now be `plot`ted and `summary`ized:

While it is possible to use a summary statistic that works on a resample of the original data, it is more efficient if it's possible to use a summary statistic that works on a reweighting of the original dataset. Instead of using `mean` above it would be better to use `weighted.mean` like this:

The result of a call to `bayesboot` will always result in a `data.frame` with one column per dimension of the summary statistic. If the summary statistic does not return a named vector the columns will be called `V1`, `V2`, etc. The result of a `bayesboot` call can be further inspected and post processed. For example:

### Comparing two groups

If we want to compare the means of two groups, we will have to call `bayesboot` twice with each dataset and then use the resulting samples to calculate the posterior difference. For example, let's say we have the heights of the opponents that lost to the presidents in `height` the first time those presidents were elected. Now we are interested in comparing the mean height of American presidents with the mean height of presidential candidates that lost.

So there is some evidence that loosing opponents could be shorter. (Though, I must add that it is quite unclear what the purpose really is with analyzing the heights of presidents and opponents...)

A slightly more complicated example, where we do Bayesian bootstrap analysis of LOESS regression applied to the `cars` dataset on the speed of cars and the resulting distance it takes to stop. The `loess` function returns, among other things, a vector of `fitted` y values, one value for each x value in the data. These y values define the smoothed LOESS line and is what you would usually plot after having fitted a LOESS. Now we want to use the Bayesian bootstrap to gauge the uncertainty in the LOESS line. As the `loess` function accepts weighted data, we'll simply create a function that takes the data with weights and returns the `fitted` y values. We'll then plug that function into `bayesboot`:

To plot this takes a couple of lines more:

For more information on the Bayesian bootstrap see Rubin's (1981) original paper and my blog post The Non-parametric Bootstrap as a Bayesian Model. The implementation of `bayesboot` is similar to the function outlined in the blog post Easy Bayesian Bootstrap in R, but the interface is slightly different.

## References

Rubin, D. B. (1981). The Bayesian bootstrap. The annals of statistics, 9(1), 130--134. link to paper

# bayesboot 0.2.2

• Fixed issue with unstated dependencies in the tests.

# bayesboot 0.2.1

• Modified the tests so that they are compatible with upcoming version of the testthat package.

# bayesboot 0.2.0

• bayesboot now warns when the posterior sample contains NAs, NaNs and NULLs.
• plot.bayesboot now correctly resets graph parameters.
• Removed bayesboot::hdi and instead depend on HDInterval::hdi .

# bayesboot 0.1.0

• Initial release.

# Reference manual

install.packages("bayesboot")

0.2.2 by Rasmus Bååth, 3 years ago

https://github.com/rasmusab/bayesboot

Report a bug at https://github.com/rasmusab/bayesboot/issues

Browse source code at https://github.com/cran/bayesboot

Authors: Rasmus Bååth [aut, cre]

Documentation:   PDF Manual