wMatlb = matrix(c(seq(weights[1], 100 + weights[1] - 1, by = 1), rep(weights[2], 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
wMatlb
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
var_ratiolb
source("Weighted_Fun.R")
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bounds
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
opt_approx_n  = c(2/N, 4/N, 2/N) # Approximate design
opt_exact_n
opt_approx_n
opt_exact_n
weights = 1/opt_exact_n
weights
wMatlb = matrix(c(seq(weights[1], 100 + weights[1] - 1, by = 1), rep(weights[2], 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
wMatlb
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
var_ratiolb
#### Paper: “New Insights and Practical Tools for Weighted Optimal Designs”
### This code generates examples from paper section 2.1
# Read in functions
source("Weighted_Fun.R")
### Examples section 2.1-----
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
opt_exact_n
1/7
weights = 1/opt_exact_n
weights
seq(weights[1], 100 + weights[1] - 1, by = 1)
weights[3]
weights[2]
weights
weights/4
weights = 1/opt_exact_n
weights = weights/4
wMatlb = matrix(c(seq(weights[1], 100 + weights[1] - 1, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
wMatlb
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
var_ratiolb
#### Paper: “New Insights and Practical Tools for Weighted Optimal Designs”
### This code generates examples from paper section 2.1
# Read in functions
source("Weighted_Fun.R")
### Examples section 2.1-----
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
## Results, section 3----
# weights set using variance lower bounds
weights = 1/opt_exact_n
weights = weights/4
wMatlb = matrix(c(seq(weights[1], 100 + weights[1] - 1, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
var_ratiolb
#### Paper: “New Insights and Practical Tools for Weighted Optimal Designs”
### This code generates examples from paper section 2.1
# Read in functions
source("Weighted_Fun.R")
### Examples section 2.1-----
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
## Results, section 3----
# weights set using variance lower bounds
weights = 1/opt_exact_n
# weights = weights/4
wMatlb = matrix(c(seq(weights[1], 100 + weights[1] - 1, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
var_ratiolb
wMatlb = matrix(c(seq(weights[1], 100 + weights[1] - 1, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
wMatlb
opt_exact_n
apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)
apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps
)
apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n)
weights = 1/opt_exact_n
weights = weights/4
wMatlb = matrix(c(seq(weights[1], 100 + weights[1] - 1, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
var_ratiolb
weights
wMatlb
wMatlb = matrix(c(weights[1], seq(2, 100, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
wMatlb
weights = 1/opt_exact_n
weights = weights/4
wMatlb = matrix(c(weights[1], seq(2, 100, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
var_ratiolb
View(wMatlb)
View(wMatlb)
# Read in functions
source("Weighted_Fun.R")
### Examples section 2.1-----
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
## Results, section 3----
# weights set using variance lower bounds
weights = 1/opt_exact_n
weights = weights/4
wMatlb = matrix(c(weights[1], seq(2, 100, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
var_ratiolb
Tab = cbind(wMatlb[, 1], var_ratiolb)
Table1 = unique(Tab)
unique(Tab)
View(Tab)
#### Paper: “On the Role of Minimum Variances in Weighted Optimal Designs”
### This code generates examples from paper section 3
# Read in functions
source("Weighted_Fun.R")
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
# weights set using variance lower bounds
weights = 1/opt_exact_n
weights = weights/4
wMatlb = matrix(c(weights[1], seq(2, 100, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
# produces results for Table 1
Tab = cbind(wMatlb[, 1], var_ratiolb)
Tab
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
#### Paper: “On the Role of Minimum Variances in Weighted Optimal Designs”
### This code generates examples from paper section 3
# Read in functions
source("Weighted_Fun.R")
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
weights = 1/opt_exact_n
weights = weights/4
wMatlb = matrix(c(weights[1], seq(2, 100, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
exact_A_CRD(N, c(2, 1, 1), Hnorm)
exact_A_CRD(N, c(2, 1, 1), Hnorm)$Reps
var-run(exact_A_CRD(N, c(2, 1, 1), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(2, 1, 1), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(2, 2, 1), Hnorm)$Reps, Hnorm)
exact_A_CRD(N, c(2, 2, 1), Hnorm)$Reps
var_fun(exact_A_CRD(N, c(2, 2, 1), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(5, 2, 1), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(4, 2, 1), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(3, 2, 1), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(2, 2, 1), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(2, 5, 1), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(2, 1, 3), Hnorm)$Reps, Hnorm)
var_fun(exact_A_CRD(N, c(2, 1, 4), Hnorm)$Reps, Hnorm)
source("Weighted_Fun.R")
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
# weights set using variance lower bounds
weights = 1/opt_exact_n
weights = weights/4
wMatlb = matrix(c(weights[1], seq(2, 100, by = 1), rep(1, 100), rep(weights[3], 100)), nrow = 100, ncol = 3)
weights
wMatlb
wMatlb
weights = 1/opt_exact_n
weights
wMatlb
unscaled_weights = matrix(c(q, 1, 1)/(q + 2), nrow = length(q), ncol = 3, byrow = TRUE)
q
q = 1:100
unscaled_weights = matrix(c(q, 1, 1)/(q + 2), nrow = length(q), ncol = 3, byrow = TRUE)
c(q, 1, 1)/(q + 2)
c(q, 1, 1)
unscaled_weights = matrix(c(q, rep(1, 2*length(q)))/(q + 2), nrow = length(q), ncol = 3, byrow = TRUE)
unscaled_weights
unscaled_weights = matrix(c(q, rep(1, length(q)), rep(1, length(q)))/(q + 2), nrow = length(q), ncol = 3, byrow = TRUE)
unscaled_weights
unscaled_weights = matrix(c((q, rep(1, length(q)), rep(1, length(q)))/(q + 2)), nrow = length(q), ncol = 3, byrow = TRUE)
c(q, rep(1, length(q)), rep(1, length(q))/(q + 2))
q/(q + 2)
3/5
rep(1, length(q))
c(q, rep(1, length(q)), rep(1, length(q)))/(q + 2)
unscaled_weights = matrix(c(q, rep(1, length(q)), rep(1, length(q)))/(q + 2), nrow = length(q), ncol = 3)
unscaled_weights
rowSums(unscaled_weights)
opt_exact_n
unscaled_weights/opt_exact_n
unscaled_weights
opt_exact_n
matrix(rep(1, 300), nrow = 100, ncol = 3)
matrix(rep(1, 300), nrow = 100, ncol = 3)/opt_exact_n
apply(matrix(rep(1, 300), nrow = 100, ncol = 3), 1, function(x)/opt_exact_n)
apply(matrix(rep(1, 300), nrow = 100, ncol = 3), 1, function(x) x/opt_exact_n)
weights = apply(unscaled_weights, 1, function(x) x/opt_exact_n)
weights
weights[2, 1]
weights.1 = weights/weights[2, 1]
weights.1
weights.1[1]
wMatlb = matrix(c(weights.1[1, ], weights.1[2, ], weights.1[3, ]), nrow = 100, ncol = 3)
var_ratiolb = t(apply(wMatlb, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)))
var_ratiolb
Tab = cbind(wMatlb[, 1], var_ratiolb)
Tab
Tab = cbind(wMatlb[1 , ], var_ratiolb)
wMatlb
Tab = cbind(wMatlb[ , 1], var_ratiolb)
Tab
wMatlb = matrix(c(weights[1, ], weights[2, ], weights[3, ]), nrow = 100, ncol = 3)
wMatlb
weights
weights = t(apply(unscaled_weights, 1, function(x) x/opt_exact_n))
weights - wMatlb
q = 1:100
unscaled_weights = matrix(c(q, rep(1, length(q)), rep(1, length(q)))/(q + 2), nrow = length(q), ncol = 3)
weights = t(apply(unscaled_weights, 1, function(x) x/opt_exact_n))
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(weights, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)))
# produces results for Table 1
Tab = cbind(weights[ , 1], var_ratiolb)
Tab
unscaled_weights
t(apply(unscaled_weights, 1, function(x) x*c(1, 100, 100)))
t(apply(unscaled_weights, 1, function(x) x*c(1, 59, 59)))
opt_exact_n
weights = t(apply(unscaled_weights, 1, function(x) x/opt_exact_n))
weights
opt_exact_n
1/7
opt_exact_n*2
1/3/(0.1428571 0.2500000 0.1428571)
(1/3)/c(0.1428571 0.2500000 0.1428571)
1/3
0.33333333333/c(0.1428571 0.2500000 0.1428571)
0.33333333333/0.1428571
(1/3)/0.2500000
weights
weights
?Apply
?PPLY
?apply
#### Paper: “On the Role of Minimum Variances in Weighted Optimal Designs”
### This code generates examples from paper section 3
# Read in functions
source("Weighted_Fun.R")
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
# weights set using variance lower bounds
### unscaled weights
# s.t. sum weights = 1
q = 1:100
# scale weights so that they sum to 1
unscaled_weights = matrix(c(q, rep(1, length(q)), rep(1, length(q)))/(q + 2), nrow = length(q), ncol = 3)
# divide by minimum possible variance
weights = t(apply(unscaled_weights, 1, function(x) x/opt_exact_n))
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(weights, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)))
# produces results for Table 1
Tab = cbind(weights[ , 1], var_ratiolb)
Tab
var_ratiolb = t(apply(weights, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
# produces results for Table 1
Tab = cbind(weights[ , 1], var_ratiolb)
Tab
unscaled_weights
Tab
Tab = cbind(weights[ , 1], unscaled_weights[, 1], var_ratiolb)
Tab
#### Paper: “On the Role of Minimum Variances in Weighted Optimal Designs”
### This code generates examples from paper section 3
# Read in functions
source("Weighted_Fun.R")
## Completely Randomized Design (CRD)
testH = matrix(c(1, -1,  0,  0,
1,  1, -1,  -1,
0,  0,  1, -1),
nrow = 3, ncol = 4, byrow = T)
N = 16
# Normalize H
Hnorm = t(apply(testH, 1, function(x) x/c(sqrt(t(x) %*% x))))
# Rank-restricted c-optimal variance lower bound
opt_exact_n   = c(apply(Hnorm, 1, function(x) sum((x^2)/ approx_c_CRD(N, x)) )) # Exact Design
# weights set using variance lower bounds
### unscaled weights
# s.t. sum weights = 1
q = 1:100
# scale weights so that they sum to 1 (w)
unscaled_weights = matrix(c(q, rep(1, length(q)), rep(1, length(q)))/(q + 2), nrow = length(q), ncol = 3)
# divide by minimum possible variance (w*)
weights = t(apply(unscaled_weights, 1, function(x) x/opt_exact_n))
# Exact design ratio of weighted variance to optimal variance
var_ratiolb = t(apply(weights, 1, function(x) var_fun(exact_A_CRD(N, x, Hnorm)$Reps, Hnorm)/opt_exact_n))
# produces results for Table 1
Tab = cbind(q, var_ratiolb)
Tab
(1/3) / (1/7)
VARIBD <- read.csv("ibd_df.csv", header = TRUE)[, 3:21]
minMatME <- matrix(ncol = 2, nrow = 50)
1 - .0001*4
q = 1:50
a = q*0.9996/(5*q + 10)
b = 0.9996/(5*q + 10)
a
b
### Code for paper "On the Role of Minimum Variances in the Construction and Evaluation of Weighted Optimal Designs"
### Purpose is to read in .csv files produced by .jsl simulations
# in order to produce rho values from weighted A-optimal designs in
# paper Sections 4.1 and 4.2
# code runs in seconds, nothing needs to be changed, except
# file path to idb_df.csv, quad_df.csv, and quad_dfDN.csv may need updating
#### Section 4.1, IBD Example------------
# Read in data
VARIBD <- read.csv("ibd_df.csv", header = TRUE)[, 3:21]
minMatME <- matrix(ncol = 2, nrow = 50)
# Check which design across those generated
# Leads to minimum A_W value across weights
q = 1:50
meIBDwtM = q*0.9996/(5*q + 10)
fiIBDwtM = 0.9996/(5*q + 10)
### Find min for emphasis on main effects
for(i in 1:50) {
w      = c(0, meIBDwtM[i], meIBDwtM[i], meIBDwtM[i], meIBDwtM[i], meIBDwtM[i],
0, 0, 0, fiIBDwtM[i], fiIBDwtM[i], fiIBDwtM[i], fiIBDwtM[i], fiIBDwtM[i],
fiIBDwtM[i], fiIBDwtM[i], fiIBDwtM[i], fiIBDwtM[i], fiIBDwtM[i])
A      = apply(VARIBD, 1, function(x) sum(w*x^2))
minMatME[i, ] = (c(i, which(A == min(A))[1]))
}
minMatI <- matrix(ncol = 2, nrow = 50)
meIBDwtF = 0.9996/(5 + 10*q)
fiIBDwtF = q*0.9996/(5 + 10*q)
# Find min for emphasis on two-factor interaction effects
for(i in 2:50) {
w      = c(0, meIBDwtF[i], meIBDwtF[i], meIBDwtF[i], meIBDwtF[i], meIBDwtF[i],
0, 0, 0, fiIBDwtF[i], fiIBDwtF[i], fiIBDwtF[i], fiIBDwtF[i], fiIBDwtF[i],
fiIBDwtF[i], fiIBDwtF[i], fiIBDwtF[i], fiIBDwtF[i], fiIBDwtF[i])
A      = apply(VARIBD[c(51:99),], 1, function(x) sum(w*x^2))
minMatI[i, ] = (c(i+49, (which(A == min(A))[1] + 50)))
}
VARIBD_MIN <- VARIBD[c(minMatME[ , 2], minMatI[ , 2]), c(2:6, 10:19)]
# Calculate min/mean/max rho values
# for main effects
VARIBD_MIN[, 16] <- apply(VARIBD_MIN[1:5], 1, function(x) min(x^2/0.04166667))
VARIBD_MIN[, 17] <- apply(VARIBD_MIN[1:5], 1, function(x) mean(x^2/0.04166667))
VARIBD_MIN[, 18] <- apply(VARIBD_MIN[1:5], 1, function(x) max(x^2/0.04166667))
## Two-factor interaction effects
VARIBD_MIN[, 19] <- apply(VARIBD_MIN[6:15], 1, function(x) min(x^2/0.04166667))
VARIBD_MIN[, 20] <- apply(VARIBD_MIN[6:15], 1, function(x) mean(x^2/0.04166667))
VARIBD_MIN[, 21] <- apply(VARIBD_MIN[6:15], 1, function(x) max(x^2/0.04166667))
## Round all to 2 decimal places
VARIBD_MIN <- round(VARIBD_MIN, 2)
colnames(VARIBD_MIN) <- c(colnames(VARIBD_MIN[, 1:15]), "min ME rho", "mean ME rho","max ME rho",
"min I rho", "mean I rho", "max I rho")
# Write .csv file
write.csv(VARIBD_MIN, file = "ibd_dfres.csv")
# Read in data
<- read.csv("ibd_df.csv", header = TRUE)[, 3:21]
VARIBD
View(VARIBD)
VARDN <- read.csv("quad_dfDN.csv", header = TRUE)[, 3:12]
a = q*0.9999/(3*q + 6)
b = 0.9999/(3*q + 6)
aME = a/0.09
b2fi = b/0.10
bquad = b/0.33
a = q*0.9999/(3*q + 6)
b = 0.9999/(3*q + 6)
aME = a/0.09
b2fi = b/0.10
bquad = b/0.33
q = 1:50
a = q*0.9999/(3*q + 6)
b = 0.9999/(3*q + 6)
aME = a/0.09
b2fi = b/0.10
bquad = b/0.33
VARDN <- read.csv("quad_dfDN.csv", header = TRUE)[, 3:12]
minMat <- matrix(ncol = 2, nrow = 50)
# Check which design is minimum for each weight
for(i in 1:50) {
w      = c(0, aME[i], aME[i], aME[i], b2fi[i], b2fi[i], b2fi[i],
bquad[i], bquad[i], bquad[i])
A      = apply(VARDN, 1, function(x) sum(w*x^2))
print(which(A == min(A)))
minMat[i, ] = (c(i, which(A == min(A))[1]))
}
VARDN_MIN <- VARDN[c(minMat[ , 2]), 2:10]
# calculate min/mean/max rho values
# Main effects
VARDN_MIN[, 10] <- apply(VARDN_MIN[1:3], 1, function(x) min(x^2/0.09))
VARDN_MIN[, 11] <- apply(VARDN_MIN[1:3], 1, function(x) mean(x^2/0.09))
VARDN_MIN[, 12] <- apply(VARDN_MIN[1:3], 1, function(x) max(x^2/0.09))
## Two-factor interaction effects
VARDN_MIN[, 13] <- apply(VARDN_MIN[4:6], 1, function(x) min(x^2/0.1))
VARDN_MIN[, 14] <- apply(VARDN_MIN[4:6], 1, function(x) mean(x^2/0.1))
VARDN_MIN[, 15] <- apply(VARDN_MIN[4:6], 1, function(x) max(x^2/0.1))
## Quadratic effects
VARDN_MIN[, 16] <- apply(VARDN_MIN[7:9], 1, function(x) min(x^2/0.33))
VARDN_MIN[, 17] <- apply(VARDN_MIN[7:9], 1, function(x) mean(x^2/0.33))
VARDN_MIN[, 18] <- apply(VARDN_MIN[7:9], 1, function(x) max(x^2/0.33))
## Round all to 2 decimal places
VARDN_MIN <- round(VARDN_MIN, 2)
colnames(VARDN_MIN) <- c(colnames(VARDN_MIN[, 1:9]), "min ME rho", "mean ME rho","max ME rho",
"min I rho", "mean I rho", "max I rho",
"min Q rho", "mean Q rho", "max Q rho")
# Write .csv file
write.csv(VARDN_MIN, file = "quad_DNres.csv")
VARC <- read.csv("quad_df.csv", header = TRUE)[, 3:12]
minMat <- matrix(ncol = 2, nrow = 50)
q = 1:50
a = q*0.9999/(3*q + 6)
b = 0.9999/(3*q + 6)
aME = a/0.09
b2fi = b/0.10
bquad = b/0.33
# Check which design is min
for(i in 1:50) {
w      = c(0, aME[i], aME[i], aME[i], b2fi[i], b2fi[i], b2fi[i],
bquad[i], bquad[i], bquad[i])
A      = apply(VARC, 1, function(x) sum(w*x^2))
print( which(A == min(A)))
minMat[i, ] = (c(i, which(A == min(A))[1]))
}
VARC_MIN <- VARC[c(minMat[ , 2]), 2:10]
# Calculate min/mean/max rho values
# Main effects
VARC_MIN[, 10] <- apply(VARC_MIN[1:3], 1, function(x) min(x^2/0.09))
VARC_MIN[, 11] <- apply(VARC_MIN[1:3], 1, function(x) mean(x^2/0.09))
VARC_MIN[, 12] <- apply(VARC_MIN[1:3], 1, function(x) max(x^2/0.09))
## Two-factor interaction effects
VARC_MIN[, 13] <- apply(VARC_MIN[4:6], 1, function(x) min(x^2/0.1))
VARC_MIN[, 14] <- apply(VARC_MIN[4:6], 1, function(x) mean(x^2/0.1))
VARC_MIN[, 15] <- apply(VARC_MIN[4:6], 1, function(x) max(x^2/0.1))
## Quadratic effects
VARC_MIN[, 16] <- apply(VARC_MIN[7:9], 1, function(x) min(x^2/0.33))
VARC_MIN[, 17] <- apply(VARC_MIN[7:9], 1, function(x) mean(x^2/0.33))
VARC_MIN[, 18] <- apply(VARC_MIN[7:9], 1, function(x) max(x^2/0.33))
## Round all to 2 decimal places
VARC_MIN <- round(VARC_MIN, 2)
colnames(VARC_MIN) <- c(colnames(VARC_MIN[, 1:9]), "min ME rho", "mean ME rho","max ME rho",
"min I rho", "mean I rho", "max I rho",
"min Q rho", "mean Q rho", "max Q rho")
# write .csv file
write.csv(VARC_MIN, file = "quad_Cres.csv")
