require(knitr)
cat(paste0("|<sub>", 
           paste0(
             c("Actions", "Code Coverage", "Website", "Doxygen", "CRAN Downloads", "CRAN"), 
             collapse="</sub>|<sub>"), 
           "</sub>|\n"))
cat(paste0("|", paste0(rep(":---:", 6), collapse="|"), "|\n"))
cat(paste0("|", 
           paste0(c("[![R build status](https://github.com/bertcarnell/lhs/workflows/R-CMD-check/badge.svg)](https://github.com/bertcarnell/lhs/actions)",
                    "[![Coverage status](https://codecov.io/gh/bertcarnell/lhs/branch/master/graph/badge.svg)](https://codecov.io/github/bertcarnell/lhs?branch=master)",
                    "[![](https://img.shields.io/badge/pkgdown-lhs-blue.svg)](https://bertcarnell.github.io/lhs/)",
                    "[![](https://img.shields.io/badge/Doxygen-lhs-blue.svg)](https://bertcarnell.github.io/lhs/html/index.html)",

                    "[![](https://cranlogs.r-pkg.org/badges/lhs)](https://cran.r-project.org/package=lhs)",
                    "[![CRAN status](https://www.r-pkg.org/badges/version/lhs)](https://cran.r-project.org/package=lhs)"), 
                  collapse="|"), 
           "|"))

lhs

lhs provides a number of methods for creating and augmenting Latin Hypercube Samples and Orthogonal Array Latin Hypercube Samples.

Installation

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")

Quick Start

Create a random LHS with 10 samples and 3 variables:

require(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)
df1 <-   data.frame(
  method = c("random","genetic","maximin","maximin","improved","optimum"),
  mean_dist = c(mean(dist(X)), mean(dist(X_gen)), mean(dist(X_max1)),
                mean(dist(X_max2)), mean(dist(X_imp)), mean(dist(X_opt))),
  min_dist = c(min(dist(X)), min(dist(X_gen)), min(dist(X_max1)),
               min(dist(X_max2)), min(dist(X_imp)), min(dist(X_opt))))
knitr::kable(df1[order(df1$min_dist, decreasing = TRUE),],
             col.names = c("Method", "Mean Distance", "Minimum Distance"),
             digits = 4)

Augment an existing design:

Y <- randomLHS(10, 5)
Z <- augmentLHS(Y, 2)
dim(Z)

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)

# 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)

Help

R-Help Examples of using the LHS package

StackExchange Examples:

Other

lhs package announcement: R-pkgs New R-Packages: Triangle and LHS



bertcarnell/lhs documentation built on July 4, 2024, 3:55 p.m.