Vignette for Package LA

This vignette gives a high level overview on how to use the R package LA to find different types of optimal designs.


Load the library first.

devtools::load_all()
#> i Loading LA
library(LA)

We start with order-of-addition designs (OofAs). Suppose we want to generate a full OofA with 4 factors. We can use the following code:

toy=rOofA(k=4);toy
#>       [,1] [,2] [,3] [,4]
#>  [1,]    1    2    3    4
#>  [2,]    1    2    4    3
#>  [3,]    1    3    4    2
#>  [4,]    1    3    2    4
#>  [5,]    1    4    2    3
#>  [6,]    1    4    3    2
#>  [7,]    2    3    4    1
#>  [8,]    2    3    1    4
#>  [9,]    2    4    1    3
#> [10,]    2    4    3    1
#> [11,]    2    1    3    4
#> [12,]    2    1    4    3
#> [13,]    3    4    1    2
#> [14,]    3    4    2    1
#> [15,]    3    1    2    4
#> [16,]    3    1    4    2
#> [17,]    3    2    4    1
#> [18,]    3    2    1    4
#> [19,]    4    1    2    3
#> [20,]    4    1    3    2
#> [21,]    4    2    3    1
#> [22,]    4    2    1    3
#> [23,]    4    3    1    2
#> [24,]    4    3    2    1

Sometimes, practitioners may not need full OofAs. If they want to generate a 12-run random OofA with 4 factors. The following code can be used:

toy=rOofA(n=12,k=4);toy
#>       [,1] [,2] [,3] [,4]
#>  [1,]    1    3    4    2
#>  [2,]    2    4    1    3
#>  [3,]    4    2    3    1
#>  [4,]    4    3    2    1
#>  [5,]    1    3    2    4
#>  [6,]    2    4    3    1
#>  [7,]    3    4    1    2
#>  [8,]    1    2    3    4
#>  [9,]    2    1    4    3
#> [10,]    3    1    2    4
#> [11,]    2    3    4    1
#> [12,]    1    4    3    2

Function “rOofA” is a fundamental support for main function “LA_OofA”. If we want to generate a D-optimal 12-run OofA with 4 factors. The following code can be used:

try.OofA=LA_OofA(n=12,k=4);try.OofA
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |======================================================================| 100%
#> [1] "average CPU time per iteration is: 0.02 seconds"
#> [1] "the number of iterations completed is: 10"
#>       [,1] [,2] [,3] [,4]
#>  [1,]    3    4    1    2
#>  [2,]    1    3    4    2
#>  [3,]    3    2    1    4
#>  [4,]    4    2    3    1
#>  [5,]    4    1    3    2
#>  [6,]    4    2    1    3
#>  [7,]    2    3    4    1
#>  [8,]    4    3    1    2
#>  [9,]    3    2    4    1
#> [10,]    1    2    4    3
#> [11,]    1    2    3    4
#> [12,]    3    1    4    2

Next, we introduce “LA_LHD” for identifying optimal Latin hypercube designs (LHDs). To generate a 6 by 3 maximin distance LHD, the following code can be used:

try.LHD1=LA_LHD(n=6,k=3);try.LHD1
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |======================================================================| 100%
#> [1] "average CPU time per iteration is: 0 seconds"
#> [1] "the number of iterations completed is: 10"
#>      [,1] [,2] [,3]
#> [1,]    3    3    6
#> [2,]    4    6    5
#> [3,]    6    2    4
#> [4,]    2    1    3
#> [5,]    5    4    1
#> [6,]    1    5    2

To generate a 9 by 4 nearly orthogonal LHD, the following code can be used:

try.LHD2=LA_LHD(n=9,k=4,OC="AvgAbsCor");try.LHD2
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |======================================================================| 100%
#> [1] "average CPU time per iteration is: 0 seconds"
#> [1] "the number of iterations completed is: 10"
#>       [,1] [,2] [,3] [,4]
#>  [1,]    2    2    7    4
#>  [2,]    9    7    9    7
#>  [3,]    6    1    5    2
#>  [4,]    3    6    3    6
#>  [5,]    7    4    4    8
#>  [6,]    1    5    6    9
#>  [7,]    4    8    8    1
#>  [8,]    8    3    2    5
#>  [9,]    5    9    1    3

To generate a 12 by 5 maximum projection LHD, the following code can be used:

try.LHD2=LA_LHD(n=12,k=5,OC="MaxProCriterion");try.LHD2
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |======================================================================| 100%
#> [1] "average CPU time per iteration is: 0 seconds"
#> [1] "the number of iterations completed is: 10"
#>       [,1] [,2] [,3] [,4] [,5]
#>  [1,]    7    3   12    6    8
#>  [2,]   10    6    9   11    3
#>  [3,]    6    2    2    8    1
#>  [4,]   12    9    7    9   12
#>  [5,]    1    4    3   12    7
#>  [6,]    4   11   10   10    9
#>  [7,]   11    1    6    4    5
#>  [8,]    3    8    4    5    4
#>  [9,]    5    7    8    2   11
#> [10,]    8   12    5    7    6
#> [11,]    9   10    1    3   10
#> [12,]    2    5   11    1    2

