[R] (no subject)

Paul Smith phhs80 at gmail.com
Sat Jul 24 23:21:21 CEST 2010


2010/7/23 w 霍 <hw_joyce_cn at hotmail.com>:
> I use the constrOptim to maximize a function with four constriants but the answer does not leave from the starting value and there is only one outer iteration. The function is defined as follows:
> tm<-function(p){
> p1<-p[1]; p2<-p[2]; p3<-p[3];
> p4<-1-p1-p2-p3;
> p1*p2*p3*p4}
>
> ##the constraints are p1>=0; p2>=0; p3>=0 and p4>=0 i.e. p1+p2+p3<=1
> start<-c(0.9999991,0.0000001,0.0000001)
> dev<-rbind(diag(3),-diag(3),rep(-1,3))
> bvec<-c(rep(0,3),rep(-1,4))
> constrOptim(start,tm,NULL,ui=dev,ci=bvec,control=list(maxit=10000))
>
> Am i missing something obviously that cause the problem or there is some bugs in constrOptim. Could you please help me out

Wenwen,

I believe that the reason why constrOptim behaves as described is
related to the fact that

(p1, p2, p3) = (1,0,0)

is a stationary point and you use it as a starting point. Try a
different starting point.

If the objective is to maximize, then you should use the following command:

constrOptim(start,tm,NULL,ui=dev,ci=bvec,control=list(maxit=10000,fnscale=-1))

(Notice fnscale=-1.)

Finally, whenever you ask something on this list, please use a
meaningful title for your message, as it will dramatically increase
the chances of you getting an answer.

Good luck,

Paul



More information about the R-help mailing list