Skip to content

feat: allow sampling from a directly specified multivariate distribution#4

Merged
roninsightrx merged 6 commits intomainfrom
feat/sample-covariates-mvtnorm-direct-distribution
Mar 17, 2026
Merged

feat: allow sampling from a directly specified multivariate distribution#4
roninsightrx merged 6 commits intomainfrom
feat/sample-covariates-mvtnorm-direct-distribution

Conversation

@roninsightrx
Copy link
Contributor

Summary

  • Add means, sigma, and sd parameters to sample_covariates_mvtnorm() so callers can sample without needing observed data
  • means + sigma: sample from the given distribution directly
  • means + sd: construct a diagonal covariance (diag(sd^2)) and sample from it
  • data is now optional; passing both data and means issues a warning that data is ignored
  • Version bumped to 0.0.0.9001

Test plan

  • means + sigma samples the correct number of rows/columns with correct names
  • means + sigma recovers the specified mean at large n
  • means + sd constructs diagonal covariance and recovers correct mean and SD at large n
  • sd length mismatch raises an error
  • means without sigma/sd raises an error
  • data = NULL without means raises an error
  • n_subjects missing when data = NULL raises an error
  • Seed reproducibility works with the new path
  • Warning is issued when both data and means are provided
  • All existing tests continue to pass

🤖 Generated with Claude Code

Add `means`, `sigma`, and `sd` parameters to `sample_covariates_mvtnorm()`
so callers can sample from a fully specified distribution without needing
observed data. Passing both `data` and `means` issues a warning that `data`
is ignored.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 extends sample_covariates_mvtnorm() to allow sampling from a caller-specified multivariate normal distribution (via means + sigma or means + sd) without requiring observed input data.

Changes:

  • Add means, sigma, and sd parameters and a new “direct specification” sampling branch.
  • Make data optional; warn when data and means are both provided.
  • Add test coverage for the new parameter combinations and bump package version to 0.0.0.9001.

Reviewed changes

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

File Description
R/sample_covariates_mvtnorm.R Implements the new direct-specification sampling path and updates argument handling/docs.
man/sample_covariates_mvtnorm.Rd Updates generated documentation for the new arguments and data = NULL behavior.
tests/testthat/test-sample_covariates_mvtnorm.R Adds new tests covering direct distribution specification, errors, warnings, and seed reproducibility.
DESCRIPTION Bumps package version.
Comments suppressed due to low confidence (1)

R/sample_covariates_mvtnorm.R:31

  • Documentation mismatch: @param ... says additional arguments are passed to mvrnorm(), but this function calls mvtnorm::rmvnorm(). Update the roxygen text to reference the correct function so the generated Rd is accurate.
#' @param seed integer random seed passed to [set.seed()] for reproducibility.
#' Default `NULL` does not set a seed.
#' @param ... additional arguments passed to `mvrnorm()` function
#'

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

roninsightrx and others added 5 commits March 16, 2026 21:07
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When both `means` and `sigma`/`sd` are named, reorder to match the order
of `means` and validate that the name sets match. Names remain optional:
unnamed inputs are assumed to be in the correct order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@roninsightrx roninsightrx merged commit 8734970 into main Mar 17, 2026
5 checks passed
@roninsightrx roninsightrx deleted the feat/sample-covariates-mvtnorm-direct-distribution branch March 17, 2026 04:35
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