Skip to content

Add weight variable and missing data handling options to rwa()#22

Open
Copilot wants to merge 19 commits intomasterfrom
copilot/add-weight-variable-support
Open

Add weight variable and missing data handling options to rwa()#22
Copilot wants to merge 19 commits intomasterfrom
copilot/add-weight-variable-support

Conversation

Copy link

Copilot AI commented Jan 21, 2026

Summary

This branch adds support for weighted analysis and configurable missing data handling in RWA.

Changes

The changes made in this PR are:

  1. Added use parameter to rwa() and rwa_multiregress() to control missing data handling in correlations (defaults to "pairwise.complete.obs" for backward compatibility)
  2. Added weight parameter to rwa() and rwa_multiregress() for weighted RWA using cov.wt() (defaults to NULL)
  3. Updated rwa() wrapper function to pass use and weight parameters through to rwa_multiregress()
  4. Updated bootstrap functions to handle both parameters consistently
  5. Added validation: weight must be numeric and positive; use must be valid cor() option
  6. Added warning when weight/use parameters are used with logistic regression (they only apply to multiple regression)
  7. Added comprehensive test coverage for both features
  8. Refactored implementation to work with the new rwa() wrapper structure from master branch

Usage:

# Pairwise vs listwise deletion
rwa(df, "outcome", c("x1", "x2"), use = "complete.obs")  # listwise
rwa(df, "outcome", c("x1", "x2"), use = "pairwise.complete.obs")  # pairwise (default)

# Weighted analysis
df$survey_weight <- c(1.2, 0.8, 1.5, ...)
rwa(df, "outcome", c("x1", "x2"), weight = "survey_weight")

Check

  • roxygen2::roxygenise() has been run prior to merging to ensure that .Rd and NAMESPACE files are up to date.
  • The R CMD checks pass (at least one or more of devtools::check() or rhub::check_for_cran())

Change Type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature (incl. changes to visualizations)
  • Technical design
  • Build related changes (e.g. tests)
  • Refactoring (no functional changes, no api changes)
  • Code style update (formatting, renaming) or Documentation content changes
  • Other (please describe):

(OPTIONAL) Note

Backward compatible - existing code continues to work unchanged. Both features integrate seamlessly with bootstrap confidence intervals and work only with multiple regression (not logistic regression). Implementation updated to work with the refactored rwa() wrapper structure from master branch.

Original prompt

This section details on the original issue you should resolve

<issue_title>weights and missings</issue_title>
<issue_description>Hi Martin, love the package, but I have 2 questions:

  1. Is it possible to run the analysis with a separate weight variable?
  2. If I'm correct the analysis is standard with listwise deletion of missings. is it also possible to run it with pairwise deletion?
    Thanks!</issue_description>

<agent_instructions>Please use the given pull request template when creating a pull request out of this issue. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@martinctc Hi @SietseDost - currently we don't have any capability in `rwa` to support a separate weight variable. @stonid - do you by any chance have an implementation of this available, so we can look at including this in the package?

With your second question @SietseDost, this is also not available but I can include this as a feature in #6 or #7. The plan is to export the parameter for use in cor() here, in rwa():

  cor_matrix <-
    cor(thedata, use = "pairwise.complete.obs") %>%
    as.data.frame(stringsAsFactors = FALSE, row.names = NULL) %>%
    remove_all_na_cols() %>%
    tidyr::drop_na()
```</body></comment_new>
<comment_new><author>@stonid</author><body>
@SietseDost @martinctc Unfortunately, I don't have an implementation for weighting. The missing data option should be relatively easy to implement as a new feature as Martin noted.</body></comment_new>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 7 commits January 21, 2026 10:06
Co-authored-by: martinctc <17925865+martinctc@users.noreply.github.com>
Co-authored-by: martinctc <17925865+martinctc@users.noreply.github.com>
Co-authored-by: martinctc <17925865+martinctc@users.noreply.github.com>
Co-authored-by: martinctc <17925865+martinctc@users.noreply.github.com>
Co-authored-by: martinctc <17925865+martinctc@users.noreply.github.com>
… consistent

Co-authored-by: martinctc <17925865+martinctc@users.noreply.github.com>
Co-authored-by: martinctc <17925865+martinctc@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for separate weight variable in analysis Add weight variable and missing data handling options to rwa() Jan 21, 2026
Copilot AI requested a review from martinctc January 21, 2026 10:17
@martinctc
Copy link
Owner

@copilot - these new changes have significant conflicts with the new master branch. The implementation / fix for #12 has to be updated to work with the new refactored rwa(). Can you please update?

Co-authored-by: martinctc <17925865+martinctc@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 22, 2026

@copilot - these new changes have significant conflicts with the new master branch. The implementation / fix for #12 has to be updated to work with the new refactored rwa(). Can you please update?

Updated in commit af35bb4. The implementation has been refactored to work with the new rwa() wrapper structure:

  • Added use and weight parameters to both rwa() and rwa_multiregress()
  • The wrapper now passes these parameters through to rwa_multiregress()
  • Updated all tests and documentation to work with the new structure
  • Both features work only with multiple regression (warning added for logistic regression)
  • Bootstrap functionality updated to support both parameters

The implementation maintains full backward compatibility and resolves the conflicts with the master branch.

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 PR adds two new parameters to the rwa() function to address user requests for weighted analysis and configurable missing data handling. The implementation adds a use parameter to control how missing data is handled when computing correlations (defaulting to "pairwise.complete.obs" for backward compatibility) and a weight parameter to enable weighted RWA using survey or importance weights. Both features are integrated with the existing bootstrap confidence interval functionality and work exclusively with multiple regression (not logistic regression).

Changes:

  • Added use and weight parameters to rwa() and rwa_multiregress() functions with comprehensive validation
  • Updated bootstrap functions to propagate both parameters through the analysis pipeline
  • Added warning when weight/use parameters are used with logistic regression
  • Added 217 lines of comprehensive test coverage for both features and their interactions

Reviewed changes

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

Show a summary per file
File Description
R/rwa.R Added parameters, validation logic, and warning for logistic regression; passes parameters to sub-functions
R/rwa_multiregress.R Implemented core weighted correlation using cov.wt() and configurable missing data handling
R/bootstrap_rwa.R Updated all bootstrap functions to handle use/weight parameters consistently
man/rwa.Rd Documented new use and weight parameters for main wrapper function
man/rwa_multiregress.Rd Documented new use and weight parameters with examples
tests/testthat/test-rwa.R Added comprehensive test coverage for validation, edge cases, and parameter combinations
NEWS.md Documented new features and improvements
NAMESPACE Added imports for complete.cases and cov.wt

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

@martinctc martinctc marked this pull request as ready for review February 27, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

weights and missings

3 participants