Skip to content

having problems with constrOptim

5 messages · Ingmar Visser, Tolga Uzuner

#
Hi,

Am having problems specifying lower and upper constraints in constrOptim...

I have a function(x)->f which takes a 5 vector array
the constraints on the elements of x are:
x[1],x[2],x[3],x[5]>0
x[4]>-1
x[1],x[2],x[3],x[4],x[5]<1

this works:
############
 > x
[1]  0.400  0.200  0.200 -0.050  0.002
 > optim(x,f)
$par
[1] 0.28630079 0.13583616 0.18752379 0.02231329 0.08640233

$value
[1] 0.0004999157

$counts
function gradient
     230       NA

$convergence
[1] 0

$message
NULL
###########
but when I try to specify the constraints, I get this:
###########
 > 
constrOptim(x,f,grad=NULL,ui=rbind(diag(5),-diag(5)),ci=c(0,0,0,-1,0,1,1,1,1,1))
Error in constrOptim(x, f, grad = NULL, ui = rbind(diag(5), -diag(5)),  :
        initial value not feasible
 >
###########
What am I doing wrong ? As above, x=c(0.400 ,0.200, 0.200,-0.050 ,0.002)

Many thanks,
Tolga
#
ui %*% theta - ci has to be larger than zero, and it is not:
[,1] [,2] [,3] [,4] [,5]
 [1,]    1    0    0    0    0
 [2,]    0    1    0    0    0
 [3,]    0    0    1    0    0
 [4,]    0    0    0    1    0
 [5,]    0    0    0    0    1
 [6,]   -1    0    0    0    0
 [7,]    0   -1    0    0    0
 [8,]    0    0   -1    0    0
 [9,]    0    0    0   -1    0
[10,]    0    0    0    0   -1
[1]  0  0  0 -1  0  1  1  1  1  1
[,1]
 [1,]  0.400
 [2,]  0.200
 [3,]  0.200
 [4,]  0.950
 [5,]  0.002
 [6,] -1.400
 [7,] -1.200
 [8,] -1.200
 [9,] -0.950
[10,] -1.002

try
[1]  0  0  0 -1  0 -1 -1 -1 -1 -1

hth, ingmar
On 4/9/05 12:29 PM, "Tolga Uzuner" <tolga at coubros.com> wrote:

            

  
    
#
subtle... thanks, that works, appreciate it
Ingmar Visser wrote:

            
#
Hi,

Is the beta distribution implemented in terms of it's mean and standard 
deviation, as opposed to alpha and beta, in any R package ?

Thanks
Tolga
#
Tolga Uzuner wrote:

            
Hmm... answering my own question... guess there is no bijection between 
{alpha,beta} and {mean,variance} which is why... ocurred to me after I 
sent the question, unless someone disagrees.