# NOT RUN {
## This example uses aceglm to find a Bayesian D-optimal design for a
## first order logistic regression model with 6 runs 4 factors. The priors are
## those used by Overstall & Woods (2017), with each of the five
## parameters having a uniform prior. The design space for each coordinate is [-1, 1].
set.seed(1)
## Set seed for reproducibility.
n<-6
## Specify the sample size (number of runs).
start.d<-matrix(2 * randomLHS(n = n,k = 4) - 1,nrow = n,ncol = 4,
dimnames = list(as.character(1:n), c("x1", "x2", "x3", "x4")))
## Generate an initial design of appropriate dimension. The initial design is a
## Latin hypercube sample.
low<-c(-3, 4, 5, -6, -2.5)
upp<-c(3, 10, 11, 0, 3.5)
## Lower and upper limits of the uniform prior distributions.
prior<-function(B){
t(t(6*matrix(runif(n = 5 * B),ncol = 5)) + low)}
## Create a function which specifies the prior. This function will return a
## B by 5 matrix where each row gives a value generated from the prior
## distribution for the model parameters.
example1<-aceglm(formula=~x1+x2+x3+x4, start.d = start.d, family = binomial,
prior = prior, method = "MC", N1 = 1, N2 = 0, B = c(1000, 1000))
## Call the aceglm function which implements the ACE algorithm requesting
## only one iteration of Phase I and zero iterations of Phase II. The Monte
## Carlo sample size for the comparison procedure (B[1]) is set to 100.
example1
## Print out a short summary.
#Generalised Linear Model
#Criterion = Bayesian D-optimality
#Formula: ~x1 + x2 + x3 + x4
#
#Family: binomial
#Link function: logit
#
#Method: MC
#
#B: 1000 1000
#
#Number of runs = 6
#
#Number of factors = 4
#
#Number of Phase I iterations = 1
#
#Number of Phase II iterations = 0
#
#Computer time = 00:00:01
example1$phase2.d
## Look at the final design.
# x1 x2 x3 x4
#1 -0.4735783 0.12870470 -0.75064318 1.0000000
#2 -0.7546841 0.78864527 0.58689270 0.2946728
#3 -0.7463834 0.33548985 -0.93497463 -0.9573198
#4 0.4446617 -0.29735212 0.74040030 0.2182800
#5 0.8459424 -0.41734194 -0.07235575 -0.4823212
#6 0.6731941 0.05742842 1.00000000 -0.1742566
prior2 <- list(support = rbind(low, upp))
## A list specifying the parameters of the uniform prior distribution
example2<-aceglm(formula = ~ x1 +x2 + x3 + x4, start.d = start.d, family = binomial,
prior = prior2, N1 = 1, N2 = 0)
## Call the aceglm function with the default method of "quadrature"
example2$phase2.d
## Final design
# x1 x2 x3 x4
#1 -0.4647271 0.07880018 -0.94648750 1.0000000
#2 -0.7102715 0.79827332 0.59848578 0.5564422
#3 -0.7645090 0.39778176 -0.74342036 -1.0000000
#4 0.4514632 -0.33687477 0.55066110 0.3994593
#5 0.7913559 -0.41856994 0.01321035 -0.8848135
#6 0.6337306 0.11578522 1.00000000 1.0000000
mean(example1$utility(d = example1$phase2.d, B = 20000))
#[1] -11.61105
mean(example2$utility(d = example2$phase2.d, B = 20000))
#[1] -11.19737
## Compare the two designs using the Monte Carlo approximation
# }
Run the code above in your browser using DataLab