简体   繁体   English

R-“缺少需要TRUE / FALSE的值”

[英]R - “ missing value where TRUE/FALSE needed ”

I'm trying to execute the following code in R 我正在尝试在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? 为什么会出现此错误,以及如何修复代码?

I suspect the error message is a result of the h function 我怀疑错误消息是h函数的结果

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. h的值始终NA并且从不改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM