R/piecewiseExp_profile_loglik_tau.r

Defines functions piecewiseExp_profile_loglik_tau

Documented in piecewiseExp_profile_loglik_tau

piecewiseExp_profile_loglik_tau <- function(tau, time, event){
  
  # Maximum likelihood function to compute lambdas in piecewise Exponential
  # time-to-event model. see Fang & Su (2011) for details
  
  k <- length(tau)
  tau <- c(0, tau, Inf)
  loglik <- 0
  
  for (j in 2:(k + 2)){
    Xtj <- sum(event[time <= tau[j]])
    Xtj1 <- sum(event[time <= tau[j - 1]])
    diff <- Xtj - Xtj1
    nenner <- sum((pmin(time, tau[j]) - tau[j - 1])[time > tau[j - 1]])
    aj <- diff / nenner
    if (diff != 0){loglik <- loglik + diff * log(aj)}
  }
  
  return(loglik) 
}

Try the eventTrack package in your browser

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

eventTrack documentation built on April 4, 2025, 2:34 a.m.