Get startedGet started for free

Model assumptions

You already had a look at the Cox PH model in the last coding exercise. In this exercise, you are going to find out if your model is appropriate at all. Your model is still stored in the object fitCPH.

This exercise is part of the course

Machine Learning for Marketing Analytics in R

View Course

Exercise instructions

  • Check the proportional hazard assumption of the model fitCPH using cox.zph(). Store the test result in an object called testCPH and print it.
  • The assumption seems to be violated for one variable at the 0.05 alpha level. Which one? Plot the coefficient beta dependent on time for this variable.
  • Validate the model using cross validation in the validate() function from the rms package.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Check proportional hazard assumption and print result
___ <- ___(fitCPH)
___(testCPH)

# Plot time-dependent beta
plot(___, var = "___")

# Load rms package
library(rms)

# Validate model
___(fitCPH, method = "___",
         B = 10, dxy = TRUE, pr = FALSE)
Edit and Run Code