Skip to content

Feature: add bootstrap CI to the rwa method#6

Merged
martinctc merged 12 commits intomasterfrom
feature/add-bootstrap-ci
Jul 14, 2025
Merged

Feature: add bootstrap CI to the rwa method#6
martinctc merged 12 commits intomasterfrom
feature/add-bootstrap-ci

Conversation

@martinctc
Copy link
Copy Markdown
Owner

@martinctc martinctc commented Feb 4, 2021

Summary

This branch adds bootstrap confidence intervals for Relative Weights Analysis, enabling statistical significance testing of predictor importance - a major enhancement addressing a long-standing limitation in RWA methodology.

Changes

The changes made in this PR are:

  1. Bootstrap Infrastructure: Added complete bootstrap functionality (R/bootstrap_rwa.R) with BCA, percentile, and basic CI methods
  2. Enhanced Main Function: Extended rwa() with bootstrap parameters (bootstrap, n_bootstrap, conf_level, focal, comprehensive, include_rescaled_ci)
  3. Statistical Rigor: Implemented proper handling of compositional data constraints for rescaled weights with user warnings
  4. Comprehensive Vignette: Created detailed documentation (vignettes/introduction-to-rwa.Rmd) showcasing methodology, examples, and best practices
  5. Package Compliance: Updated DESCRIPTION with proper dependencies, fixed CRAN notes, and modernized authorship format
  6. CI/CD Improvements: Enhanced GitHub Actions workflow with Pandoc support and streamlined testing
  7. Documentation Updates: Refreshed README with vignette information and bootstrap feature highlights

Check

  • Bootstrap confidence intervals work correctly for raw weights
  • Proper warnings implemented for rescaled weight CIs due to compositional constraints
  • Comprehensive vignette demonstrates all functionality with real examples
  • Package builds successfully with vignettes
  • All dependencies properly declared in DESCRIPTION
  • CRAN notes addressed (Authors@R field, maintainer redundancy)
  • GitHub Actions R CMD checks pass with Pandoc support
  • Backward compatibility maintained - all existing functionality preserved
  • Internal functions properly documented with @Keywords internal and @nord

Key Features Added

🎯 Bootstrap Confidence Intervals

  • Raw Weight CIs: Statistically valid confidence intervals for relative importance
  • Multiple CI Methods: BCA (preferred), percentile, and basic bootstrap methods with automatic fallback
  • Significance Testing: Automatic flagging of significant predictors (CIs not containing zero)
  • Comprehensive Analysis: Optional focal variable comparisons and random variable benchmarking

📊 Statistical Methodology

  • Compositional Data Awareness: Proper handling of rescaled weights with user warnings about interpretation limitations
  • Bootstrap Sample Control: User-configurable sample sizes with sensible defaults (1000 samples)
  • Confidence Level Flexibility: Adjustable confidence levels (default 95%)

📚 Documentation Excellence

  • Comprehensive Vignette: 400+ line tutorial covering methodology, interpretation, and best practices
  • Real-World Examples: Diamond price analysis and mtcars demonstrations
  • Academic References: Proper citations to Tonidandel & LeBreton (2015), Johnson (2000), and related literature
  • Troubleshooting Guide: Common issues and solutions for users

🔧 Technical Implementation

  • Robust Error Handling: Graceful fallbacks when BCA method fails
  • Memory Efficient: Optimized bootstrap sampling for large datasets
  • Tidyverse Integration: Seamless compatibility with dplyr pipes and modern R workflows

Impact and Significance

This enhancement addresses a critical gap identified by Tonidandel et al. (2009):

"The difficulty in determining the statistical significance of relative weights stems from the fact that the exact (or small sample) sampling distribution of relative weights is unknown."

The bootstrap implementation provides an empirical solution to this long-standing methodological challenge, making the rwa package one of the most comprehensive tools for relative importance analysis in R.

Usage Examples

# Basic bootstrap analysis
result <- mtcars %>%
  rwa(outcome = "mpg", 
      predictors = c("cyl", "disp", "hp"),
      bootstrap = TRUE, 
      n_bootstrap = 1000)

# View confidence intervals
result$bootstrap$ci_results$raw_weights

# Comprehensive analysis with focal comparison
comprehensive <- diamonds %>%
  rwa(outcome = "price",
      predictors = c("carat", "depth", "table"),
      bootstrap = TRUE,
      comprehensive = TRUE,
      focal = "carat")

Note

This major feature addition maintains full backward compatibility while providing cutting-edge statistical capabilities for relative weights analysis. The implementation follows best practices for R package development and provides a foundation for future enhancements to the relative importance analysis ecosystem.

