feat: allow sampling from a directly specified multivariate distribution#4
Merged
roninsightrx merged 6 commits intomainfrom Mar 17, 2026
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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, andsdparameters and a new “direct specification” sampling branch. - Make
dataoptional; warn whendataandmeansare 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 tomvrnorm(), but this function callsmvtnorm::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.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
means,sigma, andsdparameters tosample_covariates_mvtnorm()so callers can sample without needing observed datameans+sigma: sample from the given distribution directlymeans+sd: construct a diagonal covariance (diag(sd^2)) and sample from itdatais now optional; passing bothdataandmeansissues a warning thatdatais ignored0.0.0.9001Test plan
means+sigmasamples the correct number of rows/columns with correct namesmeans+sigmarecovers the specified mean at large nmeans+sdconstructs diagonal covariance and recovers correct mean and SD at large nsdlength mismatch raises an errormeanswithoutsigma/sdraises an errordata = NULLwithoutmeansraises an errorn_subjectsmissing whendata = NULLraises an errordataandmeansare provided🤖 Generated with Claude Code