LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Machine Learning for Marketing Analytics in R

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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)
Code bearbeiten und ausführen