Skip to content

Add unified design and transformation API (lhs_design / transform_lhs)#72

Open
bertcarnell wants to merge 2 commits into
masterfrom
claude/lhs-unified-design-api
Open

Add unified design and transformation API (lhs_design / transform_lhs)#72
bertcarnell wants to merge 2 commits into
masterfrom
claude/lhs-unified-design-api

Conversation

@bertcarnell

Copy link
Copy Markdown
Owner

Summary

Adds a high-level, "batteries-included" interface so users can go from a parameter specification to a ready-to-use data.frame in one call, instead of manually generating a [0,1] design and applying qnorm/qfactor/qinteger/qdirichlet column 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 requested type (random, improved, maximin, optimum, genetic, or oalhs) and transforms each margin, returning a named data.frame. The number of LHS columns is inferred from the variables spec, 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. from augmentLHS, or any matrix on [0,1]), so the transformation layer is reusable on its own.

Variable specification

Each named element of variables describes one variable and may be:

Spec Example Built on
a function of p function(p) qexp(p, rate = 2)
a named quantile fn list(dist = "qnorm", mean = 2, sd = 0.5) match.fun + do.call
a factor list(type = "factor", levels = c("a","b","c"), ordered = FALSE) qfactor()
an integer range list(type = "integer", min = 5L, max = 17L) qinteger()
a Dirichlet block list(type = "dirichlet", alpha = c(2,3,4)) qdirichlet() (consumes/produces length(alpha) columns)
set.seed(1234)
lhs_design(20, variables = list(
  x     = list(dist = "qnorm", mean = 2, sd = 0.5),
  grp   = list(type = "factor", levels = c("a", "b", "c")),
  count = list(type = "integer", min = 5L, max = 17L),
  z     = function(p) qexp(p, rate = 2),
  comp  = list(type = "dirichlet", alpha = c(2, 3, 4))
), type = "maximin")

What's included

  • R/lhs_design.Rlhs_design, transform_lhs, and internal helpers, with roxygen docs
  • man/lhs_design.Rd (documents both exported functions)
  • NAMESPACE exports
  • tests/testthat/test-lhs_design.R — covers every margin type, dispatch over all generator types, ... pass-through, validation, and reuse on an augmented design
  • NEWS, README (.Rmd + .md) entries, updated Description, version bump to 1.4.0

Verification

R is not available in the environment used to prepare this branch, so the testthat suite was not executed here — please run R 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-running roxygen2::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.0 and edits NEWS/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

claude and others added 2 commits June 6, 2026 18:35
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.
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