samedi 26 novembre 2016

Integration struggeles with "the condition has length > 1"

In my calculations i need to integrate a quantile function for uncommon distirubtion. i definied my own quantile function:

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

If i understand it correctly, then because of integrate my alpha_VaRisn't a numerical vector of a length 1 anymore. Is there a way to fix it?

Aucun commentaire:

Enregistrer un commentaire