Olufemi Bolarinwa
2015-Apr-28 20:51 UTC
[R] optimx: Cannot evaluate function at initial parameters
Hello,I am estimating a system of nonlinear GMM. the following are my objective function, the gradient function and the optimx code for the optimization. ?I actually worked out the gradient and hessian by hand before inputing the code into r. However, I did get the following error message in my optimx routine objective functionobj = function(initial.values,z) {? e1 = y1-(a1*x1 + a2*x2 +a3*x3 + a4*x4 + a5*x5 + a22*(exp(a6*x6 + a7*x7 + a8*x9 + a9*x10 + a10*x11 + a11*x12 + a14*x16)/(1+exp(a6*x6 + a7*x7 + a8*x9 + a9*x10 + a10*x11 + a11*x12 + a14*x16))))?? e2 = y2-(b1*x1 + b2*x2 +b3*x3 + b4*x4 + b5*x5 + b22*(exp(b6*x6 + b7*x7 + b8*x9 + b9*x10 + b10*x11 + b11*x12 + b14*x16)/(1+exp(b6*x6 + b7*x7 + b8*x9 + b9*x10 + b10*x11 + b11*x12 + b14*x16))))? e3 = y3-(exp(c1*x1 + c2*x18 + c3*x19 + c4*x20 + c5*x21 + c6*x14 + c7*x8)/(1 + exp(c1*x1 + c2*x18 + c3*x19 + c4*x20 + c5*x21 + c6*x14 + c7*x8)))? e = rbind(e1,e2,e3)? q = t(e)%x%z%x%w%x%t(z)%x%e? return(q)} gradientgradient = function(initial.values,z) {? df = 2*(t(d)%x%z%x%w%x%t(z)%x%e)? return(df)} hessian = function(initial.values,z) {? h = 2*(t(d)%x%z%x%w%x%t(z)%x%d)? return(h)} nlgmm = optimx(par=initial.values, dat= dta, fn=obj, gr=gradient,hess=hessian, method = c("BFGS","nlmind","nlm"), itnmax=c(500,500,500), control=list(maximize=TRUE))Maximizing -- use negfn and neggrError in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower, ?:?? Cannot evaluate function at initial parameters A way forward will be greatly appreciated. ThanksOlufemi? [[alternative HTML version deleted]]