整合与"条件有长度> 1"

时间:2016-11-26 08:50:45

标签: r if-statement continuous-integration quantile

在我的计算中,我需要整合分位数函数以实现罕见的解除。我确定了自己的分位数函数:

Value_at_Risk <- function(alpha_VaR){
  test <- 0
  for(i in 0:n){
    test <- test + dbinom(i,n,0.1)  ### i tried it out for binom, but my density is different
    if(test >= alpha_VaR){
      break
    }
  }
  return(as.numeric(i))
}

integrate(Value_at_Risk,0.5,0.9)
Error in integrate(Value_at_Risk, 0.5, 0.9) : 
  evaluation of function gave a result of wrong length
In addition: Warning messages:
1: In if (test >= alpha_VaR) { :
  the condition has length > 1 and only the first element will be used

如果我理解正确,那么因为integrate我的alpha_VaR不再是长度为1的数字向量。有办法解决吗?

0 个答案:

没有答案