Add unified design and transformation API (lhs_design / transform_lhs)#72
Open
bertcarnell wants to merge 2 commits into
Open
Add unified design and transformation API (lhs_design / transform_lhs)#72bertcarnell wants to merge 2 commits into
bertcarnell wants to merge 2 commits into
Conversation
Add a high-level interface that combines design generation and margin transformation: - lhs_design(n, variables, type, ...) generates a Latin hypercube sample of the requested type and transforms each margin to a distribution, factor, or integer range, returning a ready-to-use data.frame. The number of columns is inferred from the variable specifications. - transform_lhs(lhs, variables) applies the same margin transformations to an existing [0,1] Latin hypercube sample (e.g. from augmentLHS). Variable specifications support arbitrary functions of p, named quantile functions via list(dist = ...), factors, integer ranges, and Dirichlet margins, built on the existing qfactor/qinteger/qdirichlet helpers. Includes roxygen documentation and man page, NAMESPACE exports, testthat tests covering each margin type, generator dispatch, argument pass-through, and input validation, plus NEWS and README entries and a version bump to 1.4.0.
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
Adds a high-level, "batteries-included" interface so users can go from a parameter specification to a ready-to-use
data.framein one call, instead of manually generating a[0,1]design and applyingqnorm/qfactor/qinteger/qdirichletcolumn by column. This is a usability layer on top of the existing functionality — no new sampling math.lhs_design(n, variables, type = "random", ...)— generates a Latin hypercube sample of the requestedtype(random,improved,maximin,optimum,genetic, oroalhs) and transforms each margin, returning a nameddata.frame. The number of LHS columns is inferred from thevariablesspec, and...is forwarded to the underlying generator (e.g.dup,maxSweeps).transform_lhs(lhs, variables)— applies the same margin transformations to an existing[0,1]design (e.g. fromaugmentLHS, or any matrix on[0,1]), so the transformation layer is reusable on its own.Variable specification
Each named element of
variablesdescribes one variable and may be:pfunction(p) qexp(p, rate = 2)list(dist = "qnorm", mean = 2, sd = 0.5)match.fun+do.calllist(type = "factor", levels = c("a","b","c"), ordered = FALSE)qfactor()list(type = "integer", min = 5L, max = 17L)qinteger()list(type = "dirichlet", alpha = c(2,3,4))qdirichlet()(consumes/produceslength(alpha)columns)What's included
R/lhs_design.R—lhs_design,transform_lhs, and internal helpers, with roxygen docsman/lhs_design.Rd(documents both exported functions)NAMESPACEexportstests/testthat/test-lhs_design.R— covers every margin type, dispatch over all generator types,...pass-through, validation, and reuse on an augmented designNEWS,README(.Rmd+.md) entries, updatedDescription, version bump to1.4.0Verification
R is not available in the environment used to prepare this branch, so the
testthatsuite was not executed here — please runR CMD check/devtools::test()before merging. The logic was reviewed carefully (column accounting, naming, and dispatch traced by hand). The man page was hand-written to match roxygen2 output; re-runningroxygen2::roxygenise()should reproduce it. The README.md example shows only deterministic output (dimensions and column classes) since I could not knit it.Note on coordination with the sliced/nested PR
This branch is independent of #71 and also bumps the version to
1.4.0and editsNEWS/DESCRIPTION/README. If both are merged there will be small, easy-to-resolve conflicts in those metadata files (the R code does not overlap). Happy to rebase whichever merges second, or renumber the versions, however you prefer.https://claude.ai/code/session_01JNVgdYk9zNB8B4hLSn8rzj
Generated by Claude Code