Section 9.4 Exploratory Data Analysis
Before we predict if a person defaults or not, it is good to find out more about the default variable, answering some questions like:
-
How many people have defaulted?
-
What percentage of people have defaulted?
-
What are the odds that someone will default?
-
What are the preliminary relationships between default and the other variables?
table(cc_data$default)
No Yes 9677 323
# Proportion of people who default
p <- mean(cc_data$default == "Yes")
p*100
[1] 3.33
odds <- p / (1 - p)
# Below provides us with the default rate
cat("Default rate:", round(p*100,2), "%\n")
Default rate: 3.33 %
# Below provides us with the odds of someone defaulting
cat("Odds of defaulting:", round(odds,4), "\n")
Odds of defaulting: 0.0344
# Below provides us with the odds ratio
cat("Equivalent odds ratio (1 in every", round(1/odds,0), ")\n")
Equivalent odds ratio (1 in every 29 )
# Cross-tab between student status and default
cc_data |> count(default, student) |> arrange(desc(n))
default student n 1 No No 6850 2 No Yes 2817 3 Yes No 206 4 Yes Yes 127
# Quick descriptive stats
library(mosaic)
favstats(income ~ default, data = cc_data)
default min Q1 median Q3 max mean sd n 1 No 771.9677 21405.06 34589.49 43823.76 73554.23 33566.17 13318.25 9667 2 Yes 9663.7882 19027.51 31515.34 43067.33 66466.46 32089.15 13804.22 333 missing 1 0 2 0
favstats(balance ~ default, data = cc_data)
default min Q1 median Q3 max mean sd
1 No 0.0000 465.7146 802.8571 1128.249 2391.008 803.9438 456.4762
2 Yes 652.3971 1511.6110 1789.0934 1988.870 2654.323 1747.8217 341.2668
n missing
1 9667 0
2 333 0
Some things that were uncovered in the code above:
-
The probability of someone defaulting is 0.0333.
-
The percentage of people defaulting is 3.33%.
-
Note: Probabilities are always going to be a number between 0 and 1. This is incredibly important later when we are trying to create our line.
-
1 in every 29 people will default on their credit card. These are the odds, which by definition, compare successes (defaults) to failures (non-defaults).
-
While probabilities are between 0 and 1, odds are between 0 and β.
-
An overwhelming majority of students did not default.
-
The mean income of people who do not default is only slightly higher than people who do.
-
The mean balance of people who do default is more than double the amount than people who donβt.
Overall, most people donβt default on their credit cards, and while we see differences in means, we do not know if the difference is statistically significant or not.
Now that we have some insights, it is time to visualize!
