TOSTER icon indicating copy to clipboard operation
TOSTER copied to clipboard

Disallow paired parameter in formula methods to match base R behavior

Open Copilot opened this issue 2 months ago • 0 comments

Formula methods were accepting paired = TRUE, which is inconsistent with base R's t.test.formula() and can lead to incorrect usage since formula notation naturally represents independent groups, not paired data.

Changes

12 formula methods now reject any paired parameter:

  • TOST functions: t_TOST, boot_t_TOST, boot_t_test, log_TOST, boot_log_TOST, wilcox_TOST
  • Other tests: simple_htest, brunner_munzel
  • Calculation functions: smd_calc, ses_calc, boot_smd_calc, boot_ses_calc

Implementation:

# Added to each .formula method after formula validation
dots <- list(...)
if("paired" %in% names(dots))
  stop("cannot use 'paired' in formula method")

Tests updated:

  • Converted 9 tests from formula+paired to correct x/y vector form
  • Added comprehensive validation for all 12 formula methods

Documentation:

  • Clarified @param formula and @param paired parameters
  • Updated for t_TOST, boot_log_TOST, brunner_munzel

Breaking Change

# Before: allowed but semantically incorrect
t_TOST(extra ~ group, data = sleep, paired = TRUE, eqb = 1)

# After: must use vector form for paired tests
t_TOST(x = sleep$extra[sleep$group == 1],
       y = sleep$extra[sleep$group == 2],
       paired = TRUE, eqb = 1)

Error message matches base R: "cannot use 'paired' in formula method"

Original prompt

This section details on the original issue you should resolve

<issue_title>Formula interface for paired = TRUE</issue_title> <issue_description>Need to follow base R and not allow paired = TRUE with formula interface. Could introduce errors.

Example:

Error in t.test.formula(extra ~ group, data = sleep, paired = TRUE) : 
  cannot use 'paired' in formula method
```</issue_description>

<agent_instructions>Fix all functions with a formula interface to follow base stats:t.test and not allow paired with the formula interface. This will also require updating the documentation, examples, and vignettes E.g., Error in t.test.formula(extra ~ group, data = sleep, paired = TRUE) : 
  cannot use 'paired' in formula method</agent_instructions>

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

<comments>
</comments>

  • Fixes Lakens/TOSTER#101

💡 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 avatar Dec 20 '25 22:12 Copilot