Skip to content

Feature: add logistic regression and multiple regression as options#7

Merged
martinctc merged 35 commits intomasterfrom
feature/add-logistic-regression
Jan 22, 2026
Merged

Feature: add logistic regression and multiple regression as options#7
martinctc merged 35 commits intomasterfrom
feature/add-logistic-regression

Conversation

@martinctc
Copy link
Owner

@martinctc martinctc commented Feb 27, 2021

Summary

This branch adds logistic regression and multiple regression as additional options. This version is incremented to 0.1.2.9000 as the development version (not submitted to CRAN).

The changes made in this PR are:

  1. Core functions: Created rwa_logit() for binary outcomes (logistic regression) and rwa_multiregress() for continuous outcomes (multiple regression)
  2. Wrapper function: Converted rwa() to automatically detect method based on outcome variable (2 unique values → logistic, otherwise → multiple regression) with explicit method parameter override
  3. API standardization: Unified output structure across both methods (consistent column naming, rescaled weights sum to 100, lambda matrices)
  4. Numerical stability: Added safeguards in rwa_logit() for edge cases (clipping predictions away from 0/1, zero standard deviation handling)
  5. Documentation: Added comprehensive roxygen2 docs with examples for both functions and new "Regression Methods" vignette
  6. Plotting support: Extended plot_rwa() to handle both regression types with appropriate labeling
  7. Test coverage: Added test suites for logistic regression, integration tests, and validation of numerical edge cases

Usage example:

# Automatic detection - binary outcome uses logistic regression
mtcars$high_mpg <- ifelse(mtcars$mpg > median(mtcars$mpg), 1, 0)
rwa(mtcars, "high_mpg", c("cyl", "disp", "hp", "wt"))

# Automatic detection - continuous outcome uses multiple regression  
rwa(mtcars, "mpg", c("cyl", "disp", "hp", "wt"))

# Explicit method selection
rwa(mtcars, "high_mpg", c("cyl", "disp", "hp", "wt"), method = "logistic")

Check

  • All R CMD checks pass
  • roxygen2::roxygenise() has been run prior to merging to ensure that .Rd and NAMESPACE files are up to date.

@martinctc martinctc self-assigned this Feb 27, 2021
@martinctc martinctc added the enhancement New feature or request label Feb 27, 2021
- `rwa_multiregress()` is created as a duplicate of the original `rwa()`.
- `rwa()` is used as a wrapper to call `rwa_multiregress()` and `rwa_logit()`
Copy link
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 pull request adds support for logistic regression alongside the existing multiple regression functionality in the relative weights analysis (RWA) package. The changes refactor the original rwa() function into specialized implementations and convert it to a wrapper that automatically detects the appropriate regression method.

Changes:

  • Created rwa_multiregress() containing the original multiple regression implementation
  • Created rwa_logit() implementing logistic regression for binary outcomes
  • Converted rwa() into a wrapper function with automatic method detection based on outcome variable

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 22 comments.

Show a summary per file
File Description
R/rwa.R Refactored into wrapper function with method routing logic and automatic binary outcome detection
R/rwa_multiregress.R Extracted original multiple regression implementation with full import statements
R/rwa_logit.R New logistic regression implementation using SVD decomposition approach
man/rwa.Rd Updated documentation with new method parameter and logistic regression examples
man/rwa_multiregress.Rd Documentation for extracted multiple regression function
man/rwa_logit.Rd Documentation for new logistic regression function
NAMESPACE Added exports for new rwa_logit and rwa_multiregress functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
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

Copilot reviewed 15 out of 15 changed files in this pull request and generated 15 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

R/rwa_logit.R Outdated
Rescaled.RelWeight = PropWeights) %>%
mutate(Sign = sign)

complete_cases <- nrow(drop_na(thedata))
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

Missing tidyr namespace prefix. Line 18 uses 'tidyr::drop_na()', but this line uses 'drop_na()' without the namespace prefix. Use 'tidyr::drop_na()' for consistency.

Suggested change
complete_cases <- nrow(drop_na(thedata))
complete_cases <- nrow(tidyr::drop_na(thedata))

Copilot uses AI. Check for mistakes.
martinctc and others added 6 commits January 21, 2026 17:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Complete the documentation for the lambda return value, explaining that it is the transformation matrix mapping original correlated predictors to orthogonal variables while preserving their relationship to the outcome.
@martinctc martinctc marked this pull request as ready for review January 21, 2026 17:46
@martinctc martinctc requested a review from Copilot January 21, 2026 17:47
Copy link
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

Copilot reviewed 15 out of 15 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

martinctc and others added 2 commits January 21, 2026 17:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Address code review feedback for API consistency and documentation:

- rwa_logit: Use 'Variables' column name (matching rwa_multiregress)

- rwa_logit: Use the existing Variables variable instead of 'predictors'

- rwa_multiregress: Fix docs to reference rwa_multiregress() not rwa()

- plot_rwa: Remove lambda fallback in caption (lambda is a matrix, not scalar)

- vignette: Fix iris_logit\ to iris_logit\ (pseudo R-squared)

- test-rwa: Fix incorrect comment (logistic regression does return rsquare)

This ensures consistent API across both regression methods and accurate documentation throughout the package.
Copy link
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

Copilot reviewed 15 out of 15 changed files in this pull request and generated 11 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Code quality: Add dplyr:: prefix to select/mutate, stats:: to sd. Remove extraneous blank lines in test-rwa.R. Numerical stability: Clamp predicted probabilities to avoid Inf/-Inf in logit transformation. Add warning and fallback for zero stddev (perfect separation).
- rwa_logit: Write specific description instead of inheriting from rwa()

- plot_rwa: Simplify comment (both functions now use Variables column)

- vignette: Remove README-specific fig.path parameter
Copy link
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

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

martinctc and others added 3 commits January 22, 2026 10:42
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@martinctc
Copy link
Owner Author

@copilot Can you help summarise the changes in this PR in a numbered bulleted list?

Copy link

Copilot AI commented Jan 22, 2026

@martinctc I've opened a new pull request, #23, to work on those changes. Once the pull request is ready, I'll request review from you.

@martinctc
Copy link
Owner Author

All checks passing - merging 0.1.2.9000 into main now.

@martinctc martinctc merged commit e13908a into master Jan 22, 2026
3 checks passed
@martinctc martinctc deleted the feature/add-logistic-regression branch January 22, 2026 12:16
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.

3 participants