TABLE OF CONTENTS
initialization/makeas [ Functions ]
NAME
makeas --- construct discretization
FUNCTION
Split the range of event times into intervals, during which the baseline hazard is assumed constant.
SYNOPSIS
414 makeas <- function(agdata, K, alternating = FALSE)
INPUTS
agdata a data frame in Anderson-Gill format K vector the number of breakpoints for each stratum alternating boolean indicating episodic data
OUTPUTS
as matrix of size max(r) x max(K)+1 containing discretization breakpoints for each stratum
SOURCE
417 { 418 # get number of strata 419 rmax <- max(agdata$r) 420 421 # extract the portion of agdata containing events 422 agdatatemp <- agdata[agdata$delta == 1 | 423 c(diff(agdata$i * 1000 + agdata$j) != 0, TRUE), ] 424 if(!alternating) { 425 agdatatemp$start[ - 1] <- agdatatemp$stop[ - length(agdatatemp$stop)] 426 agdatatemp$start[c(1, diff(agdatatemp$i * 1000 + agdatatemp$j)) != 0] <- 0 427 } 428 429 # Initialize matrices. 430 as <- matrix(0, rmax, max(K) + 1) 431 for(r in 1:rmax){ 432 # Extract the set of event times and death times for each stratum 433 eventtimes <- c(0, sort(unique((agdatatemp$stop - 434 agdatatemp$start)[agdatatemp$r == r & agdatatemp$delta == 1]))) 435 maxtime <- max((agdatatemp$stop - agdatatemp$start)[agdatatemp$r == r])+.001 436 # Compute the set of breakpoints as quantiles, and fill in the rest 437 # of the matrix with the maximum value. 438 as[r, 1:(K[r] + 1)] <- quantile(c(eventtimes, maxtime), 439 seq(from = 0, to = 1, length = K[r] + 1)) 440 if(K[r] < max(K)) as[r, (K[r] + 2):max(K + 1)] <- maxtime 441 } 442 return(as) 443 }