Skip to contents

fwb() implements the fractional (random) weighted bootstrap, also known as the Bayesian bootstrap. Rather than resampling units to include in bootstrap samples, weights are drawn to be applied to a weighted estimator.


  R = 999,
  cluster = NULL,
  simple = FALSE,
  verbose = TRUE,
  cl = NULL,

# S3 method for fwb
print(x, digits = getOption("digits"), index = 1L:ncol(x$t), ...)



the dataset used to compute the statistic


a function, which, when applied to data, returns a vector containing the statistic(s) of interest. The function should take at least two arguments; the first argument should correspond to the dataset and the second argument should correspond to a vector of weights. Any further arguments can be passed to statistic through the ... argument.


the number of bootstrap replicates. Default is 999 but more is always better. For the percentile bootstrap confidence interval to be exact, it can be beneficial to use one less than a multiple of 100.


optional; a vector containing cluster membership. If supplied, will run the cluster bootstrap. See Details. Evaluated first in data and then in the global environment.


logical; if TRUE, weights will be computed on-the-fly in each bootstrap replication rather than all at once. This can save memory at the cost of some speed.


logical; whether to display a progress bar.


a cluster object created by parallel::makeCluster(), or an integer to indicate the number of child-processes (integer values are ignored on Windows) for parallel evaluations. See pbapply::pblapply() for details. If NULL, no parallelization will take place.


other arguments passed to statistic.


an fwb object; the output of a call to fwb().


the number of significant digits to print


the index or indices of the position of the quantity of interest in x$t0 if more than one was specified in fwb(). Default is to print all quantities.


A fwb object, which also inherits from boot, with the following components:


The observed value of statistic applied to data with uniform weights.


A matrix with R rows, each of which is a bootstrap replicate of the result of calling statistic.


The value of R as passed to fwb().


The data as passed to fwb().


The value of .Random.seed just prior to generating the weights (after the first call to statistic with uniform weights).


The function statistic as passed to fwb().


The original call to fwb().


The vector passed to cluster, if any.


fwb() implements the fractional weighted bootstrap and is meant to function as a drop-in for boot::boot(., stype = "f") (i.e., the usual bootstrap but with frequency weights representing the number of times each unit is drawn). In each bootstrap replication, the weights are sampled from independent exponential distributions with rate parameter 1 and then normalized to have a mean of 1, equivalent to drawing the weights from a Dirichlet distribution. The function supplied to statistic must incorporate the weights to compute a weighted statistic. For example, if the output is a regression coefficient, the weights supplied to the w argument of statistic should be supplied to the weights argument of lm(). These weights should be used any time frequency weights would be, since they are meant to function like frequency weights (which, in the case of the traditional bootstrap, would be integers). Unfortunately, there is no way for fwb() to know whether you are using the weights correctly, so care should be taken to ensure weights are correctly incorporated into the estimator.

When fitting binomial regression models (e.g., logistic) using glm(), it may be useful to change the family to a "quasi" variety (e.g., quasibinomial()) to avoid a spurious warning about "non-integer #successes".

The cluster bootstrap can be requested by supplying a vector of cluster membership to cluster. Rather than generating a weight for each unit, a weight is generated for each cluster and then applied to all units in that cluster.

Ideally, statistic should not involve a random element, or else it will not be straightforward to replicate the bootstrap results using the seed included in the output object. Setting a seed using set.seed() is always advised.

The print() method displays the value of the statistics, the bias (the difference between the statistic and the mean of its bootstrap distribution), and the standard error (the standard deviation of the bootstrap distribution).

Methods (by generic)

  • print(fwb): Print an fwb object

See also for calculating confidence intervals; summary.fwb() for displaying output in a clean way; plot.fwb() for plotting the bootstrap distributions; vcovFWB() for estimating the covariance matrix of estimates using the FWB; boot::boot() for the traditional bootstrap.


# Performing a Weibull analysis of the Bearing Cage
# failure data as done in Xu et al. (2020)

weibull_est <- function(data, w) {
  fit <- survival::survreg(survival::Surv(hours, failure) ~ 1,
                           data = data, weights = w,
                           dist = "weibull")

  c(eta = unname(exp(coef(fit))), beta = 1/fit$scale)

boot_est <- fwb(bearingcage, statistic = weibull_est,
                R = 199, verbose = FALSE)
#> Call:
#> fwb(data = bearingcage, statistic = weibull_est, R = 199, verbose = FALSE)
#> Bootstrap Statistics :
#>          original         bias   std. error
#> eta  11792.178173 9545.5405642 2.670076e+04
#> beta     2.035319    0.2814736 9.953201e-01

#Get standard errors and CIs; uses bias-corrected
#percentile CI by default
summary(boot_est, ci.type = "bc")
#>      Estimate Std. Error CI 2.5 % CI 97.5 %
#> eta  1.18e+04   2.67e+04 2.87e+03  1.01e+05
#> beta 2.04e+00   9.95e-01 1.14e+00  4.92e+00

#Plot statistic distributions
plot(boot_est, index = "beta", type = "hist")