[R] having problems with constrOptim
Tolga Uzuner
tolga at coubros.com
Sun Apr 10 00:59:32 CEST 2005
subtle... thanks, that works, appreciate it
Ingmar Visser wrote:
> ui %*% theta - ci has to be larger than zero, and it is not:
>
>
>
>>ui=rbind(diag(5),-diag(5))
>>ui
>>
>>
> [,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
>
>
>>ci=c(0,0,0,-1,0,1,1,1,1,1)
>>ci
>>
>>
> [1] 0 0 0 -1 0 1 1 1 1 1
>
>
>>x=c(0.400 ,0.200, 0.200,-0.050 ,0.002)
>>theta=x
>>ui %*% theta - ci
>>
>>
> [,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
>
>
>>ci
>>
>>
> [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:
>
>
>
>>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
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>
>>
>
>
>
More information about the R-help
mailing list