CommencerCommencer gratuitement

Cox Proportional Hazard Model

Now you are going to compute a Cox Proportional Hazard model on the online shop data. Your data stored in dataNextOrder now contains four additional variables: the shoppingCartValue of the first order in dollars, whether the customer used a voucher, whether the order was returned, and the gender.

The rms package is already loaded in the workspace.

Cet exercice fait partie du cours

Machine Learning for Marketing Analytics in R

Afficher le cours

Instructions

  • Compute the Cox PH model using cph(). Include the variables shoppingCartValue, voucher, returned and gender as predictors. Pay attention to specify the formula correctly. Store the result in an object called fitCPH. And, of course, print the results.
  • Take the exponential of the coefficients to interpret them. With respect to interpretation, take into account that shoppingCartValue is a continuous variable, whereas the remaining variables are categorical.
  • Plot the result summary.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Determine distributions of predictor variables
dd <- datadist(dataNextOrder)
options(datadist = "dd")

# Compute Cox PH Model and print results
___ <- ___(Surv(daysSinceFirstPurch, boughtAgain) ___ shoppingCartValue ___ voucher ___ returned ___ gender,
              data = ___,
              x = TRUE, y = TRUE, surv = TRUE)
print(___)

# Interpret coefficients
___(fitCPH$___)

# Plot result summary
___(___(fitCPH), log = TRUE)
Modifier et exécuter le code