# NOT RUN {
###################### Example for three level designs for the
#second order model in two factors with a square design region
X<-matrix(0,nrow=3^2,ncol=5)
ij=0
for (i in -1:1){
for (j in -1:1){
ij=ij+1
X[ij,]<-c(i,j, i^2,j^2, i*j)
}
}
X<-cbind(1,X)
D<-as.matrix(dist(X))
K<-tcrossprod(X)
rownames(K)<-colnames(K)<-rownames(D)<-colnames(D)<-rownames(X)<-paste("x",1:3^2, sep="")
X
library(STPGA)
ListTrain1<-GenAlgForSubsetSelectionNoTest(P=X,ntoselect=4, InitPop=NULL,
npop=100, nelite=5, mutprob=.5, mutintensity = 1,
niterations=200,minitbefstop=20, tabu=F,tabumemsize = 0,plotiters=F,
lambda=1e-9,errorstat="DOPT", mc.cores=1)
ListTrain2<-GenAlgForSubsetSelectionNoTest(P=solve(K+1e-6*diag(ncol(K))),ntoselect=4, InitPop=NULL,
npop=100, nelite=5, mutprob=.5, mutintensity = 1,
niterations=200,minitbefstop=20, tabu=F,tabumemsize = 0,plotiters=F,
lambda=1,errorstat="CDMEANMM", mc.cores=1)
par(mfrow=c(1,2),mar=c(1,1,1,1))
labelling1<-rownames(X)%in%ListTrain1[[1]]+1
plot(X[,2], X[,3], col=labelling1, pch=2*labelling1,cex=2*(labelling1-1),
xlab="", ylab="", main="DOPT", cex.main=.7,xaxt='n',yaxt='n')
for (i in -1:1){
abline(v=i, lty=2)
abline(h=i,lty=2)
}
labelling2<-rownames(X)%in%ListTrain2[[1]]+1
plot(X[,2], X[,3], col=labelling2, pch=2*labelling2,cex=2*(labelling2-1),
xlab="", ylab="", main="CDMEANMM", cex.main=.7,xaxt='n',yaxt='n')
for (i in -1:1){
abline(v=i, lty=2)
abline(h=i,lty=2)
}
########################Dopt design three level designs for the second order
#model in two factors with a square design region
par(mfrow=c(2,2),mar=c(1,1,1,1))
for (ntoselect in c(5,6,7,8)){
ListTrain<-GenAlgForSubsetSelectionNoTest(P=X,ntoselect=ntoselect, InitPop=NULL,
npop=10, nelite=3, mutprob=.5, mutintensity = 1,
niterations=200,minitbefstop=200, tabu=F,tabumemsize = 0,plotiters=F,
lambda=1e-9,errorstat="DOPT", mc.cores=1)
labelling<-rownames(X)%in%ListTrain[[1]]+1
plot(as.numeric(X[,2]), as.numeric(X[,3]), col=labelling, pch=2*labelling,cex=2*(labelling-1),
xlab="", ylab="", main="DOPT", cex.main=.7,xaxt='n',yaxt='n')
for (i in -1:1){
abline(v=i, lty=2)
abline(h=i,lty=2)
}
}
par(mfrow=c(1,1))
# }
Run the code above in your browser using DataLab