0

I'm trying to execute the following code in R

library(nloptr)

m = 0.00060981
m2 = 0.000109362
m4 = 5.21538E-08
m6 = 4.25E-11
f=function(X){  
  Y = matrix(NA, ncol = 1, nrow = 4)
  mu = X[1]
  S2=X[2]
  S2u = X[3]
  lambda= X[4]
  Y[1] = (mu-(S2/2))-m
  Y[2] = (S2+(lambda*S2u))-m2
  Y[3] = ((3*(S2^2) + 6*(lambda^2)*(S2u^2)+3*(S2u^2)*(lambda) + 6*(lambda)*(S2u)*S2))-m4
  Y[4] = (15*(S2^3) +45*(S2^2)*S2u + 45*(lambda^2)*(S2u^2)*S2 +45*(lambda)*(S2u^2)*S2 +15*(lambda^3)*(S2u^3)+45*(lambda^2)*(S2u^3)+15*lambda*(S2u^3))-m6
  return(Y) 
}
g = function(X){
  return(norm(f(X),'f'))
}
initiale=c( 0.00197,0.022,0.0036,0.8999)
hin = function(X){
h=rep(NA,1)
h[2]>0
h[3]>0
h[1]<h[2]

h
}
ans=auglag(par=initiale,fn=g,hin=hin)

But i'm getting this ERROR :

Error in if (sig > 1e+05) control.optim$reltol <- 1e-10 : 
  missing value where TRUE/FALSE needed

Why am I getting this error, and how to fix the code?

6
  • the code you psoted there has not the line sig>1e+05 you mention ...can you please post the full code? May 12, 2015 at 11:36
  • this is the full code i did not use the parameter sig!
    – Meryem
    May 12, 2015 at 11:43
  • You might want to include the required library(nloptr) in your code, if in fact this this the source of the auglag() function, though its documented arguments don't seem to match the call you're making? May 12, 2015 at 11:53
  • Where does auglag come from? What's the purpose of the hin function, that never uses its X argument and does some comparison just for its own sake? Notice that it returns always NA and I suspect that this might be related with your issue.
    – nicola
    May 12, 2015 at 11:54
  • @csgillespie is right. What do you want the hin function to do? For now, it is creating a single NA value.
    – Pierre L
    May 12, 2015 at 12:13

1 Answer 1

2

I suspect the error message is a result of the h function

hin = function(X){
       h=rep(NA,1)
       h[2]>0
       h[3]>0
       h[1]<h[2]
       h
 }

The value of h is always NA and never changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.