ComeçarComece de graça

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.

Este exercício faz parte do curso

Machine Learning for Marketing Analytics in R

Ver curso

Instruções do exercício

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

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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)
Editar e executar o código