title: Integrating a Kaplan-Meier estimator in R
body: <p>I write the following code to calculate the Kaplan-Meier estimator in R. </p>
  
  <pre><code>library(survival) 
  data(veteran)
  attach(veteran)
  
  library(Rfast)
  
  KM &lt;- function(u){
  t &lt;- sort_unique(u)
  Y &lt;- sapply(t, function(x) sum(u&gt;=x))
  d &lt;- sapply(t, function(x) sum(u==x &amp; status == 1))
  cumprod(1-d/Y)
  }
  
  KM(time) # Kaplan-Meier estimates value
  </code></pre>
  
  <p>But, I am getting the wrong results while I run the following code for estimating the integral <a href="https://i.stack.imgur.com/Qqips.png" rel="nofollow noreferrer">1</a></p>
  
  <p><code>integrate(Vectorize(KM),10,999)</code></p>
  
  <p>It would be a great help if somebody can help me writing an R code for estimating the integral <a href="https://i.stack.imgur.com/Qqips.png" rel="nofollow noreferrer">1</a> in R.</p>