Performs a Bayesian bootstrap and returns a sample of size n1 representing the posterior distribution of the statistic. Returns a vector if the statistic is one-dimensional (like for mean(...)) or a data.frame if the statistic is multi-dimensional (like for the coefficients of lm).
data: The data as either a vector, matrix or data.frame.
statistic: A function that accepts data as its first argument and if use_weights is TRUE the weights as its second argument. Function should return a numeric vector.
n1: The size of the bootstrap sample (default = 1000).
n2: The sample size used to calculate the statistic each bootstrap draw (default = 1000).
use_weights: Whether the statistic function accepts a weight argument or should be calculated using resampled data (default = FALSE).
weight_arg: If the statistic function includes a named argument for the weights this could be specified here (default = NULL).
...: Further arguments passed on to the statistic function.
Returns
A data frame containing bootstrap samples.
Examples
# linear function of seqence vs. responselm_statistic <-function(data){ lm(sequence ~ response, data)$coef
}# load datadata <- adaptation_level_small
# bootstrapdata_bootstrap <- b_bootstrap(data, lm_statistic, n1 =1000, n2 =1000)