Predicting Whether a Customer Who Receives the Catalog Will
Use the Coupon
Project Objective
To investigate the relationship between customers who receive a catalog and customers who use a coupon at Simmons's apparel stores
Step 1: Install and load required libraries
library(readxl)
library(Hmisc) #allows us to call the correlation function
## Warning: package 'Hmisc' was built under R version 4.3.3
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, units
library(pscl) #allows us to call the pseudo R-square package to evaluate our model
## Warning: package 'pscl' was built under R version 4.3.3
## Classes and Methods for R originally developed in the
## Political Science Computational Laboratory
## Department of Political Science
## Stanford University (2002-2015),
## by and under the direction of Simon Jackman.
## hurdle and zeroinfl functions by Achim Zeileis.
library(pROC) #allows us to run the Area Under Curve (AUC) package to get the plot and AUC score
## Warning: package 'pROC' was built under R version 4.3.3
## Type 'citation("pROC")' for a citation.
##
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
##
## cov, smooth, var
Step 2: Import & clean the data
# Import the Data
Sim_df <- read_excel("Chap 15.9 Simmons.xlsx")
Step 3: Summarize the data
summary(Sim_df)
## Customer Spending Card Coupon
## Min. : 1.00 Min. :1.058 Min. :0.0 Min. :0.0
## 1st Qu.: 25.75 1st Qu.:2.059 1st Qu.:0.0 1st Qu.:0.0
## Median : 50.50 Median :2.805 Median :0.5 Median :0.0
## Mean : 50.50 Mean :3.334 Mean :0.5 Mean :0.4
## 3rd Qu.: 75.25 3rd Qu.:4.468 3rd Qu.:1.0 3rd Qu.:1.0
## Max. :100.00 Max. :7.076 Max. :1.0 Max. :1.0
This gives the descriptive statistics of the data
sapply(Sim_df, sd)
## Customer Spending Card Coupon
## 29.0114920 1.7412979 0.5025189 0.4923660
This gives us the standard deviation using the "sd" function
xtabs(~Coupon + Card, data = Sim_df)
## Card
## Coupon 0 1
## 0 36 24
## 1 14 26
Step 4: Building the model
The "glm" function enables us to call the logistic regression model. The family is binomial as we are dealing with binary outcome variables
Sim_logit <- glm(Coupon ~ Spending + Card, data = Sim_df, family = "binomial")
summary(Sim_logit)
##
## Call:
## glm(formula = Coupon ~ Spending + Card, family = "binomial",
## data = Sim_df)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.1464 0.5772 -3.718 0.000201 ***
## Spending 0.3416 0.1287 2.655 0.007928 **
## Card 1.0987 0.4447 2.471 0.013483 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 134.60 on 99 degrees of freedom
## Residual deviance: 120.97 on 97 degrees of freedom
## AIC: 126.97
##
## Number of Fisher Scoring iterations: 4
Interpretation: They are all significant at alpha = 0.05
Step 5: Interpreting the Logistic Regression Equation using odds
ratios only
exp(coef(Sim_logit))
## (Intercept) Spending Card
## 0.1169074 1.4072585 3.0003587
Interpretation: For every customer that has a "Simmons Credit Card" the odds of the outcome are multipied by about 3.00. Therefore, having a card increases the odds of the outcome by 200% (three times).
For every one unit increase in "Spending", the odds of the outcome occurring are multipllied by approximately 1.4073. For each additional dollar spent, the odds of the outcome increase by 40.73%.
Odds ratios and 95% CI
exp(cbind(OR = coef(Sim_logit), confint(Sim_logit)))
## Waiting for profiling to be done...
## OR 2.5 % 97.5 %
## (Intercept) 0.1169074 0.03492214 0.3420819
## Spending 1.4072585 1.10120789 1.8311893
## Card 3.0003587 1.27732463 7.3760631
Interpretation: The CI for "Spending" does not contain the value of 1, we can conlude that x1 has a significant relationship with the estimated odds ratio. The CI for "Card" does not contain the value of 1, we can conclude that x2 has a significant relationship with the estimated odds ratio.