Package 'exactamente'

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

Help Index


Compare Bootstrap Distributions

Description

This function generates a plot comparing the density estimates of the exact and regular bootstrap distributions.

Usage

compare_bootstrap(
  exact_bootstrap_distribution,
  regular_bootstrap_distribution,
  title = "Comparison of Bootstrap Distributions"
)

Arguments

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

Value

A ggplot object showing the density estimates of the exact and regular bootstrap sample statistics, with different colors used to distinguish between the two.

Examples

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)

Compare Exact Bootstrap vs Regular Bootstrap

Description

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.

Usage

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"
)

Arguments

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

Value

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.

Examples

set.seed(123)
data <- rnorm(5)
results <- e_vs_r(data)
print(results$summary_table)
print(results$comp_plot)

Performs an Exact Bootstrap with Summary Statistics

Description

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).

Usage

exact_bootstrap(
  data,
  check_size = TRUE,
  anon = function(x) (mean(x)),
  lb = 0.025,
  ub = 0.975,
  density_args
)

Arguments

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

Value

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).

References

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

See Also

plot.extboot, summary.extboot

Examples

set.seed(123)
data <- rnorm(5)
result <- exact_bootstrap(data)
summary(result)
plot(result)

exactamente_app: Interactive Shiny App for Exploring Bootstrap Methods

Description

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.

Usage

exactamente_app()

Value

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.

Examples

if(interactive()){
  exactamente_app()
}

Plot Method for 'extboot' Class

Description

Creates a plot of the density estimates of the bootstrap sample statistics returned from the exact_bootstrap function.

Usage

## S3 method for class 'extboot'
plot(x, title = "Exact Bootstrap Distribution", ...)

Arguments

x

An object of class 'extboot', usually the output of the exact_bootstrap function.

title

A plot title. Default is "Exact Bootstrap Distribution".

...

Additional parameters (currently ignored).

Value

A ggplot object showing the density estimates of the bootstrap sample statistic.

See Also

exact_bootstrap, summary.extboot

Examples

set.seed(123)
data <- rnorm(5)
result <- exact_bootstrap(data)
plot(result)

Plot Method for 'regboot' Class

Description

Creates a plot of the density estimates of the bootstrap sample statistics returned from the reg_bootstrap function.

Usage

## S3 method for class 'regboot'
plot(x, title = "Regular Bootstrap Distribution", ...)

Arguments

x

An object of class 'regboot', usually the output of the reg_bootstrap function.

title

A plot title. Default is "Regular Bootstrap Distribution".

...

Additional parameters (currently ignored).

Value

A ggplot object showing the density estimates of the bootstrap sample statistic.

See Also

reg_bootstrap, summary.regboot

Examples

set.seed(123)
data <- rnorm(5)
result <- reg_bootstrap(data)
plot(result)

Regular Bootstrap with Summary Statistics

Description

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.

Usage

reg_bootstrap(
  data,
  n_bootstraps = 10000,
  anon = function(x) (mean(x)),
  lb = 0.025,
  ub = 0.975,
  density_args
)

Arguments

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 density function.

Value

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).

See Also

plot.regboot, summary.regboot

Examples

set.seed(123)
data <- rnorm(5)
result <- reg_bootstrap(data)
result$stats

Summary Method for 'extboot' Class

Description

Creates a summary table of the summary statistics computed in the exact_bootstrap function.

Usage

## S3 method for class 'extboot'
summary(object, ...)

Arguments

object

An object of class 'extboot', usually the output of the exact_bootstrap function.

...

Additional parameters (currently ignored).

Value

A data.frame containing the summary statistics.

See Also

exact_bootstrap, plot.extboot

Examples

set.seed(123)
data <- rnorm(5)
result <- exact_bootstrap(data)
summary(result)

Summary Method for 'regboot' Class

Description

Creates a summary table of the summary statistics computed in the reg_bootstrap function.

Usage

## S3 method for class 'regboot'
summary(object, ...)

Arguments

object

An object of class 'regboot', usually the output of the reg_bootstrap function.

...

Additional parameters (currently ignored).

Value

A data.frame containing the summary statistics.

See Also

reg_bootstrap, plot.regboot

Examples

set.seed(123)
data <- rnorm(5)
result <- reg_bootstrap(data)
summary(result)