Dear friends.
I use ConstrOptim( ) and got error message "initial value not available".
My understanding of "initial value not available" is that one of the
following 3 cases happens:

1.The objective function is not well defined at the point of the initial
value.
2. The differentiation of the objective function is not well defined at the
point of the initial value.
3. The initial value violate the constrain of "ui %*% theta - ci >= 0"

But my situation does not belong to any of the above cases.

I have attached my code bellow and could you please help me take a look?

Best Wishes
Yuchen Luo

rm(list = ls())
ui=matrix(c(1,-1,0,0,0,0,0,0,1,-1,0,0,0,0,0,0,1,-1),6,3)
ci=c(0,-0.5,0,-2,0,-0.6)

apple=expression(rr*(1.0-rec)*(1.0-(pnorm(-lambda/2.0+log(((ss+(tot/sh*
1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/lambda)-((ss+(tot/sh*1000.0)*lbar)/(tot/sh*
1000.0)/lbar*exp(lambda*lambda))*pnorm(-lambda/2.0-log(((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/lambda))+(exp(rr*(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*
1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))))*((((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))-sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))+((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))+sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))))))-(((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))-sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))+((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))+sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))))))))/((pnorm(-lambda/2.0+log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/lambda)-((ss+(tot/sh*1000.0)*lbar)/(tot/sh*
1000.0)/lbar*exp(lambda*lambda))*pnorm(-lambda/2.0-log(((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/lambda))-(pnorm(-sqrt((sigmae*ss/(ss+lbar*(tot/sh*
1000.0)))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*mat+lambda*lambda)/2.0+log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/sqrt((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*mat+lambda*lambda))-((ss+(tot/sh*
1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda))*pnorm(-sqrt((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*mat+lambda*lambda)/2.0-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/sqrt((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*mat+lambda*lambda)))*exp(-rr*mat)-(exp(rr*(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*
1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))))*((((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))-sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))+((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))+sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))))))-(((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))-sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))+((ss+(tot/sh*1000.0
)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))))))+sqrt(0.25+2.0*rr/
(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
))))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))))))))))

fit.error=function(rec,lambda,lbar)
{sum((eval(apple)*1000-orange)^2/(orange^2))
}


fit.error.grr=function(rec,lambda, lbar)
{drec=sum(eval(D(apple,'rec'))*(eval(apple)*1000-orange)/(orange^2))
dlambda=sum(eval(D(apple,'lambda'))*(eval(apple)*1000-orange)/(orange^2))
dlbar=sum(eval(D(apple,'lbar'))*(eval(apple)*1000-orange)/(orange^2))
c(drec,dlambda,dlbar)
}


rr=c(4.33,4.22,4.27,4.43,4.43,4.44,4.45,4.65,4.77,4.77)
tot=rep(13319.17,10)
sh=rep(1553656,10)
sigmae=c(0.172239074,0.188209271,0.193703774,0.172659891,0.164427247,
0.24602361,0.173555309,0.186701165,0.193150456)
ss=c(56.49,56.39,56.55,57.49,57.37,55.02,56.02,54.35,54.09)
orange=rep(21.25,10)

constrOptim(c(0.5,0.3,0.5), fit.error, fit.error.grr, ui=ui,ci=ci)

	[[alternative HTML version deleted]]

