-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSLHDvOA.R
More file actions
55 lines (48 loc) · 1.3 KB
/
SLHDvOA.R
File metadata and controls
55 lines (48 loc) · 1.3 KB
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
# Yin Lin Liu 2013
# Sliced Latin hypercube designs via orthogonal arrays
SPM <- function(n,k,s){
# Create sliced permutation matrix
N <- n*s#27 NOT SURE but probably n*s or n*k
t <- n/s
Zn <- 1:N
g <- split(Zn,ceiling(Zn/k))
G0 <- lapply(1:s,function(u){apply(t(sapply(1:t,function(i){sample(g[[i+t*(u-1)]])})),2,sample)})
G <- matrix(unlist(lapply(sample(1:s),function(u)t(G0[[u]]))),ncol=3,byrow=T)
G
}
if (F) {
SPM(n=9,k=3,s=3)
}
SLHDvSOA
# using example
n <- 9
s <- 3
d <- 4
r <- 2
k <- 3
N <- 27
# 1: randomize k OA's
OA0 <- t(matrix(c(0,0,0,0,0,1,1,2,0,2,2,1,1,0,1,1,1,1,2,0,1,2,0,2
,2,0,2,2,2,1,0,1,2,2,1,0),nrow=4))
# randomize columns and rows
OA <- lapply(1:k,function(i){OA0[sample(1:nrow(OA0)),sample(1:ncol(OA0))]})
# randomize symbols
randomize.symbols <- (function(val,replace,values){values[which(val==replace)]})
lapply(1:k,function(i){apply(OA[[i]],1:2,randomize.symbols,0:2,sample(0:2))})
mp1 <- (function(aa){aa+1})
mp1(matrix(9,2,2))
# 2: Generate d M(n,k,s)'s
M <- lapply(1:d,function(i){SPM(n,k,s)})
# 3: Replace OA's with permutations of M's
A <- OA
for(l in 1:k) {
for(j in 1:d) {
for(alpha in 0:(s-1)) {
A[[l]][alphas,j] <- M[[j]]
}
}
}
# 4: Transform design
Ds <- lapply(1:k,function(i){(A[[i]]-runif(N))/N})
# 5: Get D from D's
D <- unlist(Ds)