title: R: conditional expected value
body: <p>Hello everybody (this is my first post in here)!</p>
  
  <p>I'm having a problem with finding the conditional expected value for a given distribution. </p>
  
  <p>Suppose that we need to find E( x | x>0.5 ), where x has gev (generalised extreme value) distribution, with density dgev(x, xi, sigma, mu). What I was trying to do was</p>
  
  <pre><code>library(evir)
  
  func1 &lt;- function(x) {x*dgev(x, xi, sigma, mu)}
  integral &lt;- integrate(func1, lower = 0.5, upper = 10000, subdivisions = 10000)
  cond.exp.val &lt;- as.numeric(integral[1])/(1-q)
  </code></pre>
  
  <p>where q is the value that gives qgev(q, xi, sigma, mu) = 0.5, used for normalisation. </p>
  
  <p>The result greatly depends on the 'upper' parameter of integrate() function and for higher values of this parameter the integral diverges. As my distribution parameters are</p>
  
  <pre><code>xi &lt;- 0.81
  sigma &lt;- 0.0067
  mu &lt;- 0.0072
  </code></pre>
  
  <p>this integration should be feasible and convergent. Do you have any ideas what I am doing wrong or is there any built-in R function that may calculate such conditional expected value?</p>