Skip to content

Add col_binomial_vec wrapper function to handle vectors with missing data#34

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/add-wrapper-function-col-binomial
Draft

Add col_binomial_vec wrapper function to handle vectors with missing data#34
Copilot wants to merge 4 commits intomasterfrom
copilot/add-wrapper-function-col-binomial

Conversation

Copy link
Copy Markdown

Copilot AI commented Dec 23, 2025

Adds a new wrapper function col_binomial_vec() that simplifies proportion calculations for vectors with missing data.

Changes Made

  • New function col_binomial_vec(): A wrapper for col_binomial() that automatically handles:

    • Vectors with NA values
    • Range filtering (e.g., values between 0-1, 1-2, or NULL for all values)
    • Single or multiple success values
    • Automatic calculation of successes (n) and trials (N)
  • Comprehensive test coverage: Added 8 test cases covering various scenarios including basic usage, custom ranges, multiple success values, NA handling, and error cases

  • Documentation: Added roxygen documentation with usage examples

Motivation

Previously, users had to manually filter data and calculate statistics before calling col_binomial():

data_filtered <- data[data >= 0 & data <= 1 & !is.na(data)]
n <- sum(data_filtered == 1)
N <- length(data_filtered)
col_binomial(n, N, summarised = TRUE)

Now, users can calculate proportions with a single line:

col_binomial_vec(data, success_value = 1, range = c(0, 1))

Usage Examples

# Basic usage with 0-1 vector containing missing data
x <- c(0, 1, 1, 0, NA, 1, 0, 1)
col_binomial_vec(x)

# Custom range (1-2)
y <- c(1, 2, 2, 1, NA, 2, 1, 2)
col_binomial_vec(y, success_value = 2, range = c(1, 2))

# Multiple success values
z <- c(1, 2, 3, 4, 5, NA, 2, 3)
col_binomial_vec(z, success_value = c(2, 3), range = c(1, 5))
Original prompt

col_binomial is also useful when we want to quickly calculate proportions.

The data we typically use however, has missing data making proportion calculation a bit unwieldy. The user would typically need to:

  1. Filter the data to include only a certain range (i.e., 0 and 1 or 1 and 2)

Can you write a wrapper function that takes a single vector, and runs col_binomial


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@g-hyo
Copy link
Copy Markdown

g-hyo commented Dec 23, 2025

@copilot col_binomial is also useful when we want to quickly calculate proportions.

The data we typically use however, has missing data making proportion calculation a bit unwieldy. The user would typically need to:

  1. Filter the data to include only a certain range (i.e., 0 and 1 or 1 and 2)
  2. Calculate the number of success and trials to get the proportion

Can you write a wrapper function that takes a single vector, and returns the proportion, as well as other statistics provided by col_binomial

The wrapper function might also be used for other projectable_col objects.

Copilot AI and others added 3 commits December 23, 2025 12:57
Co-authored-by: g-hyo <14864611+g-hyo@users.noreply.github.com>
Co-authored-by: g-hyo <14864611+g-hyo@users.noreply.github.com>
Co-authored-by: g-hyo <14864611+g-hyo@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Dec 23, 2025

@copilot col_binomial is also useful when we want to quickly calculate proportions.

The data we typically use however, has missing data making proportion calculation a bit unwieldy. The user would ty...

I've implemented the wrapper function col_binomial_vec() that handles vectors with missing data.

The function:

  • Takes a single vector (with NA values)
  • Filters to a specified range (e.g., 0-1 or 1-2)
  • Calculates proportions and other statistics from col_binomial
  • Can handle multiple success values

Example usage:

# Basic 0-1 vector with missing data
x <- c(0, 1, 1, 0, NA, 1, 0, 1)
col_binomial_vec(x)

# Custom range (1-2)
y <- c(1, 2, 2, 1, NA, 2, 1, 2)
col_binomial_vec(y, success_value = 2, range = c(1, 2))

Implemented in commit 608e639.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.r-project.org
    • Triggering command: /usr/lib/R/bin/exec/R /usr/lib/R/bin/exec/R -e install.packages(c(&#39;devtools&#39;,~&#43;~&#39;testthat&#39;,~&#43;~&#39;vctrs&#39;,~&#43;~&#39;tibble&#39;,~&#43;~&#39;glue&#39;,~&#43;~&#39;rlang&#39;,~&#43;~&#39;tidyselect&#39;),~&#43;~repos=&#39;REDACTED&#39;);~&#43;~devtools::test() (dns block)
    • Triggering command: /usr/local/lib/R/bin/exec/R /usr/local/lib/R/bin/exec/R --no-save --no-restore -e install.packages(c(&#39;remotes&#39;,~&#43;~&#39;testthat&#39;),~&#43;~repos=&#39;REDACTED&#39;);~&#43;~remotes::install_deps(dependencies~&#43;~=~&#43;~TRUE);~&#43;~testthat::test_dir(&#39;tests/testthat&#39;,~&#43;~reporter~&#43;~=~&#43;~&#39;summary&#39;) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Add wrapper function for col_binomial to handle vectors Add col_binomial_vec wrapper function to handle vectors with missing data Dec 23, 2025
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.

2 participants