Survival and hazard rate function estimation using wavelets was covered in Section 4.8 and Appendix C of my book. There were a few small typos, mainly in the code, in the book and these are explained here.
Alternatively, you can download all the necessary (and hopefully correct) code here
Below is a simple example of using the wavelet survival function code
using the kidney data set from the
You can read this code into your R session via:
Here is a some example code. (see below if you don't know how to get packages)
library("logspline") # Useful logspline function estimator library("survival") # Useful survivor function estimator data(kidney) # Data set we want to use library("wavethresh") # For the wavelet's we're going to do. # # Now compute and plot the estimators. # # You can look inside fig.hazplot to see what functions I call here. # fig.hazplot()
Note, in general, this example code does not choose the smoothing parameters automatically (but someone might like to write a simple method to do this, e.g. cross-validation), it should be rewritten to more carefully modify/monitor values of the hazard function that get uncontrollably large (ie commensurately reducing the numerator). A better method would also investigate the use of wavelets smoother than Haar.
I look forward very much to seeing the result of someone who makes these improvements!
I would like to thank various citizens of the countries of Iraq and Iran, and also Yang Xu from the Mississippi State University in the USA, who have helped me improve this code and explanation.
Disclaimer: This is only EXAMPLE code. You cannot run the same code on a different example and expect to get good results. You will need to worry about the selection of the underlying smoothing wavelet and associated smoothing parameters. You will need to worry about whether your survival data set is long enough for the wavelet method here to work efficiently. The code here is intended for future developers of wavelet survival analysis to improve on.
Getting packages. To get the
survival package, you might type:
install.packages("survival")you might have to answer questions about which repository/mirror you want to use, select one and then you should see the package install (then return to the instructions above. You also need to ensure you've got the