0

I am attempting this question to calculate the variance using a survival function I have calculated, and this is my approach, however I am not sure why there is an error. Can someone kindly please help me out?

enter image description here

survfunc <- cancer_obs$KM 
B <- 100
N <- 1000

# Replace P(T > t) with the appropriate survival function or probability distribution function for T

integrand1 <- function(t) {survfunc}  
midpoint_rule1 <- function(a, b, n) {
  h <- (b - a) / n
  sum(integrand1(a + h/2 + h * (0:(n-1)))) * h
}

integrand2 <- function(t) {2*t*survfunc}
midpoint_rule2 <- function(a, b, n) {
  h <- (b - a) / n
  sum(integrand2(a + h/2 + h * (0:(n-1)))) * h
}

approx_integral1 <- midpoint_rule1(0, B, N)
approx_integral2 <- midpoint_rule2(0, B, N)

var_estimation <- approx_integral2 - (approx_integral1)^2 
r2evans
  • 141,215
  • 6
  • 77
  • 149
trying
  • 1
  • Can you elaborate more on what's the error? – Abdullah Faqih May 29 '23 at 21:24
  • 3
    trying, please realize we can't help with sample data. This has been asked on your previous questions (*"Since you didn't present any data"* and *"with enough detail"*), please see https://stackoverflow.com/q/5963269 , [mcve], and https://stackoverflow.com/tags/r/info for how to include sample data in a way that we can "just use it" (e.g., `dput` or `data.frame` are very useful). – r2evans May 29 '23 at 22:21

0 Answers0