Last, we introduce “LA_opt” for experimental designs with continuous input and function optimization. For function optimization, we have two examples here. Now define an objective function: Sum of Different Powers.

\[f(x)=\sum_{i=1}^{d}|x_{i}|^{i+1}\], where \(d\) is the dimension.

SDP=function(x){i=1:length(x);y=sum(abs(x)^(i=1));return(y)}

Use LA to find the optimal solution under 20-dimensional setting for SDP function with 10 iterations:

try=LA_opt(of=SDP,lb=rep(-1,20),ub=rep(1,20),N=10,type="mini")
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |======================================================================| 100%
#> [1] "average CPU time per iteration is: 0.03 seconds"
#> [1] "the number of iterations completed is: 10"
SDP(try)  #Note that the true global optimum is 0, but we only have 10 iterations here
#> [1] 4.500919

Another example is the Cross-in-Tray function:

\[f(x)=-0.0001(|sin(x_{1})sin(x_{2})exp\{|100-\frac{\sqrt{x_{1}^2+x_{2}^2}}{\pi} | \}|+1)^{0.1}\].

CiT=function(x){x1=x[1];x2=x[2];y=-0.0001*(abs(sin(x1)*sin(x2)*exp(abs(100-sqrt(x1^2+x2^2)/pi)))+1)^0.1;return(y)}

Use LA to find the optimal solution under 2-dimensional setting for CiT function with 10 iterations:

try2=LA_opt(of=CiT,lb=rep(-10,2),ub=rep(10,2),N=10,type="mini")
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |======================================================================| 100%
#> [1] "average CPU time per iteration is: 0 seconds"
#> [1] "the number of iterations completed is: 10"
CiT(try2) #Note that the true global optimum is -2.06261, but we only have 10 iterations
#> [1] -1.8899

For the optimal design part, we consider the following illustrative example:

A health scientist is designing an experiment to discover the relationship between cooking gas and lung function. The experiment is to be performed on rats. The response variable is maximum lung volume, and the predictor variable is time per day (in hours) exposed to a given level of cooking gas in the atmosphere. There are 20 rats available for the experiment. Assume a simple linear regression model.

Here we want to find a D-optimal 20-run design, where the input variable takes values between 0 and 24. In theory, we know the optimal design is the following:

matrix(c(rep(1,20),rep(0,10),rep(24,10)),ncol=2,nrow=20,byrow=FALSE)
#>       [,1] [,2]
#>  [1,]    1    0
#>  [2,]    1    0
#>  [3,]    1    0
#>  [4,]    1    0
#>  [5,]    1    0
#>  [6,]    1    0
#>  [7,]    1    0
#>  [8,]    1    0
#>  [9,]    1    0
#> [10,]    1    0
#> [11,]    1   24
#> [12,]    1   24
#> [13,]    1   24
#> [14,]    1   24
#> [15,]    1   24
#> [16,]    1   24
#> [17,]    1   24
#> [18,]    1   24
#> [19,]    1   24
#> [20,]    1   24

So Let’s see if LA is able to identify that. Now define the D-optimality criterion in simple linear regression model:

D=function(x){IM=t(x)%*%x;return(det(IM))}

Use LA to find the optimal solution for above problem, and we want to maximize the determinant of the information matrix.

try3=LA_opt(n=20,lb=c(1,0),ub=c(1,24),N=10,OC=D,type="maxi")
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |======================================================================| 100%
#> [1] "average CPU time per iteration is: 0 seconds"
#> [1] "the number of iterations completed is: 10"
try3 #with more iterations, LA would return even better result.
#>       [,1]       [,2]
#>  [1,]    1  0.6297860
#>  [2,]    1  4.1575986
#>  [3,]    1 10.0284879
#>  [4,]    1  1.6114168
#>  [5,]    1  6.5009963
#>  [6,]    1 21.6000000
#>  [7,]    1 24.0000000
#>  [8,]    1  8.2110965
#>  [9,]    1 15.2373091
#> [10,]    1 24.0000000
#> [11,]    1  0.1495878
#> [12,]    1 24.0000000
#> [13,]    1  7.4949327
#> [14,]    1  2.6066587
#> [15,]    1  2.8196749
#> [16,]    1  1.4253878
#> [17,]    1 21.6000000
#> [18,]    1 21.3797448
#> [19,]    1 23.5224000
#> [20,]    1 24.0000000