-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathREADME.Rmd
153 lines (122 loc) · 7.46 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
title: "lhs"
output:
md_document:
variant: markdown_github
---
<div>
<table>
<tr>
<td>
<img align="left" width="200" height="200" src="logo.svg"/>
</td>
</tr>
</table>
</div>
```{r setup, include=FALSE}
require(knitr)
```
```{r badges, echo=FALSE, results="asis"}
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("[](https://github.com/bertcarnell/lhs/actions)",
"[](https://codecov.io/github/bertcarnell/lhs?branch=master)",
"[](https://bertcarnell.github.io/lhs/)",
"[](https://bertcarnell.github.io/lhs/html/index.html)",
"[](https://cran.r-project.org/package=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.
- Reverse Dependency Checks
- [Depends](etc/revdep_README_Depends.md)
- [Imports](etc/revdep_README_Imports.md)
- [Suggests](etc/revdep_README_Suggests.md)
- Docker Images for Testing
- [lhs-debug](https://hub.docker.com/repository/docker/bertcarnell/lhs-debug)
- [lhs-revdep](https://hub.docker.com/repository/docker/bertcarnell/lhs_revdep) built from [here](https://github.com/bertcarnell/r-debug)
## Installation
You can install the released version of `lhs` from [CRAN](https://CRAN.R-project.org) with:
```{r install1, echo=TRUE, eval=FALSE}
install.packages("lhs")
```
You can also install the development version of `lhs` from github with:
```{r install2, echo=TRUE, eval=FALSE}
if (!require(devtools)) install.packages("devtools")
devtools::install_github("bertcarnell/lhs")
```
## Quick Start
Create a random LHS with 10 samples and 3 variables:
```{r random, echo=TRUE}
require(lhs)
set.seed(1776)
X <- randomLHS(n = 10, k = 3)
```
Create a design that is more optimal than the random case:
```{r compare, echo=TRUE}
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)
```
```{r compare.table, echo=FALSE}
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:
```{r augment, echo=TRUE}
Y <- randomLHS(10, 5)
Z <- augmentLHS(Y, 2)
dim(Z)
```
Build an orthogonal array LHS:
```{r oalhs, echo=TRUE}
# 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
- [Latin hyper cube sampling from expand.grid()](https://stat.ethz.ch/pipermail/r-help/2007-January/124143.html)
- [Latin Hypercube Sampling with a condition](https://stat.ethz.ch/pipermail/r-help/2011-June/279906.html)
- [Latin Hypercube with condition sum = 1](https://stat.ethz.ch/pipermail/r-help/2008-November/180929.html)
- [Latin hypercube sampling](https://www.mail-archive.com/[email protected]/msg192704.html)
- [Latin Hypercube Sample and transformation to uniformly distributed integers or classes](https://stat.ethz.ch/pipermail/r-help/2013-October/361263.html)
- [Latin hypercube sampling from a non-uniform distribution](https://stat.ethz.ch/pipermail/r-help/2017-August/448475.html)
- [Latin Hypercube Sampling when parameters are defined according to specific probability distributions](https://stat.ethz.ch/pipermail/r-help/2017-June/447266.html)
StackExchange Examples:
- [Latin Hypercube around set points](https://stats.stackexchange.com/questions/370983/latin-hypercube-around-set-points)
- [Latin hypercube sampling with categorical variables](https://stats.stackexchange.com/questions/388963/latin-hypercube-sampling-with-categorical-variables)
- [Are Latin hypercube samples uncorrelated](https://stats.stackexchange.com/questions/147789/are-latin-hypercube-samples-uncorrelated)
- [Stopping rule for Latin hypercube sampling (LHS)](https://stats.stackexchange.com/questions/407262/stopping-rule-for-latin-hypercube-sampling-lhs)
- [Is a group of random hypercube samples equivalent to a single latin hypercube with more samples?](https://stats.stackexchange.com/questions/411085/is-a-group-of-random-hypercube-samples-equivalent-to-a-single-latin-hypercube-wi)
- [Taking samples of data using Latin Hypercube Sampling](https://stats.stackexchange.com/questions/439271/taking-samples-of-data-using-latin-hypercube-sampling)
- [Number of parameter sets generated by latin hyercube sampling](https://stats.stackexchange.com/questions/460918/number-of-parameter-sets-generated-by-latin-hyercube-sampling)
- [Is there a way to check if sample obeys the Latin Hypercube Sampling rule?](https://stats.stackexchange.com/questions/465492/is-there-a-way-to-check-if-sample-obeys-the-latin-hypercube-sampling-rule)
- [Effectiveness of Latin Hypercube Sampling](https://stats.stackexchange.com/questions/468202/effectiveness-of-latin-hypercube-sampling)
- [Dividing CDF rather than PDF equally in Latin Hypercube Sampling](https://stats.stackexchange.com/questions/468293/dividing-cdf-rather-than-pdf-equally-in-latin-hypercube-sampling)
- [Stratified sampling / QMC simulation for compound Poisson rv](https://stats.stackexchange.com/questions/469963/stratified-sampling-qmc-simulation-for-compound-poisson-rv)
- [Using Latin Hypercube Sampling with a condition that the sum of two variables should be less than one](https://stats.stackexchange.com/questions/474911/using-latin-hypercube-sampling-with-a-condition-that-the-sum-of-two-variables-sh)
- [How to generate a design for a response surface with a discrete input random variable?](https://stats.stackexchange.com/questions/444997/how-to-generate-a-design-for-a-response-surface-with-a-discrete-input-random-var)
- [Is it necessary to shuffle X coordinates in Latin hypercube Sampling?](https://stats.stackexchange.com/questions/498492/is-it-necessary-to-shuffle-x-coordinates-in-latin-hypercube-sampling-lhc)
## Other
lhs package announcement: [R-pkgs New R-Packages: Triangle and LHS](https://stat.ethz.ch/pipermail/r-packages/2006/000715.html)