[R] MAXIMIZATION WITH CONSTRAINTS

miri.dago at virgilio.it miri.dago at virgilio.it
Fri Dec 8 12:56:42 CET 2006


Dear R users, 
I’m a graduate students and in my master thesis I  must 
obtain the values of the parameters x_i which maximize this  
Multinomial log–likelihood function
log(n!)-sum_{i=1]^4 log(n_i!)+sum_
{i=1}^4 n_i log(x_i)

under the following constraints:
a) sum_i x_i=1, 
x_i>=0, 
b) x_1<=x_2+x_3+x_4
c)x_2<=x_3+x_4
I have been using the 
“ConstrOptim” R-function with the instructions I report below, and I 
have tried to implement them with different values of “n”. BUT I have 
encountered 2 problems:

1) the result of the maximization is the same 
of the minimization, i.e. the maximum value of the   function is equal 
to the minimum (TOO OFTEN)
2) a lot of times the algorithm returns 
errors such as “value out of range in 'gammafn'” 

In both cases 1) 2) 
I don’t know where is the problem, which is my mistake. Can you help 
me?! Do you know another way to solve my problem of maximization under 
constraints? 
THANKS!

My R instructions

n=c(10,20,3,5)
n1=n[1]
n2=n
[2]
n3=n[3]
n4=n[4]

logfr=function(x) { ##function to maximize 
x1= x
[1] 
x2= x[2] 
x3= x[3]
x4= x[4]
log(factorial(sum(n)))-sum(log
(factorial(n)))+sum(n*log(x)) 
} 
grr.log <- function(x) { ## Gradient 
of 'log fr'
x1=x[1] 
x2=x[2] 
x3=x[3]
x4=x[4]
return(n/x)
} 
par.start= 
c(.19999999,.15,.4,.25)
constr.coeff = rbind(diag(1,4,4),c(-1,1,1,1),c
(0,-1,1,1),c(-1,-1,-1,-1), c(1,1,1,1))
constr.tn= c(0,0,0,0,0,0,-1,.
9999999)
min= constrOptim(par.start, logfr, grr.log, ui=constr.coeff, 
ci=constr.tn)
max=constrOptim(par.start, logfr, grr.log, ui=constr.
coeff, ci=constr.tn, control=list(fnscale=-1))




More information about the R-help mailing list