Title: | Explore the Exact Bootstrap Method |
---|---|
Description: | Researchers often use the bootstrap to understand a sample drawn from a population with unknown distribution. The exact bootstrap method is a practical tool for exploring the distribution of small sample size data. For a sample of size n, the exact bootstrap method generates the entire space of n to the power of n resamples and calculates all realizations of the selected statistic. The 'exactamente' package includes functions for implementing two bootstrap methods, the exact bootstrap and the regular bootstrap. The exact_bootstrap() function applies the exact bootstrap method following methodologies outlined in Kisielinska (2013) <doi:10.1007/s00180-012-0350-0>. The regular_bootstrap() function offers a more traditional bootstrap approach, where users can determine the number of resamples. The e_vs_r() function allows users to directly compare results from these bootstrap methods. To augment user experience, 'exactamente' includes the function exactamente_app() which launches an interactive 'shiny' web application. This application facilitates exploration and comparison of the bootstrap methods, providing options for modifying various parameters and visualizing results. |
Authors: | Mackson Ncube [aut, cre], mightymetrika, LLC [cph, fnd] |
Maintainer: | Mackson Ncube <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1.9000 |
Built: | 2025-01-30 03:36:52 UTC |
Source: | https://github.com/mightymetrika/exactamente |
This function generates a plot comparing the density estimates of the exact and regular bootstrap distributions.
compare_bootstrap( exact_bootstrap_distribution, regular_bootstrap_distribution, title = "Comparison of Bootstrap Distributions" )
compare_bootstrap( exact_bootstrap_distribution, regular_bootstrap_distribution, title = "Comparison of Bootstrap Distributions" )
exact_bootstrap_distribution |
An named list returned from exact_bootstrap() with components dens$x (the coordinates of the points where the density is estimated) and y (the estimated density values), representing the density estimate of the exact bootstrap sample statistic. |
regular_bootstrap_distribution |
An named list returned from reg_bootstrap() with components dens$x (the coordinates of the points where the density is estimated) and y (the estimated density values), representing the density estimate of the regular bootstrap sample statistic. |
title |
Plot title |
A ggplot object showing the density estimates of the exact and regular bootstrap sample statistics, with different colors used to distinguish between the two.
set.seed(123) data <- rnorm(5) exact_bootstrap_result <- exact_bootstrap(data) regular_bootstrap_result <- reg_bootstrap(data) compare_bootstrap(exact_bootstrap_result, regular_bootstrap_result)
set.seed(123) data <- rnorm(5) exact_bootstrap_result <- exact_bootstrap(data) regular_bootstrap_result <- reg_bootstrap(data) compare_bootstrap(exact_bootstrap_result, regular_bootstrap_result)
This function runs the exact and regular bootstrap functions on a dataset, summarizes the results, and provides a comparative plot. It provides a convenient way to compare these two methods of bootstrapping.
e_vs_r( data, n_bootstraps = 10000, check_size = TRUE, anon = function(x) (mean(x)), lb = 0.025, ub = 0.975, density_args, title = "Comparison of Bootstrap Distributions" )
e_vs_r( data, n_bootstraps = 10000, check_size = TRUE, anon = function(x) (mean(x)), lb = 0.025, ub = 0.975, density_args, title = "Comparison of Bootstrap Distributions" )
data |
A numeric vector of data values to be bootstrapped. |
n_bootstraps |
The number of bootstrap samples to generate. Defaults to 10000. |
check_size |
Logical indicating if a check should be performed to ensure the dataset has less than 10 observations for the exact bootstrap. Defaults to TRUE. |
anon |
An anonymous function to compute the statistic of interest on each bootstrap sample. Defaults to mean. |
lb |
Lower bound for the confidence interval. Defaults to 0.025. |
ub |
Upper bound for the confidence interval. Defaults to 0.975. |
density_args |
Pass additional arguments to stats::density |
title |
Plot title |
A list containing two items:
summary_table: A summary table containing the mode, median, mean, standard deviation, and confidence interval for each bootstrap method.
comp_plot: A ggplot object comparing the bootstrap distributions.
set.seed(123) data <- rnorm(5) results <- e_vs_r(data) print(results$summary_table) print(results$comp_plot)
set.seed(123) data <- rnorm(5) results <- e_vs_r(data) print(results$summary_table) print(results$comp_plot)
Performs an exact bootstrap method on small datasets and returns a set of summary statistics. This function implements a popular variant of exact bootstrapping where the total number of combinations is expressed as N^N (i.e., the vector c(1 ,2, 7) has 3^3 = 27 combinations rather than the 10 combinations obtained from exact case bootstrapping), giving more weight to a resample with larger variation, thus potentially increasing the bootstrap estimate's accuracy. This technique is described in Kisielinska (2013).
exact_bootstrap( data, check_size = TRUE, anon = function(x) (mean(x)), lb = 0.025, ub = 0.975, density_args )
exact_bootstrap( data, check_size = TRUE, anon = function(x) (mean(x)), lb = 0.025, ub = 0.975, density_args )
data |
A numeric vector of data points. |
check_size |
A logical value indicating whether to check if the size of the dataset is less than 10. Default is TRUE. |
anon |
A function to compute the sample statistic for each bootstrap sample. Default is the mean function. |
lb |
Lower bound for the confidence interval. Default is 0.025. |
ub |
Upper bound for the confidence interval. Default is 0.975. |
density_args |
Pass additional arguments to stats::density |
A list with two elements:
dens: a density estimate of the bootstrap sample statistics,
stats: a list of summary statistics including number of resamples, mode, median, mean, standard deviation, lower confidence interval (lCI), and upper confidence interval (uCI).
Kisielinska, J. (2013). The exact bootstrap method shown on the example of the mean and variance estimation. Computational Statistics, 28, 1061–1077. doi:10.1007/s00180-012-0350-0
set.seed(123) data <- rnorm(5) result <- exact_bootstrap(data) summary(result) plot(result)
set.seed(123) data <- rnorm(5) result <- exact_bootstrap(data) summary(result) plot(result)
Launches a Shiny app to interactively explore and compare Exact and Regular bootstrap methods and All. The app provides a user-friendly interface, allowing users to modify various parameters associated with each bootstrap method, visualize the results, and understand the differences between the methods.
exactamente_app()
exactamente_app()
A shinyApp object representing the running Shiny application. This function is primarily called for its side effects, which include the launching and running of the Shiny app.
if(interactive()){ exactamente_app() }
if(interactive()){ exactamente_app() }
Creates a plot of the density estimates of the bootstrap sample statistics
returned from the exact_bootstrap
function.
## S3 method for class 'extboot' plot(x, title = "Exact Bootstrap Distribution", ...)
## S3 method for class 'extboot' plot(x, title = "Exact Bootstrap Distribution", ...)
x |
An object of class 'extboot', usually the output of the |
title |
A plot title. Default is "Exact Bootstrap Distribution". |
... |
Additional parameters (currently ignored). |
A ggplot object showing the density estimates of the bootstrap sample statistic.
exact_bootstrap
, summary.extboot
set.seed(123) data <- rnorm(5) result <- exact_bootstrap(data) plot(result)
set.seed(123) data <- rnorm(5) result <- exact_bootstrap(data) plot(result)
Creates a plot of the density estimates of the bootstrap sample statistics
returned from the reg_bootstrap
function.
## S3 method for class 'regboot' plot(x, title = "Regular Bootstrap Distribution", ...)
## S3 method for class 'regboot' plot(x, title = "Regular Bootstrap Distribution", ...)
x |
An object of class 'regboot', usually the output of the |
title |
A plot title. Default is "Regular Bootstrap Distribution". |
... |
Additional parameters (currently ignored). |
A ggplot object showing the density estimates of the bootstrap sample statistic.
reg_bootstrap
, summary.regboot
set.seed(123) data <- rnorm(5) result <- reg_bootstrap(data) plot(result)
set.seed(123) data <- rnorm(5) result <- reg_bootstrap(data) plot(result)
Performs a regular bootstrap to generate a distribution of sample statistics and computes a set of summary statistics: mode, median, mean, standard deviation, and lower and upper confidence intervals.
reg_bootstrap( data, n_bootstraps = 10000, anon = function(x) (mean(x)), lb = 0.025, ub = 0.975, density_args )
reg_bootstrap( data, n_bootstraps = 10000, anon = function(x) (mean(x)), lb = 0.025, ub = 0.975, density_args )
data |
A numeric vector of data points. |
n_bootstraps |
An integer indicating the number of bootstrap samples to generate. Default is 10000. |
anon |
A function to compute the sample statistic for each bootstrap sample. Default is the mean function. |
lb |
Lower bound for the confidence interval. Default is 0.025. |
ub |
Upper bound for the confidence interval. Default is 0.975. |
density_args |
Additional arguments to be passed to |
A list with two elements:
dens: a density estimate of the bootstrap sample statistics,
stats: a list of summary statistics including number of resamples, mode, median, mean, standard deviation, lower confidence interval (lCI), and upper confidence interval (uCI).
set.seed(123) data <- rnorm(5) result <- reg_bootstrap(data) result$stats
set.seed(123) data <- rnorm(5) result <- reg_bootstrap(data) result$stats
Creates a summary table of the summary statistics computed in the
exact_bootstrap
function.
## S3 method for class 'extboot' summary(object, ...)
## S3 method for class 'extboot' summary(object, ...)
object |
An object of class 'extboot', usually the output of the |
... |
Additional parameters (currently ignored). |
A data.frame containing the summary statistics.
set.seed(123) data <- rnorm(5) result <- exact_bootstrap(data) summary(result)
set.seed(123) data <- rnorm(5) result <- exact_bootstrap(data) summary(result)
Creates a summary table of the summary statistics computed in the
reg_bootstrap
function.
## S3 method for class 'regboot' summary(object, ...)
## S3 method for class 'regboot' summary(object, ...)
object |
An object of class 'regboot', usually the output of the |
... |
Additional parameters (currently ignored). |
A data.frame containing the summary statistics.
set.seed(123) data <- rnorm(5) result <- reg_bootstrap(data) summary(result)
set.seed(123) data <- rnorm(5) result <- reg_bootstrap(data) summary(result)