R code for chapter 4
Quicklinks for Chapter 4
Section 4.2
We start by computing the cumulative hazards using the mvna package. First step: Creation of a matrix of logical values indicating the possible transition types.  |  		
  |  		
| We have to do a slight modification of the data set to comply with the mvna function. | 
  |  		
| First load the library. Then, you can compute the cumulative hazards. | 
  |  		
| Figure 4.2 | 
  |  		
Subsection: Survival function
| Estimation of P(T > t) using the survfit function of the survival package. | 
  |  		
| Figure 4.3 | 
  |  		
Subsection: Estimating the survival function from a multistate perspective
| Estimation of the survival function using etm. and creation of a matrix with logical components defining the possible transitions. | 
  |  		
| Transformation of the data. New event indicator to takes 1 if an event (of any type), "cens" otherwise. | 
  |  		
| Call to etm(). | 
  |  		
| You can now check the results and compare them to Figure 4.3. | 
  |  		
Subsection: Cumulative incidence functions
| Estimation of the CIFs using the cuminc function in the cmprsk package. | 
  |  		
| Figure 4.4 | 
  |  		
Subsection: Estimating the cumulative incidence functions from a multistate perspective
| Estimation of the CIFs using etm. | 
  |  		
| Estimates at t1 | 
  |  		
Subsection: Left-truncation
| We add left-truncation (Gamma distributed) to the simulated data set. | 
  |  		
| The entry times will be defined as the left-truncation times lt.times. People for whom entry > exit will not be included (formally, they are never oberved in the 'study'). | 
  |  		
| Next, we estimate the cumulative hazards. | 
  |  		
| Figure 4.5 | 
  |  		
| Figure 4.6 | 
  |  		
| Estimation of the survival function using survfit: | 
  |  		
| and using etm. | 
  |  		
Section 4.3
| First, load the data. | 
  |  		
Cause-specific hazards We transform sir.adm into a multistate-type data set.  |  		
  |  		
Estimation of the cumulative CSH, stratified pneumonia status on admission:  |  		
  |  		
| Figure 4.7 | 
  |  		
| Plot for "no pneumonia": | 
  |  		
| Plot for those having pneumomia: | 
  |  		
| Display the 2 plots together. | 
  |  		
Cumulative incidence functions Estimation of the cumulative incidence function using the cuminc function.  |  		
  |  		
| Using etm, stratified on pneumomia status. | 
  |  		
| Figure 4.9 | 
  |  		
| Figure 4.10 | 
  |  		
Section 4.4
| Load the data. | 
  |  		
| Figure 4.11 | 
  |  		
CIFs First, you have to modify the data set.  |  		
  |  		
| Matrix of logicals defining the possible transitions. | 
  |  		
| Call to etm for computing the CIFs, stratified on treatment. | 
  |  		
| Figure 4.12 | 
  |  		

