Latin Hypercube Samples (lhs)

Theory of Latin Hypercube Sampling

For the technical basis of Latin Hypercube Sampling (LHS) and Latin Hypercube Designs (LHD) please see:

This package was created to bring these designs to R and to implement many of the articles that followed on optimized sampling methods.

Create a Simple LHS

Basic LHS's are created using randomLHS.

# set the seed for reproducibility
set.seed(1111)
# a design with 5 samples from 4 parameters
A <- randomLHS(5, 4)
A
##        [,1]    [,2]   [,3]     [,4]
## [1,] 0.6329 0.48112 0.1612 0.005234
## [2,] 0.2842 0.80692 0.7862 0.508942
## [3,] 0.1678 0.67711 0.2936 0.822694
## [4,] 0.9975 0.32779 0.4718 0.679668
## [5,] 0.4125 0.04328 0.8336 0.203668

In general, the LHS is uniform on the margins until transformed (Figure 1):

Figure 1. Two dimensions of a Uniform random LHS with 5 samples

plot of chunk figureX

It is common to transform the margins of the design (the columns) into other distributions (Figure 2)

B <- matrix(nrow = nrow(A), ncol = ncol(A))
B[, 1] <- qnorm(A[, 1], mean = 0, sd = 1)
B[, 2] <- qlnorm(A[, 2], meanlog = 0.5, sdlog = 1)
B[, 3] <- A[, 3]
B[, 4] <- qunif(A[, 4], min = 7, max = 10)
B
##         [,1]   [,2]   [,3]  [,4]
## [1,]  0.3395 1.5725 0.1612 7.016
## [2,] -0.5703 3.9220 0.7862 8.527
## [3,] -0.9628 2.6107 0.2936 9.468
## [4,]  2.8037 1.0555 0.4718 9.039
## [5,] -0.2211 0.2971 0.8336 7.611
Figure 2. Two dimensions of a transformed random LHS with 5 samples

plot of chunk figureY

Optimizing the Design

The LHS can be optimized using a number of methods in the lhs package. Each method attempts to improve on the random design by ensuring that the selected points are as uncorrelated and space filling as possible. Table 1 shows some results. Figure 3, Figure 4, and Figure 5 show corresponding plots.

set.seed(101)
A <- randomLHS(30, 10)
A1 <- optimumLHS(30, 10, maxSweeps = 4, eps = 0.01)
A2 <- maximinLHS(30, 10, dup = 5)
A3 <- improvedLHS(30, 10, dup = 5)
A4 <- geneticLHS(30, 10, pop = 1000, gen = 8, pMut = 0.1, criterium = "S")
A5 <- geneticLHS(30, 10, pop = 1000, gen = 8, pMut = 0.1, criterium = "Maximin")

Table 1. Sample results and metrics of various LHS algorithms
Method Min Distance btwn pts Mean Distance btwn pts Max Correlation btwn pts
randomLHS 0.6336 1.2895 0.5137
optimumLHS 0.8718 1.3002 0.1268
maximinLHS 0.5954 1.2835 0.2984
improvedLHS 0.6426 1.2747 0.5712
geneticLHS (S) 0.7397 1.2969 0.3031
geneticLHS (Maximin) 0.8164 1.2956 0.3991

Figure 3. Pairwise margins of a randomLHS

plot of chunk Z


Figure 4. Pairwise margins of a optimumLHS

plot of chunk W


Figure 5. Pairwise margins of a maximinLHS

plot of chunk G