|
|
| Actions | Code Coverage | Website | Doxygen | CRAN Downloads | CRAN |
|---|---|---|---|---|---|
| R-Universe | CRAN Packages | DOI |
|---|---|---|
lhs provides a number of methods for creating and augmenting Latin
Hypercube Samples and Orthogonal Array Latin Hypercube Samples.
You can install the released version of lhs from
CRAN with:
install.packages("lhs")
You can also install the development version of lhs from github with:
if (!require(devtools)) install.packages("devtools")
devtools::install_github("bertcarnell/lhs")
Create a random LHS with 10 samples and 3 variables:
require(lhs)
## Loading required package: lhs
set.seed(1776)
X <- randomLHS(n = 10, k = 3)
Create a design that is more optimal than the random case:
X_gen <- geneticLHS(10, 3, pop = 100, gen = 5, pMut = 0.1)
X_max1 <- maximinLHS(10, 3, method = "build", dup = 5)
X_max2 <- maximinLHS(10, 3, method = "iterative", optimize.on = "result", eps = 0.01, maxIter = 300)
X_imp <- improvedLHS(10, 3, dup = 5)
X_opt <- optimumLHS(10, 3, maxSweeps = 10, eps = 0.01)
| Method | Mean Distance | Minimum Distance | |
|---|---|---|---|
| 6 | optimum | 0.7289 | 0.4598 |
| 2 | genetic | 0.7190 | 0.4059 |
| 4 | maximin | 0.7246 | 0.3975 |
| 5 | improved | 0.7028 | 0.3872 |
| 3 | maximin | 0.7296 | 0.3611 |
| 1 | random | 0.7067 | 0.2709 |
Augment an existing design:
Y <- randomLHS(10, 5)
Z <- augmentLHS(Y, 2)
dim(Z)
## [1] 12 5
Build an orthogonal array LHS:
# a 9 row design is returned because a 10 row design is not possible with these algorithms
W9 <- create_oalhs(10, 3, bChooseLargerDesign = FALSE, bverbose = FALSE)
dim(W9)
## [1] 9 3
# a 16 row design is returned because a 10 row design is not possible with these algorithms
W16 <- create_oalhs(10, 3, bChooseLargerDesign = TRUE, bverbose = FALSE)
dim(W16)
## [1] 16 3
Create a sliced design where each slice is a Latin hypercube and the union is a Latin hypercube:
S <- slicedLHS(m = 4, t = 3, k = 2)
dim(S)
## [1] 12 2
attr(S, "slices")
## [1] 1 1 1 1 2 2 2 2 3 3 3 3
Create a nested design where the small design is a subset of the large design:
N <- nestedLHS(small = 4, large = 12, k = 2)
dim(N$large)
## [1] 12 2
all(N$small == N$large[1:4, ])
## [1] TRUE
R-Help Examples of using the LHS package
StackExchange Examples:
lhs package announcement: R-pkgs New R-Packages: Triangle and LHS