R/CalcSurvFromCox.R

Defines functions CalcSurvFromCox

CalcSurvFromCox <- function(fit.cox, Qb, points, hz.times)
{
  n.points <- length(points)
  hz <- fit.cox$hz
  surv.probs <- base<- vector(length = n.points)
  intervals <- sapply(points,FindIntervalCPP, w = t(as.matrix(hz.times)))
  for (i in 1:n.points)
  {
    if (intervals[i]==1)
    {
      base[i] <- hz[1]*points[i]/hz.times[1]
    } else
      if(intervals[i]==length(hz.times)+1) {base[i] <- hz[length(hz.times)]
      } else {
    base[i] <- (hz[intervals[i]-1] +  (hz[intervals[i]]-hz[intervals[i]-1])*(points[i]-hz.times[intervals[i]-1])/
                                                                        (hz.times[intervals[i]]-hz.times[intervals[i]-1]))#Extrapolation
      }
  }
  surv.probs <- exp(-base*exp(Qb))
}

Try the ICcalib package in your browser

Any scripts or data that you put into this service are public.

ICcalib documentation built on Jan. 20, 2018, 9:52 a.m.