This fixes #1.

work in progress code - does not work yet
@martinctc martinctc self-assigned this Feb 4, 2021
@martinctc martinctc requested a review from stonid June 29, 2021 10:15
@martinctc martinctc added the enhancement New feature or request label Jun 29, 2021
@stonid stonid marked this pull request as ready for review June 30, 2021 17:48
@stonid
Copy link
Copy Markdown
Collaborator

stonid commented Jun 30, 2021 via email

@martinctc
Copy link
Copy Markdown
Owner Author

Hey Martin,

The code in there for review doesn't seem to match any of the material I
sent for implementing the bootstrap. How can I best help integrate that?

Best,
Scott T

On Tue, Jun 29, 2021 at 6:16 AM Martin Chan @.***>
wrote:

@martinctc https://github.com/martinctc requested your review on: #6
#6 Feature: add bootstrap CI to
the rwa method.


You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
#6 (comment), or unsubscribe
https://github.com/notifications/unsubscribe-auth/AIT53LWAU2G7XD5VX5BQBADTVGMOLANCNFSM4XDUG75A
.

Hey @stonid this pull request is still a draft and I haven't properly coded anything yet! Just wanted to add you to this, will ping you when it is ready for review.

@stonid
Copy link
Copy Markdown
Collaborator

stonid commented Jun 30, 2021 via email

This was referenced Dec 10, 2023
@martinctc martinctc requested a review from Copilot July 13, 2025 23:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces bootstrap confidence interval functionality into the rwa() function, enabling statistical inference on relative weights. It also updates documentation, vignettes, and CI/CD to support the new feature.

  • Added full bootstrap infrastructure with multiple CI methods in R/bootstrap_rwa.R and integrated it into rwa()
  • Extended documentation (man/*.Rd, vignettes/*.Rmd, README.md) to cover bootstrap parameters and examples
  • Updated CI/CD workflow and package metadata for Pandoc support, CRAN compliance, and new dependencies

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
R/rwa.R Integrated bootstrap, n_bootstrap, conf_level, focal, comprehensive, include_rescaled_ci parameters and logic
R/bootstrap_rwa.R Implemented bootstrap sampling and CI extraction functions
man/rwa.Rd Updated Rd usage, arguments, and examples for bootstrap
man/run_rwa_bootstrap.Rd Added internal documentation for bootstrap helper
man/extract_ci.Rd Added internal documentation for CI extraction
vignettes/introduction-to-rwa.Rmd New detailed vignette covering basic and bootstrap features
vignettes/README.md Added instructions to access the vignette
README.md Updated to highlight bootstrap CIs and documentation
DESCRIPTION Bumped version, modernized Authors field, added new imports
NAMESPACE Imported new functions from boot, purrr, utils
.github/workflows/R-CMD-check.yaml Switched to Ubuntu runner, added Pandoc setup and artifact upload
.Rbuildignore Added _dev to ignore list
Comments suppressed due to low confidence (1)

R/rwa.R:20

  • The new bootstrap parameters and logic are not covered by any unit tests. Please add tests for rwa(..., bootstrap = TRUE) and for the underlying bootstrap helper functions (e.g., run_rwa_bootstrap, extract_ci) to ensure correct behavior.
#' @param bootstrap Logical value specifying whether to calculate bootstrap confidence intervals. Defaults to `FALSE`.

#' @keywords internal
#' Bootstrap statistic function for basic RWA weights
#' @noRd
rwa_boot_statistic <- function(data, indices, outcome, predictors) {
Copy link

Copilot AI Jul 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The functions rwa_boot_statistic and rwa_boot_statistic_rescaled share nearly identical data preparation and eigen decomposition code. Consider extracting the common steps into a helper to reduce duplication and simplify future maintenance.

Copilot uses AI. Check for mistakes.
ci_results <- purrr::map_dfr(1:n_weights, function(i) {
tryCatch({
# Try BCA first
ci <- boot::boot.ci(boot_object, type = "bca", index = i, conf = conf_level)
Copy link

Copilot AI Jul 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extracting CIs by calling boot::boot.ci inside a loop for each weight can be slow for large bootstrap samples. Consider offering an option to use a faster percentile‐only method or parallelizing the CI extraction to improve performance.

Copilot uses AI. Check for mistakes.
@martinctc martinctc merged commit 591727e into master Jul 14, 2025
2 checks passed
@martinctc martinctc deleted the feature/add-bootstrap-ci branch July 16, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confidence Intervals for Weights

3 participants