Hello Everyone,
I am a MS students in the Department of Statistics, Biostatistics &
Informatics, in University of Dhaka, Bangladesh. Recently, I am doing thesis on
"D-optimal Designs for Regression models in Biostatistics". In my
thesis work, I am having problem with a particular program where I need to
replace each element of a vector one by one by every element of another seq
(which is of higher length than that of the vector), and then calculated a
quantity from each of the resulting vector and compare them. I have written the
following program, but I think it is not running correctly, Can anyone please
correct this Please!
dopt<-function(beta)
{
set.covar<-seq(-1,1,0.001)
n<-length(set.covar)
xi<-sample(set.covar,5)
## start of information loop
infor<-function(xi)
{
mu<-exp(t(xi)*beta)/(1+exp(t(xi)*beta))
mui<-mu%*%t(1-mu)
xmui<-mui%*%t(xi)
info<-xmui%*%xi
}
## end of information loop
info<-infor(xi)
##start of loop to replace every element of x (i loop)
for(i in 1:5)
{
## start of a loop to replace each element of xi with every element of
set.covar (j loop)
for(j in 1:n)
{
x<-xi
xi<-replace(x,i,set.covar[j])
infoi<-infor(xi)
info<-ifelse(infoi>info,c(infoi,return(xi)),c(info,return(x)))
} ## end of j loop
} ## end of i loop
} ## end of mainloop (dopt)
Please help me with the loop.
With best regards,
Farzana.
[[alternative HTML version deleted]]