Transformed Latin hypercube with a multivariate distribution
Source:R/correlatedLHS.R
correlatedLHS.RdA method to create a transformed Latin Hypercube sample where the marginal distributions can be correlated according to an arbitrary set of criteria contained in a minimized cost function
Usage
correlatedLHS(
lhs,
marginal_transform_function,
cost_function,
debug = FALSE,
maxiter = 10000,
...
)Arguments
- lhs
a Latin hypercube sample that is uniformly distributed on the margins
- marginal_transform_function
a function that takes Latin hypercube sample as the first argument and other passed-through variables as desired.
...must be passed as a argument. For example,f <- function(W, second_argument, ...). Must return amatrixordata.frame- cost_function
a function that takes a transformed Latin hypercube sample as the first argument and other passed-through variables as desired.
...must be passed as a argument. For example,f <- function(W, second_argument, ...)- debug
Should debug messages be printed. Causes cost function output and iterations to be printed to aid in setting the maximum number of iterations
- maxiter
the maximum number of iterations. The algorithm proceeds by swapping one variable of two points at a time. Each swap is an iteration.
- ...
Additional arguments to be passed through to the
marginal_transform_functionandcost_function
Value
a list of the Latin hypercube with uniform margins, the transformed Latin hypercube, and the final cost
Examples
correlatedLHS(lhs::randomLHS(30, 2),
marginal_transform_function = function(W, ...) {
W[,1] <- qnorm(W[,1], 1, 3)
W[,2] <- qexp(W[,2], 2)
return(W)
},
cost_function = function(W, ...) {
(cor(W[,1], W[,2]) - 0.5)^2
},
debug = FALSE,
maxiter = 1000)
#> $lhs
#> [,1] [,2]
#> [1,] 0.67347321 0.314314799
#> [2,] 0.96795476 0.871124630
#> [3,] 0.96612117 0.971835399
#> [4,] 0.75216920 0.214517702
#> [5,] 0.24263854 0.123776719
#> [6,] 0.57072726 0.798343498
#> [7,] 0.79710293 0.740655221
#> [8,] 0.85990535 0.731528437
#> [9,] 0.06474536 0.370782370
#> [10,] 0.36386581 0.591475907
#> [11,] 0.11677517 0.666486608
#> [12,] 0.21061486 0.449537847
#> [13,] 0.43669230 0.841718190
#> [14,] 0.89563861 0.916565539
#> [15,] 0.52113665 0.565407428
#> [16,] 0.91085606 0.237581113
#> [17,] 0.30433207 0.197143897
#> [18,] 0.18553223 0.530272305
#> [19,] 0.08271250 0.354391427
#> [20,] 0.48225974 0.816758327
#> [21,] 0.14743490 0.144146201
#> [22,] 0.41992478 0.411899569
#> [23,] 0.02091592 0.291386673
#> [24,] 0.70944865 0.966026217
#> [25,] 0.81922709 0.081301402
#> [26,] 0.37428666 0.002738602
#> [27,] 0.63329136 0.607822042
#> [28,] 0.29960558 0.486729918
#> [29,] 0.56167550 0.679186646
#> [30,] 0.65183755 0.042675259
#>
#> $transformed_lhs
#> [,1] [,2]
#> [1,] 2.3485725 0.18866832
#> [2,] 6.5546496 1.02445473
#> [3,] 6.4798453 1.78484469
#> [4,] 3.0439953 0.12072868
#> [5,] -1.0935209 0.06606717
#> [6,] 1.5346780 0.80059476
#> [7,] 3.4939533 0.67479845
#> [8,] 4.2396826 0.65750514
#> [9,] -3.5483398 0.23163904
#> [10,] -0.0444337 0.44760219
#> [11,] -2.5737891 0.54903613
#> [12,] -1.4128689 0.29849854
#> [13,] 0.5219175 0.92168911
#> [14,] 4.7712557 1.24184693
#> [15,] 1.1590196 0.41667315
#> [16,] 5.0381362 0.13562958
#> [17,] -0.5359437 0.10978989
#> [18,] -1.6834438 0.37780106
#> [19,] -3.1611650 0.21878094
#> [20,] 0.8665513 0.84847469
#> [21,] -2.1424950 0.07782786
#> [22,] 0.3937422 0.26542877
#> [23,] -5.1055674 0.17222264
#> [24,] 2.6553242 1.69108307
#> [25,] 3.7372705 0.04239859
#> [26,] 0.0384366 0.00137118
#> [27,] 2.0217500 0.46801978
#> [28,] -0.5766057 0.33347655
#> [29,] 1.4656557 0.56844789
#> [30,] 2.1708587 0.02180631
#>
#> $cost
#> [1] 3.200557e-09
#>