You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For more information on the Bayesian bootstrap see [Rubin's (1981) original paper](https://projecteuclid.org/euclid.aos/1176345338) and my blog post [The Non-parametric Bootstrap as a Bayesian Model](http://sumsar.net/blog/2015/04/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](http://sumsar.net/blog/2015/07/easy-bayesian-bootstrap-in-r/), but the interface is slightly different.
116
+
For more information on the Bayesian bootstrap see [Rubin's (1981) original paper](https://projecteuclid.org/euclid.aos/1176345338) and my blog post [The Non-parametric Bootstrap as a Bayesian Model](https://www.sumsar.net/blog/2015/04/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](https://www.sumsar.net/blog/2015/07/easy-bayesian-bootstrap-in-r/), but the interface is slightly different.
Copy file name to clipboardExpand all lines: README.md
+55-20Lines changed: 55 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,20 @@
1
-
`bayesboot`: Easy Bayesian Bootstrap in R
2
-
=========================================
1
+
# `bayesboot`: Easy Bayesian Bootstrap in R
3
2
4
-
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.
3
+
The `bayesboot` package implements a function `bayesboot` that performs
4
+
the Bayesian bootstrap introduced by Rubin (1981). The implementation
5
+
can both handle summary statistics that works on a weighted version of
6
+
the data or that works on a resampled data set.
5
7
6
8
`bayesboot` is available on CRAN and can be installed in the usual way:
7
9
8
10
```r
9
11
install.packages("bayesboot")
10
12
```
11
13
12
-
A simple example
13
-
----------------
14
+
## A simple example
14
15
15
-
Here is a Bayesian bootstrap analysis of the mean height of the last ten American presidents:
16
+
Here is a Bayesian bootstrap analysis of the mean height of the last ten
17
+
American presidents:
16
18
17
19
```r
18
20
# Heights of the last ten American presidents in cm (Kennedy to Obama).
@@ -22,7 +24,8 @@ library(bayesboot)
22
24
b1<- bayesboot(heights, mean)
23
25
```
24
26
25
-
The resulting posterior distribution in `b1` can now be `plot`ted and `summary`ized:
27
+
The resulting posterior distribution in `b1` can now be `plot`ted and
28
+
`summary`ized:
26
29
27
30
```r
28
31
summary(b1)
@@ -45,13 +48,21 @@ plot(b1)
45
48
46
49

47
50
48
-
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:
51
+
While it is possible to use a summary statistic that works on a resample
52
+
of the original data, it is more efficient if it’s possible to use a
53
+
summary statistic that works on a *reweighting* of the original dataset.
54
+
Instead of using `mean` above it would be better to use `weighted.mean`
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:
61
+
The result of a call to `bayesboot` will always result in a `data.frame`
62
+
with one column per dimension of the summary statistic. If the summary
63
+
statistic does not return a named vector the columns will be called
64
+
`V1`, `V2`, etc. The result of a `bayesboot` call can be further
65
+
inspected and post processed. For example:
55
66
56
67
```r
57
68
# Given the model and the data, this is the probability that the mean
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.
77
+
If we want to compare the means of two groups, we will have to call
78
+
`bayesboot` twice with each dataset and then use the resulting samples
79
+
to calculate the posterior difference. For example, let’s say we have
80
+
the heights of the opponents that lost to the presidents in `height` the
81
+
first time those presidents were elected. Now we are interested in
82
+
comparing the mean height of American presidents with the mean height of
83
+
presidential candidates that lost.
67
84
68
85
```r
69
86
# The heights of oponents of American presidents (first time they were elected).
@@ -82,12 +99,23 @@ plot(b_diff)
82
99
83
100

84
101
85
-
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...)
102
+
So there is some evidence that loosing opponents could be shorter.
103
+
(Though, I must add that it is quite unclear what the purpose really is
104
+
with analyzing the heights of presidents and opponents…)
86
105
87
-
A more advanced example
88
-
-----------------------
106
+
## A more advanced example
89
107
90
-
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`:
108
+
A slightly more complicated example, where we do Bayesian bootstrap
109
+
analysis of LOESS regression applied to the `cars` dataset on the speed
110
+
of cars and the resulting distance it takes to stop. The `loess`
111
+
function returns, among other things, a vector of `fitted`*y* values,
112
+
one value for each *x* value in the data. These *y* values define the
113
+
smoothed LOESS line and is what you would usually plot after having
114
+
fitted a LOESS. Now we want to use the Bayesian bootstrap to gauge the
115
+
uncertainty in the LOESS line. As the `loess` function accepts weighted
116
+
data, we’ll simply create a function that takes the data with weights
117
+
and returns the `fitted`*y* values. We’ll then plug that function into
For more information on the Bayesian bootstrap see [Rubin's (1981) original paper](https://projecteuclid.org/euclid.aos/1176345338) and my blog post [The Non-parametric Bootstrap as a Bayesian Model](http://sumsar.net/blog/2015/04/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](http://sumsar.net/blog/2015/07/easy-bayesian-bootstrap-in-r/), but the interface is slightly different.
148
+
For more information on the Bayesian bootstrap see [Rubin’s (1981)
149
+
original paper](https://projecteuclid.org/euclid.aos/1176345338) and my
150
+
blog post [The Non-parametric Bootstrap as a Bayesian
Rubin, D. B. (1981). The Bayesian bootstrap. *The annals of statistics*, 9(1), 130--134. [link to paper](https://projecteuclid.org/euclid.aos/1176345338)
159
+
Rubin, D. B. (1981). The Bayesian bootstrap. *The annals of statistics*,
0 commit comments