[R] having problems with constrOptim
Tolga Uzuner
tolga at coubros.com
Sat Apr 9 18:29:55 CEST 2005
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
More information about the R-help
mailing list